request: make CreateDeploymentScript work with NEFs
And use it in testing code.
This commit is contained in:
parent
4d0eaef510
commit
470e1592d9
3 changed files with 11 additions and 18 deletions
|
@ -767,7 +767,7 @@ func contractDeploy(ctx *cli.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
txScript, err := request.CreateDeploymentScript(f, m)
|
txScript, err := request.CreateDeploymentScript(&nefFile, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli.NewExitError(fmt.Errorf("failed to create deployment script: %w", err), 1)
|
return cli.NewExitError(fmt.Errorf("failed to create deployment script: %w", err), 1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package testchain
|
package testchain
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
gio "io"
|
gio "io"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/compiler"
|
"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/config/netmode"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
"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/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/native"
|
||||||
"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/rpc/request"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/nef"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/nef"
|
||||||
"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"
|
||||||
|
@ -62,28 +61,17 @@ func NewDeployTx(name string, sender util.Uint160, r gio.Reader) (*transaction.T
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, util.Uint160{}, err
|
return nil, util.Uint160{}, err
|
||||||
}
|
}
|
||||||
neb, err := ne.Bytes()
|
|
||||||
if err != nil {
|
|
||||||
return nil, util.Uint160{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
m, err := di.ConvertToManifest(name, nil)
|
m, err := di.ConvertToManifest(name, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, util.Uint160{}, err
|
return nil, util.Uint160{}, err
|
||||||
}
|
}
|
||||||
bs, err := json.Marshal(m)
|
|
||||||
|
txScript, err := request.CreateDeploymentScript(ne, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, util.Uint160{}, err
|
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 := transaction.New(Network(), txScript, 100*native.GASFactor)
|
||||||
tx.Signers = []transaction.Signer{{Account: sender}}
|
tx.Signers = []transaction.Signer{{Account: sender}}
|
||||||
h := state.CreateContractHash(tx.Sender(), avm)
|
h := state.CreateContractHash(tx.Sender(), avm)
|
||||||
|
|
|
@ -11,6 +11,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/smartcontract"
|
"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/smartcontract/nef"
|
||||||
"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"
|
||||||
|
@ -18,14 +19,18 @@ import (
|
||||||
|
|
||||||
// CreateDeploymentScript returns a script that deploys given smart contract
|
// CreateDeploymentScript returns a script that deploys given smart contract
|
||||||
// with its metadata.
|
// 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()
|
script := io.NewBufBinWriter()
|
||||||
rawManifest, err := json.Marshal(manif)
|
rawManifest, err := json.Marshal(manif)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
neb, err := ne.Bytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
emit.Bytes(script.BinWriter, rawManifest)
|
emit.Bytes(script.BinWriter, rawManifest)
|
||||||
emit.Bytes(script.BinWriter, avm)
|
emit.Bytes(script.BinWriter, neb)
|
||||||
emit.Syscall(script.BinWriter, interopnames.SystemContractCreate)
|
emit.Syscall(script.BinWriter, interopnames.SystemContractCreate)
|
||||||
return script.Bytes(), nil
|
return script.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue