// Open loads an already-created wallet from the passed database and namespaces. func Open(pubPass []byte, params *chaincfg.Params, db walletdb.DB, waddrmgrNS, wtxmgrNS walletdb.Namespace, cbs *waddrmgr.OpenCallbacks) (*Wallet, error) { addrMgr, err := waddrmgr.Open(waddrmgrNS, pubPass, params, cbs) if err != nil { return nil, err } txMgr, err := wtxmgr.Open(wtxmgrNS) if err != nil { if !wtxmgr.IsNoExists(err) { return nil, err } log.Info("No recorded transaction history -- needs full rescan") err = addrMgr.SetSyncedTo(nil) if err != nil { return nil, err } txMgr, err = wtxmgr.Create(wtxmgrNS) if err != nil { return nil, err } } log.Infof("Opened wallet") // TODO: log balance? last sync height? w := &Wallet{ db: db, Manager: addrMgr, TxStore: txMgr, lockedOutpoints: map[wire.OutPoint]struct{}{}, FeeIncrement: defaultFeeIncrement, rescanAddJob: make(chan *RescanJob), rescanBatch: make(chan *rescanBatch), rescanNotifications: make(chan interface{}), rescanProgress: make(chan *RescanProgressMsg), rescanFinished: make(chan *RescanFinishedMsg), createTxRequests: make(chan createTxRequest), unlockRequests: make(chan unlockRequest), lockRequests: make(chan struct{}), holdUnlockRequests: make(chan chan HeldUnlock), lockState: make(chan bool), changePassphrase: make(chan changePassphraseRequest), chainParams: params, quit: make(chan struct{}), } return w, nil }
func exampleCreateTxStore() (*wtxmgr.Store, func(), error) { dir, err := ioutil.TempDir("", "pool_test_txstore") if err != nil { return nil, nil, err } db, err := walletdb.Create("bdb", filepath.Join(dir, "txstore.db")) if err != nil { return nil, nil, err } wtxmgrNamespace, err := db.Namespace([]byte("testtxstore")) if err != nil { return nil, nil, err } err = wtxmgr.Create(wtxmgrNamespace) if err != nil { return nil, nil, err } s, err := wtxmgr.Open(wtxmgrNamespace, &chaincfg.MainNetParams) if err != nil { return nil, nil, err } return s, func() { os.RemoveAll(dir) }, nil }
func TstCreateTxStore(t *testing.T) (store *wtxmgr.Store, tearDown func()) { dir, err := ioutil.TempDir("", "pool_test_txstore") if err != nil { t.Fatalf("Failed to create txstore dir: %v", err) } db, err := walletdb.Create("bdb", filepath.Join(dir, "txstore.db")) if err != nil { t.Fatalf("Failed to create walletdb: %v", err) } wtxmgrNamespace, err := db.Namespace([]byte("testtxstore")) if err != nil { t.Fatalf("Failed to create walletdb namespace: %v", err) } err = wtxmgr.Create(wtxmgrNamespace) if err != nil { t.Fatalf("Failed to create txstore: %v", err) } s, err := wtxmgr.Open(wtxmgrNamespace, &chaincfg.MainNetParams) if err != nil { t.Fatalf("Failed to open txstore: %v", err) } return s, func() { os.RemoveAll(dir) } }