diff --git a/client/client.go b/client/client.go index d131f510b8af05ee34f0566500bf377e97b1cceb..be06862e96171411a698c4df40571f698af74dee 100644 --- a/client/client.go +++ b/client/client.go @@ -23,6 +23,7 @@ import ( "github.com/eris-ltd/eris-db/account" tendermint_client "github.com/eris-ltd/eris-db/rpc/tendermint/client" + rpc_types "github.com/eris-ltd/eris-db/rpc/tendermint/core/types" "github.com/eris-ltd/eris-db/txs" ) @@ -30,6 +31,8 @@ type NodeClient interface { Broadcast(transaction txs.Tx) (*txs.Receipt, error) GetAccount(address []byte) (*account.Account, error) + + Status() (*rpc_types.ResultStatus, error) } // NOTE [ben] Compiler check to ensure ErisClient successfully implements @@ -80,3 +83,13 @@ func (erisClient *ErisNodeClient) GetAccount(address []byte) (*account.Account, return account.Copy(), nil } + +func (erisClient *ErisNodeClient) Status() (*rpc_types.ResultStatus, error) { + client := rpcclient.NewClientURI(erisClient.broadcastRPC) + res, err := tendermint_client.Status(client) + if err != nil { + err = fmt.Errorf("Error connecting to node (%s) to get status: %s", + erisClient.broadcastRPC, err.Error()) + return nil, err + } +} diff --git a/client/core/transaction_factory_test.go b/client/core/transaction_factory_test.go index aa492b986d1bb70a525422b1d83f944118183b0c..f480fcaf57d68df6f1e99bfcc69977b1f7b7958b 100644 --- a/client/core/transaction_factory_test.go +++ b/client/core/transaction_factory_test.go @@ -150,4 +150,4 @@ func testTransactionFactoryPermissions(t *testing.T, t.Fail() } // TODO: test content of Transaction -} \ No newline at end of file +} diff --git a/client/core/transaction_factory_util.go b/client/core/transaction_factory_util.go index b5ed8250b4fc3affe355c85ac4d799c5f0086af6..6178da75f3b1a738117e6a24fbd41e3a8372e35e 100644 --- a/client/core/transaction_factory_util.go +++ b/client/core/transaction_factory_util.go @@ -170,4 +170,4 @@ func checkCommon(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey, } return -} \ No newline at end of file +} diff --git a/client/mock/client_mock.go b/client/mock/client_mock.go index 0fc7e576753a3d123650e99ea27f0b839a47bdec..0b71e303301d71720c77e751d9097a2f3a5fc402 100644 --- a/client/mock/client_mock.go +++ b/client/mock/client_mock.go @@ -18,6 +18,7 @@ package mock import ( "github.com/tendermint/go-crypto" + "github.com/tendermint/go-p2p" acc "github.com/eris-ltd/eris-db/account" . "github.com/eris-ltd/eris-db/client" @@ -68,3 +69,29 @@ func (mock *MockNodeClient) MockAddAccount(account *acc.Account) { addressString := string(account.Address[:]) mock.accounts[addressString] = account.Copy() } + +func (mock *MockNodeClient) Status() (*rpc_types.ResultStatus, error) { + // make zero account + var zero [32]byte + pub := crypto.PubKey(crypto.PubKeyEd25519(zero)) + + // create a status + nodeInfo := &p2p.NodeInfo{ + PubKey: pub, + Moniker: "Mock", + Network: "MockNet", + RemoteAddr: "127.0.0.1", + ListenAddr: "127.0.0.1", + Version: "0.12.0", + Other: []string{}, + } + + return &rpc_types.ResultStatus{ + NodeInfo: nodeInfo, + GenesisHash: nil, + PubKey: pub, + LatestBlockHash: nil, + LatestBlockHeight: 1, + LatestBlockTime: 1, + } +}