diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index b2d0c8c8d..82b26fbd7 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -1086,21 +1086,23 @@ func (bc *Blockchain) ForEachTransfer(acc util.Uint160, tr *state.Transfer, f fu return nil } -// GetNEP5TransferLog returns NEP5 transfer log for the acc. -func (bc *Blockchain) GetNEP5TransferLog(acc util.Uint160) *state.TransferLog { +// ForEachNEP5Transfer executes f for each nep5 transfer in log. +func (bc *Blockchain) ForEachNEP5Transfer(acc util.Uint160, tr *state.NEP5Transfer, f func() error) error { balances, err := bc.dao.GetNEP5Balances(acc) if err != nil { return nil } - result := new(state.TransferLog) for i := uint32(0); i <= balances.NextTransferBatch; i++ { lg, err := bc.dao.GetNEP5TransferLog(acc, i) if err != nil { return nil } - result.Raw = append(result.Raw, lg.Raw...) + err = lg.ForEach(state.NEP5TransferSize, tr, f) + if err != nil { + return err + } } - return result + return nil } // GetNEP5Balances returns NEP5 balances for the acc. diff --git a/pkg/core/blockchainer.go b/pkg/core/blockchainer.go index 910c3074e..03f0bd4e3 100644 --- a/pkg/core/blockchainer.go +++ b/pkg/core/blockchainer.go @@ -26,6 +26,7 @@ type Blockchainer interface { GetBlock(hash util.Uint256) (*block.Block, error) GetContractState(hash util.Uint160) *state.Contract GetEnrollments() ([]*state.Validator, error) + ForEachNEP5Transfer(util.Uint160, *state.NEP5Transfer, func() error) error ForEachTransfer(util.Uint160, *state.Transfer, func() error) error GetHeaderHash(int) util.Uint256 GetHeader(hash util.Uint256) (*block.Header, error) @@ -37,7 +38,6 @@ type Blockchainer interface { GetAccountState(util.Uint160) *state.Account GetAppExecResult(util.Uint256) (*state.AppExecResult, error) GetNEP5Metadata(util.Uint160) (*state.NEP5Metadata, error) - GetNEP5TransferLog(util.Uint160) *state.TransferLog GetNEP5Balances(util.Uint160) *state.NEP5Balances GetValidators(txes ...*transaction.Transaction) ([]*keys.PublicKey, error) GetScriptHashesForVerifying(*transaction.Transaction) ([]util.Uint160, error) diff --git a/pkg/network/helper_test.go b/pkg/network/helper_test.go index 8fd5d3d36..93aa36ccf 100644 --- a/pkg/network/helper_test.go +++ b/pkg/network/helper_test.go @@ -96,7 +96,7 @@ func (chain testChain) GetAccountState(util.Uint160) *state.Account { func (chain testChain) GetNEP5Metadata(util.Uint160) (*state.NEP5Metadata, error) { panic("TODO") } -func (chain testChain) GetNEP5TransferLog(util.Uint160) *state.TransferLog { +func (chain testChain) ForEachNEP5Transfer(util.Uint160, *state.NEP5Transfer, func() error) error { panic("TODO") } func (chain testChain) GetNEP5Balances(util.Uint160) *state.NEP5Balances { diff --git a/pkg/rpc/server/server.go b/pkg/rpc/server/server.go index d1bf31de8..07318983c 100644 --- a/pkg/rpc/server/server.go +++ b/pkg/rpc/server/server.go @@ -726,9 +726,8 @@ func (s *Server) getNEP5Transfers(ps request.Params) (interface{}, *response.Err Received: []result.NEP5Transfer{}, Sent: []result.NEP5Transfer{}, } - lg := s.chain.GetNEP5TransferLog(u) tr := new(state.NEP5Transfer) - err = lg.ForEach(state.NEP5TransferSize, tr, func() error { + err = s.chain.ForEachNEP5Transfer(u, tr, func() error { transfer := result.NEP5Transfer{ Timestamp: tr.Timestamp, Asset: tr.Asset,