Skip to content
Snippets Groups Projects
Unverified Commit f819a37a authored by Benjamin Bollen's avatar Benjamin Bollen
Browse files

client: further assertion on eris-client tx send

parent 604f1e65
No related branches found
No related tags found
No related merge requests found
...@@ -31,7 +31,6 @@ import ( ...@@ -31,7 +31,6 @@ import (
"github.com/tendermint/go-rpc/client" "github.com/tendermint/go-rpc/client"
// ptypes "github.com/eris-ltd/permission/types" // ptypes "github.com/eris-ltd/permission/types"
// cclient "github.com/eris-ltd/tendermint/rpc/client"
log "github.com/eris-ltd/eris-logger" log "github.com/eris-ltd/eris-logger"
...@@ -315,7 +314,7 @@ func Pub(addr, rpcAddr string) (pubBytes []byte, err error) { ...@@ -315,7 +314,7 @@ func Pub(addr, rpcAddr string) (pubBytes []byte, err error) {
func Sign(signBytes, signAddr, signRPC string) (sig [64]byte, err error) { func Sign(signBytes, signAddr, signRPC string) (sig [64]byte, err error) {
args := map[string]string{ args := map[string]string{
"msg": signBytes, "msg": signBytes,
"hash": signBytes, // backwards compatibility "hash": signBytes, // TODO:[ben] backwards compatibility
"addr": signAddr, "addr": signAddr,
} }
sigS, err := RequestResponse(signRPC, "sign", args) sigS, err := RequestResponse(signRPC, "sign", args)
...@@ -484,7 +483,9 @@ func SignAndBroadcast(chainID, nodeAddr, signAddr string, tx txs.Tx, sign, broad ...@@ -484,7 +483,9 @@ func SignAndBroadcast(chainID, nodeAddr, signAddr string, tx txs.Tx, sign, broad
// // if broadcast threw an error, just return // // if broadcast threw an error, just return
// return // return
// } // }
// logger.Debugln("Waiting for tx to be committed ...") // log.WithFields(log.Fields{
// "",
// }).Debug("Waiting for tx to be committed")
// msg := <-ch // msg := <-ch
// if msg.Error != nil { // if msg.Error != nil {
// logger.Infof("Encountered error waiting for event: %v\n", msg.Error) // logger.Infof("Encountered error waiting for event: %v\n", msg.Error)
...@@ -506,8 +507,8 @@ func SignAndBroadcast(chainID, nodeAddr, signAddr string, tx txs.Tx, sign, broad ...@@ -506,8 +507,8 @@ func SignAndBroadcast(chainID, nodeAddr, signAddr string, tx txs.Tx, sign, broad
Hash: receipt.TxHash, Hash: receipt.TxHash,
} }
// NOTE: [ben] is this consistent with the Ethereum protocol? It should seem // NOTE: [ben] is this consistent with the Ethereum protocol? It should seem
// reasonable to get this returned from the chain directly. The returned benefit // reasonable to get this returned from the chain directly. Alternatively,
// is that the we don't need to trust the chain node // the benefit is that the we don't need to trust the chain node
if tx_, ok := tx.(*txs.CallTx); ok { if tx_, ok := tx.(*txs.CallTx); ok {
if len(tx_.Address) == 0 { if len(tx_.Address) == 0 {
txResult.Address = txs.NewContractAddress(tx_.Input.Address, tx_.Input.Sequence) txResult.Address = txs.NewContractAddress(tx_.Input.Address, tx_.Input.Sequence)
...@@ -517,28 +518,43 @@ func SignAndBroadcast(chainID, nodeAddr, signAddr string, tx txs.Tx, sign, broad ...@@ -517,28 +518,43 @@ func SignAndBroadcast(chainID, nodeAddr, signAddr string, tx txs.Tx, sign, broad
return return
} }
// //------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// // wait for events // wait for events
// type Msg struct { type Msg struct {
// BlockHash []byte BlockHash []byte
// Value []byte Value []byte
// Exception string Exception string
// Error error Error error
// } }
// func subscribeAndWait(tx types.Tx, chainID, nodeAddr string, inputAddr []byte) (chan Msg, error) { // func subscribeAndWait(tx txs.Tx, chainID, nodeAddr string, inputAddr []byte) (chan Msg, error) {
// // subscribe to event and wait for tx to be committed // // subscribe to event and wait for tx to be committed
// wsAddr := strings.TrimPrefix(nodeAddr, "http://") // var wsAddr string
// wsAddr = "ws://" + wsAddr + "websocket" // if strings.HasPrefix(nodeAddr, "http://") {
// logger.Debugf("Websocket Address %s\n", wsAddr) // wsAddr = strings.TrimPrefix(nodeAddr, "http://")
// wsClient := cclient.NewWSClient(wsAddr) // }
// if strings.HasPrefix(nodeAddr, "tcp://") {
// wsAddr = strings.TrimPrefix(nodeAddr, "tcp://")
// }
// if strings.HasPrefix(nodeAddr, "unix://") {
// log.WithFields(log.Fields{
// "node address": nodeAddr,
// }).Warn("Unable to subscribe to websocket from unix socket.")
// return nil, fmt.Errorf("Unable to subscribe to websocket from unix socket: %s", nodeAddr)
// }
// wsAddr = "ws://" + wsAddr
// log.WithFields(log.Fields{
// "websocket address": wsAddr,
// "endpoint": "/websocket",
// }).Debug("Subscribing to websocket address")
// wsClient := rpcclient.NewWSClient(wsAddr, "/websocket")
// wsClient.Start() // wsClient.Start()
// eid := types.EventStringAccInput(inputAddr) // eid := txs.EventStringAccInput(inputAddr)
// if err := wsClient.Subscribe(eid); err != nil { // if err := wsClient.Subscribe(eid); err != nil {
// return nil, fmt.Errorf("Error subscribing to AccInput event: %v", err) // return nil, fmt.Errorf("Error subscribing to AccInput event: %v", err)
// } // }
// if err := wsClient.Subscribe(types.EventStringNewBlock()); err != nil { // if err := wsClient.Subscribe(txs.EventStringNewBlock()); err != nil {
// return nil, fmt.Errorf("Error subscribing to NewBlock event: %v", err) // return nil, fmt.Errorf("Error subscribing to NewBlock event: %v", err)
// } // }
...@@ -551,9 +567,9 @@ func SignAndBroadcast(chainID, nodeAddr, signAddr string, tx txs.Tx, sign, broad ...@@ -551,9 +567,9 @@ func SignAndBroadcast(chainID, nodeAddr, signAddr string, tx txs.Tx, sign, broad
// for { // for {
// result := <-wsClient.EventsCh // result := <-wsClient.EventsCh
// // if its a block, remember the block hash // // if its a block, remember the block hash
// blockData, ok := result.Data.(types.EventDataNewBlock) // blockData, ok := result.Data.(txs.EventDataNewBlock)
// if ok { // if ok {
// logger.Infoln(blockData.Block) // log.Infoln(blockData.Block)
// latestBlockHash = blockData.Block.Hash() // latestBlockHash = blockData.Block.Hash()
// continue // continue
// } // }
...@@ -653,16 +669,12 @@ func checkCommon(nodeAddr, signAddr, pubkey, addr, amtS, nonceS string) (pub cry ...@@ -653,16 +669,12 @@ func checkCommon(nodeAddr, signAddr, pubkey, addr, amtS, nonceS string) (pub cry
if nonceS == "" { if nonceS == "" {
if nodeAddr == "" { if nodeAddr == "" {
err = fmt.Errorf("input must specify a nonce with the --nonce flag or use --node-addr (or MINTX_NODE_ADDR) to fetch the nonce from a node") err = fmt.Errorf("input must specify a nonce with the --nonce flag or use --node-addr (or ERIS_CLIENT_NODE_ADDR) to fetch the nonce from a node")
return return
} }
// fetch nonce from node // fetch nonce from node
client := rpcclient.NewClientURI(nodeAddr) client := rpcclient.NewClientURI(nodeAddr)
log.WithFields(log.Fields{
"node address": nodeAddr,
"account address": fmt.Sprintf("%X", addrBytes),
}).Debug("Fetch nonce from node")
account, err2 := tendermint_client.GetAccount(client, addrBytes) account, err2 := tendermint_client.GetAccount(client, addrBytes)
if err2 != nil { if err2 != nil {
err = fmt.Errorf("Error connecting to node (%s) to fetch nonce: %s", nodeAddr, err2.Error()) err = fmt.Errorf("Error connecting to node (%s) to fetch nonce: %s", nodeAddr, err2.Error())
...@@ -673,6 +685,11 @@ func checkCommon(nodeAddr, signAddr, pubkey, addr, amtS, nonceS string) (pub cry ...@@ -673,6 +685,11 @@ func checkCommon(nodeAddr, signAddr, pubkey, addr, amtS, nonceS string) (pub cry
return return
} }
nonce = int64(account.Sequence) + 1 nonce = int64(account.Sequence) + 1
log.WithFields(log.Fields{
"nonce": nonce,
"node address": nodeAddr,
"account address": fmt.Sprintf("%X", addrBytes),
}).Debug("Fetch nonce from node")
} else { } else {
nonce, err = strconv.ParseInt(nonceS, 10, 64) nonce, err = strconv.ParseInt(nonceS, 10, 64)
if err != nil { if err != nil {
......
...@@ -17,8 +17,9 @@ ...@@ -17,8 +17,9 @@
package transaction package transaction
import ( import (
// "fmt" "fmt"
// "io/ioutil" // "io/ioutil"
"os"
log "github.com/eris-ltd/eris-logger" log "github.com/eris-ltd/eris-logger"
...@@ -32,7 +33,33 @@ func Send(do *definitions.ClientDo) { ...@@ -32,7 +33,33 @@ func Send(do *definitions.ClientDo) {
if err != nil { if err != nil {
log.Fatalf("Failed on Send Transaction: %s", err) log.Fatalf("Failed on Send Transaction: %s", err)
} }
// unpackSignAndBroadcast( unpackSignAndBroadcast(
core.SignAndBroadcast(do.ChainidFlag, do.NodeAddrFlag, core.SignAndBroadcast(do.ChainidFlag, do.NodeAddrFlag,
do.SignAddrFlag, sendTransaction, true, do.BroadcastFlag, do.WaitFlag)//) do.SignAddrFlag, sendTransaction, true, do.BroadcastFlag, do.WaitFlag))
} }
\ No newline at end of file
//----------------------------------------------------------------------
// Helper functions
func unpackSignAndBroadcast(result *core.TxResult, err error) {
if err != nil {
log.Fatalf("Failed on signing (and broadcasting) transaction: %s", err)
os.Exit(1)
}
if result == nil {
// if we don't provide --sign or --broadcast
return
}
printResult := log.Fields {
"transaction hash": fmt.Sprintf("%X", result.Hash),
}
if result.Address != nil {
printResult["Contract Address"] = fmt.Sprintf("%X", result.Address)
}
if result.Return != nil {
printResult["Block Hash"] = fmt.Sprintf("%X", result.BlockHash)
printResult["Return Value"] = fmt.Sprintf("%X", result.Return)
printResult["Exception"] = fmt.Sprintf("%s", result.Exception)
}
log.WithFields(printResult).Warn("Result")
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment