Skip to content

Commit

Permalink
feat: possibility to use different decimals
Browse files Browse the repository at this point in the history
This will allow discord faucet to be used in multiple different decimals
other than micro
  • Loading branch information
jlehtimaki committed Sep 25, 2024
1 parent 8e5bc6b commit a724eb4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 6 additions & 5 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ type Config struct {
Token string `env:"TOKEN" envDefault:"" mapstructure:"TOKEN"`
PurgeInterval string `env:"PURGE_INTERVAL" envDefault:"10s" mapstructure:"PURGE_INTERVAL"`
Mnemonic string `env:"MNEMONIC" envDefault:"" mapstructure:"MNEMONIC"`
Node string `env:"NODE" envDefault:"https://rpc.buenavista.wardenprotocol.org:443" mapstructure:"NODE"`
ChainID string `env:"CHAIN_ID" envDefault:"buenavista-1" mapstructure:"CHAIN_ID"`
Node string `env:"NODE" envDefault:"https://rpc.chiado.wardenprotocol.org:443" mapstructure:"NODE"`
ChainID string `env:"CHAIN_ID" envDefault:"chiado_10010-1" mapstructure:"CHAIN_ID"`
CliName string `env:"CLI_NAME" envDefault:"wardend" mapstructure:"CLI_NAME"`
AccountName string `env:"ACCOUNT_NAME" envDefault:"faucet" mapstructure:"ACCOUNT_NAME"`
Denom string `env:"DENOM" envDefault:"uward" mapstructure:"DENOM"`
Amount string `env:"AMOUNT" envDefault:"10000000" mapstructure:"AMOUNT"`
Fees string `env:"FEES" envDefault:"25uward" mapstructure:"FEES"`
Denom string `env:"DENOM" envDefault:"award" mapstructure:"DENOM"`
Amount string `env:"AMOUNT" envDefault:"10" mapstructure:"AMOUNT"`
Decimal int `env:"DECIMAL" envDefault:"18" mapstructure:"DECIMAL"`
Fees string `env:"FEES" envDefault:"25000000000000award" mapstructure:"FEES"`
TXRetry int `env:"TX_RETRY" envDefault:"10" mapstructure:"TX_RETRY"`
CoolDown string `env:"COOLDOWN" envDefault:"10s" mapstructure:"COOLDOWN"`
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/faucet/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Faucet struct {
TXRetry int
Requests map[string]time.Time
Logger zerolog.Logger
Decimals int
}

const (
Expand Down Expand Up @@ -121,6 +122,7 @@ func InitFaucet(config config.Config) (Faucet, error) {
Amount: config.Amount,
Fees: config.Fees,
TXRetry: config.TXRetry,
Decimals: config.Decimal,
}
if err = env.Parse(&f); err != nil {
return Faucet{}, err
Expand Down Expand Up @@ -160,7 +162,7 @@ func (f *Faucet) Send(addr string, retry int) (string, error) {

f.Logger.Info().Msgf("sending %s%s to %v", f.Amount, f.Denom, addr)

amount := f.Amount + f.Denom
amount := f.Amount + strings.Repeat("0", f.Decimals) + f.Denom

cmd := strings.Join([]string{
f.CliName,
Expand Down

0 comments on commit a724eb4

Please sign in to comment.