forked from TrueCloudLab/frostfs-node
[#1711] *: Simplify code using neo-go actors
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
4354359aed
commit
4bd8608b37
15 changed files with 92 additions and 105 deletions
|
@ -134,7 +134,7 @@ func setConfigCmd(cmd *cobra.Command, args []string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = wCtx.sendCommitteeTx(bw.Bytes(), -1, true)
|
err = wCtx.sendCommitteeTx(bw.Bytes(), true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,7 +188,7 @@ func restoreContainers(cmd *cobra.Command, _ []string) error {
|
||||||
panic(bw.Err)
|
panic(bw.Err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := wCtx.sendCommitteeTx(bw.Bytes(), -1, true); err != nil {
|
if err := wCtx.sendCommitteeTx(bw.Bytes(), true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,7 +168,7 @@ func deployContractCmd(cmd *cobra.Command, args []string) error {
|
||||||
panic(fmt.Errorf("BUG: can't create deployment script: %w", w.Err))
|
panic(fmt.Errorf("BUG: can't create deployment script: %w", w.Err))
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.sendCommitteeTx(w.Bytes(), -1, false); err != nil {
|
if err := c.sendCommitteeTx(w.Bytes(), false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return c.awaitTx()
|
return c.awaitTx()
|
||||||
|
|
|
@ -34,7 +34,7 @@ func forceNewEpochCmd(cmd *cobra.Command, args []string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := wCtx.sendCommitteeTx(bw.Bytes(), -1, true); err != nil {
|
if err := wCtx.sendCommitteeTx(bw.Bytes(), true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -195,7 +195,7 @@ func refillGas(cmd *cobra.Command, gasFlag string, createWallet bool) error {
|
||||||
return fmt.Errorf("BUG: invalid transfer arguments: %w", bw.Err)
|
return fmt.Errorf("BUG: invalid transfer arguments: %w", bw.Err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := wCtx.sendCommitteeTx(bw.Bytes(), -1, false); err != nil {
|
if err := wCtx.sendCommitteeTx(bw.Bytes(), false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ 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/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
|
||||||
"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/vmstate"
|
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
|
||||||
|
@ -364,57 +364,45 @@ loop:
|
||||||
}
|
}
|
||||||
|
|
||||||
// sendCommitteeTx creates transaction from script and sends it to RPC.
|
// sendCommitteeTx creates transaction from script and sends it to RPC.
|
||||||
// If sysFee is -1, it is calculated automatically. If tryGroup is false,
|
// Test invocation will be performed and the result will be checked. If tryGroup
|
||||||
// global scope is used for the signer (useful when working with native contracts).
|
// is false, global scope is used for the signer (useful when working with native
|
||||||
func (c *initializeContext) sendCommitteeTx(script []byte, sysFee int64, tryGroup bool) error {
|
// contracts).
|
||||||
cosigners := []rpcclient.SignerAccount{{
|
func (c *initializeContext) sendCommitteeTx(script []byte, tryGroup bool) error {
|
||||||
Signer: c.getSigner(tryGroup),
|
sigCount := len(c.CommitteeAcc.Contract.Parameters)
|
||||||
Account: c.CommitteeAcc,
|
|
||||||
}}
|
signers := make([]actor.SignerAccount, 0, sigCount)
|
||||||
tx, err := c.Client.CreateTxFromScript(script, c.CommitteeAcc, sysFee, 0, cosigners)
|
signer := c.getSigner(tryGroup)
|
||||||
|
|
||||||
|
for i, w := range c.Wallets {
|
||||||
|
if i == sigCount {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
acc, err := getWalletAccount(w, committeeAccountName)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not get %s account for %d wallet: %w",
|
||||||
|
committeeAccountName, i, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
signers = append(signers, actor.SignerAccount{
|
||||||
|
Signer: signer,
|
||||||
|
Account: acc,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
act, err := actor.New(c.Client, signers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't create tx: %w", err)
|
return fmt.Errorf("could not create actor: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tx.Attributes = append(tx.Attributes, transaction.Attribute{Type: transaction.HighPriority})
|
txHash, _, err := act.SendTunedRun(script, []transaction.Attribute{{Type: transaction.HighPriority}}, nil)
|
||||||
|
|
||||||
// Calculate network fee again, because tx size has changed.
|
|
||||||
_, accounts, err := getSigners(c.CommitteeAcc, cosigners)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Errorf("BUG: can't calculate network fee: %w", err))
|
return fmt.Errorf("cound not send transaction: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tx.NetworkFee = 0
|
c.Hashes = append(c.Hashes, txHash)
|
||||||
err = c.Client.AddNetworkFee(tx, 0, accounts...)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to add network fee: %w", err)
|
|
||||||
}
|
|
||||||
return c.multiSignAndSend(tx, committeeAccountName)
|
|
||||||
}
|
|
||||||
|
|
||||||
// sendSingleTx creates transaction signed by a simple account and pushes in onto the chain.
|
return nil
|
||||||
// It neither waits until tx persists nor checks the execution result.
|
|
||||||
func (c *initializeContext) sendSingleTx(script []byte, sysFee int64, acc *wallet.Account) error {
|
|
||||||
tx, err := c.Client.CreateTxFromScript(script, acc, sysFee, 0, []rpcclient.SignerAccount{{
|
|
||||||
Signer: transaction.Signer{
|
|
||||||
Account: acc.Contract.ScriptHash(),
|
|
||||||
Scopes: transaction.CalledByEntry,
|
|
||||||
},
|
|
||||||
Account: acc,
|
|
||||||
}})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
magic, err := c.Client.GetNetwork()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't fetch network magic: %w", err)
|
|
||||||
}
|
|
||||||
if err := acc.SignTx(magic, tx); err != nil {
|
|
||||||
return fmt.Errorf("can't sign tx: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.sendTx(tx, c.Command, false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getWalletAccount(w *wallet.Wallet, typ string) (*wallet.Account, error) {
|
func getWalletAccount(w *wallet.Wallet, typ string) (*wallet.Account, error) {
|
||||||
|
|
|
@ -18,6 +18,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
io2 "github.com/nspcc-dev/neo-go/pkg/io"
|
io2 "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/rpcclient/actor"
|
||||||
"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"
|
||||||
|
@ -203,18 +204,7 @@ func (c *initializeContext) updateContracts() error {
|
||||||
emit.AppCallNoArgs(w.BinWriter, ctrHash, updateMethodName, callflag.All)
|
emit.AppCallNoArgs(w.BinWriter, ctrHash, updateMethodName, callflag.All)
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := c.Client.InvokeScript(w.Bytes(), []transaction.Signer{{
|
if err := c.sendCommitteeTx(w.Bytes(), false); err != nil {
|
||||||
Account: c.CommitteeAcc.Contract.ScriptHash(),
|
|
||||||
Scopes: transaction.Global,
|
|
||||||
}})
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't update alphabet contracts: %w", err)
|
|
||||||
}
|
|
||||||
if res.State != vmstate.Halt.String() {
|
|
||||||
return fmt.Errorf("can't update alphabet contracts: %s", res.FaultException)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := c.sendCommitteeTx(res.Script, res.GasConsumed, false); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,7 +284,7 @@ func (c *initializeContext) updateContracts() error {
|
||||||
emit.Opcodes(w.BinWriter, opcode.LDSFLD0)
|
emit.Opcodes(w.BinWriter, opcode.LDSFLD0)
|
||||||
emit.AppCallNoArgs(w.BinWriter, nnsHash, "setPrice", callflag.All)
|
emit.AppCallNoArgs(w.BinWriter, nnsHash, "setPrice", callflag.All)
|
||||||
|
|
||||||
if err := c.sendCommitteeTx(w.Bytes(), -1, false); err != nil {
|
if err := c.sendCommitteeTx(w.Bytes(), false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return c.awaitTx()
|
return c.awaitTx()
|
||||||
|
@ -325,20 +315,17 @@ func (c *initializeContext) deployContracts() error {
|
||||||
keysParam = append(keysParam, acc.PrivateKey().PublicKey().Bytes())
|
keysParam = append(keysParam, acc.PrivateKey().PublicKey().Bytes())
|
||||||
params := getContractDeployParameters(alphaCs, c.getAlphabetDeployItems(i, len(c.Wallets)))
|
params := getContractDeployParameters(alphaCs, c.getAlphabetDeployItems(i, len(c.Wallets)))
|
||||||
|
|
||||||
res, err := invokeFunction(c.Client, mgmtHash, deployMethodName, params, []transaction.Signer{{
|
act, err := actor.NewSimple(c.Client, acc)
|
||||||
Account: acc.Contract.ScriptHash(),
|
if err != nil {
|
||||||
Scopes: transaction.CalledByEntry,
|
return fmt.Errorf("could not create actor: %w", err)
|
||||||
}})
|
}
|
||||||
|
|
||||||
|
txHash, _, err := act.SendCall(mgmtHash, deployMethodName, params...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't deploy alphabet #%d contract: %w", i, err)
|
return fmt.Errorf("can't deploy alphabet #%d contract: %w", i, err)
|
||||||
}
|
}
|
||||||
if res.State != vmstate.Halt.String() {
|
|
||||||
return fmt.Errorf("can't deploy alpabet #%d contract: %s", i, res.FaultException)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := c.sendSingleTx(res.Script, res.GasConsumed, acc); err != nil {
|
c.Hashes = append(c.Hashes, txHash)
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, ctrName := range contractList {
|
for _, ctrName := range contractList {
|
||||||
|
@ -369,7 +356,7 @@ func (c *initializeContext) deployContracts() error {
|
||||||
return fmt.Errorf("can't deploy %s contract: %s", ctrName, res.FaultException)
|
return fmt.Errorf("can't deploy %s contract: %s", ctrName, res.FaultException)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.sendCommitteeTx(res.Script, res.GasConsumed, false); err != nil {
|
if err := c.sendCommitteeTx(res.Script, false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ func (c *initializeContext) setNNS() error {
|
||||||
"neofs", c.CommitteeAcc.Contract.ScriptHash(),
|
"neofs", c.CommitteeAcc.Contract.ScriptHash(),
|
||||||
"ops@nspcc.ru", int64(3600), int64(600), int64(defaultExpirationTime), int64(3600))
|
"ops@nspcc.ru", int64(3600), int64(600), int64(defaultExpirationTime), int64(3600))
|
||||||
emit.Opcodes(bw.BinWriter, opcode.ASSERT)
|
emit.Opcodes(bw.BinWriter, opcode.ASSERT)
|
||||||
if err := c.sendCommitteeTx(bw.Bytes(), -1, true); err != nil {
|
if err := c.sendCommitteeTx(bw.Bytes(), true); err != nil {
|
||||||
return fmt.Errorf("can't add domain root to NNS: %w", err)
|
return fmt.Errorf("can't add domain root to NNS: %w", err)
|
||||||
}
|
}
|
||||||
if err := c.awaitTx(); err != nil {
|
if err := c.awaitTx(); err != nil {
|
||||||
|
@ -94,7 +94,7 @@ func (c *initializeContext) updateNNSGroup(nnsHash util.Uint160, pub *keys.Publi
|
||||||
script = w.Bytes()
|
script = w.Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.sendCommitteeTx(script, -1, true)
|
return c.sendCommitteeTx(script, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// emitUpdateNNSGroupScript emits script for updating group key stored in NNS.
|
// emitUpdateNNSGroupScript emits script for updating group key stored in NNS.
|
||||||
|
@ -199,7 +199,7 @@ func (c *initializeContext) nnsRegisterDomain(nnsHash, expectedHash util.Uint160
|
||||||
domain, int64(nns.TXT), expectedHash.StringLE())
|
domain, int64(nns.TXT), expectedHash.StringLE())
|
||||||
emit.AppCall(w.BinWriter, nnsHash, "addRecord", callflag.All,
|
emit.AppCall(w.BinWriter, nnsHash, "addRecord", callflag.All,
|
||||||
domain, int64(nns.TXT), address.Uint160ToString(expectedHash))
|
domain, int64(nns.TXT), address.Uint160ToString(expectedHash))
|
||||||
return c.sendCommitteeTx(w.Bytes(), -1, true)
|
return c.sendCommitteeTx(w.Bytes(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *initializeContext) nnsRootRegistered(nnsHash util.Uint160, zone string) (bool, error) {
|
func (c *initializeContext) nnsRootRegistered(nnsHash util.Uint160, zone string) (bool, error) {
|
||||||
|
|
|
@ -104,7 +104,7 @@ func (c *initializeContext) transferNEOToAlphabetContracts() error {
|
||||||
emit.Opcodes(bw.BinWriter, opcode.ASSERT)
|
emit.Opcodes(bw.BinWriter, opcode.ASSERT)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.sendCommitteeTx(bw.Bytes(), -1, false); err != nil {
|
if err := c.sendCommitteeTx(bw.Bytes(), false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ func (c *initializeContext) setNotaryAndAlphabetNodes() error {
|
||||||
emit.AppCall(w.BinWriter, designateHash, "designateAsRole",
|
emit.AppCall(w.BinWriter, designateHash, "designateAsRole",
|
||||||
callflag.States|callflag.AllowNotify, int64(noderoles.NeoFSAlphabet), pubs)
|
callflag.States|callflag.AllowNotify, int64(noderoles.NeoFSAlphabet), pubs)
|
||||||
|
|
||||||
if err := c.sendCommitteeTx(w.Bytes(), -1, false); err != nil {
|
if err := c.sendCommitteeTx(w.Bytes(), false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -179,6 +179,21 @@ func (l *localClient) SignAndPushInvocationTx(_ []byte, _ *wallet.Account, _ int
|
||||||
panic("unexpected call")
|
panic("unexpected call")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *localClient) GetVersion() (*result.Version, error) {
|
||||||
|
// not used by `morph init` command
|
||||||
|
panic("unexpected call")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *localClient) InvokeContractVerify(contract util.Uint160, params []smartcontract.Parameter, signers []transaction.Signer, witnesses ...transaction.Witness) (*result.Invoke, error) {
|
||||||
|
// not used by `morph init` command
|
||||||
|
panic("unexpected call")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *localClient) CalculateNetworkFee(tx *transaction.Transaction) (int64, error) {
|
||||||
|
// not used by `morph init` command
|
||||||
|
panic("unexpected call")
|
||||||
|
}
|
||||||
|
|
||||||
// AddNetworkFee adds network fee for each witness script and optional extra
|
// AddNetworkFee adds network fee for each witness script and optional extra
|
||||||
// network fee to transaction. `accs` is an array signer's accounts.
|
// network fee to transaction. `accs` is an array signer's accounts.
|
||||||
// Copied from neo-go with minor corrections (no need to support contract signers):
|
// Copied from neo-go with minor corrections (no need to support contract signers):
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
"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/wallet"
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||||
|
@ -30,12 +31,16 @@ type Client interface {
|
||||||
GetNativeContracts() ([]state.NativeContract, error)
|
GetNativeContracts() ([]state.NativeContract, error)
|
||||||
GetNetwork() (netmode.Magic, error)
|
GetNetwork() (netmode.Magic, error)
|
||||||
GetApplicationLog(util.Uint256, *trigger.Type) (*result.ApplicationLog, error)
|
GetApplicationLog(util.Uint256, *trigger.Type) (*result.ApplicationLog, error)
|
||||||
|
GetVersion() (*result.Version, error)
|
||||||
CreateTxFromScript([]byte, *wallet.Account, int64, int64, []rpcclient.SignerAccount) (*transaction.Transaction, error)
|
CreateTxFromScript([]byte, *wallet.Account, int64, int64, []rpcclient.SignerAccount) (*transaction.Transaction, error)
|
||||||
NEP17BalanceOf(util.Uint160, util.Uint160) (int64, error)
|
NEP17BalanceOf(util.Uint160, util.Uint160) (int64, error)
|
||||||
|
InvokeContractVerify(contract util.Uint160, params []smartcontract.Parameter, signers []transaction.Signer, witnesses ...transaction.Witness) (*result.Invoke, error)
|
||||||
|
InvokeFunction(contract util.Uint160, operation string, params []smartcontract.Parameter, signers []transaction.Signer) (*result.Invoke, error)
|
||||||
InvokeScript([]byte, []transaction.Signer) (*result.Invoke, error)
|
InvokeScript([]byte, []transaction.Signer) (*result.Invoke, error)
|
||||||
SendRawTransaction(*transaction.Transaction) (util.Uint256, error)
|
SendRawTransaction(*transaction.Transaction) (util.Uint256, error)
|
||||||
GetCommittee() (keys.PublicKeys, error)
|
GetCommittee() (keys.PublicKeys, error)
|
||||||
CalculateNotaryFee(uint8) (int64, error)
|
CalculateNotaryFee(uint8) (int64, error)
|
||||||
|
CalculateNetworkFee(tx *transaction.Transaction) (int64, error)
|
||||||
AddNetworkFee(*transaction.Transaction, int64, ...*wallet.Account) error
|
AddNetworkFee(*transaction.Transaction, int64, ...*wallet.Account) error
|
||||||
SignAndPushInvocationTx([]byte, *wallet.Account, int64, fixedn.Fixed8, []rpcclient.SignerAccount) (util.Uint256, error)
|
SignAndPushInvocationTx([]byte, *wallet.Account, int64, fixedn.Fixed8, []rpcclient.SignerAccount) (util.Uint256, error)
|
||||||
SignAndPushP2PNotaryRequest(*transaction.Transaction, []byte, int64, int64, uint32, *wallet.Account) (*payload.P2PNotaryRequest, error)
|
SignAndPushP2PNotaryRequest(*transaction.Transaction, []byte, int64, int64, uint32, *wallet.Account) (*payload.P2PNotaryRequest, error)
|
||||||
|
|
|
@ -2,6 +2,7 @@ package morph
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/big"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/cli/input"
|
"github.com/nspcc-dev/neo-go/cli/input"
|
||||||
|
@ -9,11 +10,8 @@ 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/actor"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/nep17"
|
||||||
"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/vm/opcode"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
@ -105,15 +103,7 @@ func depositNotary(cmd *cobra.Command, _ []string) error {
|
||||||
return fmt.Errorf("can't get current height: %v", err)
|
return fmt.Errorf("can't get current height: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
bw := io.NewBufBinWriter()
|
act, err := actor.New(c, []actor.SignerAccount{{
|
||||||
emit.AppCall(bw.BinWriter, gasHash, "transfer", callflag.All,
|
|
||||||
accHash, notaryHash.BytesBE(), int64(gasAmount), []interface{}{nil, int64(height) + till})
|
|
||||||
emit.Opcodes(bw.BinWriter, opcode.ASSERT)
|
|
||||||
if bw.Err != nil {
|
|
||||||
return fmt.Errorf("BUG: invalid transfer arguments: %w", bw.Err)
|
|
||||||
}
|
|
||||||
|
|
||||||
tx, err := c.CreateTxFromScript(bw.Bytes(), acc, -1, 0, []rpcclient.SignerAccount{{
|
|
||||||
Signer: transaction.Signer{
|
Signer: transaction.Signer{
|
||||||
Account: acc.Contract.ScriptHash(),
|
Account: acc.Contract.ScriptHash(),
|
||||||
Scopes: transaction.Global,
|
Scopes: transaction.Global,
|
||||||
|
@ -121,21 +111,23 @@ func depositNotary(cmd *cobra.Command, _ []string) error {
|
||||||
Account: acc,
|
Account: acc,
|
||||||
}})
|
}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't create tx: %w", err)
|
return fmt.Errorf("could not create actor: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
mn, err := c.GetNetwork()
|
gas := nep17.New(act, gasHash)
|
||||||
if err != nil {
|
|
||||||
// error appears only if client
|
|
||||||
// has not been initialized
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = acc.SignTx(mn, tx)
|
txHash, _, err := gas.Transfer(
|
||||||
|
accHash,
|
||||||
|
notaryHash,
|
||||||
|
big.NewInt(int64(gasAmount)),
|
||||||
|
[]interface{}{nil, int64(height) + till},
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't sign tx: %w", err)
|
return fmt.Errorf("could not send tx: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cc := defaultClientContext(c)
|
cc := defaultClientContext(c)
|
||||||
return cc.sendTx(tx, cmd, true)
|
cc.Hashes = append(cc.Hashes, txHash)
|
||||||
|
|
||||||
|
return cc.awaitTx(cmd)
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ func setPolicyCmd(cmd *cobra.Command, args []string) error {
|
||||||
emit.AppCall(bw.BinWriter, policyHash, "set"+kv[0], callflag.All, int64(value))
|
emit.AppCall(bw.BinWriter, policyHash, "set"+kv[0], callflag.All, int64(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := wCtx.sendCommitteeTx(bw.Bytes(), -1, false); err != nil {
|
if err := wCtx.sendCommitteeTx(bw.Bytes(), false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ func removeNodesCmd(cmd *cobra.Command, args []string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := wCtx.sendCommitteeTx(bw.Bytes(), -1, true); err != nil {
|
if err := wCtx.sendCommitteeTx(bw.Bytes(), true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue