From a82156aa06110a4c1eb7a6f35aa7debd2e7dc878 Mon Sep 17 00:00:00 2001 From: Donald Adu-Poku Date: Mon, 8 Jul 2019 13:49:16 +0000 Subject: [PATCH] udb: add script storage testdata. --- wallet/udb/testdata/v12.db.go | 109 ++++++++++++++++++++++++++++++++++ wallet/udb/testdata/v12.db.gz | Bin 0 -> 3226 bytes 2 files changed, 109 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..488542466 --- /dev/null +++ b/wallet/udb/testdata/v12.db.go @@ -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() +} diff --git a/wallet/udb/testdata/v12.db.gz b/wallet/udb/testdata/v12.db.gz new file mode 100644 index 0000000000000000000000000000000000000000..a1216d74c01a2fecf1d6f35bbcf31378545ccbc6 GIT binary patch literal 3226 zcmZ`)XHXLg5{6R*73mO>BA^IJufmgFq=(*1r1#!y1eF@)QKSVD1$hDrA%Fx#iUOg8 zB1lmwK{`T!P!b3!ck}Li|89Tm&g^`%`_0aNyEk*0=>9g^?&4K-+XO7#fg&JsKDL(N z`PAOT_ICb~EvDGis;WsEC$ESuk{^XcY_r$chjeCn#=Nr3cfC8UzJ16e%>FjU1;vEC zY{gMdR2)<58a)a;P9`KQrNB0cl;n*gIQ&S9b_96IE*ppj+c3PJ543KRFpl_s6SJ5#e1rMu27Ey z&YGN*ukWfQ({sKi20PeOW7v5#Ik<9l&<1jtu_2g8>4-eu{utP?=rKMpV&Dd1SvntW z?fOJ|CqAL_z+1d{QQ+jWX_ZOmxNTmYy%8srBL8%RjsJtB|I~9cy@Y71U-drR+h@Wr zhRSqBy~QNME1q7Nd7Y^OmjjCg)O>0AqUPHT@OpY-;4*j|M$J15iAtUsFl zFME(DbZ_y_+uA5-6}BO2yJ6yR;K{>8{1(4Vn#9S7d=1P)wg|Jz5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