From 3c6d9653b08bc97ade2ddb36d5bdaa661f3ecdcc Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 12 Mar 2020 12:32:24 +0300 Subject: [PATCH] core/state: add Size() method to NEP5TransferLog --- pkg/core/state/nep5.go | 5 +++++ pkg/core/state/nep5_test.go | 2 ++ 2 files changed, 7 insertions(+) diff --git a/pkg/core/state/nep5.go b/pkg/core/state/nep5.go index 60ed630f9..9ca8a0466 100644 --- a/pkg/core/state/nep5.go +++ b/pkg/core/state/nep5.go @@ -106,6 +106,11 @@ func (lg *NEP5TransferLog) ForEach(f func(*NEP5Transfer) error) error { return nil } +// Size returns an amount of transfer written in log. +func (lg *NEP5TransferLog) Size() int { + return len(lg.Raw) / NEP5TransferSize +} + // EncodeBinary implements io.Serializable interface. func (t *NEP5Tracker) EncodeBinary(w *io.BinWriter) { w.WriteU64LE(uint64(t.Balance)) diff --git a/pkg/core/state/nep5_test.go b/pkg/core/state/nep5_test.go index b4e70f5ea..36c20f7b5 100644 --- a/pkg/core/state/nep5_test.go +++ b/pkg/core/state/nep5_test.go @@ -25,6 +25,8 @@ func TestNEP5TransferLog_Append(t *testing.T) { require.NoError(t, lg.Append(tr)) } + require.Equal(t, len(expected), lg.Size()) + i := 0 err := lg.ForEach(func(tr *NEP5Transfer) error { require.Equal(t, expected[i], tr)