From 7fbac989afc87af8d62dedfa6158144aecb64f80 Mon Sep 17 00:00:00 2001 From: Benjamin Bollen <ben@erisindustries.com> Date: Tue, 27 Sep 2016 14:44:16 +0200 Subject: [PATCH] client: complete rpc chainId for chainname, chainid, and genesisHash --- client/client.go | 2 +- client/core/transaction_factory.go | 8 +++----- client/core/transaction_factory_test.go | 3 +++ client/methods/status.go | 18 ++++++++++++++---- definitions/tendermint_pipe.go | 1 + manager/eris-mint/pipe.go | 4 ++-- rpc/tendermint/client/client.go | 2 +- rpc/tendermint/core/types/responses.go | 2 +- 8 files changed, 26 insertions(+), 14 deletions(-) diff --git a/client/client.go b/client/client.go index 24a1384a..16588f53 100644 --- a/client/client.go +++ b/client/client.go @@ -100,7 +100,7 @@ func (erisNodeClient *ErisNodeClient) Status() (GenesisHash []byte, ValidatorPub func (erisNodeClient *ErisNodeClient) ChainId() (ChainName, ChainId string, GenesisHash []byte, err error) { client := rpcclient.NewClientJSONRPC(erisNodeClient.broadcastRPC) - chainIdResult, err := tendermint_client.ChainId() + chainIdResult, err := tendermint_client.ChainId(client) if err != nil { err = fmt.Errorf("Error connecting to node (%s) to get chain id: %s", erisNodeClient.broadcastRPC, err.Error()) diff --git a/client/core/transaction_factory.go b/client/core/transaction_factory.go index af1bcd00..e631144c 100644 --- a/client/core/transaction_factory.go +++ b/client/core/transaction_factory.go @@ -22,11 +22,11 @@ import ( "strconv" // "strings" // "time" + log "github.com/eris-ltd/eris-logger" ptypes "github.com/eris-ltd/eris-db/permission/types" - // log "github.com/eris-ltd/eris-logger" - + "github.com/eris-ltd/eris-db/account" "github.com/eris-ltd/eris-db/client" "github.com/eris-ltd/eris-db/keys" "github.com/eris-ltd/eris-db/txs" @@ -281,9 +281,7 @@ func SignAndBroadcast(chainID string, nodeClient client.NodeClient, keyClient ke return nil, err } log.WithFields(log.Fields{ - "transaction sign bytes": fmt.Sprintf("%X", signBytes), - "account address": fmt.Sprintf("%X", inputAddr), - "signature": fmt.Sprintf("%X", sig64), + "transaction": string(account.SignBytes(chainID, tx)), }).Debug("Signed transaction") } diff --git a/client/core/transaction_factory_test.go b/client/core/transaction_factory_test.go index f480fcaf..4544655e 100644 --- a/client/core/transaction_factory_test.go +++ b/client/core/transaction_factory_test.go @@ -20,6 +20,8 @@ import ( "fmt" "testing" + // "github.com/stretchr/testify/assert" + mockclient "github.com/eris-ltd/eris-db/client/mock" mockkeys "github.com/eris-ltd/eris-db/keys/mock" ) @@ -60,6 +62,7 @@ func testTransactionFactorySend(t *testing.T, t.Logf("Error in SendTx: %s", err) t.Fail() } + // assert.NotEqual(t, txSend) // TODO: test content of Transaction } diff --git a/client/methods/status.go b/client/methods/status.go index 63046f6d..2954fd1d 100644 --- a/client/methods/status.go +++ b/client/methods/status.go @@ -27,17 +27,27 @@ import ( func Status(do *definitions.ClientDo) { erisNodeClient := client.NewErisNodeClient(do.NodeAddrFlag) - chainId, validatorPublicKey, latestBlockHash, latestBlockHeight, latestBlockTime, err := erisNodeClient.Status() + genesisHash, validatorPublicKey, latestBlockHash, latestBlockHeight, latestBlockTime, err := erisNodeClient.Status() if err != nil { log.Errorf("Error requesting status from chain at (%s): %s", do.NodeAddrFlag, err) return - } + } + + chainName, chainId, genesisHashfromChainId, err := erisNodeClient.ChainId() + if err != nil { + log.Errorf("Error requesting chainId from chain at (%s): %s", do.NodeAddrFlag, err) + return + } + log.WithFields(log.Fields{ "chain": do.NodeAddrFlag, - "chainid": fmt.Sprintf("%X", chainId), + "genesisHash": fmt.Sprintf("%X", genesisHash), + "chainName": chainName, + "chainId": chainId, + "genesisHash from chainId":fmt.Sprintf("%X", genesisHashfromChainId), "validator public key": fmt.Sprintf("%X", validatorPublicKey), "latest block hash": fmt.Sprintf("%X", latestBlockHash), "latest block height": latestBlockHeight, "latest block time": latestBlockTime, }).Info("status") -} \ No newline at end of file +} diff --git a/definitions/tendermint_pipe.go b/definitions/tendermint_pipe.go index 37973ce4..e933194d 100644 --- a/definitions/tendermint_pipe.go +++ b/definitions/tendermint_pipe.go @@ -41,6 +41,7 @@ type TendermintPipe interface { Status() (*rpc_tm_types.ResultStatus, error) NetInfo() (*rpc_tm_types.ResultNetInfo, error) Genesis() (*rpc_tm_types.ResultGenesis, error) + ChainId() (*rpc_tm_types.ResultChainId, error) // Accounts GetAccount(address []byte) (*rpc_tm_types.ResultGetAccount, error) diff --git a/manager/eris-mint/pipe.go b/manager/eris-mint/pipe.go index e38592b6..b8cc00c6 100644 --- a/manager/eris-mint/pipe.go +++ b/manager/eris-mint/pipe.go @@ -311,13 +311,13 @@ func (pipe *erisMintPipe) ChainId() (*rpc_tm_types.ResultChainId, error) { if pipe.blockchain == nil { return nil, fmt.Errorf("Blockchain not initialised in Erismint pipe.") } - chainId := pipe.blockchain().ChainId() + chainId := pipe.blockchain.ChainId() return &rpc_tm_types.ResultChainId{ ChainName: chainId, // MARMOT: copy ChainId for ChainName as a placehodlder ChainId: chainId, GenesisHash: pipe.GenesisHash(), - } + }, nil } func (pipe *erisMintPipe) NetInfo() (*rpc_tm_types.ResultNetInfo, error) { diff --git a/rpc/tendermint/client/client.go b/rpc/tendermint/client/client.go index 2de60d1a..3da5a128 100644 --- a/rpc/tendermint/client/client.go +++ b/rpc/tendermint/client/client.go @@ -20,7 +20,7 @@ func Status(client rpcclient.Client) (*rpc_types.ResultStatus, error) { return res.(*rpc_types.ResultStatus), nil } -func ChainId(client rpcclient.Client) (*rpc_types.ResultChainId) { +func ChainId(client rpcclient.Client) (*rpc_types.ResultChainId, error) { res, err := performCall(client, "chain_id") if err != nil { return nil, err diff --git a/rpc/tendermint/core/types/responses.go b/rpc/tendermint/core/types/responses.go index 304fe38b..daa053e6 100644 --- a/rpc/tendermint/core/types/responses.go +++ b/rpc/tendermint/core/types/responses.go @@ -62,7 +62,7 @@ type ResultStatus struct { type ResultChainId struct { ChainName string `json:"chain_name"` - ChainID string `json:"chain_id"` + ChainId string `json:"chain_id"` GenesisHash []byte `json:"genesis_hash"` } -- GitLab