mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-02-16 21:16:30 +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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/dao"
|
"github.com/nspcc-dev/neo-go/pkg/core/dao"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
"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) {
|
if err != nil || !isTraceableBlock(ic, h) {
|
||||||
return stackitem.Null{}
|
return stackitem.Null{}
|
||||||
}
|
}
|
||||||
return SignersToStackItem(tx.Signers)
|
return transaction.SignersToStackItem(tx.Signers)
|
||||||
}
|
}
|
||||||
|
|
||||||
// getTransactionVMState returns VM state got after transaction invocation.
|
// 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)
|
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 (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"math/big"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The maximum number of AllowedContracts or AllowedGroups.
|
// The maximum number of AllowedContracts or AllowedGroups.
|
||||||
|
@ -57,3 +59,30 @@ func (c *Signer) DecodeBinary(br *io.BinReader) {
|
||||||
br.ReadArray(&c.Rules, maxSubitems)
|
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…
Add table
Reference in a new issue