From 72b681a1bcc79157e42376da5826baacb79874d5 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Fri, 10 Jul 2015 05:56:38 +0000 Subject: [PATCH] fix TxID to use ripemd160 in events and rpc return --- rpc/core/mempool.go | 2 +- rpc/test/client_ws_test.go | 3 +-- rpc/test/tests.go | 5 ++--- rpc/test/ws_helpers.go | 4 ++-- state/execution.go | 2 +- types/events.go | 2 +- types/tx.go | 4 +++- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/rpc/core/mempool.go b/rpc/core/mempool.go index 140cf0998..919e13dfe 100644 --- a/rpc/core/mempool.go +++ b/rpc/core/mempool.go @@ -16,7 +16,7 @@ func BroadcastTx(tx types.Tx) (*ctypes.Receipt, error) { return nil, fmt.Errorf("Error broadcasting transaction: %v", err) } - txHash := types.TxId(mempoolReactor.Mempool.GetState().ChainID, tx) + txHash := types.TxID(mempoolReactor.Mempool.GetState().ChainID, tx) var createsContract uint8 var contractAddr []byte // check if creates new contract diff --git a/rpc/test/client_ws_test.go b/rpc/test/client_ws_test.go index d2a4e63a4..aa8a9cb5e 100644 --- a/rpc/test/client_ws_test.go +++ b/rpc/test/client_ws_test.go @@ -4,7 +4,6 @@ import ( "fmt" "testing" - "github.com/tendermint/tendermint/account" _ "github.com/tendermint/tendermint/config/tendermint_test" "github.com/tendermint/tendermint/types" ) @@ -208,6 +207,6 @@ func TestWSCallCall(t *testing.T) { waitForEvent(t, con, eid1, true, func() { tx := makeDefaultCallTx(t, wsTyp, contractAddr2, nil, amt, gasLim, fee) broadcastTx(t, wsTyp, tx) - *txid = account.HashSignBytes(chainID, tx) + *txid = types.TxID(chainID, tx) }, unmarshalValidateCallCall(user[0].Address, returnVal, txid)) } diff --git a/rpc/test/tests.go b/rpc/test/tests.go index 215eb9b3f..3dbd17d5a 100644 --- a/rpc/test/tests.go +++ b/rpc/test/tests.go @@ -3,7 +3,6 @@ package rpctest import ( "bytes" "fmt" - "github.com/tendermint/tendermint/account" . "github.com/tendermint/tendermint/common" "github.com/tendermint/tendermint/types" "testing" @@ -59,9 +58,9 @@ func testSignedTx(t *testing.T, typ string) { func testOneSignTx(t *testing.T, typ string, addr []byte, amt int64) { tx := makeDefaultSendTx(t, typ, addr, amt) tx2 := signTx(t, typ, tx, user[0]) - tx2hash := account.HashSignBytes(chainID, tx2) + tx2hash := types.TxID(chainID, tx2) tx.SignInput(chainID, 0, user[0]) - txhash := account.HashSignBytes(chainID, tx) + txhash := types.TxID(chainID, tx) if bytes.Compare(txhash, tx2hash) != 0 { t.Fatal("Got different signatures for signing via rpc vs tx_utils") } diff --git a/rpc/test/ws_helpers.go b/rpc/test/ws_helpers.go index 211493d13..2ab6c4d5b 100644 --- a/rpc/test/ws_helpers.go +++ b/rpc/test/ws_helpers.go @@ -250,8 +250,8 @@ func unmarshalValidateCallCall(origin, returnCode []byte, txid *[]byte) func(str if bytes.Compare(ret, returnCode) != 0 { return fmt.Errorf("Call did not return correctly. Got %x, expected %x", ret, returnCode) } - if bytes.Compare(response.Data.TxId, *txid) != 0 { - return fmt.Errorf("TxIds do not match up! Got %x, expected %x", response.Data.TxId, *txid) + if bytes.Compare(response.Data.TxID, *txid) != 0 { + return fmt.Errorf("TxIDs do not match up! Got %x, expected %x", response.Data.TxID, *txid) } return nil } diff --git a/state/execution.go b/state/execution.go index 929f4ce74..11ff01002 100644 --- a/state/execution.go +++ b/state/execution.go @@ -465,7 +465,7 @@ func ExecTx(blockCache *BlockCache, tx_ types.Tx, runCall bool, evc events.Firea txCache.UpdateAccount(caller) // because we bumped nonce txCache.UpdateAccount(callee) // so the txCache knows about the callee and the create and/or transfer takes effect - vmach := vm.NewVM(txCache, params, caller.Address, account.HashSignBytes(_s.ChainID, tx)) + vmach := vm.NewVM(txCache, params, caller.Address, types.TxID(_s.ChainID, tx)) vmach.SetFireable(evc) // NOTE: Call() transfers the value from caller to callee iff call succeeds. diff --git a/types/events.go b/types/events.go index 31cedf121..39744ad33 100644 --- a/types/events.go +++ b/types/events.go @@ -62,7 +62,7 @@ type CallData struct { type EventMsgCall struct { CallData *CallData `json:"call_data"` Origin []byte `json:"origin"` - TxId []byte `json:"tx_id"` + TxID []byte `json:"tx_id"` Return []byte `json:"return"` Exception string `json:"exception"` } diff --git a/types/tx.go b/types/tx.go index 690528bcf..36c910829 100644 --- a/types/tx.go +++ b/types/tx.go @@ -314,7 +314,9 @@ func (tx *DupeoutTx) String() string { //----------------------------------------------------------------------------- -func TxId(chainID string, tx Tx) []byte { +// NOTE: the tx merkle tree uses sha256, so this TxID is really just for +// reference when using the rpc and catching events +func TxID(chainID string, tx Tx) []byte { signBytes := account.SignBytes(chainID, tx) return binary.BinaryRipemd160(signBytes) }