Browse Source

add hash field to ResultTx (/tx and /tx_search endpoints) (#1374)

Refs #1367
pull/1376/head
Anton Kaliaev 6 years ago
committed by GitHub
parent
commit
2d857c4b1b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 13 deletions
  1. +5
    -0
      CHANGELOG.md
  2. +11
    -11
      rpc/client/rpc_test.go
  3. +8
    -2
      rpc/core/tx.go
  4. +1
    -0
      rpc/core/types/responses.go

+ 5
- 0
CHANGELOG.md View File

@ -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:


+ 11
- 11
rpc/client/rpc_test.go View File

@ -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


+ 8
- 2
rpc/core/tx.go View File

@ -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,


+ 1
- 0
rpc/core/types/responses.go View File

@ -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…
Cancel
Save