diff --git a/client/client.go b/client/client.go index f733ec1b8cdebd5cd1a48a648e181964e1a390be..81584b291dd296740a7d667e1c3d6f194cb71a15 100644 --- a/client/client.go +++ b/client/client.go @@ -26,10 +26,10 @@ import ( acc "github.com/eris-ltd/eris-db/account" consensus_types "github.com/eris-ltd/eris-db/consensus/types" + core_types "github.com/eris-ltd/eris-db/core/types" tendermint_client "github.com/eris-ltd/eris-db/rpc/tendermint/client" tendermint_types "github.com/eris-ltd/eris-db/rpc/tendermint/core/types" "github.com/eris-ltd/eris-db/txs" - core_types "github.com/eris-ltd/eris-db/core/types" ) type NodeClient interface { @@ -42,7 +42,7 @@ type NodeClient interface { QueryContract(callerAddress, calleeAddress, data []byte) (ret []byte, gasUsed int64, err error) QueryContractCode(address, code, data []byte) (ret []byte, gasUsed int64, err error) - DumpStorage(address []byte) (storage *core_types.Storage, err error) + DumpStorage(address []byte) (storage *core_types.Storage, err error) GetName(name string) (owner []byte, data string, expirationBlock int, err error) ListValidators() (blockHeight int, bondedValidators, unbondingValidators []consensus_types.Validator, err error) } @@ -107,7 +107,7 @@ func (erisNodeClient *ErisNodeClient) DeriveWebsocketClient() (nodeWsClient Node wsAddr = nodeAddr log.WithFields(log.Fields{ "websocket address": wsAddr, - "endpoint": "/websocket", + "endpoint": "/websocket", }).Debug("Subscribing to websocket address") wsClient := rpcclient.NewWSClient(wsAddr, "/websocket") if _, err = wsClient.Start(); err != nil { @@ -155,11 +155,11 @@ func (erisNodeClient *ErisNodeClient) ChainId() (ChainName, ChainId string, Gene ChainId = chainIdResult.ChainId GenesisHash = make([]byte, len(chainIdResult.GenesisHash)) copy(GenesisHash[:], chainIdResult.GenesisHash) - return + return } // QueryContract executes the contract code at address with the given data -// NOTE: there is no check on the caller; +// NOTE: there is no check on the caller; func (erisNodeClient *ErisNodeClient) QueryContract(callerAddress, calleeAddress, data []byte) (ret []byte, gasUsed int64, err error) { client := rpcclient.NewClientJSONRPC(erisNodeClient.broadcastRPC) callResult, err := tendermint_client.Call(client, callerAddress, calleeAddress, data) @@ -251,6 +251,5 @@ func (erisNodeClient *ErisNodeClient) ListValidators() (blockHeight int, blockHeight = validatorsResult.BlockHeight bondedValidators = validatorsResult.BondedValidators unbondingValidators = validatorsResult.UnbondingValidators - return + return } - diff --git a/client/cmd/status.go b/client/cmd/status.go index 376976300942b6af0d41fead8a5f1eb21ad052d0..5b29803d848fba681b028bcc0cae3cf969853968 100644 --- a/client/cmd/status.go +++ b/client/cmd/status.go @@ -23,8 +23,8 @@ import ( ) var StatusCmd = &cobra.Command{ - Use: "status", - Short: "eris-client status returns the current status from a chain.", + Use: "status", + Short: "eris-client status returns the current status from a chain.", Long: `eris-client status returns the current status from a chain. `, Run: func(cmd *cobra.Command, args []string) { @@ -33,7 +33,7 @@ var StatusCmd = &cobra.Command{ } func buildStatusCommand() { - addStatusPersistentFlags() + addStatusPersistentFlags() } func addStatusPersistentFlags() { diff --git a/client/core/transaction_factory.go b/client/core/transaction_factory.go index f1cd9daefbada90730fe9f43d3b13f2ccf8758a2..437d6d6900c7b714bb5a4a2236f2d10924f0c359 100644 --- a/client/core/transaction_factory.go +++ b/client/core/transaction_factory.go @@ -301,7 +301,7 @@ func SignAndBroadcast(chainID string, nodeClient client.NodeClient, keyClient ke return } log.Debug("Waiting for transaction to be confirmed.") - confirmation := <- confirmationChannel + confirmation := <-confirmationChannel if confirmation.Error != nil { log.Errorf("Encountered error waiting for event: %s\n", confirmation.Error) err = confirmation.Error diff --git a/client/methods/status.go b/client/methods/status.go index 2954fd1d283c759e24eabf66ed6499fd74ff397f..ba2470e7645ba0759445daed1042211c8f184401 100644 --- a/client/methods/status.go +++ b/client/methods/status.go @@ -25,7 +25,7 @@ import ( "github.com/eris-ltd/eris-db/definitions" ) -func Status(do *definitions.ClientDo) { +func Status(do *definitions.ClientDo) { erisNodeClient := client.NewErisNodeClient(do.NodeAddrFlag) genesisHash, validatorPublicKey, latestBlockHash, latestBlockHeight, latestBlockTime, err := erisNodeClient.Status() if err != nil { @@ -40,14 +40,14 @@ func Status(do *definitions.ClientDo) { } log.WithFields(log.Fields{ - "chain": do.NodeAddrFlag, - "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, + "chain": do.NodeAddrFlag, + "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") } diff --git a/client/mock/client_mock.go b/client/mock/client_mock.go index 89b22c5ccf76bb94b6cd5e0ee3a5d97ed0ceed9e..12cdd76cf9b15f9575898224889a1528eb8a58b7 100644 --- a/client/mock/client_mock.go +++ b/client/mock/client_mock.go @@ -19,10 +19,10 @@ package mock import ( "github.com/tendermint/go-crypto" - consensus_types "github.com/eris-ltd/eris-db/consensus/types" - core_types "github.com/eris-ltd/eris-db/core/types" acc "github.com/eris-ltd/eris-db/account" . "github.com/eris-ltd/eris-db/client" + consensus_types "github.com/eris-ltd/eris-db/consensus/types" + core_types "github.com/eris-ltd/eris-db/core/types" "github.com/eris-ltd/eris-db/txs" ) @@ -54,7 +54,6 @@ func (mock *MockNodeClient) DeriveWebsocketClient() (nodeWsClient NodeWebsocketC return nil, nil } - func (mock *MockNodeClient) GetAccount(address []byte) (*acc.Account, error) { // make zero account var zero [32]byte @@ -93,7 +92,6 @@ func (mock *MockNodeClient) Status() (ChainId []byte, return } - // QueryContract executes the contract code at address with the given data func (mock *MockNodeClient) QueryContract(callerAddress, calleeAddress, data []byte) (ret []byte, gasUsed int64, err error) { // return zero @@ -108,7 +106,6 @@ func (mock *MockNodeClient) QueryContractCode(address, code, data []byte) (ret [ return ret, 0, nil } - func (mock *MockNodeClient) DumpStorage(address []byte) (storage *core_types.Storage, err error) { return nil, nil } @@ -117,6 +114,6 @@ func (mock *MockNodeClient) GetName(name string) (owner []byte, data string, exp return nil, "", 0, nil } -func (mock *MockNodeClient) ListValidators() (blockHeight int, bondedValidators, unbondingValidators []consensus_types.Validator, err error){ +func (mock *MockNodeClient) ListValidators() (blockHeight int, bondedValidators, unbondingValidators []consensus_types.Validator, err error) { return 0, nil, nil, nil } diff --git a/client/websocket_client.go b/client/websocket_client.go index 41d795ccd87bde2f676d6bd37ae1f10e94c425fa..42f1bf37d384f999cb5d913cbf741124e71f1736 100644 --- a/client/websocket_client.go +++ b/client/websocket_client.go @@ -26,8 +26,8 @@ import ( log "github.com/eris-ltd/eris-logger" - "github.com/eris-ltd/eris-db/txs" ctypes "github.com/eris-ltd/eris-db/rpc/tendermint/core/types" + "github.com/eris-ltd/eris-db/txs" ) const ( @@ -64,7 +64,7 @@ func (erisNodeWebsocketClient *ErisNodeWebsocketClient) Unsubscribe(subscription // Returns a channel that will receive a confirmation with a result or the exception that // has been confirmed; or an error is returned and the confirmation channel is nil. func (erisNodeWebsocketClient *ErisNodeWebsocketClient) WaitForConfirmation(tx txs.Tx, chainId string, inputAddr []byte) (chan Confirmation, error) { - // check no errors are reported on the websocket + // check no errors are reported on the websocket if err := erisNodeWebsocketClient.assertNoErrors(); err != nil { return nil, err } @@ -84,7 +84,7 @@ func (erisNodeWebsocketClient *ErisNodeWebsocketClient) WaitForConfirmation(tx t go func() { var err error for { - resultBytes := <- erisNodeWebsocketClient.tendermintWebsocket.ResultsCh + resultBytes := <-erisNodeWebsocketClient.tendermintWebsocket.ResultsCh result := new(ctypes.ErisDBResult) if wire.ReadJSONPtr(result, resultBytes, &err); err != nil { // keep calm and carry on @@ -101,24 +101,24 @@ func (erisNodeWebsocketClient *ErisNodeWebsocketClient) WaitForConfirmation(tx t subscription.Event, subscription.SubscriptionId) continue } - + event, ok := (*result).(*ctypes.ResultEvent) if !ok { // keep calm and carry on - log.Errorf("[eris-client] Failed to cast to ResultEvent for websocket event: %s", *result) + log.Warnf("[eris-client] Failed to cast to ResultEvent for websocket event: %s", *result) continue } - + blockData, ok := event.Data.(txs.EventDataNewBlock) if ok { latestBlockHash = blockData.Block.Hash() log.WithFields(log.Fields{ - "new block": blockData.Block, + "new block": blockData.Block, "latest hash": latestBlockHash, }).Debug("Registered new block") continue } - + // we don't accept events unless they came after a new block (ie. in) if latestBlockHash == nil { log.Infof("[eris-client] no first block has been registered, so ignoring event: %s", event.Event) @@ -135,9 +135,9 @@ func (erisNodeWebsocketClient *ErisNodeWebsocketClient) WaitForConfirmation(tx t // We are on the lookout for EventDataTx confirmationChannel <- Confirmation{ BlockHash: latestBlockHash, - Event: nil, + Event: nil, Exception: fmt.Errorf("response error: expected result.Data to be *types.EventDataTx"), - Error: nil, + Error: nil, } return } @@ -153,18 +153,18 @@ func (erisNodeWebsocketClient *ErisNodeWebsocketClient) WaitForConfirmation(tx t if data.Exception != "" { confirmationChannel <- Confirmation{ BlockHash: latestBlockHash, - Event: &data, + Event: &data, Exception: fmt.Errorf("Transaction confirmed with exception:", data.Exception), - Error: nil, + Error: nil, } return } // success, return the full event and blockhash and exit go-routine confirmationChannel <- Confirmation{ BlockHash: latestBlockHash, - Event: &data, + Event: &data, Exception: nil, - Error: nil, + Error: nil, } return } @@ -176,12 +176,12 @@ func (erisNodeWebsocketClient *ErisNodeWebsocketClient) WaitForConfirmation(tx t timeout := time.After(time.Duration(MaxCommitWaitTimeSeconds) * time.Second) go func() { - <- timeout + <-timeout confirmationChannel <- Confirmation{ BlockHash: nil, - Event: nil, + Event: nil, Exception: nil, - Error: fmt.Errorf("timed out waiting for event"), + Error: fmt.Errorf("timed out waiting for event"), } return }() @@ -205,4 +205,4 @@ func (erisNodeWebsocketClient *ErisNodeWebsocketClient) assertNoErrors() error { } else { return fmt.Errorf("Eris-client has no websocket initialised.") } -} \ No newline at end of file +}