Skip to content

Commit

Permalink
[nspcc-dev#684] neofs-adm: transfer gas to the proxy contract
Browse files Browse the repository at this point in the history
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
  • Loading branch information
fyrchik authored and alexvanin committed Jul 26, 2021
1 parent c783508 commit cf5f8a8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cmd/neofs-adm/internal/modules/morph/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-adm/internal/modules/morph/initialize_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
37 changes: 37 additions & 0 deletions cmd/neofs-adm/internal/modules/morph/initialize_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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()
}

0 comments on commit cf5f8a8

Please sign in to comment.