Skip to content

Commit

Permalink
Move ExchangeRate impl inside wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
cpacia committed Sep 19, 2018
1 parent 3a0ea7e commit 479de36
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 1 addition & 4 deletions cmd/spvwallet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/OpenBazaar/spvwallet/api"
"github.com/OpenBazaar/spvwallet/cli"
"github.com/OpenBazaar/spvwallet/db"
"github.com/OpenBazaar/spvwallet/exchangerates"
"github.com/OpenBazaar/spvwallet/gui"
"github.com/OpenBazaar/spvwallet/gui/bootstrap"
wi "github.com/OpenBazaar/wallet-interface"
Expand Down Expand Up @@ -304,8 +303,6 @@ func (x *Start) Execute(args []string) error {
if x.Gui {
go wallet.Start()

exchangeRates := exchangerates.NewBitcoinPriceFetcher(nil)

type Stats struct {
Confirmed int64 `json:"confirmed"`
Fiat string `json:"fiat"`
Expand Down Expand Up @@ -366,7 +363,7 @@ func (x *Start) Execute(args []string) error {
astilog.Errorf(err.Error())
return
}
rate, err := exchangeRates.GetExchangeRate(p.CurrencyCode)
rate, err := wallet.ExchangeRates().GetExchangeRate(p.CurrencyCode)
if err != nil {
astilog.Errorf("Failed to get exchange rate")
return
Expand Down
9 changes: 9 additions & 0 deletions wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"io"
"sync"
"time"
"github.com/OpenBazaar/spvwallet/exchangerates"
)

type SPVWallet struct {
Expand Down Expand Up @@ -45,6 +46,8 @@ type SPVWallet struct {
running bool

config *PeerManagerConfig

exchangeRates wallet.ExchangeRates
}

var log = logging.MustGetLogger("bitcoin")
Expand Down Expand Up @@ -77,6 +80,7 @@ func NewSPVWallet(config *Config) (*SPVWallet, error) {
if err != nil {
return nil, err
}
er := exchangerates.NewBitcoinPriceFetcher(config.Proxy)
w := &SPVWallet{
repoPath: config.RepoPath,
masterPrivateKey: mPrivKey,
Expand All @@ -95,6 +99,7 @@ func NewSPVWallet(config *Config) (*SPVWallet, error) {
fPositives: make(chan *peer.Peer),
fpAccumulator: make(map[int32]int32),
mutex: new(sync.RWMutex),
exchangeRates: er,
}

w.keyManager, err = NewKeyManager(config.DB.Keys(), w.params, w.masterPrivateKey)
Expand Down Expand Up @@ -432,3 +437,7 @@ func (w *SPVWallet) ReSyncBlockchain(fromDate time.Time) {
w.txstore.PopulateAdrs()
w.wireService.Resync()
}

func (w *SPVWallet) ExchangeRates() wallet.ExchangeRates {
return w.exchangeRates
}

0 comments on commit 479de36

Please sign in to comment.