rpc/server: add new getalltransfertx API
It unifies UTXO and NEP5 transfers for a given address and presents it with transaction-level grouping (and additional metadata).
This commit is contained in:
parent
010c22e2b5
commit
23719f7e72
4 changed files with 326 additions and 0 deletions
|
@ -1223,6 +1223,108 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) []
|
|||
require.NoError(t, json.Unmarshal(res, actual))
|
||||
checkNep5TransfersAux(t, e, actual, true)
|
||||
})
|
||||
|
||||
t.Run("getalltransfertx", func(t *testing.T) {
|
||||
testGetTxs := func(t *testing.T, asset string, start, stop, limit, page int, present []util.Uint256) {
|
||||
ps := []string{`"AKkkumHbBipZ46UMZJoFynJMXzSRnBvKcs"`}
|
||||
ps = append(ps, strconv.Itoa(start))
|
||||
ps = append(ps, strconv.Itoa(stop))
|
||||
if limit != 0 {
|
||||
ps = append(ps, strconv.Itoa(limit))
|
||||
}
|
||||
if page != 0 {
|
||||
ps = append(ps, strconv.Itoa(page))
|
||||
}
|
||||
p := strings.Join(ps, ", ")
|
||||
rpc := fmt.Sprintf(`{"jsonrpc": "2.0", "id": 1, "method": "getalltransfertx", "params": [%s]}`, p)
|
||||
body := doRPCCall(rpc, httpSrv.URL, t)
|
||||
res := checkErrGetResult(t, body, false)
|
||||
actualp := new([]result.TransferTx)
|
||||
require.NoError(t, json.Unmarshal(res, actualp))
|
||||
actual := *actualp
|
||||
require.Equal(t, len(present), len(actual))
|
||||
for _, id := range present {
|
||||
var isThere bool
|
||||
var ttx result.TransferTx
|
||||
for i := range actual {
|
||||
if id.Equals(actual[i].TxID) {
|
||||
ttx = actual[i]
|
||||
isThere = true
|
||||
break
|
||||
}
|
||||
}
|
||||
require.True(t, isThere)
|
||||
tx, h, err := e.chain.GetTransaction(id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, h, ttx.Index)
|
||||
require.Equal(t, int64(e.chain.SystemFee(tx)), ttx.SystemFee)
|
||||
require.Equal(t, int64(e.chain.NetworkFee(tx)), ttx.NetworkFee)
|
||||
require.Equal(t, len(tx.Inputs)+len(tx.Outputs), len(ttx.Elements))
|
||||
}
|
||||
}
|
||||
b, err := e.chain.GetBlock(e.chain.GetHeaderHash(1))
|
||||
require.NoError(t, err)
|
||||
txMoveNeo := b.Transactions[1].Hash()
|
||||
b, err = e.chain.GetBlock(e.chain.GetHeaderHash(202))
|
||||
require.NoError(t, err)
|
||||
txNeoRT := b.Transactions[1].Hash()
|
||||
b, err = e.chain.GetBlock(e.chain.GetHeaderHash(203))
|
||||
require.NoError(t, err)
|
||||
txGasClaim := b.Transactions[1].Hash()
|
||||
b, err = e.chain.GetBlock(e.chain.GetHeaderHash(204))
|
||||
require.NoError(t, err)
|
||||
txDeploy := b.Transactions[1].Hash()
|
||||
ts204 := int(b.Timestamp)
|
||||
b, err = e.chain.GetBlock(e.chain.GetHeaderHash(206))
|
||||
require.NoError(t, err)
|
||||
txNeoTo1 := b.Transactions[1].Hash()
|
||||
b, err = e.chain.GetBlock(e.chain.GetHeaderHash(207))
|
||||
require.NoError(t, err)
|
||||
txNep5Tr := b.Transactions[2].Hash()
|
||||
b, err = e.chain.GetBlock(e.chain.GetHeaderHash(208))
|
||||
require.NoError(t, err)
|
||||
txNep5To1 := b.Transactions[1].Hash()
|
||||
ts208 := int(b.Timestamp)
|
||||
b, err = e.chain.GetBlock(e.chain.GetHeaderHash(209))
|
||||
require.NoError(t, err)
|
||||
txMigrate := b.Transactions[1].Hash()
|
||||
b, err = e.chain.GetBlock(e.chain.GetHeaderHash(210))
|
||||
require.NoError(t, err)
|
||||
txNep5To0 := b.Transactions[1].Hash()
|
||||
lastTs := int(b.Timestamp)
|
||||
t.Run("All", func(t *testing.T) {
|
||||
testGetTxs(t, "", 0, lastTs, 0, 0, []util.Uint256{
|
||||
txMoveNeo, txNeoRT, txGasClaim, txDeploy, txNeoTo1, txNep5Tr,
|
||||
txNep5To1, txMigrate, txNep5To0,
|
||||
})
|
||||
})
|
||||
t.Run("last 3", func(t *testing.T) {
|
||||
testGetTxs(t, "", 0, lastTs, 3, 0, []util.Uint256{
|
||||
txNep5To1, txMigrate, txNep5To0,
|
||||
})
|
||||
})
|
||||
t.Run("3, page 1", func(t *testing.T) {
|
||||
testGetTxs(t, "", 0, lastTs, 3, 1, []util.Uint256{
|
||||
txDeploy, txNeoTo1, txNep5Tr,
|
||||
})
|
||||
})
|
||||
t.Run("3, page 2", func(t *testing.T) {
|
||||
testGetTxs(t, "", 0, lastTs, 3, 2, []util.Uint256{
|
||||
txMoveNeo, txNeoRT, txGasClaim,
|
||||
})
|
||||
})
|
||||
t.Run("3, page 3", func(t *testing.T) {
|
||||
testGetTxs(t, "", 0, lastTs, 3, 3, []util.Uint256{})
|
||||
})
|
||||
t.Run("no dates", func(t *testing.T) {
|
||||
testGetTxs(t, "", 0, 1000000, 0, 0, []util.Uint256{})
|
||||
})
|
||||
t.Run("204-208", func(t *testing.T) {
|
||||
testGetTxs(t, "", ts204, ts208, 0, 0, []util.Uint256{
|
||||
txDeploy, txNeoTo1, txNep5Tr, txNep5To1,
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (tc rpcTestCase) getResultPair(e *executor) (expected interface{}, res interface{}) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue