From 7037b3dfa36da4145f98f4ba68de9fea9263ad6e Mon Sep 17 00:00:00 2001 From: Donald Adu-Poku Date: Tue, 6 Aug 2019 11:10:01 +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..ab995ee10 --- /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/v2" + "github.com/decred/dcrd/hdkeychain/v2" + _ "github.com/decred/dcrwallet/wallet/v3/drivers/bdb" + "github.com/decred/dcrwallet/wallet/v3/udb" + "github.com/decred/dcrwallet/wallet/v3/walletdb" + "github.com/decred/dcrwallet/walletseed" +) + +const dbname = "v12.db" + +var ( + pubPass = []byte("public") + privPass = []byte("private") +) + +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 + } + + params := chaincfg.TestNet3Params() + err = udb.Initialize(db, params, seed, pubPass, privPass) + if err != nil { + return err + } + + amgr, txStore, _, err := udb.Open(db, params, 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..c60c43e47021d1d7a6826da3fb83509de0f1ef2d GIT binary patch literal 3346 zcmZ`+XE+-Q)YhWaR_#)yMy;q-t4fjDd$(#+F|WNs30l<}5ix3y^ioPo2(^MJ8hcdK zCTh<#R&2?4pL@T4|Gx9%oFDJ|rfdo{ zTBdAlWii+F=YSlSpFP#2*P~C3ja{y`XJfuzROWpvLyKKa)AL!%Gp4XaE;>wT56Ym zkN;<@&%*l{dRs4{!G1A}=6?gGOUz|i$8J={Q)6OM0K772wMeZG> z{lohPe041SjN9-UT?}3I?yF`RPh|w4;OeiKm8+~JOH^U!`2dM3D3*wVC|e5Y?TcC& zwmWmtsIAjqQ3{-i=XKn2_L)w;X|*k)3leCdg1zGVBm^5Y_D}?!2dB2%f12f;<6t3j z_;?Kj*}Ny)Xt-0N2w3WIU4N&oDub#rKl=MOe22qGMIw$f;bUK~=GcgVaK6K&7LV0N z7i}X_f|PM^2nPvLj?Rei#swE(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