From 541d4b49e1b77df807c603bf7f2c61d2fd2eb19c Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 8 Sep 2022 13:07:49 +0300 Subject: [PATCH] context: define a constant for transaction context type --- cli/paramcontext/context.go | 2 +- pkg/rpcclient/actor/doc_test.go | 2 +- pkg/smartcontract/context/context.go | 8 +++++++- pkg/smartcontract/context/context_test.go | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/cli/paramcontext/context.go b/cli/paramcontext/context.go index d8fe06999..3d6429cf4 100644 --- a/cli/paramcontext/context.go +++ b/cli/paramcontext/context.go @@ -15,7 +15,7 @@ import ( // as an input to `multisig sign`. If a wallet.Account is given and can sign, // it's signed as well using it. 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() { sign := acc.SignHashable(net, tx) if err := scCtx.AddSignature(acc.ScriptHash(), acc.Contract, acc.PublicKey(), sign); err != nil { diff --git a/pkg/rpcclient/actor/doc_test.go b/pkg/rpcclient/actor/doc_test.go index 7121cc564..a1297b2bc 100644 --- a/pkg/rpcclient/actor/doc_test.go +++ b/pkg/rpcclient/actor/doc_test.go @@ -108,7 +108,7 @@ func ExampleActor() { tx, _ := policyContract.SetStoragePriceUnsigned(10) 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) _ = scCtx.AddSignature(w.Accounts[0].ScriptHash(), w.Accounts[0].Contract, w.Accounts[0].PublicKey(), sign) diff --git a/pkg/smartcontract/context/context.go b/pkg/smartcontract/context/context.go index eb307dbf8..13d2927f7 100644 --- a/pkg/smartcontract/context/context.go +++ b/pkg/smartcontract/context/context.go @@ -21,6 +21,12 @@ import ( "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. type ParameterContext struct { // Type is a type of a verifiable item. @@ -213,7 +219,7 @@ func (c *ParameterContext) UnmarshalJSON(data []byte) error { var verif crypto.VerifiableDecodable switch pc.Type { - case "Neo.Core.ContractTransaction", "Neo.Network.P2P.Payloads.Transaction": + case compatTransactionType, TransactionType: tx := new(transaction.Transaction) verif = tx default: diff --git a/pkg/smartcontract/context/context_test.go b/pkg/smartcontract/context/context_test.go index 5675e0289..9d3468bef 100644 --- a/pkg/smartcontract/context/context_test.go +++ b/pkg/smartcontract/context/context_test.go @@ -102,7 +102,7 @@ func TestParameterContext_AddSignatureMultisig(t *testing.T) { }, } tx := getContractTx(ctr.ScriptHash()) - c := NewParameterContext("Neo.Network.P2P.Payloads.Transaction", netmode.UnitTestNet, tx) + c := NewParameterContext(TransactionType, netmode.UnitTestNet, tx) priv, err := keys.NewPrivateKey() require.NoError(t, err) sig := priv.SignHashable(uint32(c.Network), tx)