From cf5f8a8f7867c0022861124a0419533c608f7b0b Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 23 Jul 2021 15:07:44 +0300 Subject: [PATCH] [#684] neofs-adm: transfer gas to the proxy contract Signed-off-by: Evgenii Stratonikov --- .../internal/modules/morph/initialize.go | 5 +++ .../modules/morph/initialize_deploy.go | 2 +- .../modules/morph/initialize_transfer.go | 37 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/cmd/neofs-adm/internal/modules/morph/initialize.go b/cmd/neofs-adm/internal/modules/morph/initialize.go index c11b63cad..f3e5bdcef 100644 --- a/cmd/neofs-adm/internal/modules/morph/initialize.go +++ b/cmd/neofs-adm/internal/modules/morph/initialize.go @@ -68,6 +68,11 @@ func initializeSideChainCmd(cmd *cobra.Command, args []string) error { return err } + cmd.Println("Stage 4.1: Transfer GAS to proxy contract.") + if err := initCtx.transferGASToProxy(); err != nil { + return err + } + cmd.Println("Stage 5: register candidates.") if err := initCtx.registerCandidates(); err != nil { return err diff --git a/cmd/neofs-adm/internal/modules/morph/initialize_deploy.go b/cmd/neofs-adm/internal/modules/morph/initialize_deploy.go index 4020fba44..bbcad0659 100644 --- a/cmd/neofs-adm/internal/modules/morph/initialize_deploy.go +++ b/cmd/neofs-adm/internal/modules/morph/initialize_deploy.go @@ -138,7 +138,7 @@ func (c *initializeContext) deployContracts() error { } res, err := c.Client.InvokeFunction(mgmtHash, "deploy", params, []transaction.Signer{signer}) if err != nil { - return fmt.Errorf("can't deploy contract: %w", err) + return fmt.Errorf("can't deploy alphabet #%d contract: %w", i, err) } h, err := c.Client.SignAndPushInvocationTx(res.Script, acc, -1, 0, []client.SignerAccount{{ Signer: signer, diff --git a/cmd/neofs-adm/internal/modules/morph/initialize_transfer.go b/cmd/neofs-adm/internal/modules/morph/initialize_transfer.go index e5407b811..51d0cd136 100644 --- a/cmd/neofs-adm/internal/modules/morph/initialize_transfer.go +++ b/cmd/neofs-adm/internal/modules/morph/initialize_transfer.go @@ -5,6 +5,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/native" "github.com/nspcc-dev/neo-go/pkg/core/native/nativenames" + "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/rpc/client" scContext "github.com/nspcc-dev/neo-go/pkg/smartcontract/context" @@ -14,6 +15,8 @@ const ( gasInitialTotalSupply = 30000000 * native.GASFactor // initialAlphabetGASAmount represents amount of GAS given to each alphabet node. initialAlphabetGASAmount = 10_000 * native.GASFactor + // initialProxyGASAmount represents amount of GAS given to proxy contract. + initialProxyGASAmount = 50_000 * native.GASFactor ) func (c *initializeContext) transferFunds() error { @@ -145,3 +148,37 @@ func (c *initializeContext) multiSign(tx *transaction.Transaction, accType strin return nil } + +func (c *initializeContext) transferGASToProxy() error { + gasHash, err := c.Client.GetNativeContractHash(nativenames.Gas) + if err != nil { + return fmt.Errorf("can't fetch %s hash: %w", nativenames.Gas, err) + } + + ctrPath, err := c.Command.Flags().GetString(contractsInitFlag) + if err != nil { + return fmt.Errorf("missing contracts path: %w", err) + } + + cs, err := c.readContract(ctrPath, proxyContract) + if err != nil { + return err + } + + h := state.CreateContractHash(c.CommitteeAcc.Contract.ScriptHash(), cs.NEF.Checksum, cs.Manifest.Name) + bal, err := c.Client.NEP17BalanceOf(gasHash, h) + if err != nil || bal > 0 { + return err + } + + tx, err := c.Client.CreateNEP17TransferTx(c.CommitteeAcc, h, gasHash, initialProxyGASAmount, 0, nil, nil) + if err != nil { + return err + } + + if err := c.multiSignAndSend(tx, committeeAccountName); err != nil { + return err + } + + return c.awaitTx() +}