Exemplo n.º 1
0
// openWallet returns a wallet. The function handles opening an existing wallet
// database, the address manager and the transaction store and uses the values
// to open a wallet.Wallet
func openWallet() (*wallet.Wallet, walletdb.DB, error) {
	netdir := networkDir(cfg.DataDir, activeNet.Params)

	db, err := openDb(netdir, walletDbName)
	if err != nil {
		log.Errorf("Failed to open database: %v", err)
		return nil, nil, err
	}

	addrMgrNS, err := db.Namespace(waddrmgrNamespaceKey)
	if err != nil {
		return nil, nil, err
	}
	txMgrNS, err := db.Namespace(wtxmgrNamespaceKey)
	if err != nil {
		return nil, nil, err
	}
	cbs := &waddrmgr.OpenCallbacks{
		ObtainSeed:        promptSeed,
		ObtainPrivatePass: promptPrivPassPhrase,
	}
	w, err := wallet.Open([]byte(cfg.WalletPass), activeNet.Params, db,
		addrMgrNS, txMgrNS, cbs)
	return w, db, err
}
Exemplo n.º 2
0
func openWallet(db walletdb.DB, privPass string, seed []byte) (*Wallet, error) {
	addrMgrNS, err := db.Namespace(waddrmgrNamespaceKey)
	if err != nil {
		return nil, err
	}
	txMgrNS, err := db.Namespace(wtxmgrNamespaceKey)
	if err != nil {
		return nil, err
	}

	cbs := &waddrmgr.OpenCallbacks{
		ObtainSeed:        returnBytes(seed),
		ObtainPrivatePass: returnBytes([]byte(privPass)),
	}
	backWallet, err := wallet.Open(nil, bitcoinNetwork.Params, db, addrMgrNS, txMgrNS, cbs)
	if err != nil {
		return nil, err
	}

	// TODO: use more than 1 node
	node := electrum.NewNode()
	if err := node.ConnectTCP("btc.mustyoshi.com:50001"); err != nil {
		return nil, err
	}

	w := &Wallet{
		wallet: backWallet,
		node:   node,
	}

	addrs, err := w.Addresses()
	if err != nil {
		return nil, err
	}
	for _, addr := range addrs {
		if err := w.watchAddress(addr.String()); err != nil {
			return nil, err
		}
	}

	return w, nil
}
Exemplo n.º 3
0
// openWallet returns a wallet. The function handles opening an existing wallet
// database, the address manager and the transaction store and uses the values
// to open a wallet.Wallet
func openWallet(pubPass []byte, dbDir string) (*wallet.Wallet, walletdb.DB, error) {
	db, err := openDb(dbDir, walletDbName)
	if err != nil {
		return nil, nil, fmt.Errorf("Failed to open database: %v", err)
	}
	addrMgrNS, err := db.Namespace(waddrmgrNamespaceKey)
	if err != nil {
		return nil, nil, err
	}
	txMgrNS, err := db.Namespace(wtxmgrNamespaceKey)
	if err != nil {
		return nil, nil, err
	}
	// TODO(roasbeef): pass these in as funcs instead, priv pass already
	// loaded into memory, use tadge's format to read HD seed.
	cbs := &waddrmgr.OpenCallbacks{
		ObtainSeed:        promptSeed,
		ObtainPrivatePass: promptPrivPassPhrase,
	}
	w, err := wallet.Open(pubPass, ActiveNetParams, db, addrMgrNS, txMgrNS,
		cbs)
	return w, db, err
}