From 923b5b86c7c322dd1c3771c48a822e7c8ee53b65 Mon Sep 17 00:00:00 2001 From: Chris Pacia Date: Mon, 17 Sep 2018 13:31:45 -0400 Subject: [PATCH] Merge master --- api/rpc.go | 4 ++-- client/client_test.go | 12 +++++------- config/config.go | 33 ++++++++++++++++++++++++++++++--- datastore/mock.go | 7 +++++++ multiwallet.go | 7 +++++++ 5 files changed, 51 insertions(+), 12 deletions(-) diff --git a/api/rpc.go b/api/rpc.go index 9e709e2..8c0687e 100644 --- a/api/rpc.go +++ b/api/rpc.go @@ -6,14 +6,14 @@ import ( "github.com/OpenBazaar/multiwallet/api/pb" "github.com/OpenBazaar/multiwallet/bitcoin" "github.com/OpenBazaar/multiwallet/bitcoincash" + "github.com/OpenBazaar/multiwallet/litecoin" + "github.com/OpenBazaar/multiwallet/zcash" "github.com/OpenBazaar/wallet-interface" "github.com/btcsuite/btcutil" "golang.org/x/net/context" "google.golang.org/grpc" "google.golang.org/grpc/reflection" "net" - "github.com/OpenBazaar/multiwallet/litecoin" - "github.com/OpenBazaar/multiwallet/zcash" ) const Addr = "127.0.0.1:8234" diff --git a/client/client_test.go b/client/client_test.go index cb8e08d..c60ab4f 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -8,11 +8,12 @@ import ( "testing" "time" + "sync" + "github.com/OpenBazaar/golang-socketio" "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcutil" "gopkg.in/jarcoal/httpmock.v1" - "sync" ) func NewTestClient() *InsightClient { @@ -413,17 +414,14 @@ func TestInsightClient_Broadcast(t *testing.T) { setup() defer teardown() - type Txid struct { - Result string `json:"result"` - } type Response struct { - Txid Txid `json:"txid"` + Txid string `json:"txid"` } var ( c = NewTestClient() testPath = fmt.Sprintf("http://%s/tx/send", c.apiUrl.Host) - expected = Response{Txid{"1be612e4f2b79af279e0b307337924072b819b3aca09fcb20370dd9492b83428"}} + expected = Response{"1be612e4f2b79af279e0b307337924072b819b3aca09fcb20370dd9492b83428"} ) response, err := httpmock.NewJsonResponse(http.StatusOK, expected) @@ -441,7 +439,7 @@ func TestInsightClient_Broadcast(t *testing.T) { if err != nil { t.Error(err) } - if id != expected.Txid.Result { + if id != expected.Txid { t.Error("Returned incorrect txid") } } diff --git a/config/config.go b/config/config.go index 2224b08..0fbadf9 100644 --- a/config/config.go +++ b/config/config.go @@ -1,15 +1,16 @@ package config import ( + "net/url" + "os" + "time" + "github.com/OpenBazaar/multiwallet/cache" "github.com/OpenBazaar/multiwallet/datastore" "github.com/OpenBazaar/wallet-interface" "github.com/btcsuite/btcd/chaincfg" "github.com/op/go-logging" "golang.org/x/net/proxy" - "net/url" - "os" - "time" ) type Config struct { @@ -161,5 +162,31 @@ func NewDefaultConfig(coinTypes map[wallet.CoinType]bool, params *chaincfg.Param } cfg.Coins = append(cfg.Coins, ltcCfg) } + if coinTypes[wallet.Ethereum] { + var apiEndpoint string + if !testnet { + apiEndpoint = "https://rinkeby.infura.io" + } else { + apiEndpoint = "https://rinkeby.infura.io" + } + clientApi, _ := url.Parse(apiEndpoint) + db, _ := mockDB.GetDatastoreForWallet(wallet.Ethereum) + ethCfg := CoinConfig{ + CoinType: wallet.Ethereum, + FeeAPI: url.URL{}, + LowFee: 140, + MediumFee: 160, + HighFee: 180, + MaxFee: 2000, + ClientAPI: *clientApi, + DB: db, + Options: map[string]interface{}{ + "RegistryAddress": "0xab8dd0e05b73529b440d9c9df00b5f490c8596ff", + "RinkebyRegistryAddress": "0xab8dd0e05b73529b440d9c9df00b5f490c8596ff", + "RopstenRegistryAddress": "0x029d6a0cd4ce98315690f4ea52945545d9c0f460", + }, + } + cfg.Coins = append(cfg.Coins, ethCfg) + } return cfg } diff --git a/datastore/mock.go b/datastore/mock.go index 1f5ef8c..8c66e27 100644 --- a/datastore/mock.go +++ b/datastore/mock.go @@ -67,6 +67,13 @@ func NewMockMultiwalletDatastore() *MockMultiwalletDatastore { &MockTxnStore{txns: make(map[string]*txnStoreEntry)}, &MockWatchedScriptsStore{scripts: make(map[string][]byte)}, }) + db[wallet.Ethereum] = wallet.Datastore(&MockDatastore{ + &MockKeyStore{Keys: make(map[string]*KeyStoreEntry)}, + &MockUtxoStore{utxos: make(map[string]*wallet.Utxo)}, + &MockStxoStore{stxos: make(map[string]*wallet.Stxo)}, + &MockTxnStore{txns: make(map[string]*txnStoreEntry)}, + &MockWatchedScriptsStore{scripts: make(map[string][]byte)}, + }) return &MockMultiwalletDatastore{db: db} } diff --git a/multiwallet.go b/multiwallet.go index 9ef2d2f..2a16dce 100644 --- a/multiwallet.go +++ b/multiwallet.go @@ -5,6 +5,7 @@ import ( "strings" "time" + eth "github.com/OpenBazaar/go-ethwallet/wallet" "github.com/OpenBazaar/multiwallet/bitcoin" "github.com/OpenBazaar/multiwallet/bitcoincash" "github.com/OpenBazaar/multiwallet/client" @@ -87,6 +88,12 @@ func NewMultiWallet(cfg *config.Config) (MultiWallet, error) { } else { multiwallet[wallet.TestnetLitecoin] = w } + case wallet.Ethereum: + w, err = eth.NewEthereumWallet(coin, cfg.Mnemonic) + if err != nil { + return nil, err + } + multiwallet[coin.CoinType] = w } } return multiwallet, nil