From 18d887d2eabd9863f8d1e371013c2d1727430350 Mon Sep 17 00:00:00 2001 From: Donald Adu-Poku Date: Tue, 9 Jul 2019 14:22:21 +0000 Subject: [PATCH] udb: add script storage testdata. --- wallet/udb/testdata/v12.db.go | 116 ++++++++++++++++++++++++++++++++++ wallet/udb/testdata/v12.db.gz | Bin 0 -> 3346 bytes 2 files changed, 116 insertions(+) create mode 100644 wallet/udb/testdata/v12.db.go create mode 100644 wallet/udb/testdata/v12.db.gz diff --git a/wallet/udb/testdata/v12.db.go b/wallet/udb/testdata/v12.db.go new file mode 100644 index 000000000..bb6a46de2 --- /dev/null +++ b/wallet/udb/testdata/v12.db.go @@ -0,0 +1,116 @@ +// 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/v2/drivers/bdb" + "github.com/decred/dcrwallet/wallet/v2/udb" + "github.com/decred/dcrwallet/wallet/v2/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, txStore, _, err := udb.Open(db, chainParams, pubPass) + if err != nil { + return err + } + + err = walletdb.Update(db, func(tx walletdb.ReadWriteTx) error { + amgrns := tx.ReadWriteBucket([]byte("waddrmgr")) + txmgrns := tx.ReadWriteBucket([]byte("wtxmgr")) + + if err := amgr.Unlock(amgrns, privPass); err != nil { + return err + } + + script := hexToBytes("51210373c717acda38b5aa4c00c33932e059cdbc" + + "11deceb5f00490a9101704cc444c5151ae") + + _, err := amgr.ImportScript(amgrns, script) + if err != nil { + return err + } + + return txStore.InsertTxScript(txmgrns, script) + }) + + 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() +} diff --git a/wallet/udb/testdata/v12.db.gz b/wallet/udb/testdata/v12.db.gz new file mode 100644 index 0000000000000000000000000000000000000000..c53d1979af5bbadb7b4a060d5d3cc76bb91cff17 GIT binary patch literal 3346 zcmZvec{J1y_s22$-ZQZVamRaZL-D4GWIRo zpqMfk`!IHc&+|LqPQUZ~@!WszAFua0_ulup=bj6SrJ?vYfQ>mig;Xd&u`S8kq^fPi zClS5%dO&DS%|R1Ww#oO(`^@;MqY5;S~z0GA!{&Go%PP$0k=BI63hd2YAejDhJ1)bMd= zvO|mu<}+$-3-iooW3F8M(+&kiNU;1xFgFsY5-<(|r!U|s1i)$eI{im|TeBNVjZJ@L z6i3tyN<}0pVM^Yv&TcAAniL-%eF=I?@pO=CY8=%sH-3GC+!#!bsUnZa2Z7@o;3CVN zJK+pDeK)S*q!)UyMitr!8!DFJiy8{l;+86pRxT>{Zgpqxr@9LPV-=WKYXavPDboun z(y{Vhud&q)8Bw)cgJHIkG0PAw;K6mkcy_z97QGk!mcpeYYlYL)U02fc_k#<`%af2v zML(BK>_jcyk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