mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-04 19:19:44 +00:00
core/state: reverse the order of ForEachTransfer
When using limits we're usually concerned about the most recent transfers. Returning 3 transfers from the middle of the chain isn't very helpful.
This commit is contained in:
parent
6761efff24
commit
d3e415d3bd
4 changed files with 18 additions and 17 deletions
|
@ -1031,8 +1031,8 @@ func (bc *Blockchain) ForEachTransfer(acc util.Uint160, tr *state.Transfer, f fu
|
|||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
for i := uint32(0); i <= nb; i++ {
|
||||
lg, err := bc.dao.GetTransferLog(acc, i)
|
||||
for i := int(nb); i >= 0; i-- {
|
||||
lg, err := bc.dao.GetTransferLog(acc, uint32(i))
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
@ -1050,8 +1050,8 @@ func (bc *Blockchain) ForEachNEP5Transfer(acc util.Uint160, tr *state.NEP5Transf
|
|||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
for i := uint32(0); i <= balances.NextTransferBatch; i++ {
|
||||
lg, err := bc.dao.GetNEP5TransferLog(acc, i)
|
||||
for i := int(balances.NextTransferBatch); i >= 0; i-- {
|
||||
lg, err := bc.dao.GetNEP5TransferLog(acc, uint32(i))
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -114,8 +114,8 @@ func (lg *TransferLog) ForEach(size int, tr io.Serializable, f func() error) err
|
|||
if lg == nil {
|
||||
return nil
|
||||
}
|
||||
for i := 0; i < len(lg.Raw); i += size {
|
||||
r := io.NewBinReaderFromBuf(lg.Raw[i : i+size])
|
||||
for i := len(lg.Raw); i > 0; i -= size {
|
||||
r := io.NewBinReaderFromBuf(lg.Raw[i-size : i])
|
||||
tr.DecodeBinary(r)
|
||||
if r.Err != nil {
|
||||
return r.Err
|
||||
|
|
|
@ -28,11 +28,11 @@ func TestNEP5TransferLog_Append(t *testing.T) {
|
|||
|
||||
require.Equal(t, len(expected), lg.Size()/NEP5TransferSize)
|
||||
|
||||
i := 0
|
||||
i := len(expected) - 1
|
||||
tr := new(NEP5Transfer)
|
||||
err := lg.ForEach(NEP5TransferSize, tr, func() error {
|
||||
require.Equal(t, expected[i], tr)
|
||||
i++
|
||||
i--
|
||||
return nil
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -1284,24 +1284,25 @@ func checkNep5TransfersAux(t *testing.T, e *executor, acc interface{}, onlyFirst
|
|||
|
||||
if onlyFirst {
|
||||
require.Equal(t, 1, len(res.Received))
|
||||
require.Equal(t, "1000", res.Received[0].Amount)
|
||||
require.Equal(t, assetHashOld, res.Received[0].Asset)
|
||||
require.Equal(t, address.Uint160ToString(assetHashOld), res.Received[0].Address)
|
||||
} else {
|
||||
require.Equal(t, 3, len(res.Received))
|
||||
}
|
||||
|
||||
require.Equal(t, "1000", res.Received[0].Amount)
|
||||
require.Equal(t, assetHashOld, res.Received[0].Asset)
|
||||
require.Equal(t, address.Uint160ToString(assetHashOld), res.Received[0].Address)
|
||||
require.Equal(t, "1000", res.Received[2].Amount)
|
||||
require.Equal(t, assetHashOld, res.Received[2].Asset)
|
||||
require.Equal(t, address.Uint160ToString(assetHashOld), res.Received[2].Address)
|
||||
|
||||
if !onlyFirst {
|
||||
require.Equal(t, "2", res.Received[1].Amount)
|
||||
require.Equal(t, assetHash, res.Received[1].Asset)
|
||||
require.Equal(t, "AWLYWXB8C9Lt1nHdDZJnC5cpYJjgRDLk17", res.Received[1].Address)
|
||||
require.Equal(t, uint32(0), res.Received[1].NotifyIndex)
|
||||
|
||||
require.Equal(t, "1", res.Received[2].Amount)
|
||||
require.Equal(t, assetHash, res.Received[2].Asset)
|
||||
require.Equal(t, "AWLYWXB8C9Lt1nHdDZJnC5cpYJjgRDLk17", res.Received[2].Address)
|
||||
require.Equal(t, uint32(1), res.Received[2].NotifyIndex)
|
||||
require.Equal(t, "1", res.Received[0].Amount)
|
||||
require.Equal(t, assetHash, res.Received[0].Asset)
|
||||
require.Equal(t, "AWLYWXB8C9Lt1nHdDZJnC5cpYJjgRDLk17", res.Received[0].Address)
|
||||
require.Equal(t, uint32(1), res.Received[0].NotifyIndex)
|
||||
}
|
||||
|
||||
require.Equal(t, 1, len(res.Sent))
|
||||
|
|
Loading…
Reference in a new issue