mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-29 03:41:45 +00:00
context: define a constant for transaction context type
This commit is contained in:
parent
6be9367f03
commit
541d4b49e1
4 changed files with 10 additions and 4 deletions
|
@ -15,7 +15,7 @@ import (
|
||||||
// as an input to `multisig sign`. If a wallet.Account is given and can sign,
|
// as an input to `multisig sign`. If a wallet.Account is given and can sign,
|
||||||
// it's signed as well using it.
|
// it's signed as well using it.
|
||||||
func InitAndSave(net netmode.Magic, tx *transaction.Transaction, acc *wallet.Account, filename string) error {
|
func InitAndSave(net netmode.Magic, tx *transaction.Transaction, acc *wallet.Account, filename string) error {
|
||||||
scCtx := context.NewParameterContext("Neo.Network.P2P.Payloads.Transaction", net, tx)
|
scCtx := context.NewParameterContext(context.TransactionType, net, tx)
|
||||||
if acc != nil && acc.CanSign() {
|
if acc != nil && acc.CanSign() {
|
||||||
sign := acc.SignHashable(net, tx)
|
sign := acc.SignHashable(net, tx)
|
||||||
if err := scCtx.AddSignature(acc.ScriptHash(), acc.Contract, acc.PublicKey(), sign); err != nil {
|
if err := scCtx.AddSignature(acc.ScriptHash(), acc.Contract, acc.PublicKey(), sign); err != nil {
|
||||||
|
|
|
@ -108,7 +108,7 @@ func ExampleActor() {
|
||||||
tx, _ := policyContract.SetStoragePriceUnsigned(10)
|
tx, _ := policyContract.SetStoragePriceUnsigned(10)
|
||||||
|
|
||||||
net := a.GetNetwork()
|
net := a.GetNetwork()
|
||||||
scCtx := sccontext.NewParameterContext("Neo.Network.P2P.Payloads.Transaction", net, tx)
|
scCtx := sccontext.NewParameterContext(sccontext.TransactionType, net, tx)
|
||||||
sign := w.Accounts[0].SignHashable(net, tx)
|
sign := w.Accounts[0].SignHashable(net, tx)
|
||||||
_ = scCtx.AddSignature(w.Accounts[0].ScriptHash(), w.Accounts[0].Contract, w.Accounts[0].PublicKey(), sign)
|
_ = scCtx.AddSignature(w.Accounts[0].ScriptHash(), w.Accounts[0].Contract, w.Accounts[0].PublicKey(), sign)
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,12 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TransactionType is the ParameterContext Type used for transactions.
|
||||||
|
const TransactionType = "Neo.Network.P2P.Payloads.Transaction"
|
||||||
|
|
||||||
|
// compatTransactionType is the old, 2.x type used for transactions.
|
||||||
|
const compatTransactionType = "Neo.Core.ContractTransaction"
|
||||||
|
|
||||||
// ParameterContext represents smartcontract parameter's context.
|
// ParameterContext represents smartcontract parameter's context.
|
||||||
type ParameterContext struct {
|
type ParameterContext struct {
|
||||||
// Type is a type of a verifiable item.
|
// Type is a type of a verifiable item.
|
||||||
|
@ -213,7 +219,7 @@ func (c *ParameterContext) UnmarshalJSON(data []byte) error {
|
||||||
|
|
||||||
var verif crypto.VerifiableDecodable
|
var verif crypto.VerifiableDecodable
|
||||||
switch pc.Type {
|
switch pc.Type {
|
||||||
case "Neo.Core.ContractTransaction", "Neo.Network.P2P.Payloads.Transaction":
|
case compatTransactionType, TransactionType:
|
||||||
tx := new(transaction.Transaction)
|
tx := new(transaction.Transaction)
|
||||||
verif = tx
|
verif = tx
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -102,7 +102,7 @@ func TestParameterContext_AddSignatureMultisig(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
tx := getContractTx(ctr.ScriptHash())
|
tx := getContractTx(ctr.ScriptHash())
|
||||||
c := NewParameterContext("Neo.Network.P2P.Payloads.Transaction", netmode.UnitTestNet, tx)
|
c := NewParameterContext(TransactionType, netmode.UnitTestNet, tx)
|
||||||
priv, err := keys.NewPrivateKey()
|
priv, err := keys.NewPrivateKey()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
sig := priv.SignHashable(uint32(c.Network), tx)
|
sig := priv.SignHashable(uint32(c.Network), tx)
|
||||||
|
|
Loading…
Reference in a new issue