Skip to content

Commit

Permalink
feat(cli): implement transaction timeout config
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Aug 10, 2022
1 parent bbf6451 commit 973570c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
1 change: 1 addition & 0 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ const (
FlagGasLimit = "gas-limit"
FlagNoTLS = "no-tls"
FlagTLSSkipVerify = "tls-skip-verify"
FlagTxTimeout = "tx-timeout"
)
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"strings"
"time"

"okp4/cosmos-faucet/pkg"

Expand Down Expand Up @@ -50,6 +51,7 @@ func Execute() {
FlagTLSSkipVerify,
false,
"Encryption with the GRPC endpoint but skip certificates verification")
rootCmd.PersistentFlags().DurationVar(&config.TxTimeout, FlagTxTimeout, 5*time.Second, "Transaction timeout")

err := rootCmd.Execute()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewSendCommand() *cobra.Command {
return err
}

send <- client.MakeTriggerTx(client.WithDeadline(time.Now().Add(5 * time.Second)))
send <- client.MakeTriggerTx(client.WithDeadline(time.Now().Add(config.TxTimeout)))

return err
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewStartCommand() *cobra.Command {
triggerTxChan := make(chan *client.TriggerTx)
go func() {
for range time.Tick(5 * time.Second) {
triggerTxChan <- client.MakeTriggerTx(client.WithDeadline(time.Now().Add(5 * time.Second)))
triggerTxChan <- client.MakeTriggerTx(client.WithDeadline(time.Now().Add(config.TxTimeout)))
}
}()

Expand Down
25 changes: 14 additions & 11 deletions pkg/config.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package pkg

import "time"

type Config struct {
GrpcAddress string `mapstructure:"grpc-address"`
Mnemonic string `mapstructure:"mnemonic"`
ChainID string `mapstructure:"chain-id"`
Denom string `mapstructure:"denom"`
Prefix string `mapstructure:"prefix"`
FeeAmount int64 `mapstructure:"fee-amount"`
AmountSend int64 `mapstructure:"amount-send"`
Memo string `mapstructure:"memo"`
GasLimit uint64 `mapstructure:"gas-limit"`
NoTLS bool `mapstructure:"no-tls"`
TLSSkipVerify bool `mapstructure:"tls-skip-verify"`
GrpcAddress string `mapstructure:"grpc-address"`
Mnemonic string `mapstructure:"mnemonic"`
ChainID string `mapstructure:"chain-id"`
Denom string `mapstructure:"denom"`
Prefix string `mapstructure:"prefix"`
FeeAmount int64 `mapstructure:"fee-amount"`
AmountSend int64 `mapstructure:"amount-send"`
Memo string `mapstructure:"memo"`
GasLimit uint64 `mapstructure:"gas-limit"`
NoTLS bool `mapstructure:"no-tls"`
TLSSkipVerify bool `mapstructure:"tls-skip-verify"`
TxTimeout time.Duration `mapstructure:"tx-timeout"`
}

0 comments on commit 973570c

Please sign in to comment.