diff --git a/cli/smartcontract/smart_contract.go b/cli/smartcontract/smart_contract.go index e8555d0b0..a556570de 100644 --- a/cli/smartcontract/smart_contract.go +++ b/cli/smartcontract/smart_contract.go @@ -767,7 +767,7 @@ func contractDeploy(ctx *cli.Context) error { return err } - txScript, err := request.CreateDeploymentScript(f, m) + txScript, err := request.CreateDeploymentScript(&nefFile, m) if err != nil { return cli.NewExitError(fmt.Errorf("failed to create deployment script: %w", err), 1) } diff --git a/internal/testchain/transaction.go b/internal/testchain/transaction.go index 02bf32791..c024ad85c 100644 --- a/internal/testchain/transaction.go +++ b/internal/testchain/transaction.go @@ -1,7 +1,6 @@ package testchain import ( - "encoding/json" gio "io" "github.com/nspcc-dev/neo-go/pkg/compiler" @@ -9,11 +8,11 @@ import ( "github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/core/blockchainer" "github.com/nspcc-dev/neo-go/pkg/core/fee" - "github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames" "github.com/nspcc-dev/neo-go/pkg/core/native" "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/io" + "github.com/nspcc-dev/neo-go/pkg/rpc/request" "github.com/nspcc-dev/neo-go/pkg/smartcontract/nef" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/emit" @@ -62,28 +61,17 @@ func NewDeployTx(name string, sender util.Uint160, r gio.Reader) (*transaction.T if err != nil { return nil, util.Uint160{}, err } - neb, err := ne.Bytes() - if err != nil { - return nil, util.Uint160{}, err - } m, err := di.ConvertToManifest(name, nil) if err != nil { return nil, util.Uint160{}, err } - bs, err := json.Marshal(m) + + txScript, err := request.CreateDeploymentScript(ne, m) if err != nil { return nil, util.Uint160{}, err } - w := io.NewBufBinWriter() - emit.Bytes(w.BinWriter, bs) - emit.Bytes(w.BinWriter, neb) - emit.Syscall(w.BinWriter, interopnames.SystemContractCreate) - if w.Err != nil { - return nil, util.Uint160{}, w.Err - } - txScript := w.Bytes() tx := transaction.New(Network(), txScript, 100*native.GASFactor) tx.Signers = []transaction.Signer{{Account: sender}} h := state.CreateContractHash(tx.Sender(), avm) diff --git a/pkg/rpc/request/txBuilder.go b/pkg/rpc/request/txBuilder.go index a096e99f2..a405d7de1 100644 --- a/pkg/rpc/request/txBuilder.go +++ b/pkg/rpc/request/txBuilder.go @@ -11,6 +11,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/io" "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/nef" "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" @@ -18,14 +19,18 @@ import ( // CreateDeploymentScript returns a script that deploys given smart contract // with its metadata. -func CreateDeploymentScript(avm []byte, manif *manifest.Manifest) ([]byte, error) { +func CreateDeploymentScript(ne *nef.File, manif *manifest.Manifest) ([]byte, error) { script := io.NewBufBinWriter() rawManifest, err := json.Marshal(manif) if err != nil { return nil, err } + neb, err := ne.Bytes() + if err != nil { + return nil, err + } emit.Bytes(script.BinWriter, rawManifest) - emit.Bytes(script.BinWriter, avm) + emit.Bytes(script.BinWriter, neb) emit.Syscall(script.BinWriter, interopnames.SystemContractCreate) return script.Bytes(), nil }