diff --git a/client/core/transaction_factory.go b/client/core/transaction_factory.go index 15dd140b11a52e299fb9eb85060e5ff8f72e63f0..f1cd9daefbada90730fe9f43d3b13f2ccf8758a2 100644 --- a/client/core/transaction_factory.go +++ b/client/core/transaction_factory.go @@ -306,16 +306,21 @@ func SignAndBroadcast(chainID string, nodeClient client.NodeClient, keyClient ke log.Errorf("Encountered error waiting for event: %s\n", confirmation.Error) err = confirmation.Error return - } - eventDataTx, ok := confirmation.Event.(txs.EventDataTx) + } + if confirmation.Exception != nil { + log.Errorf("Encountered Exception from chain w: %s\n", confirmation.Error) + err = confirmation.Exception + return + } + txResult.BlockHash = confirmation.BlockHash + txResult.Exception = "" + eventDataTx, ok := confirmation.Event.(*txs.EventDataTx) if !ok { log.Errorf("Received wrong event type.") err = fmt.Errorf("Received wrong event type.") return } - txResult.BlockHash = confirmation.BlockHash txResult.Return = eventDataTx.Return - txResult.Exception = confirmation.Exception.Error() }() } } diff --git a/client/websocket_client.go b/client/websocket_client.go index 627de09986b953e612eb7422c5930f8c0db24c9a..41d795ccd87bde2f676d6bd37ae1f10e94c425fa 100644 --- a/client/websocket_client.go +++ b/client/websocket_client.go @@ -74,7 +74,12 @@ func (erisNodeWebsocketClient *ErisNodeWebsocketClient) WaitForConfirmation(tx t var latestBlockHash []byte eid := txs.EventStringAccInput(inputAddr) - + if err := erisNodeWebsocketClient.tendermintWebsocket.Subscribe(eid); err != nil { + return nil, fmt.Errorf("Error subscribing to AccInput event (%s): %v", eid, err) + } + if err := erisNodeWebsocketClient.tendermintWebsocket.Subscribe(txs.EventStringNewBlock()); err != nil { + return nil, fmt.Errorf("Error subscribing to NewBlock event: %v", err) + } // Read the incoming events go func() { var err error @@ -83,14 +88,24 @@ func (erisNodeWebsocketClient *ErisNodeWebsocketClient) WaitForConfirmation(tx t result := new(ctypes.ErisDBResult) if wire.ReadJSONPtr(result, resultBytes, &err); err != nil { // keep calm and carry on - log.Errorf("eris-client - Failed to unmarshal json bytes for websocket event: %s", err) + log.Errorf("[eris-client] Failed to unmarshal json bytes for websocket event: %s", err) + continue + } + + subscription, ok := (*result).(*ctypes.ResultSubscribe) + if ok { + // Received confirmation of subscription to event streams + // TODO: collect subscription IDs, push into channel and on completion + // unsubscribe + log.Infof("[eris-client] recceived confirmation for event (%s) with subscription id (%s).", + subscription.Event, subscription.SubscriptionId) continue } event, ok := (*result).(*ctypes.ResultEvent) if !ok { // keep calm and carry on - log.Error("eris-client - Failed to cast to ResultEvent for websocket event") + log.Errorf("[eris-client] Failed to cast to ResultEvent for websocket event: %s", *result) continue } @@ -106,11 +121,12 @@ func (erisNodeWebsocketClient *ErisNodeWebsocketClient) WaitForConfirmation(tx t // 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) continue } if event.Event != eid { - log.Warnf("Received unsolicited event! Got %s, expected %s\n", event.Event, eid) + log.Warnf("[eris-client] received unsolicited event! Got %s, expected %s\n", event.Event, eid) continue } @@ -143,7 +159,6 @@ func (erisNodeWebsocketClient *ErisNodeWebsocketClient) WaitForConfirmation(tx t } return } - // success, return the full event and blockhash and exit go-routine confirmationChannel <- Confirmation{ BlockHash: latestBlockHash,