[#684] neofs-adm: transfer gas to the proxy contract

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2021-07-23 15:07:44 +03:00 committed by Alex Vanin
parent c78350846a
commit cf5f8a8f78
3 changed files with 43 additions and 1 deletions

View file

@ -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

View file

@ -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,

View file

@ -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()
}