From da086b28bd8b10e591cea748f4aed5527ab63503 Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Mon, 14 Oct 2024 21:14:13 +0400 Subject: [PATCH] handle single address for faucet, handle send token from holder itself if distributor is empty --- starship/charts/devnet/templates/registry.yaml | 2 +- starship/faucet/app.go | 7 ++++++- starship/faucet/distributor.go | 7 ++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/starship/charts/devnet/templates/registry.yaml b/starship/charts/devnet/templates/registry.yaml index a81671d9..556add2a 100644 --- a/starship/charts/devnet/templates/registry.yaml +++ b/starship/charts/devnet/templates/registry.yaml @@ -145,7 +145,7 @@ data: ], "coingecko_id": "{{ $chain.name }}" } - ] + ] {{- end }} } chain.json: |- diff --git a/starship/faucet/app.go b/starship/faucet/app.go index eb3c40e4..eb7f370c 100644 --- a/starship/faucet/app.go +++ b/starship/faucet/app.go @@ -208,7 +208,12 @@ func (a *AppServer) Run() error { } }() - // start distributor + // start distributor if distrubutor.Addrs is not empty + if a.distributor.Addrs == nil { + a.logger.Info("no distributor addresses provided") + return nil + } + go func() { for { disStatus, err := a.distributor.Status() diff --git a/starship/faucet/distributor.go b/starship/faucet/distributor.go index b06ed0ff..46cdc4b4 100644 --- a/starship/faucet/distributor.go +++ b/starship/faucet/distributor.go @@ -163,8 +163,13 @@ func (d *Distributor) Status() ([]AccountBalances, error) { // SendTokens will transfer tokens to the given address and denom from one of distributor addresses func (d *Distributor) SendTokens(address string, denom string) error { - randIndex := rand.Intn(len(d.Addrs)) amount := d.CreditCoins.GetDenomAmount(denom) + + if d.Addrs == nil { + return d.Holder.SendTokens(address, denom, amount) + } + + randIndex := rand.Intn(len(d.Addrs)) if amount == "" { return fmt.Errorf("invalid denom: %s, expected denoms: %s", denom, d.CreditCoins.GetDenoms()) }