*: reuse smartcontract package to create standard entry scripts

This commit is contained in:
Roman Khimov 2022-07-25 22:07:13 +03:00
parent 32ebb4a90d
commit f749aaff3c
10 changed files with 73 additions and 88 deletions

View file

@ -10,12 +10,9 @@ import (
"github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/core/transaction"
"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/encoding/address" "github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/rpcclient" "github.com/nspcc-dev/neo-go/pkg/rpcclient"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
"github.com/nspcc-dev/neo-go/pkg/wallet" "github.com/nspcc-dev/neo-go/pkg/wallet"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -122,10 +119,11 @@ func handleCandidate(ctx *cli.Context, method string, sysGas int64) error {
if err != nil { if err != nil {
return err return err
} }
w := io.NewBufBinWriter() script, err := smartcontract.CreateCallWithAssertScript(neoContractHash, method, acc.PrivateKey().PublicKey().Bytes())
emit.AppCall(w.BinWriter, neoContractHash, method, callflag.States, acc.PrivateKey().PublicKey().Bytes()) if err != nil {
emit.Opcodes(w.BinWriter, opcode.ASSERT) return cli.NewExitError(err, 1)
res, err := c.SignAndPushInvocationTx(w.Bytes(), acc, sysGas, gas, []rpcclient.SignerAccount{{ }
res, err := c.SignAndPushInvocationTx(script, acc, sysGas, gas, []rpcclient.SignerAccount{{
Signer: transaction.Signer{ Signer: transaction.Signer{
Account: acc.Contract.ScriptHash(), Account: acc.Contract.ScriptHash(),
Scopes: transaction.CalledByEntry, Scopes: transaction.CalledByEntry,
@ -182,11 +180,11 @@ func handleVote(ctx *cli.Context) error {
if err != nil { if err != nil {
return cli.NewExitError(err, 1) return cli.NewExitError(err, 1)
} }
w := io.NewBufBinWriter() script, err := smartcontract.CreateCallWithAssertScript(neoContractHash, "vote", addr.BytesBE(), pubArg)
emit.AppCall(w.BinWriter, neoContractHash, "vote", callflag.States, addr.BytesBE(), pubArg) if err != nil {
emit.Opcodes(w.BinWriter, opcode.ASSERT) return cli.NewExitError(err, 1)
}
res, err := c.SignAndPushInvocationTx(w.Bytes(), acc, -1, gas, []rpcclient.SignerAccount{{ res, err := c.SignAndPushInvocationTx(script, acc, -1, gas, []rpcclient.SignerAccount{{
Signer: transaction.Signer{ Signer: transaction.Signer{
Account: acc.Contract.ScriptHash(), Account: acc.Contract.ScriptHash(),
Scopes: transaction.CalledByEntry, Scopes: transaction.CalledByEntry,

View file

@ -6,7 +6,7 @@ import (
gio "io" gio "io"
"strings" "strings"
"github.com/nspcc-dev/neo-go/cli/smartcontract" clisc "github.com/nspcc-dev/neo-go/cli/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/compiler" "github.com/nspcc-dev/neo-go/pkg/compiler"
"github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/config"
"github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/block"
@ -16,11 +16,9 @@ import (
"github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/crypto/hash" "github.com/nspcc-dev/neo-go/pkg/crypto/hash"
"github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
) )
// Ledger is an interface that abstracts the implementation of the blockchain. // Ledger is an interface that abstracts the implementation of the blockchain.
@ -42,14 +40,11 @@ var (
// NewTransferFromOwner returns a transaction transferring funds from NEO and GAS owner. // NewTransferFromOwner returns a transaction transferring funds from NEO and GAS owner.
func NewTransferFromOwner(bc Ledger, contractHash, to util.Uint160, amount int64, func NewTransferFromOwner(bc Ledger, contractHash, to util.Uint160, amount int64,
nonce, validUntil uint32) (*transaction.Transaction, error) { nonce, validUntil uint32) (*transaction.Transaction, error) {
w := io.NewBufBinWriter() script, err := smartcontract.CreateCallWithAssertScript(contractHash, "transfer", ownerHash, to, amount, nil)
emit.AppCall(w.BinWriter, contractHash, "transfer", callflag.All, ownerHash, to, amount, nil) if err != nil {
emit.Opcodes(w.BinWriter, opcode.ASSERT) return nil, err
if w.Err != nil {
return nil, w.Err
} }
script := w.Bytes()
tx := transaction.New(script, 11000000) tx := transaction.New(script, 11000000)
tx.ValidUntilBlock = validUntil tx.ValidUntilBlock = validUntil
tx.Nonce = nonce tx.Nonce = nonce
@ -74,7 +69,7 @@ func NewDeployTx(bc Ledger, name string, sender util.Uint160, r gio.Reader, conf
NoEventsCheck: true, NoEventsCheck: true,
} }
if confFile != nil { if confFile != nil {
conf, err := smartcontract.ParseContractConfig(*confFile) conf, err := clisc.ParseContractConfig(*confFile)
if err != nil { if err != nil {
return nil, util.Uint160{}, nil, fmt.Errorf("failed to parse configuration: %w", err) return nil, util.Uint160{}, nil, fmt.Errorf("failed to parse configuration: %w", err)
} }
@ -108,13 +103,12 @@ func NewDeployTx(bc Ledger, name string, sender util.Uint160, r gio.Reader, conf
if err != nil { if err != nil {
return nil, util.Uint160{}, nil, err return nil, util.Uint160{}, nil, err
} }
buf := io.NewBufBinWriter() script, err := smartcontract.CreateCallScript(bc.ManagementContractHash(), "deploy", neb, rawManifest)
emit.AppCall(buf.BinWriter, bc.ManagementContractHash(), "deploy", callflag.All, neb, rawManifest) if err != nil {
if buf.Err != nil { return nil, util.Uint160{}, nil, err
return nil, util.Uint160{}, nil, buf.Err
} }
tx := transaction.New(buf.Bytes(), 100*native.GASFactor) tx := transaction.New(script, 100*native.GASFactor)
tx.Signers = []transaction.Signer{{Account: sender}} tx.Signers = []transaction.Signer{{Account: sender}}
h := state.CreateContractHash(tx.Sender(), ne.Checksum, m.Name) h := state.CreateContractHash(tx.Sender(), ne.Checksum, m.Name)

View file

@ -22,7 +22,6 @@ import (
"github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/io"
npayload "github.com/nspcc-dev/neo-go/pkg/network/payload" npayload "github.com/nspcc-dev/neo-go/pkg/network/payload"
"github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/emit" "github.com/nspcc-dev/neo-go/pkg/vm/emit"
"github.com/nspcc-dev/neo-go/pkg/vm/opcode" "github.com/nspcc-dev/neo-go/pkg/vm/opcode"
@ -55,16 +54,16 @@ func initServiceNextConsensus(t *testing.T, newAcc *wallet.Account, offset uint3
newPriv := newAcc.PrivateKey() newPriv := newAcc.PrivateKey()
// Transfer funds to new validator. // Transfer funds to new validator.
w := io.NewBufBinWriter() b := smartcontract.NewBuilder()
emit.AppCall(w.BinWriter, bc.GoverningTokenHash(), "transfer", callflag.All, b.InvokeWithAssert(bc.GoverningTokenHash(), "transfer",
acc.Contract.ScriptHash().BytesBE(), newPriv.GetScriptHash().BytesBE(), int64(native.NEOTotalSupply), nil) acc.Contract.ScriptHash().BytesBE(), newPriv.GetScriptHash().BytesBE(), int64(native.NEOTotalSupply), nil)
emit.Opcodes(w.BinWriter, opcode.ASSERT)
emit.AppCall(w.BinWriter, bc.UtilityTokenHash(), "transfer", callflag.All,
acc.Contract.ScriptHash().BytesBE(), newPriv.GetScriptHash().BytesBE(), int64(10000_000_000_000), nil)
emit.Opcodes(w.BinWriter, opcode.ASSERT)
require.NoError(t, w.Err)
tx := transaction.New(w.Bytes(), 21_000_000) b.InvokeWithAssert(bc.UtilityTokenHash(), "transfer",
acc.Contract.ScriptHash().BytesBE(), newPriv.GetScriptHash().BytesBE(), int64(10000_000_000_000), nil)
script, err := b.Script()
require.NoError(t, err)
tx := transaction.New(script, 21_000_000)
tx.ValidUntilBlock = bc.BlockHeight() + 1 tx.ValidUntilBlock = bc.BlockHeight() + 1
tx.NetworkFee = 10_000_000 tx.NetworkFee = 10_000_000
tx.Signers = []transaction.Signer{{Scopes: transaction.Global, Account: acc.Contract.ScriptHash()}} tx.Signers = []transaction.Signer{{Scopes: transaction.Global, Account: acc.Contract.ScriptHash()}}
@ -75,11 +74,12 @@ func initServiceNextConsensus(t *testing.T, newAcc *wallet.Account, offset uint3
srv.dbft.Start() srv.dbft.Start()
// Register new candidate. // Register new candidate.
w.Reset() b.Reset()
emit.AppCall(w.BinWriter, bc.GoverningTokenHash(), "registerCandidate", callflag.All, newPriv.PublicKey().Bytes()) b.InvokeWithAssert(bc.GoverningTokenHash(), "registerCandidate", newPriv.PublicKey().Bytes())
require.NoError(t, w.Err) script, err = b.Script()
require.NoError(t, err)
tx = transaction.New(w.Bytes(), 1001_00000000) tx = transaction.New(script, 1001_00000000)
tx.ValidUntilBlock = bc.BlockHeight() + 1 tx.ValidUntilBlock = bc.BlockHeight() + 1
tx.NetworkFee = 20_000_000 tx.NetworkFee = 20_000_000
tx.Signers = []transaction.Signer{{Scopes: transaction.Global, Account: newPriv.GetScriptHash()}} tx.Signers = []transaction.Signer{{Scopes: transaction.Global, Account: newPriv.GetScriptHash()}}
@ -94,13 +94,13 @@ func initServiceNextConsensus(t *testing.T, newAcc *wallet.Account, offset uint3
} }
// Vote for new candidate. // Vote for new candidate.
w.Reset() b.Reset()
emit.AppCall(w.BinWriter, bc.GoverningTokenHash(), "vote", callflag.All, b.InvokeWithAssert(bc.GoverningTokenHash(), "vote",
newPriv.GetScriptHash(), newPriv.PublicKey().Bytes()) newPriv.GetScriptHash(), newPriv.PublicKey().Bytes())
emit.Opcodes(w.BinWriter, opcode.ASSERT) script, err = b.Script()
require.NoError(t, w.Err) require.NoError(t, err)
tx = transaction.New(w.Bytes(), 20_000_000) tx = transaction.New(script, 20_000_000)
tx.ValidUntilBlock = bc.BlockHeight() + 1 tx.ValidUntilBlock = bc.BlockHeight() + 1
tx.NetworkFee = 20_000_000 tx.NetworkFee = 20_000_000
tx.Signers = []transaction.Signer{{Scopes: transaction.Global, Account: newPriv.GetScriptHash()}} tx.Signers = []transaction.Signer{{Scopes: transaction.Global, Account: newPriv.GetScriptHash()}}

View file

@ -14,12 +14,9 @@ import (
"github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig" "github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig"
"github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/core/transaction"
"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/neotest" "github.com/nspcc-dev/neo-go/pkg/neotest"
"github.com/nspcc-dev/neo-go/pkg/neotest/chain" "github.com/nspcc-dev/neo-go/pkg/neotest/chain"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
"github.com/nspcc-dev/neo-go/pkg/wallet" "github.com/nspcc-dev/neo-go/pkg/wallet"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -96,13 +93,12 @@ func benchmarkForEachNEP17Transfer(t *testing.B, ps storage.Store, startFromBloc
from := e.Validator.ScriptHash() from := e.Validator.ScriptHash()
for j := 0; j < chainHeight; j++ { for j := 0; j < chainHeight; j++ {
w := io.NewBufBinWriter() b := smartcontract.NewBuilder()
for i := 0; i < transfersPerBlock; i++ { for i := 0; i < transfersPerBlock; i++ {
emit.AppCall(w.BinWriter, gasHash, "transfer", callflag.All, from, acc, 1, nil) b.InvokeWithAssert(gasHash, "transfer", from, acc, 1, nil)
emit.Opcodes(w.BinWriter, opcode.ASSERT)
} }
require.NoError(t, w.Err) script, err := b.Script()
script := w.Bytes() require.NoError(t, err)
tx := transaction.New(script, int64(1100_0000*transfersPerBlock)) tx := transaction.New(script, int64(1100_0000*transfersPerBlock))
tx.NetworkFee = 1_0000_000 tx.NetworkFee = 1_0000_000
tx.ValidUntilBlock = bc.BlockHeight() + 1 tx.ValidUntilBlock = bc.BlockHeight() + 1

View file

@ -26,6 +26,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/neotest" "github.com/nspcc-dev/neo-go/pkg/neotest"
"github.com/nspcc-dev/neo-go/pkg/neotest/chain" "github.com/nspcc-dev/neo-go/pkg/neotest/chain"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/nef" "github.com/nspcc-dev/neo-go/pkg/smartcontract/nef"
@ -424,9 +425,9 @@ func TestGetInvocationCounter(t *testing.T) {
require.EqualValues(t, 42, v.Estack().Pop().BigInt().Int64()) require.EqualValues(t, 42, v.Estack().Pop().BigInt().Int64())
}) })
t.Run("Contract", func(t *testing.T) { t.Run("Contract", func(t *testing.T) {
w := io.NewBufBinWriter() script, err := smartcontract.CreateCallScript(cs.Hash, "invocCounter")
emit.AppCall(w.BinWriter, cs.Hash, "invocCounter", callflag.All) require.NoError(t, err)
v.LoadWithFlags(w.Bytes(), callflag.All) v.LoadWithFlags(script, callflag.All)
require.NoError(t, v.Run()) require.NoError(t, v.Run())
require.EqualValues(t, 1, v.Estack().Pop().BigInt().Int64()) require.EqualValues(t, 1, v.Estack().Pop().BigInt().Int64())
}) })

View file

@ -14,10 +14,8 @@ import (
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles" "github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
"github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/core/transaction"
"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/neotest" "github.com/nspcc-dev/neo-go/pkg/neotest"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -81,11 +79,9 @@ func TestOracle_Request(t *testing.T) {
// Finish. // Finish.
prepareResponseTx := func(t *testing.T, requestID uint64) *transaction.Transaction { prepareResponseTx := func(t *testing.T, requestID uint64) *transaction.Transaction {
w := io.NewBufBinWriter() script, err := smartcontract.CreateCallScript(oracleCommitteeInvoker.Hash, "finish")
emit.AppCall(w.BinWriter, oracleCommitteeInvoker.Hash, "finish", callflag.All) require.NoError(t, err)
require.NoError(t, w.Err)
script := w.Bytes()
tx := transaction.New(script, 1000_0000) tx := transaction.New(script, 1000_0000)
tx.Nonce = neotest.Nonce() tx.Nonce = neotest.Nonce()
tx.ValidUntilBlock = e.Chain.BlockHeight() + 1 tx.ValidUntilBlock = e.Chain.BlockHeight() + 1

View file

@ -20,13 +20,11 @@ import (
"github.com/nspcc-dev/neo-go/pkg/crypto/hash" "github.com/nspcc-dev/neo-go/pkg/crypto/hash"
"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/encoding/bigint" "github.com/nspcc-dev/neo-go/pkg/encoding/bigint"
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/util/slice" "github.com/nspcc-dev/neo-go/pkg/util/slice"
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
) )
@ -556,10 +554,9 @@ func (o *Oracle) updateCache(d *dao.Simple) error {
// CreateOracleResponseScript returns a script that is used to create the native Oracle // CreateOracleResponseScript returns a script that is used to create the native Oracle
// response. // response.
func CreateOracleResponseScript(nativeOracleHash util.Uint160) []byte { func CreateOracleResponseScript(nativeOracleHash util.Uint160) []byte {
w := io.NewBufBinWriter() script, err := smartcontract.CreateCallScript(nativeOracleHash, "finish")
emit.AppCall(w.BinWriter, nativeOracleHash, "finish", callflag.All) if err != nil {
if w.Err != nil { panic(fmt.Errorf("failed to create Oracle response script: %w", err))
panic(fmt.Errorf("failed to create Oracle response script: %w", w.Err))
} }
return w.Bytes() return script
} }

View file

@ -16,11 +16,11 @@ import (
"github.com/nspcc-dev/neo-go/pkg/core/state" "github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm" "github.com/nspcc-dev/neo-go/pkg/vm"
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate" "github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
"github.com/nspcc-dev/neo-go/pkg/wallet" "github.com/nspcc-dev/neo-go/pkg/wallet"
@ -81,11 +81,9 @@ func (e *Executor) NativeID(t testing.TB, name string) int32 {
// NewUnsignedTx creates a new unsigned transaction which invokes the method of the contract with the hash. // NewUnsignedTx creates a new unsigned transaction which invokes the method of the contract with the hash.
func (e *Executor) NewUnsignedTx(t testing.TB, hash util.Uint160, method string, args ...interface{}) *transaction.Transaction { func (e *Executor) NewUnsignedTx(t testing.TB, hash util.Uint160, method string, args ...interface{}) *transaction.Transaction {
w := io.NewBufBinWriter() script, err := smartcontract.CreateCallScript(hash, method, args...)
emit.AppCall(w.BinWriter, hash, method, callflag.All, args...) require.NoError(t, err)
require.NoError(t, w.Err)
script := w.Bytes()
tx := transaction.New(script, 0) tx := transaction.New(script, 0)
tx.Nonce = Nonce() tx.Nonce = Nonce()
tx.ValidUntilBlock = e.Chain.BlockHeight() + 1 tx.ValidUntilBlock = e.Chain.BlockHeight() + 1
@ -266,11 +264,10 @@ func NewDeployTxBy(t testing.TB, bc *core.Blockchain, signer Signer, c *Contract
neb, err := c.NEF.Bytes() neb, err := c.NEF.Bytes()
require.NoError(t, err) require.NoError(t, err)
buf := io.NewBufBinWriter() script, err := smartcontract.CreateCallScript(bc.ManagementContractHash(), "deploy", neb, rawManifest, data)
emit.AppCall(buf.BinWriter, bc.ManagementContractHash(), "deploy", callflag.All, neb, rawManifest, data) require.NoError(t, err)
require.NoError(t, buf.Err)
tx := transaction.New(buf.Bytes(), 100*native.GASFactor) tx := transaction.New(script, 100*native.GASFactor)
tx.Nonce = Nonce() tx.Nonce = Nonce()
tx.ValidUntilBlock = bc.BlockHeight() + 1 tx.ValidUntilBlock = bc.BlockHeight() + 1
tx.Signers = []transaction.Signer{{ tx.Signers = []transaction.Signer{{

View file

@ -77,6 +77,15 @@ func CreateCallAndUnwrapIteratorScript(contract util.Uint160, operation string,
return bytes, nil return bytes, nil
} }
// CreateCallScript returns a script that calls contract's method with
// the specified parameters. Whatever this method returns remains on the stack.
// See also (*Builder).InvokeMethod.
func CreateCallScript(contract util.Uint160, method string, params ...interface{}) ([]byte, error) {
b := NewBuilder()
b.InvokeMethod(contract, method, params...)
return b.Script()
}
// CreateCallWithAssertScript returns a script that calls contract's method with // CreateCallWithAssertScript returns a script that calls contract's method with
// the specified parameters expecting a Boolean value to be return that then is // the specified parameters expecting a Boolean value to be return that then is
// used for ASSERT. See also (*Builder).InvokeWithAssert. // used for ASSERT. See also (*Builder).InvokeWithAssert.

View file

@ -20,8 +20,6 @@ import (
"github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
"github.com/nspcc-dev/neo-go/pkg/wallet" "github.com/nspcc-dev/neo-go/pkg/wallet"
"go.uber.org/zap" "go.uber.org/zap"
"go.uber.org/zap/zapcore" "go.uber.org/zap/zapcore"
@ -99,11 +97,10 @@ func main() {
_, err = rand.Read(value) _, err = rand.Read(value)
handleError("can't get random data for value", err) handleError("can't get random data for value", err)
w := io.NewBufBinWriter() script, err := smartcontract.CreateCallScript(contractHash, "put", key, value)
emit.AppCall(w.BinWriter, contractHash, "put", callflag.All, key, value) handleError("can't create transaction", err)
handleError("can't create transaction", w.Err)
tx := transaction.New(w.Bytes(), 4_040_000) tx := transaction.New(script, 4_040_000)
tx.ValidUntilBlock = i + 1 tx.ValidUntilBlock = i + 1
tx.NetworkFee = 4_000_000 tx.NetworkFee = 4_000_000
tx.Nonce = nonce tx.Nonce = nonce