-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// Copyright (c) 2019 The Decred developers | ||
// Use of this source code is governed by an ISC | ||
// license that can be found in the LICENSE file. | ||
|
||
// This file should compiled from the commit the file was introduced, otherwise | ||
// it may not compile due to API changes, or may not create the database with | ||
// the correct old version. This file should not be updated for API changes. | ||
|
||
package main | ||
|
||
import ( | ||
"compress/gzip" | ||
"encoding/hex" | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
"github.com/decred/dcrd/chaincfg" | ||
"github.com/decred/dcrd/hdkeychain" | ||
_ "github.com/decred/dcrwallet/wallet/internal/bdb" | ||
"github.com/decred/dcrwallet/wallet/udb" | ||
"github.com/decred/dcrwallet/wallet/walletdb" | ||
"github.com/decred/dcrwallet/walletseed" | ||
) | ||
|
||
const dbname = "v12.db" | ||
|
||
var ( | ||
pubPass = []byte("public") | ||
privPass = []byte("private") | ||
) | ||
|
||
var chainParams = &chaincfg.TestNet3Params | ||
|
||
func main() { | ||
err := setup() | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "setup: %v\n", err) | ||
os.Exit(1) | ||
} | ||
err = compress() | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "compress: %v\n", err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func hexToBytes(origHex string) []byte { | ||
buf, err := hex.DecodeString(origHex) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return buf | ||
} | ||
|
||
func setup() error { | ||
db, err := walletdb.Create("bdb", dbname) | ||
if err != nil { | ||
return err | ||
} | ||
defer db.Close() | ||
seed, err := walletseed.GenerateRandomSeed(hdkeychain.RecommendedSeedLen) | ||
if err != nil { | ||
return err | ||
} | ||
err = udb.Initialize(db, chainParams, seed, pubPass, privPass) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
amgr, _, _, err := udb.Open(db, chainParams, pubPass) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = walletdb.Update(db, func(tx walletdb.ReadWriteTx) error { | ||
ns := tx.ReadWriteBucket([]byte("waddrmgr")) | ||
if err := amgr.Unlock(ns, privPass); err != nil { | ||
return err | ||
} | ||
|
||
script := hexToBytes("51210373c717acda38b5aa4c00c33932e059cdbc" + | ||
"11deceb5f00490a9101704cc444c5151ae") | ||
_, err := amgr.ImportScript(ns, script) | ||
return err | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func compress() error { | ||
db, err := os.Open(dbname) | ||
if err != nil { | ||
return err | ||
} | ||
defer os.Remove(dbname) | ||
defer db.Close() | ||
dbgz, err := os.Create(dbname + ".gz") | ||
if err != nil { | ||
return err | ||
} | ||
defer dbgz.Close() | ||
gz := gzip.NewWriter(dbgz) | ||
_, err = io.Copy(gz, db) | ||
if err != nil { | ||
return err | ||
} | ||
return gz.Close() | ||
} |
Binary file not shown.