2021-07-09 09:53:10 +00:00
|
|
|
package morph
|
|
|
|
|
|
|
|
import (
|
2021-07-19 11:04:19 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2022-03-18 11:12:58 +00:00
|
|
|
"os"
|
2022-02-02 13:28:08 +00:00
|
|
|
"path/filepath"
|
2021-07-19 11:04:19 +00:00
|
|
|
"time"
|
|
|
|
|
2021-08-19 10:27:43 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
2022-02-02 14:19:27 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
2021-07-20 12:08:47 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
2021-07-19 11:04:19 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
2022-08-29 19:31:32 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
|
2021-07-19 11:04:19 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2022-07-18 08:33:53 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
|
2021-07-19 11:04:19 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
|
|
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-adm/internal/modules/config"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/innerring"
|
2022-01-29 11:15:05 +00:00
|
|
|
morphClient "github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
2021-07-09 09:53:10 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
2022-02-02 14:19:27 +00:00
|
|
|
type cache struct {
|
|
|
|
nnsCs *state.Contract
|
|
|
|
groupKey *keys.PublicKey
|
|
|
|
}
|
|
|
|
|
2021-07-19 11:04:19 +00:00
|
|
|
type initializeContext struct {
|
2021-11-30 11:45:40 +00:00
|
|
|
clientContext
|
2022-02-02 14:19:27 +00:00
|
|
|
cache
|
2022-04-21 11:28:05 +00:00
|
|
|
// CommitteeAcc is used for retrieving the committee address and the verification script.
|
2021-07-19 11:04:19 +00:00
|
|
|
CommitteeAcc *wallet.Account
|
2022-04-21 11:28:05 +00:00
|
|
|
// ConsensusAcc is used for retrieving the committee address and the verification script.
|
2021-07-19 11:04:19 +00:00
|
|
|
ConsensusAcc *wallet.Account
|
|
|
|
Wallets []*wallet.Wallet
|
2022-04-21 11:28:05 +00:00
|
|
|
// ContractWallet is a wallet for providing the contract group signature.
|
2021-11-29 12:33:46 +00:00
|
|
|
ContractWallet *wallet.Wallet
|
2021-07-30 11:26:44 +00:00
|
|
|
// Accounts contains simple signature accounts in the same order as in Wallets.
|
|
|
|
Accounts []*wallet.Account
|
2021-07-21 10:09:59 +00:00
|
|
|
Contracts map[string]*contractState
|
2021-07-20 14:51:45 +00:00
|
|
|
Command *cobra.Command
|
2021-07-29 13:23:36 +00:00
|
|
|
ContractPath string
|
2021-07-29 13:35:57 +00:00
|
|
|
Natives map[string]util.Uint160
|
2021-07-19 11:04:19 +00:00
|
|
|
}
|
|
|
|
|
2021-07-09 09:53:10 +00:00
|
|
|
func initializeSideChainCmd(cmd *cobra.Command, args []string) error {
|
2021-07-20 14:51:45 +00:00
|
|
|
initCtx, err := newInitializeContext(cmd, viper.GetViper())
|
2021-07-19 11:04:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("initialization error: %w", err)
|
|
|
|
}
|
2022-04-07 12:47:13 +00:00
|
|
|
defer initCtx.close()
|
2021-07-19 11:04:19 +00:00
|
|
|
|
|
|
|
// 1. Transfer funds to committee accounts.
|
|
|
|
cmd.Println("Stage 1: transfer GAS to alphabet nodes.")
|
|
|
|
if err := initCtx.transferFunds(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-07-20 12:08:47 +00:00
|
|
|
cmd.Println("Stage 2: set notary and alphabet nodes in designate contract.")
|
|
|
|
if err := initCtx.setNotaryAndAlphabetNodes(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-07-21 10:09:59 +00:00
|
|
|
// 3. Deploy NNS contract.
|
|
|
|
cmd.Println("Stage 3: deploy NNS contract.")
|
2021-11-29 10:15:03 +00:00
|
|
|
if err := initCtx.deployNNS(deployMethodName); err != nil {
|
2021-07-21 10:09:59 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// 4. Deploy NeoFS contracts.
|
|
|
|
cmd.Println("Stage 4: deploy NeoFS contracts.")
|
2021-12-27 10:26:22 +00:00
|
|
|
if err := initCtx.deployContracts(); err != nil {
|
2021-07-21 10:09:59 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-07-23 12:07:44 +00:00
|
|
|
cmd.Println("Stage 4.1: Transfer GAS to proxy contract.")
|
|
|
|
if err := initCtx.transferGASToProxy(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:57:11 +00:00
|
|
|
cmd.Println("Stage 5: register candidates.")
|
|
|
|
if err := initCtx.registerCandidates(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.Println("Stage 6: transfer NEO to alphabet contracts.")
|
|
|
|
if err := initCtx.transferNEOToAlphabetContracts(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-07-19 11:04:19 +00:00
|
|
|
|
2021-07-22 09:52:44 +00:00
|
|
|
cmd.Println("Stage 7: set addresses in NNS.")
|
|
|
|
if err := initCtx.setNNS(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-07-09 09:53:10 +00:00
|
|
|
return nil
|
|
|
|
}
|
2021-07-19 11:04:19 +00:00
|
|
|
|
2022-04-07 12:47:13 +00:00
|
|
|
func (c *initializeContext) close() {
|
|
|
|
if local, ok := c.Client.(*localClient); ok {
|
|
|
|
err := local.dump()
|
|
|
|
if err != nil {
|
|
|
|
c.Command.PrintErrf("Can't write dump: %v\n", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-20 14:51:45 +00:00
|
|
|
func newInitializeContext(cmd *cobra.Command, v *viper.Viper) (*initializeContext, error) {
|
2021-08-04 17:47:58 +00:00
|
|
|
walletDir := config.ResolveHomePath(viper.GetString(alphabetWalletsFlag))
|
2022-04-08 14:58:21 +00:00
|
|
|
wallets, err := openAlphabetWallets(v, walletDir)
|
2021-07-19 11:04:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-08-15 15:27:23 +00:00
|
|
|
var w *wallet.Wallet
|
|
|
|
if cmd.Name() != "deploy" {
|
|
|
|
w, err = openContractWallet(v, cmd, walletDir)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-11-29 12:33:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-07 12:47:13 +00:00
|
|
|
var c Client
|
|
|
|
if v.GetString(localDumpFlag) != "" {
|
|
|
|
if cmd.Name() != "init" {
|
|
|
|
return nil, errors.New("dump creation is only supported for `init` command")
|
|
|
|
}
|
|
|
|
if v.GetString(endpointFlag) != "" {
|
|
|
|
return nil, fmt.Errorf("`%s` and `%s` flags are mutually exclusive", endpointFlag, localDumpFlag)
|
|
|
|
}
|
|
|
|
c, err = newLocalClient(v, wallets)
|
|
|
|
} else {
|
|
|
|
c, err = getN3Client(v)
|
|
|
|
}
|
2021-07-19 11:04:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("can't create N3 client: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
committeeAcc, err := getWalletAccount(wallets[0], committeeAccountName)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("can't find committee account: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
consensusAcc, err := getWalletAccount(wallets[0], consensusAccountName)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("can't find consensus account: %w", err)
|
|
|
|
}
|
|
|
|
|
2021-08-02 07:18:42 +00:00
|
|
|
var ctrPath string
|
2021-07-28 09:21:04 +00:00
|
|
|
if cmd.Name() == "init" {
|
|
|
|
if viper.GetInt64(epochDurationInitFlag) <= 0 {
|
|
|
|
return nil, fmt.Errorf("epoch duration must be positive")
|
|
|
|
}
|
2021-07-29 10:06:25 +00:00
|
|
|
|
2021-07-28 09:21:04 +00:00
|
|
|
if viper.GetInt64(maxObjectSizeInitFlag) <= 0 {
|
|
|
|
return nil, fmt.Errorf("max object size must be positive")
|
|
|
|
}
|
2021-08-06 11:28:07 +00:00
|
|
|
}
|
2021-10-25 13:19:56 +00:00
|
|
|
|
|
|
|
needContracts := cmd.Name() == "update-contracts" || cmd.Name() == "init"
|
|
|
|
if needContracts {
|
2021-08-02 07:18:42 +00:00
|
|
|
ctrPath, err = cmd.Flags().GetString(contractsInitFlag)
|
|
|
|
if err != nil {
|
2021-10-25 13:19:56 +00:00
|
|
|
return nil, fmt.Errorf("invalid contracts path: %w", err)
|
2021-10-21 15:32:01 +00:00
|
|
|
}
|
2021-07-29 13:23:36 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 11:57:58 +00:00
|
|
|
nativeHashes, err := getNativeHashes(c)
|
2021-07-29 13:35:57 +00:00
|
|
|
if err != nil {
|
2021-11-30 11:57:58 +00:00
|
|
|
return nil, err
|
2021-08-19 10:27:43 +00:00
|
|
|
}
|
2021-07-29 13:35:57 +00:00
|
|
|
|
2021-07-30 11:26:44 +00:00
|
|
|
accounts := make([]*wallet.Account, len(wallets))
|
|
|
|
for i, w := range wallets {
|
|
|
|
acc, err := getWalletAccount(w, singleAccountName)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("wallet %s is invalid (no single account): %w", w.Path(), err)
|
|
|
|
}
|
|
|
|
accounts[i] = acc
|
|
|
|
}
|
|
|
|
|
2022-09-05 12:45:38 +00:00
|
|
|
cliCtx, err := defaultClientContext(c, committeeAcc)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("client context: %w", err)
|
|
|
|
}
|
|
|
|
|
2021-07-19 11:04:19 +00:00
|
|
|
initCtx := &initializeContext{
|
2022-09-05 12:45:38 +00:00
|
|
|
clientContext: *cliCtx,
|
2021-11-29 12:33:46 +00:00
|
|
|
ConsensusAcc: consensusAcc,
|
|
|
|
CommitteeAcc: committeeAcc,
|
|
|
|
ContractWallet: w,
|
|
|
|
Wallets: wallets,
|
|
|
|
Accounts: accounts,
|
|
|
|
Command: cmd,
|
|
|
|
Contracts: make(map[string]*contractState),
|
|
|
|
ContractPath: ctrPath,
|
|
|
|
Natives: nativeHashes,
|
2021-07-19 11:04:19 +00:00
|
|
|
}
|
|
|
|
|
2021-10-25 13:19:56 +00:00
|
|
|
if needContracts {
|
|
|
|
err := initCtx.readContracts(fullContractList)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-19 11:04:19 +00:00
|
|
|
return initCtx, nil
|
|
|
|
}
|
|
|
|
|
2021-07-29 13:35:57 +00:00
|
|
|
func (c *initializeContext) nativeHash(name string) util.Uint160 {
|
|
|
|
return c.Natives[name]
|
|
|
|
}
|
|
|
|
|
2022-04-08 14:58:21 +00:00
|
|
|
func openAlphabetWallets(v *viper.Viper, walletDir string) ([]*wallet.Wallet, error) {
|
2022-03-18 11:12:58 +00:00
|
|
|
walletFiles, err := os.ReadDir(walletDir)
|
2021-07-19 11:04:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("can't read alphabet wallets dir: %w", err)
|
|
|
|
}
|
|
|
|
|
2021-11-29 13:55:31 +00:00
|
|
|
var size int
|
|
|
|
loop:
|
2022-04-05 07:16:35 +00:00
|
|
|
for i := 0; i < len(walletFiles); i++ {
|
|
|
|
name := innerring.GlagoliticLetter(i).String() + ".json"
|
|
|
|
for j := range walletFiles {
|
|
|
|
if walletFiles[j].Name() == name {
|
2021-11-29 13:55:31 +00:00
|
|
|
size++
|
|
|
|
continue loop
|
|
|
|
}
|
|
|
|
}
|
2022-04-05 07:16:35 +00:00
|
|
|
break
|
2021-11-29 13:55:31 +00:00
|
|
|
}
|
2021-07-19 11:04:19 +00:00
|
|
|
if size == 0 {
|
|
|
|
return nil, errors.New("alphabet wallets dir is empty (run `generate-alphabet` command first)")
|
|
|
|
}
|
|
|
|
|
|
|
|
wallets := make([]*wallet.Wallet, size)
|
|
|
|
for i := 0; i < size; i++ {
|
2022-04-08 14:58:21 +00:00
|
|
|
letter := innerring.GlagoliticLetter(i).String()
|
|
|
|
p := filepath.Join(walletDir, letter+".json")
|
2021-07-19 11:04:19 +00:00
|
|
|
w, err := wallet.NewWalletFromFile(p)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("can't open wallet: %w", err)
|
|
|
|
}
|
|
|
|
|
2022-04-08 14:58:21 +00:00
|
|
|
password, err := config.GetPassword(v, letter)
|
2021-07-19 11:04:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("can't fetch password: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range w.Accounts {
|
|
|
|
if err := w.Accounts[i].Decrypt(password, keys.NEP2ScryptParams()); err != nil {
|
|
|
|
return nil, fmt.Errorf("can't unlock wallet: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wallets[i] = w
|
|
|
|
}
|
|
|
|
|
|
|
|
return wallets, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *initializeContext) awaitTx() error {
|
2021-11-30 11:45:40 +00:00
|
|
|
return c.clientContext.awaitTx(c.Command)
|
|
|
|
}
|
|
|
|
|
2022-02-02 14:19:27 +00:00
|
|
|
func (c *initializeContext) nnsContractState() (*state.Contract, error) {
|
|
|
|
if c.nnsCs != nil {
|
|
|
|
return c.nnsCs, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
cs, err := c.Client.GetContractStateByID(1)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
c.nnsCs = cs
|
|
|
|
return cs, nil
|
|
|
|
}
|
|
|
|
|
2022-04-05 14:21:11 +00:00
|
|
|
func (c *initializeContext) getSigner(tryGroup bool) transaction.Signer {
|
|
|
|
if tryGroup && c.groupKey != nil {
|
2022-02-02 14:19:27 +00:00
|
|
|
return transaction.Signer{
|
2022-06-27 14:44:22 +00:00
|
|
|
Account: c.CommitteeAcc.Contract.ScriptHash(),
|
2022-02-02 14:19:27 +00:00
|
|
|
Scopes: transaction.CustomGroups,
|
|
|
|
AllowedGroups: keys.PublicKeys{c.groupKey},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
signer := transaction.Signer{
|
|
|
|
Account: c.CommitteeAcc.Contract.ScriptHash(),
|
|
|
|
Scopes: transaction.Global, // Scope is important, as we have nested call to container contract.
|
|
|
|
}
|
|
|
|
|
2022-04-05 14:21:11 +00:00
|
|
|
if !tryGroup {
|
|
|
|
return signer
|
|
|
|
}
|
|
|
|
|
2022-02-02 14:19:27 +00:00
|
|
|
nnsCs, err := c.nnsContractState()
|
|
|
|
if err != nil {
|
|
|
|
return signer
|
|
|
|
}
|
|
|
|
|
2022-09-05 12:45:38 +00:00
|
|
|
groupKey, err := nnsResolveKey(c.ReadOnlyInvoker, nnsCs.Hash, morphClient.NNSGroupKeyName)
|
2022-02-02 14:19:27 +00:00
|
|
|
if err == nil {
|
|
|
|
c.groupKey = groupKey
|
|
|
|
|
|
|
|
signer.Scopes = transaction.CustomGroups
|
|
|
|
signer.AllowedGroups = keys.PublicKeys{groupKey}
|
|
|
|
}
|
|
|
|
return signer
|
|
|
|
}
|
|
|
|
|
2021-11-30 11:45:40 +00:00
|
|
|
func (c *clientContext) awaitTx(cmd *cobra.Command) error {
|
2021-07-26 07:55:51 +00:00
|
|
|
if len(c.Hashes) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-04-07 12:47:13 +00:00
|
|
|
if local, ok := c.Client.(*localClient); ok {
|
|
|
|
if err := local.putTransactions(); err != nil {
|
|
|
|
return fmt.Errorf("can't persist transactions: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-05 12:45:38 +00:00
|
|
|
err := awaitTx(cmd, c.Client, c.Hashes)
|
|
|
|
c.Hashes = c.Hashes[:0]
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func awaitTx(cmd *cobra.Command, c Client, hashes []util.Uint256) error {
|
2021-11-30 11:45:40 +00:00
|
|
|
cmd.Println("Waiting for transactions to persist...")
|
2021-07-20 14:51:45 +00:00
|
|
|
|
2022-09-05 12:45:38 +00:00
|
|
|
// improve TX awaiting process:
|
|
|
|
// https://github.com/nspcc-dev/neofs-node/issues/1741
|
|
|
|
const pollInterval = time.Second
|
|
|
|
const waitDuration = 30 * time.Second
|
|
|
|
|
|
|
|
tick := time.NewTicker(pollInterval)
|
2021-07-19 11:04:19 +00:00
|
|
|
defer tick.Stop()
|
|
|
|
|
2022-09-05 12:45:38 +00:00
|
|
|
timer := time.NewTimer(waitDuration)
|
2021-07-19 11:04:19 +00:00
|
|
|
defer timer.Stop()
|
|
|
|
|
|
|
|
at := trigger.Application
|
|
|
|
|
2022-04-05 14:01:59 +00:00
|
|
|
var retErr error
|
|
|
|
|
2021-07-19 11:04:19 +00:00
|
|
|
loop:
|
2022-09-05 12:45:38 +00:00
|
|
|
for i := range hashes {
|
|
|
|
res, err := c.GetApplicationLog(hashes[i], &at)
|
2021-07-20 14:51:45 +00:00
|
|
|
if err == nil {
|
2022-07-18 08:33:53 +00:00
|
|
|
if retErr == nil && len(res.Executions) > 0 && res.Executions[0].VMState != vmstate.Halt {
|
2022-04-07 12:47:13 +00:00
|
|
|
retErr = fmt.Errorf("tx %d persisted in %s state: %s",
|
|
|
|
i, res.Executions[0].VMState, res.Executions[0].FaultException)
|
2022-04-05 14:01:59 +00:00
|
|
|
}
|
2021-07-20 14:51:45 +00:00
|
|
|
continue loop
|
|
|
|
}
|
2021-07-19 11:04:19 +00:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-tick.C:
|
2022-09-05 12:45:38 +00:00
|
|
|
res, err := c.GetApplicationLog(hashes[i], &at)
|
2021-07-19 11:04:19 +00:00
|
|
|
if err == nil {
|
2022-07-18 08:33:53 +00:00
|
|
|
if retErr == nil && len(res.Executions) > 0 && res.Executions[0].VMState != vmstate.Halt {
|
2022-04-07 12:47:13 +00:00
|
|
|
retErr = fmt.Errorf("tx %d persisted in %s state: %s",
|
|
|
|
i, res.Executions[0].VMState, res.Executions[0].FaultException)
|
2022-04-05 14:01:59 +00:00
|
|
|
}
|
2021-07-19 11:04:19 +00:00
|
|
|
continue loop
|
|
|
|
}
|
|
|
|
case <-timer.C:
|
|
|
|
return errors.New("timeout while waiting for transaction to persist")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-05 14:01:59 +00:00
|
|
|
return retErr
|
2021-07-19 11:04:19 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 14:21:11 +00:00
|
|
|
// sendCommitteeTx creates transaction from script and sends it to RPC.
|
2022-09-05 12:45:38 +00:00
|
|
|
// If tryGroup is false, global scope is used for the signer (useful when
|
|
|
|
// working with native contracts).
|
2022-08-29 19:31:32 +00:00
|
|
|
func (c *initializeContext) sendCommitteeTx(script []byte, tryGroup bool) error {
|
2022-09-05 12:45:38 +00:00
|
|
|
var act *actor.Actor
|
|
|
|
var err error
|
|
|
|
|
|
|
|
if tryGroup {
|
|
|
|
act, err = actor.New(c.Client, []actor.SignerAccount{{
|
|
|
|
Signer: c.getSigner(tryGroup),
|
|
|
|
Account: c.CommitteeAcc,
|
|
|
|
}})
|
|
|
|
} else {
|
|
|
|
act, err = c.CommitteeAct, nil
|
2022-08-18 10:28:10 +00:00
|
|
|
}
|
|
|
|
if err != nil {
|
2022-08-29 19:31:32 +00:00
|
|
|
return fmt.Errorf("could not create actor: %w", err)
|
2022-08-18 10:28:10 +00:00
|
|
|
}
|
2021-07-20 12:08:47 +00:00
|
|
|
|
2022-09-05 12:45:38 +00:00
|
|
|
tx, err := act.MakeUnsignedRun(script, []transaction.Attribute{{Type: transaction.HighPriority}})
|
2022-04-07 08:10:35 +00:00
|
|
|
if err != nil {
|
2022-09-05 12:45:38 +00:00
|
|
|
return fmt.Errorf("could not perform test invocation: %w", err)
|
2022-04-07 08:10:35 +00:00
|
|
|
}
|
|
|
|
|
2022-09-05 12:45:38 +00:00
|
|
|
return c.multiSignAndSend(tx, committeeAccountName)
|
2022-04-07 08:10:35 +00:00
|
|
|
}
|
|
|
|
|
2021-07-19 11:04:19 +00:00
|
|
|
func getWalletAccount(w *wallet.Wallet, typ string) (*wallet.Account, error) {
|
|
|
|
for i := range w.Accounts {
|
|
|
|
if w.Accounts[i].Label == typ {
|
|
|
|
return w.Accounts[i], nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, fmt.Errorf("account for '%s' not found", typ)
|
|
|
|
}
|
2021-11-30 11:57:58 +00:00
|
|
|
|
2022-04-07 08:10:35 +00:00
|
|
|
func getNativeHashes(c Client) (map[string]util.Uint160, error) {
|
2021-11-30 11:57:58 +00:00
|
|
|
ns, err := c.GetNativeContracts()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("can't get native contract hashes: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
notaryEnabled := false
|
|
|
|
nativeHashes := make(map[string]util.Uint160, len(ns))
|
|
|
|
for i := range ns {
|
|
|
|
if ns[i].Manifest.Name == nativenames.Notary {
|
|
|
|
notaryEnabled = len(ns[i].UpdateHistory) > 0
|
|
|
|
}
|
|
|
|
nativeHashes[ns[i].Manifest.Name] = ns[i].Hash
|
|
|
|
}
|
|
|
|
if !notaryEnabled {
|
|
|
|
return nil, errors.New("notary contract must be enabled")
|
|
|
|
}
|
|
|
|
return nativeHashes, nil
|
|
|
|
}
|