mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-22 09:29:38 +00:00
core: move SignersToStackItem to transaction package
It will be reused from interops. Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
parent
b2205940fa
commit
90b01bcea6
2 changed files with 30 additions and 29 deletions
|
@ -3,7 +3,6 @@ package native
|
|||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"math/big"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/dao"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||||
|
@ -163,7 +162,7 @@ func (l *Ledger) getTransactionSigners(ic *interop.Context, params []stackitem.I
|
|||
if err != nil || !isTraceableBlock(ic, h) {
|
||||
return stackitem.Null{}
|
||||
}
|
||||
return SignersToStackItem(tx.Signers)
|
||||
return transaction.SignersToStackItem(tx.Signers)
|
||||
}
|
||||
|
||||
// getTransactionVMState returns VM state got after transaction invocation.
|
||||
|
@ -231,30 +230,3 @@ func getTransactionAndHeight(d *dao.Simple, item stackitem.Item) (*transaction.T
|
|||
}
|
||||
return d.GetTransaction(hash)
|
||||
}
|
||||
|
||||
// SignersToStackItem converts transaction.Signers to stackitem.Item.
|
||||
func SignersToStackItem(signers []transaction.Signer) stackitem.Item {
|
||||
res := make([]stackitem.Item, len(signers))
|
||||
for i, s := range signers {
|
||||
contracts := make([]stackitem.Item, len(s.AllowedContracts))
|
||||
for j, c := range s.AllowedContracts {
|
||||
contracts[j] = stackitem.NewByteArray(c.BytesBE())
|
||||
}
|
||||
groups := make([]stackitem.Item, len(s.AllowedGroups))
|
||||
for j, g := range s.AllowedGroups {
|
||||
groups[j] = stackitem.NewByteArray(g.Bytes())
|
||||
}
|
||||
rules := make([]stackitem.Item, len(s.Rules))
|
||||
for j, r := range s.Rules {
|
||||
rules[j] = r.ToStackItem()
|
||||
}
|
||||
res[i] = stackitem.NewArray([]stackitem.Item{
|
||||
stackitem.NewByteArray(s.Account.BytesBE()),
|
||||
stackitem.NewBigInteger(big.NewInt(int64(s.Scopes))),
|
||||
stackitem.NewArray(contracts),
|
||||
stackitem.NewArray(groups),
|
||||
stackitem.NewArray(rules),
|
||||
})
|
||||
}
|
||||
return stackitem.NewArray(res)
|
||||
}
|
||||
|
|
|
@ -2,10 +2,12 @@ package transaction
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"math/big"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
)
|
||||
|
||||
// The maximum number of AllowedContracts or AllowedGroups.
|
||||
|
@ -57,3 +59,30 @@ func (c *Signer) DecodeBinary(br *io.BinReader) {
|
|||
br.ReadArray(&c.Rules, maxSubitems)
|
||||
}
|
||||
}
|
||||
|
||||
// SignersToStackItem converts transaction.Signers to stackitem.Item.
|
||||
func SignersToStackItem(signers []Signer) stackitem.Item {
|
||||
res := make([]stackitem.Item, len(signers))
|
||||
for i, s := range signers {
|
||||
contracts := make([]stackitem.Item, len(s.AllowedContracts))
|
||||
for j, c := range s.AllowedContracts {
|
||||
contracts[j] = stackitem.NewByteArray(c.BytesBE())
|
||||
}
|
||||
groups := make([]stackitem.Item, len(s.AllowedGroups))
|
||||
for j, g := range s.AllowedGroups {
|
||||
groups[j] = stackitem.NewByteArray(g.Bytes())
|
||||
}
|
||||
rules := make([]stackitem.Item, len(s.Rules))
|
||||
for j, r := range s.Rules {
|
||||
rules[j] = r.ToStackItem()
|
||||
}
|
||||
res[i] = stackitem.NewArray([]stackitem.Item{
|
||||
stackitem.NewByteArray(s.Account.BytesBE()),
|
||||
stackitem.NewBigInteger(big.NewInt(int64(s.Scopes))),
|
||||
stackitem.NewArray(contracts),
|
||||
stackitem.NewArray(groups),
|
||||
stackitem.NewArray(rules),
|
||||
})
|
||||
}
|
||||
return stackitem.NewArray(res)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue