diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 141f8a58b0..6621b16cd3 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -50,75 +50,75 @@ }, { "ImportPath": "github.com/OpenBazaar/multiwallet", - "Rev": "6cd7f7b4c959dd313f120ebe4db22f0117f260f0" + "Rev": "50a83be212c5258ba9dbe59360778a8759e7e241" }, { "ImportPath": "github.com/OpenBazaar/multiwallet/bitcoin", - "Rev": "6cd7f7b4c959dd313f120ebe4db22f0117f260f0" + "Rev": "50a83be212c5258ba9dbe59360778a8759e7e241" }, { "ImportPath": "github.com/OpenBazaar/multiwallet/bitcoincash", - "Rev": "6cd7f7b4c959dd313f120ebe4db22f0117f260f0" + "Rev": "50a83be212c5258ba9dbe59360778a8759e7e241" }, { "ImportPath": "github.com/OpenBazaar/multiwallet/cache", - "Rev": "6cd7f7b4c959dd313f120ebe4db22f0117f260f0" + "Rev": "50a83be212c5258ba9dbe59360778a8759e7e241" }, { "ImportPath": "github.com/OpenBazaar/multiwallet/client", - "Rev": "6cd7f7b4c959dd313f120ebe4db22f0117f260f0" + "Rev": "50a83be212c5258ba9dbe59360778a8759e7e241" }, { "ImportPath": "github.com/OpenBazaar/multiwallet/client/blockbook", - "Rev": "6cd7f7b4c959dd313f120ebe4db22f0117f260f0" + "Rev": "50a83be212c5258ba9dbe59360778a8759e7e241" }, { "ImportPath": "github.com/OpenBazaar/multiwallet/client/transport", - "Rev": "6cd7f7b4c959dd313f120ebe4db22f0117f260f0" + "Rev": "50a83be212c5258ba9dbe59360778a8759e7e241" }, { "ImportPath": "github.com/OpenBazaar/multiwallet/config", - "Rev": "6cd7f7b4c959dd313f120ebe4db22f0117f260f0" + "Rev": "50a83be212c5258ba9dbe59360778a8759e7e241" }, { "ImportPath": "github.com/OpenBazaar/multiwallet/datastore", - "Rev": "6cd7f7b4c959dd313f120ebe4db22f0117f260f0" + "Rev": "50a83be212c5258ba9dbe59360778a8759e7e241" }, { "ImportPath": "github.com/OpenBazaar/multiwallet/keys", - "Rev": "6cd7f7b4c959dd313f120ebe4db22f0117f260f0" + "Rev": "50a83be212c5258ba9dbe59360778a8759e7e241" }, { "ImportPath": "github.com/OpenBazaar/multiwallet/litecoin", - "Rev": "6cd7f7b4c959dd313f120ebe4db22f0117f260f0" + "Rev": "50a83be212c5258ba9dbe59360778a8759e7e241" }, { "ImportPath": "github.com/OpenBazaar/multiwallet/litecoin/address", - "Rev": "6cd7f7b4c959dd313f120ebe4db22f0117f260f0" + "Rev": "50a83be212c5258ba9dbe59360778a8759e7e241" }, { "ImportPath": "github.com/OpenBazaar/multiwallet/litecoin/params", - "Rev": "6cd7f7b4c959dd313f120ebe4db22f0117f260f0" + "Rev": "50a83be212c5258ba9dbe59360778a8759e7e241" }, { "ImportPath": "github.com/OpenBazaar/multiwallet/model", - "Rev": "6cd7f7b4c959dd313f120ebe4db22f0117f260f0" + "Rev": "50a83be212c5258ba9dbe59360778a8759e7e241" }, { "ImportPath": "github.com/OpenBazaar/multiwallet/service", - "Rev": "6cd7f7b4c959dd313f120ebe4db22f0117f260f0" + "Rev": "50a83be212c5258ba9dbe59360778a8759e7e241" }, { "ImportPath": "github.com/OpenBazaar/multiwallet/util", - "Rev": "6cd7f7b4c959dd313f120ebe4db22f0117f260f0" + "Rev": "50a83be212c5258ba9dbe59360778a8759e7e241" }, { "ImportPath": "github.com/OpenBazaar/multiwallet/zcash", - "Rev": "6cd7f7b4c959dd313f120ebe4db22f0117f260f0" + "Rev": "50a83be212c5258ba9dbe59360778a8759e7e241" }, { "ImportPath": "github.com/OpenBazaar/multiwallet/zcash/address", - "Rev": "6cd7f7b4c959dd313f120ebe4db22f0117f260f0" + "Rev": "50a83be212c5258ba9dbe59360778a8759e7e241" }, { "ImportPath": "github.com/OpenBazaar/spvwallet", @@ -2513,7 +2513,7 @@ }, { "ImportPath": "github.com/OpenBazaar/multiwallet/client/errors", - "Rev": "6cd7f7b4c959dd313f120ebe4db22f0117f260f0" + "Rev": "50a83be212c5258ba9dbe59360778a8759e7e241" }, { "ImportPath": "github.com/OpenBazaar/multiwallet/vendor/github.com/OpenBazaar/wallet-interface", diff --git a/vendor/github.com/OpenBazaar/multiwallet/Gopkg.lock b/vendor/github.com/OpenBazaar/multiwallet/Gopkg.lock index fc280fab3e..b160c04341 100644 --- a/vendor/github.com/OpenBazaar/multiwallet/Gopkg.lock +++ b/vendor/github.com/OpenBazaar/multiwallet/Gopkg.lock @@ -26,11 +26,11 @@ [[projects]] branch = "master" - digest = "1:cdb20ba34409b4eb78ff013e71eafce40e49b42485dafcfb675b64c5cb3cdaca" + digest = "1:41045b2cbf58bf6007d65103b1fb17cbc092777af415546eb40fe4e005da3780" name = "github.com/OpenBazaar/wallet-interface" packages = ["."] pruneopts = "UT" - revision = "aa8e214acd9b86f0c7a190d2eaf269070f5b5f3c" + revision = "ba95db86ca2f75d561554d3270623db4d5ed0467" [[projects]] digest = "1:0f98f59e9a2f4070d66f0c9c39561f68fcd1dc837b22a852d28d0003aebd1b1e" @@ -457,4 +457,4 @@ "gopkg.in/jarcoal/httpmock.v1", ] solver-name = "gps-cdcl" - solver-version = 1 + solver-version = 1 \ No newline at end of file diff --git a/vendor/github.com/OpenBazaar/multiwallet/bitcoin/wallet.go b/vendor/github.com/OpenBazaar/multiwallet/bitcoin/wallet.go index a9b27e7ddc..7ac92c55da 100644 --- a/vendor/github.com/OpenBazaar/multiwallet/bitcoin/wallet.go +++ b/vendor/github.com/OpenBazaar/multiwallet/bitcoin/wallet.go @@ -146,17 +146,30 @@ func (w *BitcoinWallet) ChildKey(keyBytes []byte, chaincode []byte, isPrivateKey } func (w *BitcoinWallet) CurrentAddress(purpose wi.KeyPurpose) btc.Address { - key, _ := w.km.GetCurrentKey(purpose) - addr, _ := key.Address(w.params) - return btc.Address(addr) + key, err := w.km.GetCurrentKey(purpose) + if err != nil { + w.log.Errorf("Error generating current key: %s", err) + } + addr, err := w.km.KeyToAddress(key) + if err != nil { + w.log.Errorf("Error converting key to address: %s", err) + } + return addr } func (w *BitcoinWallet) NewAddress(purpose wi.KeyPurpose) btc.Address { - i, _ := w.db.Keys().GetUnused(purpose) - key, _ := w.km.GenerateChildKey(purpose, uint32(i[1])) - addr, _ := key.Address(w.params) - w.db.Keys().MarkKeyAsUsed(addr.ScriptAddress()) - return btc.Address(addr) + key, err := w.km.GetNextUnused(purpose) + if err != nil { + w.log.Errorf("Error generating next unused key: %s", err) + } + addr, err := w.km.KeyToAddress(key) + if err != nil { + w.log.Errorf("Error converting key to address: %s", err) + } + if err := w.db.Keys().MarkKeyAsUsed(addr.ScriptAddress()); err != nil { + w.log.Errorf("Error marking key as used: %s", err) + } + return addr } func (w *BitcoinWallet) DecodeAddress(addr string) (btc.Address, error) { @@ -331,11 +344,13 @@ func (w *BitcoinWallet) AddWatchedAddresses(addrs ...btc.Address) error { var watchedScripts [][]byte for _, addr := range addrs { - script, err := w.AddressToScript(addr) - if err != nil { - return err + if !w.HasKey(addr) { + script, err := w.AddressToScript(addr) + if err != nil { + return err + } + watchedScripts = append(watchedScripts, script) } - watchedScripts = append(watchedScripts, script) } err := w.db.WatchedScripts().PutAll(watchedScripts) diff --git a/vendor/github.com/OpenBazaar/multiwallet/bitcoincash/exchange_rates.go b/vendor/github.com/OpenBazaar/multiwallet/bitcoincash/exchange_rates.go index 96af7697ac..c036a701e7 100644 --- a/vendor/github.com/OpenBazaar/multiwallet/bitcoincash/exchange_rates.go +++ b/vendor/github.com/OpenBazaar/multiwallet/bitcoincash/exchange_rates.go @@ -35,7 +35,6 @@ func NewBitcoinCashPriceFetcher(dialer proxy.Dialer) *BitcoinCashPriceFetcher { b := BitcoinCashPriceFetcher{ cache: make(map[string]float64), } - var client *http.Client if dialer != nil { dial := dialer.Dial @@ -45,6 +44,7 @@ func NewBitcoinCashPriceFetcher(dialer proxy.Dialer) *BitcoinCashPriceFetcher { client = &http.Client{Timeout: time.Minute} } + b.providers = []*ExchangeRateProvider{ {"https://ticker.openbazaar.org/api", b.cache, client, OpenBazaarDecoder{}}, } diff --git a/vendor/github.com/OpenBazaar/multiwallet/bitcoincash/wallet.go b/vendor/github.com/OpenBazaar/multiwallet/bitcoincash/wallet.go index 807c508add..3b69435995 100644 --- a/vendor/github.com/OpenBazaar/multiwallet/bitcoincash/wallet.go +++ b/vendor/github.com/OpenBazaar/multiwallet/bitcoincash/wallet.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/hex" "fmt" + "github.com/op/go-logging" "io" "log" "time" @@ -40,6 +41,7 @@ type BitcoinCashWallet struct { mPubKey *hd.ExtendedKey exchangeRates wi.ExchangeRates + log *logging.Logger } var _ = wi.Wallet(&BitcoinCashWallet{}) @@ -76,7 +78,18 @@ func NewBitcoinCashWallet(cfg config.CoinConfig, mnemonic string, params *chainc fp := util.NewFeeProvider(cfg.MaxFee, cfg.HighFee, cfg.MediumFee, cfg.LowFee, exchangeRates) - return &BitcoinCashWallet{cfg.DB, km, params, c, wm, fp, mPrivKey, mPubKey, exchangeRates}, nil + return &BitcoinCashWallet{ + db: cfg.DB, + km: km, + params: params, + client: c, + ws: wm, + fp: fp, + mPrivKey: mPrivKey, + mPubKey: mPubKey, + exchangeRates: exchangeRates, + log: logging.MustGetLogger("bitcoin-cash-wallet"), + }, nil } func bitcoinCashAddress(key *hd.ExtendedKey, params *chaincfg.Params) (btcutil.Address, error) { @@ -136,17 +149,30 @@ func (w *BitcoinCashWallet) ChildKey(keyBytes []byte, chaincode []byte, isPrivat } func (w *BitcoinCashWallet) CurrentAddress(purpose wi.KeyPurpose) btcutil.Address { - key, _ := w.km.GetCurrentKey(purpose) - addr, _ := w.km.KeyToAddress(key) - return btcutil.Address(addr) + key, err := w.km.GetCurrentKey(purpose) + if err != nil { + w.log.Errorf("Error generating current key: %s", err) + } + addr, err := w.km.KeyToAddress(key) + if err != nil { + w.log.Errorf("Error converting key to address: %s", err) + } + return addr } func (w *BitcoinCashWallet) NewAddress(purpose wi.KeyPurpose) btcutil.Address { - i, _ := w.db.Keys().GetUnused(purpose) - key, _ := w.km.GenerateChildKey(purpose, uint32(i[1])) - addr, _ := w.km.KeyToAddress(key) - w.db.Keys().MarkKeyAsUsed(addr.ScriptAddress()) - return btcutil.Address(addr) + key, err := w.km.GetNextUnused(purpose) + if err != nil { + w.log.Errorf("Error generating next unused key: %s", err) + } + addr, err := w.km.KeyToAddress(key) + if err != nil { + w.log.Errorf("Error converting key to address: %s", err) + } + if err := w.db.Keys().MarkKeyAsUsed(addr.ScriptAddress()); err != nil { + w.log.Errorf("Error marking key as used: %s", err) + } + return addr } func (w *BitcoinCashWallet) DecodeAddress(addr string) (btcutil.Address, error) { @@ -310,11 +336,13 @@ func (w *BitcoinCashWallet) AddWatchedAddresses(addrs ...btcutil.Address) error var watchedScripts [][]byte for _, addr := range addrs { - script, err := w.AddressToScript(addr) - if err != nil { - return err + if !w.HasKey(addr) { + script, err := w.AddressToScript(addr) + if err != nil { + return err + } + watchedScripts = append(watchedScripts, script) } - watchedScripts = append(watchedScripts, script) } err := w.db.WatchedScripts().PutAll(watchedScripts) diff --git a/vendor/github.com/OpenBazaar/multiwallet/client/blockbook/client.go b/vendor/github.com/OpenBazaar/multiwallet/client/blockbook/client.go index 977db3f466..2a3280e897 100644 --- a/vendor/github.com/OpenBazaar/multiwallet/client/blockbook/client.go +++ b/vendor/github.com/OpenBazaar/multiwallet/client/blockbook/client.go @@ -141,7 +141,6 @@ func NewBlockBookClient(apiUrl string, proxyDialer proxy.Dialer) (*BlockBookClie txNotifyChan: tch, listenLock: sync.Mutex{}, } - ic.websocketWatchdog = newWebsocketWatchdog(ic) ic.RequestFunc = ic.doRequest return ic, nil diff --git a/vendor/github.com/OpenBazaar/multiwallet/client/pool.go b/vendor/github.com/OpenBazaar/multiwallet/client/pool.go index b47ba9c69b..af584ac1fb 100644 --- a/vendor/github.com/OpenBazaar/multiwallet/client/pool.go +++ b/vendor/github.com/OpenBazaar/multiwallet/client/pool.go @@ -377,10 +377,7 @@ func (p *ClientPool) ListenAddresses(addrs ...btcutil.Address) { var client = p.poolManager.AcquireCurrentWhenReady() defer p.poolManager.ReleaseCurrent() - for _, addr := range addrs { - p.listenAddrs = append(p.listenAddrs, addr) - } - + p.listenAddrs = append(p.listenAddrs, addrs...) client.ListenAddresses(addrs...) } diff --git a/vendor/github.com/OpenBazaar/multiwallet/keys/keys.go b/vendor/github.com/OpenBazaar/multiwallet/keys/keys.go index f902b643fa..e155b5e788 100644 --- a/vendor/github.com/OpenBazaar/multiwallet/keys/keys.go +++ b/vendor/github.com/OpenBazaar/multiwallet/keys/keys.go @@ -78,7 +78,7 @@ func (km *KeyManager) GetCurrentKey(purpose wallet.KeyPurpose) (*hd.ExtendedKey, return nil, err } if len(i) == 0 { - return nil, errors.New("No unused keys in database") + return nil, errors.New("no unused keys in database") } return km.GenerateChildKey(purpose, uint32(i[0])) } @@ -105,7 +105,7 @@ func (km *KeyManager) GetFreshKey(purpose wallet.KeyPurpose) (*hd.ExtendedKey, e if err != nil { return nil, err } - p := wallet.KeyPath{wallet.KeyPurpose(purpose), index} + p := wallet.KeyPath{Purpose: purpose, Index: index} err = km.datastore.Put(addr.ScriptAddress(), p) if err != nil { return nil, err @@ -113,6 +113,21 @@ func (km *KeyManager) GetFreshKey(purpose wallet.KeyPurpose) (*hd.ExtendedKey, e return childKey, nil } +func (km *KeyManager) GetNextUnused(purpose wallet.KeyPurpose) (*hd.ExtendedKey, error) { + if err := km.lookahead(); err != nil { + return nil, err + } + i, err := km.datastore.GetUnused(purpose) + if err != nil { + return nil, err + } + key, err := km.GenerateChildKey(purpose, uint32(i[1])) + if err != nil { + return nil, err + } + return key, nil +} + func (km *KeyManager) GetKeys() []*hd.ExtendedKey { var keys []*hd.ExtendedKey keyPaths, err := km.datastore.GetAll() @@ -163,7 +178,7 @@ func (km *KeyManager) GenerateChildKey(purpose wallet.KeyPurpose, index uint32) } else if purpose == wallet.INTERNAL { return km.internalKey.Child(index) } - return nil, errors.New("Unknown key purpose") + return nil, errors.New("unknown key purpose") } func (km *KeyManager) lookahead() error { diff --git a/vendor/github.com/OpenBazaar/multiwallet/litecoin/exchange_rates.go b/vendor/github.com/OpenBazaar/multiwallet/litecoin/exchange_rates.go index 57ca7cb461..47f08f0a78 100644 --- a/vendor/github.com/OpenBazaar/multiwallet/litecoin/exchange_rates.go +++ b/vendor/github.com/OpenBazaar/multiwallet/litecoin/exchange_rates.go @@ -54,10 +54,10 @@ func NewLitecoinPriceFetcher(dialer proxy.Dialer) *LitecoinPriceFetcher { } z.providers = []*ExchangeRateProvider{ - //{"https://ticker.openbazaar.org/api", z.cache, client, OpenBazaarDecoder{}, nil}, - //{"https://bittrex.com/api/v1.1/public/getticker?market=btc-ltc", z.cache, client, BittrexDecoder{}, bp}, - //{"https://api.bitfinex.com/v1/pubticker/ltcbtc", z.cache, client, BitfinexDecoder{}, bp}, - //{"https://poloniex.com/public?command=returnTicker", z.cache, client, PoloniexDecoder{}, bp}, + {"https://ticker.openbazaar.org/api", z.cache, client, OpenBazaarDecoder{}, nil}, + {"https://bittrex.com/api/v1.1/public/getticker?market=btc-ltc", z.cache, client, BittrexDecoder{}, bp}, + {"https://api.bitfinex.com/v1/pubticker/ltcbtc", z.cache, client, BitfinexDecoder{}, bp}, + {"https://poloniex.com/public?command=returnTicker", z.cache, client, PoloniexDecoder{}, bp}, {"https://api.kraken.com/0/public/Ticker?pair=LTCXBT", z.cache, client, KrakenDecoder{}, bp}, } go z.run() diff --git a/vendor/github.com/OpenBazaar/multiwallet/litecoin/wallet.go b/vendor/github.com/OpenBazaar/multiwallet/litecoin/wallet.go index 190ba009d4..d5de776650 100644 --- a/vendor/github.com/OpenBazaar/multiwallet/litecoin/wallet.go +++ b/vendor/github.com/OpenBazaar/multiwallet/litecoin/wallet.go @@ -150,8 +150,14 @@ func (w *LitecoinWallet) ChildKey(keyBytes []byte, chaincode []byte, isPrivateKe func (w *LitecoinWallet) CurrentAddress(purpose wi.KeyPurpose) btcutil.Address { var addr btcutil.Address for { - key, _ := w.km.GetCurrentKey(purpose) - addr, _ = litecoinAddress(key, w.params) + key, err := w.km.GetCurrentKey(purpose) + if err != nil { + w.log.Errorf("Error generating current key: %s", err) + } + addr, err = w.km.KeyToAddress(key) + if err != nil { + w.log.Errorf("Error converting key to address: %s", err) + } if !strings.HasPrefix(strings.ToLower(addr.String()), "ltc1") { break @@ -160,23 +166,28 @@ func (w *LitecoinWallet) CurrentAddress(purpose wi.KeyPurpose) btcutil.Address { w.log.Errorf("Error marking key as used: %s", err) } } - return btcutil.Address(addr) + return addr } func (w *LitecoinWallet) NewAddress(purpose wi.KeyPurpose) btcutil.Address { var addr btcutil.Address for { - i, _ := w.db.Keys().GetUnused(purpose) - key, _ := w.km.GenerateChildKey(purpose, uint32(i[1])) - addr, _ = litecoinAddress(key, w.params) + key, err := w.km.GetNextUnused(purpose) + if err != nil { + w.log.Errorf("Error generating next unused key: %s", err) + } + addr, err = w.km.KeyToAddress(key) + if err != nil { + w.log.Errorf("Error converting key to address: %s", err) + } if err := w.db.Keys().MarkKeyAsUsed(addr.ScriptAddress()); err != nil { - w.log.Error("Error marking key as used: %s", err) + w.log.Errorf("Error marking key as used: %s", err) } if !strings.HasPrefix(strings.ToLower(addr.String()), "ltc1") { break } } - return btcutil.Address(addr) + return addr } func (w *LitecoinWallet) DecodeAddress(addr string) (btcutil.Address, error) { @@ -337,11 +348,13 @@ func (w *LitecoinWallet) AddWatchedAddresses(addrs ...btcutil.Address) error { var watchedScripts [][]byte for _, addr := range addrs { - script, err := w.AddressToScript(addr) - if err != nil { - return err + if !w.HasKey(addr) { + script, err := w.AddressToScript(addr) + if err != nil { + return err + } + watchedScripts = append(watchedScripts, script) } - watchedScripts = append(watchedScripts, script) } err := w.db.WatchedScripts().PutAll(watchedScripts) diff --git a/vendor/github.com/OpenBazaar/multiwallet/zcash/exchange_rates.go b/vendor/github.com/OpenBazaar/multiwallet/zcash/exchange_rates.go index 1373a6f896..cd19504666 100644 --- a/vendor/github.com/OpenBazaar/multiwallet/zcash/exchange_rates.go +++ b/vendor/github.com/OpenBazaar/multiwallet/zcash/exchange_rates.go @@ -53,6 +53,7 @@ func NewZcashPriceFetcher(dialer proxy.Dialer) *ZcashPriceFetcher { client = &http.Client{Timeout: time.Minute} } + z.providers = []*ExchangeRateProvider{ {"https://ticker.openbazaar.org/api", z.cache, client, OpenBazaarDecoder{}, nil}, {"https://bittrex.com/api/v1.1/public/getticker?market=btc-zec", z.cache, client, BittrexDecoder{}, bp}, diff --git a/vendor/github.com/OpenBazaar/multiwallet/zcash/sign.go b/vendor/github.com/OpenBazaar/multiwallet/zcash/sign.go index 8e67e90f79..2bd11ca829 100644 --- a/vendor/github.com/OpenBazaar/multiwallet/zcash/sign.go +++ b/vendor/github.com/OpenBazaar/multiwallet/zcash/sign.go @@ -38,8 +38,8 @@ var ( ) const ( - sigHashMask = 0x1f - branchID = 0x2BB40E60 + sigHashMask = 0x1f + branchID = 0x2BB40E60 ) func (w *ZCashWallet) buildTx(amount int64, addr btc.Address, feeLevel wi.FeeLevel, optionalOutput *wire.TxOut) (*wire.MsgTx, error) { @@ -53,9 +53,9 @@ func (w *ZCashWallet) buildTx(amount int64, addr btc.Address, feeLevel wi.FeeLev } var ( - additionalPrevScripts map[wire.OutPoint][]byte + additionalPrevScripts map[wire.OutPoint][]byte additionalKeysByAddress map[string]*btc.WIF - inVals map[wire.OutPoint]btc.Amount + inVals map[wire.OutPoint]btc.Amount ) // Create input source @@ -78,7 +78,7 @@ func (w *ZCashWallet) buildTx(amount int64, addr btc.Address, feeLevel wi.FeeLev } additionalPrevScripts = make(map[wire.OutPoint][]byte) additionalKeysByAddress = make(map[string]*btc.WIF) - inVals = make(map[wire.OutPoint]btc.Amount) + inVals = make(map[wire.OutPoint]btc.Amount) for _, c := range coins.Coins() { total += c.Value() outpoint := wire.NewOutPoint(c.Hash(), c.Index()) diff --git a/vendor/github.com/OpenBazaar/multiwallet/zcash/wallet.go b/vendor/github.com/OpenBazaar/multiwallet/zcash/wallet.go index c068fb4237..73af2fbbc2 100644 --- a/vendor/github.com/OpenBazaar/multiwallet/zcash/wallet.go +++ b/vendor/github.com/OpenBazaar/multiwallet/zcash/wallet.go @@ -55,7 +55,7 @@ func NewZCashWallet(cfg config.CoinConfig, mnemonic string, params *chaincfg.Par if err != nil { return nil, err } - km, err := keys.NewKeyManager(cfg.DB.Keys(), params, mPrivKey, wi.Zcash, zcashCashAddress) + km, err := keys.NewKeyManager(cfg.DB.Keys(), params, mPrivKey, wi.Zcash, zcashAddress) if err != nil { return nil, err } @@ -91,7 +91,7 @@ func NewZCashWallet(cfg config.CoinConfig, mnemonic string, params *chaincfg.Par }, nil } -func zcashCashAddress(key *hd.ExtendedKey, params *chaincfg.Params) (btcutil.Address, error) { +func zcashAddress(key *hd.ExtendedKey, params *chaincfg.Params) (btcutil.Address, error) { addr, err := key.Address(params) if err != nil { return nil, err @@ -148,17 +148,30 @@ func (w *ZCashWallet) ChildKey(keyBytes []byte, chaincode []byte, isPrivateKey b } func (w *ZCashWallet) CurrentAddress(purpose wi.KeyPurpose) btcutil.Address { - key, _ := w.km.GetCurrentKey(purpose) - addr, _ := zcashCashAddress(key, w.params) - return btcutil.Address(addr) + key, err := w.km.GetCurrentKey(purpose) + if err != nil { + w.log.Errorf("Error generating current key: %s", err) + } + addr, err := w.km.KeyToAddress(key) + if err != nil { + w.log.Errorf("Error converting key to address: %s", err) + } + return addr } func (w *ZCashWallet) NewAddress(purpose wi.KeyPurpose) btcutil.Address { - i, _ := w.db.Keys().GetUnused(purpose) - key, _ := w.km.GenerateChildKey(purpose, uint32(i[1])) - addr, _ := zcashCashAddress(key, w.params) - w.db.Keys().MarkKeyAsUsed(addr.ScriptAddress()) - return btcutil.Address(addr) + key, err := w.km.GetNextUnused(purpose) + if err != nil { + w.log.Errorf("Error generating next unused key: %s", err) + } + addr, err := w.km.KeyToAddress(key) + if err != nil { + w.log.Errorf("Error converting key to address: %s", err) + } + if err := w.db.Keys().MarkKeyAsUsed(addr.ScriptAddress()); err != nil { + w.log.Errorf("Error marking key as used: %s", err) + } + return addr } func (w *ZCashWallet) DecodeAddress(addr string) (btcutil.Address, error) { @@ -333,11 +346,13 @@ func (w *ZCashWallet) AddWatchedAddresses(addrs ...btcutil.Address) error { var watchedScripts [][]byte for _, addr := range addrs { - script, err := w.AddressToScript(addr) - if err != nil { - return err + if !w.HasKey(addr) { + script, err := w.AddressToScript(addr) + if err != nil { + return err + } + watchedScripts = append(watchedScripts, script) } - watchedScripts = append(watchedScripts, script) } err := w.db.WatchedScripts().PutAll(watchedScripts)