From dede4fa7b1097b4ded6b65e94606c09052de1a52 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 3 Aug 2021 00:02:42 +0300 Subject: [PATCH] state: convert NEO balance to stack item directly Avoid calling Append() that will reallocate the slice, we know the length of the slice exactly. --- pkg/core/state/native_state.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/core/state/native_state.go b/pkg/core/state/native_state.go index 44e1adb50..5a59d1699 100644 --- a/pkg/core/state/native_state.go +++ b/pkg/core/state/native_state.go @@ -91,15 +91,18 @@ func (s *NEOBalance) Bytes() []byte { // ToStackItem implements stackitem.Convertible interface. It never returns an error. func (s *NEOBalance) ToStackItem() (stackitem.Item, error) { - resItem, _ := s.NEP17Balance.ToStackItem() - result := resItem.(*stackitem.Struct) - result.Append(stackitem.NewBigInteger(big.NewInt(int64(s.BalanceHeight)))) + var voteItem stackitem.Item + if s.VoteTo != nil { - result.Append(stackitem.NewByteArray(s.VoteTo.Bytes())) + voteItem = stackitem.NewByteArray(s.VoteTo.Bytes()) } else { - result.Append(stackitem.Null{}) + voteItem = stackitem.Null{} } - return result, nil + return stackitem.NewStruct([]stackitem.Item{ + stackitem.NewBigInteger(&s.Balance), + stackitem.NewBigInteger(big.NewInt(int64(s.BalanceHeight))), + voteItem, + }), nil } // FromStackItem converts stackitem.Item to NEOBalance.