From 56643523012f94d25e0ee003cab926a533391091 Mon Sep 17 00:00:00 2001 From: artemijspavlovs <19916123+artemijspavlovs@users.noreply.github.com> Date: Sun, 24 Nov 2024 15:05:20 +0700 Subject: [PATCH] feat: prompt to fund the relayer key continuously --- utils/keys/relayer.go | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/utils/keys/relayer.go b/utils/keys/relayer.go index b40f2578..e797e156 100644 --- a/utils/keys/relayer.go +++ b/utils/keys/relayer.go @@ -1,6 +1,7 @@ package keys import ( + "errors" "fmt" "os/exec" "path" @@ -85,10 +86,9 @@ func GetRelayerKeysConfig(rollappConfig roller.RollappConfig) map[string]KeyConf } func GetRelayerKeysToFund(rollappConfig roller.RollappConfig) error { - relayerAddresses := make([]KeyInfo, 0) relayerKeys := GetRelayerKeysConfig(rollappConfig) - relayerHubAddress, err := GetRelayerAddressInfo( + rhki, err := GetRelayerAddressInfo( relayerKeys[consts.KeysIds.HubRelayer], rollappConfig.HubData.ID, ) @@ -96,15 +96,32 @@ func GetRelayerKeysToFund(rollappConfig roller.RollappConfig) error { return err } - relayerAddresses = append( - relayerAddresses, *relayerHubAddress, - ) + for { + cqc := ChainQueryConfig{ + Binary: consts.Executables.Dymension, + Denom: consts.Denoms.Hub, + RPC: rollappConfig.HubData.RpcUrl, + } + balance, err := QueryBalance(cqc, rhki.Address) + if err != nil { + return err + } - pterm.Info.Println( - "please fund the hub relayer key with at least 20 dym tokens: ", - ) - for _, k := range relayerAddresses { - k.Print(WithName()) + if !balance.Amount.IsPositive() { + pterm.Info.Println( + "please fund the addresses below to operate the relayer.", + ) + rhki.Print(WithName()) + proceed, _ := pterm.DefaultInteractiveConfirm.WithDefaultValue(false). + WithDefaultText( + "press 'y' when the wallets are funded", + ).Show() + if !proceed { + return errors.New("cancelled by user") + } + } else { + break + } } return nil