add hash field to ResultTx (/tx and /tx_search endpoints) (#1374)
Refs #1367
This commit is contained in:
parent
2b63f57b4c
commit
2d857c4b1b
|
@ -25,6 +25,11 @@ BUG FIXES:
|
|||
- Graceful handling/recovery for apps that have non-determinism or fail to halt
|
||||
- Graceful handling/recovery for violations of safety, or liveness
|
||||
|
||||
## 0.17.2 (TBD)
|
||||
|
||||
IMPROVEMENTS:
|
||||
- [rpc] `/tx` and `/tx_search` responses now include the transaction hash
|
||||
|
||||
## 0.17.1 (March 27th, 2018)
|
||||
|
||||
BUG FIXES:
|
||||
|
|
|
@ -253,13 +253,11 @@ func TestBroadcastTxCommit(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTx(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
|
||||
// first we broadcast a tx
|
||||
c := getHTTPClient()
|
||||
_, _, tx := MakeTxKV()
|
||||
bres, err := c.BroadcastTxCommit(tx)
|
||||
require.Nil(err, "%+v", err)
|
||||
require.Nil(t, err, "%+v", err)
|
||||
|
||||
txHeight := bres.Height
|
||||
txHash := bres.Hash
|
||||
|
@ -289,18 +287,19 @@ func TestTx(t *testing.T) {
|
|||
ptx, err := c.Tx(tc.hash, tc.prove)
|
||||
|
||||
if !tc.valid {
|
||||
require.NotNil(err)
|
||||
require.NotNil(t, err)
|
||||
} else {
|
||||
require.Nil(err, "%+v", err)
|
||||
assert.EqualValues(txHeight, ptx.Height)
|
||||
assert.EqualValues(tx, ptx.Tx)
|
||||
assert.Zero(ptx.Index)
|
||||
assert.True(ptx.TxResult.IsOK())
|
||||
require.Nil(t, err, "%+v", err)
|
||||
assert.EqualValues(t, txHeight, ptx.Height)
|
||||
assert.EqualValues(t, tx, ptx.Tx)
|
||||
assert.Zero(t, ptx.Index)
|
||||
assert.True(t, ptx.TxResult.IsOK())
|
||||
assert.EqualValues(t, txHash, ptx.Hash)
|
||||
|
||||
// time to verify the proof
|
||||
proof := ptx.Proof
|
||||
if tc.prove && assert.EqualValues(tx, proof.Data) {
|
||||
assert.True(proof.Proof.Verify(proof.Index, proof.Total, txHash, proof.RootHash))
|
||||
if tc.prove && assert.EqualValues(t, tx, proof.Data) {
|
||||
assert.True(t, proof.Proof.Verify(proof.Index, proof.Total, txHash, proof.RootHash))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -333,6 +332,7 @@ func TestTxSearch(t *testing.T) {
|
|||
assert.EqualValues(t, tx, ptx.Tx)
|
||||
assert.Zero(t, ptx.Index)
|
||||
assert.True(t, ptx.TxResult.IsOK())
|
||||
assert.EqualValues(t, txHash, ptx.Hash)
|
||||
|
||||
// time to verify the proof
|
||||
proof := ptx.Proof
|
||||
|
|
|
@ -44,7 +44,8 @@ import (
|
|||
// "code": 0
|
||||
// },
|
||||
// "index": 0,
|
||||
// "height": 52
|
||||
// "height": 52,
|
||||
// "hash": "2B8EC32BA2579B3B8606E42C06DE2F7AFA2556EF"
|
||||
// },
|
||||
// "id": "",
|
||||
// "jsonrpc": "2.0"
|
||||
|
@ -67,6 +68,7 @@ import (
|
|||
// - `tx_result`: the `abci.Result` object
|
||||
// - `index`: `int` - index of the transaction
|
||||
// - `height`: `int` - height of the block where this transaction was in
|
||||
// - `hash`: `[]byte` - hash of the transaction
|
||||
func Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {
|
||||
|
||||
// if index is disabled, return error
|
||||
|
@ -93,6 +95,7 @@ func Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {
|
|||
}
|
||||
|
||||
return &ctypes.ResultTx{
|
||||
Hash: hash,
|
||||
Height: height,
|
||||
Index: uint32(index),
|
||||
TxResult: r.Result,
|
||||
|
@ -137,7 +140,8 @@ func Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {
|
|||
// "tx": "mvZHHa7HhZ4aRT0xMDA=",
|
||||
// "tx_result": {},
|
||||
// "index": 31,
|
||||
// "height": 12
|
||||
// "height": 12,
|
||||
// "hash": "2B8EC32BA2579B3B8606E42C06DE2F7AFA2556EF"
|
||||
// }
|
||||
// ],
|
||||
// "id": "",
|
||||
|
@ -161,6 +165,7 @@ func Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {
|
|||
// - `tx_result`: the `abci.Result` object
|
||||
// - `index`: `int` - index of the transaction
|
||||
// - `height`: `int` - height of the block where this transaction was in
|
||||
// - `hash`: `[]byte` - hash of the transaction
|
||||
func TxSearch(query string, prove bool) ([]*ctypes.ResultTx, error) {
|
||||
// if index is disabled, return error
|
||||
if _, ok := txIndexer.(*null.TxIndex); ok {
|
||||
|
@ -191,6 +196,7 @@ func TxSearch(query string, prove bool) ([]*ctypes.ResultTx, error) {
|
|||
}
|
||||
|
||||
apiResults[i] = &ctypes.ResultTx{
|
||||
Hash: r.Tx.Hash(),
|
||||
Height: height,
|
||||
Index: index,
|
||||
TxResult: r.Result,
|
||||
|
|
|
@ -123,6 +123,7 @@ type ResultBroadcastTxCommit struct {
|
|||
}
|
||||
|
||||
type ResultTx struct {
|
||||
Hash cmn.HexBytes `json:"hash"`
|
||||
Height int64 `json:"height"`
|
||||
Index uint32 `json:"index"`
|
||||
TxResult abci.ResponseDeliverTx `json:"tx_result"`
|
||||
|
|
Loading…
Reference in New Issue