Skip to content

Commit

Permalink
feat: set fee amount for tx (#3)
Browse files Browse the repository at this point in the history
* feat: set fee amount for tx

* add flag in readme
  • Loading branch information
mazzy89 authored Nov 14, 2023
1 parent 144b26b commit 07fc803
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 44 deletions.
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,22 @@ $ make install
You can configure the faucet either using command line flags or environment variables. The following table
shows the available configuration options and respective defaults:

| flag | env | description | default |
|------------------|-------------------|-------------------------------------------------------------- |-----------|
| port | PORT | tcp port where faucet will be listening for requests | 8000 |
| account-name | ACCOUNT_NAME | name of the account to be used by the faucet | faucet |
| mnemonic | MNEMONIC | mnemonic for restoring an account | |
| keyring-password | KEYRING_PASSWORD | password for accessing keyring | |
| denoms | DENOMS | denomination of the coins sent by default (comma separated) | uatom |
| credit-amount | CREDIT_AMOUNT | amount to credit in each request | 10000000 |
| max-credit | MAX_CREDIT | maximum credit per account | 100000000 |
| sdk-version | SDK_VERSION | version of sdk (launchpad or stargate) | stargate |
| node | NODE | address of tendermint RPC endpoint for this chain | |
| keyring-backend | KEYRING_BACKEND | keyring backend to be used | |
| coin-type | COIN_TYPE | registered coin type number for HD derivation (BIP-0044) | 118 |
| home | HOME | replaces the default home used by the chain | |
| | | | |
| flag | env | description | default |
|------------------|------------------|-------------------------------------------------------------- |-----------|
| port | PORT | tcp port where faucet will be listening for requests | 8000 |
| account-name | ACCOUNT_NAME | name of the account to be used by the faucet | faucet |
| mnemonic | MNEMONIC | mnemonic for restoring an account | |
| keyring-password | KEYRING_PASSWORD | password for accessing keyring | |
| denoms | DENOMS | denomination of the coins sent by default (comma separated) | uatom |
| credit-amount | CREDIT_AMOUNT | amount to credit in each request | 10000000 |
| max-credit | MAX_CREDIT | maximum credit per account | 100000000 |
| fee-amount | FEE_AMOUNT | fee to pay along with the transaction | 0 |
| sdk-version | SDK_VERSION | version of sdk (launchpad or stargate) | stargate |
| node | NODE | address of tendermint RPC endpoint for this chain | |
| keyring-backend | KEYRING_BACKEND | keyring backend to be used | |
| coin-type | COIN_TYPE | registered coin type number for HD derivation (BIP-0044) | 118 |
| home | HOME | replaces the default home used by the chain | |
| | | | |

### [gaia](https://github.com/cosmos/gaia) example

Expand Down
5 changes: 5 additions & 0 deletions cmd/faucet/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var (
defaultDenoms string
creditAmount uint64
maxCredit uint64
feeAmount uint64
nodeAddress string
coinType string
home string
Expand Down Expand Up @@ -70,6 +71,10 @@ func init() {
"max-credit", environ.GetUint64("MAX_CREDIT", cosmosfaucet.DefaultMaxAmount),
"maximum credit per account",
)
flag.Uint64Var(&feeAmount,
"fee-amount", environ.GetUint64("FEE_AMOUNT", 0),
"fee to pay along with the transaction",
)
flag.StringVar(&nodeAddress, "node",
environ.GetString("NODE", ""),
"address of tendermint RPC endpoint for this chain",
Expand Down
6 changes: 6 additions & 0 deletions cmd/faucet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"strings"

sdkmath "cosmossdk.io/math"
log "github.com/sirupsen/logrus"

"github.com/ignite/cli/ignite/pkg/chaincmd"
Expand Down Expand Up @@ -47,10 +48,15 @@ func main() {

faucetOptions := make([]cosmosfaucet.Option, len(coins))
for i, coin := range coins {
creditAmount := sdkmath.NewInt(int64(creditAmount))
maxCredit := sdkmath.NewInt(int64(maxCredit))

faucetOptions[i] = cosmosfaucet.Coin(creditAmount, maxCredit, coin)
}

faucetOptions = append(faucetOptions, cosmosfaucet.Account(keyName, keyMnemonic, coinType))
// it is fair to consider the first coin added because it is considered as the default coin during transfer requests.
faucetOptions = append(faucetOptions, cosmosfaucet.FeeAmount(sdkmath.NewInt(int64(feeAmount)), coins[0]))

faucet, err := cosmosfaucet.New(context.Background(), cr, faucetOptions...)
if err != nil {
Expand Down
24 changes: 13 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
module github.com/tendermint/faucet

go 1.21
go 1.21.1

toolchain go1.21.4

require (
github.com/ignite/cli v0.27.1
cosmossdk.io/math v1.0.1
github.com/ignite/cli v0.27.2-0.20231113174004-0691e0df824b
github.com/sirupsen/logrus v1.9.2
)

require (
cosmossdk.io/errors v1.0.0-beta.7 // indirect
cosmossdk.io/math v1.0.1 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
Expand All @@ -22,7 +24,7 @@ require (
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cometbft/cometbft v0.37.1 // indirect
github.com/cometbft/cometbft v0.37.2 // indirect
github.com/cometbft/cometbft-db v0.7.0 // indirect
github.com/confio/ics23/go v0.9.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
Expand Down Expand Up @@ -99,16 +101,16 @@ require (
github.com/zondax/hid v0.9.1 // indirect
github.com/zondax/ledger-go v0.14.1 // indirect
go.etcd.io/bbolt v1.3.7 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/exp v0.0.0-20230519143937-03e91628a987 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/grpc v1.55.0 // indirect
google.golang.org/grpc v1.56.3 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading

0 comments on commit 07fc803

Please sign in to comment.