Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions bitcoin/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/OpenBazaar/multiwallet/service"
"github.com/OpenBazaar/multiwallet/util"
"github.com/OpenBazaar/spvwallet"
"github.com/OpenBazaar/spvwallet/exchangerates"
wi "github.com/OpenBazaar/wallet-interface"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
Expand All @@ -37,9 +38,11 @@ type BitcoinWallet struct {

mPrivKey *hd.ExtendedKey
mPubKey *hd.ExtendedKey

exchangeRates wi.ExchangeRates
}

func NewBitcoinWallet(cfg config.CoinConfig, mnemonic string, params *chaincfg.Params, proxy proxy.Dialer, cache cache.Cacher) (*BitcoinWallet, error) {
func NewBitcoinWallet(cfg config.CoinConfig, mnemonic string, params *chaincfg.Params, proxy proxy.Dialer, cache cache.Cacher, disableExchangeRates bool) (*BitcoinWallet, error) {
seed := bip39.NewSeed(mnemonic, "")

mPrivKey, err := hd.NewMaster(seed, params)
Expand All @@ -59,6 +62,10 @@ func NewBitcoinWallet(cfg config.CoinConfig, mnemonic string, params *chaincfg.P
if err != nil {
return nil, err
}
var er wi.ExchangeRates
if !disableExchangeRates {
er = exchangerates.NewBitcoinPriceFetcher(proxy)
}

wm, err := service.NewWalletService(cfg.DB, km, c, params, wi.Bitcoin, cache)
if err != nil {
Expand All @@ -67,7 +74,7 @@ func NewBitcoinWallet(cfg config.CoinConfig, mnemonic string, params *chaincfg.P

fp := spvwallet.NewFeeProvider(cfg.MaxFee, cfg.HighFee, cfg.MediumFee, cfg.LowFee, cfg.FeeAPI.String(), proxy)

return &BitcoinWallet{cfg.DB, km, params, c, wm, fp, mPrivKey, mPubKey}, nil
return &BitcoinWallet{cfg.DB, km, params, c, wm, fp, mPrivKey, mPubKey, er}, nil
}

func keyToAddress(key *hd.ExtendedKey, params *chaincfg.Params) (btc.Address, error) {
Expand Down Expand Up @@ -302,6 +309,10 @@ func (w *BitcoinWallet) Close() {
w.client.Close()
}

func (w *BitcoinWallet) ExchangeRates() wi.ExchangeRates {
return w.exchangeRates
}

func (w *BitcoinWallet) DumpTables(wr io.Writer) {
fmt.Fprintln(wr, "Transactions-----")
txns, _ := w.db.Txns().GetAll(true)
Expand Down
16 changes: 13 additions & 3 deletions bitcoincash/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ type BitcoinCashWallet struct {

mPrivKey *hd.ExtendedKey
mPubKey *hd.ExtendedKey

exchangeRates wi.ExchangeRates
}

func NewBitcoinCashWallet(cfg config.CoinConfig, mnemonic string, params *chaincfg.Params, proxy proxy.Dialer, cache cache.Cacher) (*BitcoinCashWallet, error) {
func NewBitcoinCashWallet(cfg config.CoinConfig, mnemonic string, params *chaincfg.Params, proxy proxy.Dialer, cache cache.Cacher, disableExchangeRates bool) (*BitcoinCashWallet, error) {
seed := bip39.NewSeed(mnemonic, "")

mPrivKey, err := hd.NewMaster(seed, params)
Expand All @@ -65,10 +67,14 @@ func NewBitcoinCashWallet(cfg config.CoinConfig, mnemonic string, params *chainc
if err != nil {
return nil, err
}
var exchangeRates wi.ExchangeRates
if !disableExchangeRates {
exchangeRates = er.NewBitcoinCashPriceFetcher(proxy)
}

fp := bcw.NewFeeProvider(cfg.MaxFee, cfg.HighFee, cfg.MediumFee, cfg.LowFee, er.NewBitcoinCashPriceFetcher(proxy))
fp := bcw.NewFeeProvider(cfg.MaxFee, cfg.HighFee, cfg.MediumFee, cfg.LowFee, exchangeRates)

return &BitcoinCashWallet{cfg.DB, km, params, c, wm, fp, mPrivKey, mPubKey}, nil
return &BitcoinCashWallet{cfg.DB, km, params, c, wm, fp, mPrivKey, mPubKey, exchangeRates}, nil
}

func bitcoinCashAddress(key *hd.ExtendedKey, params *chaincfg.Params) (btcutil.Address, error) {
Expand Down Expand Up @@ -315,6 +321,10 @@ func (w *BitcoinCashWallet) Close() {
w.client.Close()
}

func (w *BitcoinCashWallet) ExchangeRates() wi.ExchangeRates {
return w.exchangeRates
}

func (w *BitcoinCashWallet) DumpTables(wr io.Writer) {
fmt.Fprintln(wr, "Transactions-----")
txns, _ := w.db.Txns().GetAll(true)
Expand Down
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ type Config struct {

// A list of coin configs. One config should be included for each coin to be used.
Coins []CoinConfig

// Disable the exchange rate functionality in each wallet
DisableExchangeRates bool
}

type CoinConfig struct {
Expand Down
Loading