From 9040ca9de2fd6de76c334db839561adda12704f8 Mon Sep 17 00:00:00 2001 From: dusan-maksimovic <94966669+dusan-maksimovic@users.noreply.github.com> Date: Thu, 25 May 2023 08:21:34 +0200 Subject: [PATCH] Modify rootchain command to use the provided private key to fund validators (#1540) * Modified rootchain command to use the provided private key to fund validators --- command/rootchain/fund/fund.go | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/command/rootchain/fund/fund.go b/command/rootchain/fund/fund.go index 10d6310680..fdf87da36f 100644 --- a/command/rootchain/fund/fund.go +++ b/command/rootchain/fund/fund.go @@ -91,19 +91,16 @@ func runCommand(cmd *cobra.Command, _ []string) { return } - var ( - deployerKey ethgo.Key - stakeTokenAddr types.Address - ) + deployerKey, err := helper.GetRootchainPrivateKey(params.deployerPrivateKey) + if err != nil { + outputter.SetError(fmt.Errorf("failed to initialize deployer private key: %w", err)) - if params.mintStakeToken { - deployerKey, err = helper.GetRootchainPrivateKey(params.deployerPrivateKey) - if err != nil { - outputter.SetError(fmt.Errorf("failed to initialize deployer private key: %w", err)) + return + } - return - } + var stakeTokenAddr types.Address + if params.mintStakeToken { stakeTokenAddr = types.StringToAddress(params.stakeTokenAddr) } @@ -126,7 +123,14 @@ func runCommand(cmd *cobra.Command, _ []string) { Value: params.amountValues[i], } - receipt, err := txRelayer.SendTransactionLocal(txn) + var receipt *ethgo.Receipt + + if params.deployerPrivateKey != "" { + receipt, err = txRelayer.SendTransaction(txn, deployerKey) + } else { + receipt, err = txRelayer.SendTransactionLocal(txn) + } + if err != nil { return fmt.Errorf("failed to send fund validator '%s' transaction: %w", validatorAddr, err) }