Skip to content

Commit

Permalink
feat: generate a default mnemonic for chains without keys (#33)
Browse files Browse the repository at this point in the history
* bump ignite repos

* run go work sync

* generate a default mnemonic for chains without keys

* improve logs

* bump cli version

* fix missing import

* fix makefile and tools

* fix makefile

* use only one tools file

* fix readme

* reduce gas values

* add generate config flag

* fix line scape

* add missing parameters

* add missing parameters and fix default values

* remove go.work.sum

* change flag `generate-config` to `overwrite-config`

* add stdin

* use dec coin instead coin

* set option for json output

* organize the code

---------

Co-authored-by: Pantani <Pantani>
  • Loading branch information
Pantani authored Dec 21, 2023
1 parent 05f4a8e commit 4438ed1
Show file tree
Hide file tree
Showing 6 changed files with 381 additions and 161 deletions.
241 changes: 182 additions & 59 deletions hermes/cmd/hermes_configure.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions hermes/cmd/hermes_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func hermesStartHandler(cmd *cobra.Command, args []string) (err error) {
return h.Start(
cmd.Context(),
hermes.WithConfigFile(cfgPath),
hermes.WithStdIn(cmd.InOrStdin()),
hermes.WithStdOut(cmd.OutOrStdout()),
hermes.WithStdErr(cmd.ErrOrStderr()),
)
Expand Down
4 changes: 2 additions & 2 deletions hermes/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ go 1.21.1

require (
github.com/cosmos/cosmos-sdk v0.50.1
github.com/cosmos/go-bip39 v1.0.0
github.com/gookit/color v1.5.4
github.com/hashicorp/go-plugin v1.5.2
github.com/ignite/cli/v28 v28.0.0
github.com/ignite/ignite-files/hermes v0.0.1
github.com/ignite/ignite-files/hermes v0.0.3
github.com/manifoldco/promptui v0.9.0
github.com/pelletier/go-toml/v2 v2.1.0
github.com/spf13/cobra v1.8.0
Expand Down Expand Up @@ -57,7 +58,6 @@ require (
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-db v1.0.0 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.3 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/gogoproto v1.4.11 // indirect
github.com/cosmos/iavl v1.0.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions hermes/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ignite/cli/v28 v28.0.0 h1:f9TTOEgO463PI8eyeMEhsWszQmxNjoqpS15dpRAh/z0=
github.com/ignite/cli/v28 v28.0.0/go.mod h1:e6WsdlAhZzduD5f8ZuR86pi7Hu+8xgIsDVJ4HTQYdD4=
github.com/ignite/ignite-files/hermes v0.0.1 h1:iOJSVg/JPLAdTC1GXDl/OoHwWcDPvZmGMxmK3mSRPMQ=
github.com/ignite/ignite-files/hermes v0.0.1/go.mod h1:kPjepcAop4Wet3TaFai2MXQBAPq3U1j8/kZL5mmVC0o=
github.com/ignite/ignite-files/hermes v0.0.3 h1:Mki12RE2bfhWumNGIeQFkqkdXTlxmVmcXwZDKSGxFOE=
github.com/ignite/ignite-files/hermes v0.0.3/go.mod h1:gEV6t8um6pTNR8A49C7gyXTUjQJdHx50AhpcSij9KN0=
github.com/improbable-eng/grpc-web v0.15.0 h1:BN+7z6uNXZ1tQGcNAuaU1YjsLTApzkjt2tzCixLaUPQ=
github.com/improbable-eng/grpc-web v0.15.0/go.mod h1:1sy9HKV4Jt9aEs9JSnkWlRJPuPtwNr0l57L4f878wP8=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
Expand Down
239 changes: 155 additions & 84 deletions hermes/pkg/hermes/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,99 @@ const (
type (
// Config represents the Hermes config struct.
Config struct {
Chains Chains `toml:"chains" json:"chains"`
Global Global `toml:"global" json:"global"`
Telemetry Telemetry `toml:"telemetry" json:"telemetry"`
Mode Mode `toml:"mode" json:"mode"`
Rest Rest `toml:"rest" json:"rest"`
Telemetry Telemetry `toml:"telemetry" json:"telemetry"`
Chains Chains `toml:"chains" json:"chains"`
}

// Global represents the global values into the Hermes config struct.
Global struct {
LogLevel string `toml:"log_level" json:"log_level"`
}

// Mode represents the mode into the Hermes config struct.
Mode struct {
Clients Clients `toml:"clients" json:"clients"`
Connections Connections `toml:"connections" json:"connections"`
Channels Channels `toml:"channels" json:"channels"`
Packets Packets `toml:"packets" json:"packets"`
}

// Clients represents the mode clients into the Hermes config struct.
Clients struct {
Enabled bool `toml:"enabled" json:"enabled"`
Refresh bool `toml:"refresh" json:"refresh"`
Misbehaviour bool `toml:"misbehaviour" json:"misbehaviour"`
}

// Connections represents the mode connections into the Hermes config struct.
Connections struct {
Enabled bool `toml:"enabled" json:"enabled"`
}

// Channels represents the mode channels into the Hermes config struct.
Channels struct {
Enabled bool `toml:"enabled" json:"enabled"`
}

// Packets represents the mode packets into the Hermes config struct.
Packets struct {
Enabled bool `toml:"enabled" json:"enabled"`
ClearInterval uint64 `toml:"clear_interval" json:"clear_interval"`
ClearOnStart bool `toml:"clear_on_start" json:"clear_on_start"`
TxConfirmation bool `toml:"tx_confirmation" json:"tx_confirmation"`
AutoRegisterCounterpartyPayee bool `toml:"auto_register_counterparty_payee" json:"auto_register_counterparty_payee"`
}

// Rest represents the rest into the Hermes config struct.
Rest struct {
Enabled bool `toml:"enabled" json:"enabled"`
Host string `toml:"host" json:"host"`
Port uint64 `toml:"port" json:"port"`
}

// Telemetry represents the telemetry into the Hermes config struct.
Telemetry struct {
Enabled bool `toml:"enabled" json:"enabled"`
Host string `toml:"host" json:"host"`
Port uint64 `toml:"port" json:"port"`
}

// TracingServer represents the tracing server into the Hermes config struct.
TracingServer struct {
Enabled bool `toml:"enabled" json:"enabled"`
Port uint64 `toml:"port" json:"port"`
}

// Chains represents a list of chains.
Chains []Chain

// Chain represents the chain into the Hermes config struct.
Chain struct {
ID string `toml:"id" json:"id"`
RPCAddr string `toml:"rpc_addr" json:"rpc_addr"`
GRPCAddr string `toml:"grpc_addr" json:"grpc_addr"`
EventSource EventSource `toml:"event_source,inline" json:"event_source"`
RPCTimeout string `toml:"rpc_timeout" json:"rpc_timeout"`
AccountPrefix string `toml:"account_prefix" json:"account_prefix"`
KeyName string `toml:"key_name" json:"key_name"`
StorePrefix string `toml:"store_prefix" json:"store_prefix"`
DefaultGas uint64 `toml:"default_gas" json:"default_gas"`
MaxGas uint64 `toml:"max_gas" json:"max_gas"`
GasPrice GasPrice `toml:"gas_price,inline" json:"gas_price"`
GasMultiplier float64 `toml:"gas_multiplier" json:"gas_multiplier"`
MaxMsgNum uint64 `toml:"max_msg_num" json:"max_msg_num"`
MaxTxSize uint64 `toml:"max_tx_size" json:"max_tx_size"`
ClockDrift string `toml:"clock_drift" json:"clock_drift"`
MaxBlockTime string `toml:"max_block_time" json:"max_block_time"`
TrustingPeriod string `toml:"trusting_period" json:"trusting_period"`
TrustThreshold TrustThreshold `toml:"trust_threshold,inline" json:"trust_threshold"`
AddressType AddressType `toml:"address_type,inline" json:"address_type"`
ID string `toml:"id" json:"id"`
CCVConsumerChain bool `toml:"ccv_consumer_chain" json:"ccv_consumer_chain"`
RPCAddr string `toml:"rpc_addr" json:"rpc_addr"`
GRPCAddr string `toml:"grpc_addr" json:"grpc_addr"`
EventSource EventSource `toml:"event_source,inline" json:"event_source"`
RPCTimeout string `toml:"rpc_timeout" json:"rpc_timeout"`
TrustedNode bool `toml:"trusted_node" json:"trusted_node"`
AccountPrefix string `toml:"account_prefix" json:"account_prefix"`
KeyName string `toml:"key_name" json:"key_name"`
AddressType AddressType `toml:"address_type,inline" json:"address_type"`
StorePrefix string `toml:"store_prefix" json:"store_prefix"`
DefaultGas uint64 `toml:"default_gas" json:"default_gas"`
MaxGas uint64 `toml:"max_gas" json:"max_gas"`
GasPrice GasPrice `toml:"gas_price,inline" json:"gas_price"`
GasMultiplier float64 `toml:"gas_multiplier" json:"gas_multiplier"`
MaxMsgNum uint64 `toml:"max_msg_num" json:"max_msg_num"`
MaxTxSize uint64 `toml:"max_tx_size" json:"max_tx_size"`
ClockDrift string `toml:"clock_drift" json:"clock_drift"`
MaxBlockTime string `toml:"max_block_time" json:"max_block_time"`
TrustingPeriod string `toml:"trusting_period" json:"trusting_period"`
TrustThreshold TrustThreshold `toml:"trust_threshold,inline" json:"trust_threshold"`
MemoPrefix string `toml:"memo_prefix" json:"memo_prefix"`
}

// EventSource represents the chain event source into the Hermes config struct.
Expand All @@ -82,51 +145,6 @@ type (
Derivation string `toml:"derivation" json:"derivation"`
}

// Global represents the global values into the Hermes config struct.
Global struct {
LogLevel string `toml:"log_level" json:"log_level"`
}

// Telemetry represents the telemetry into the Hermes config struct.
Telemetry struct {
Enabled bool `toml:"enabled" json:"enabled"`
Host string `toml:"host" json:"host"`
Port uint64 `toml:"port" json:"port"`
}

// Mode represents the mode into the Hermes config struct.
Mode struct {
Channels Channels `toml:"channels" json:"channels"`
Clients Clients `toml:"clients" json:"clients"`
Connections Connections `toml:"connections" json:"connections"`
Packets Packets `toml:"packets" json:"packets"`
}

// Channels represents the mode channels into the Hermes config struct.
Channels struct {
Enabled bool `toml:"enabled" json:"enabled"`
}

// Clients represents the mode clients into the Hermes config struct.
Clients struct {
Enabled bool `toml:"enabled" json:"enabled"`
Misbehaviour bool `toml:"misbehaviour" json:"misbehaviour"`
Refresh bool `toml:"refresh" json:"refresh"`
}

// Connections represents the mode connections into the Hermes config struct.
Connections struct {
Enabled bool `toml:"enabled" json:"enabled"`
}

// Packets represents the mode packets into the Hermes config struct.
Packets struct {
ClearInterval uint64 `toml:"clear_interval" json:"clear_interval"`
ClearOnStart bool `toml:"clear_on_start" json:"clear_on_start"`
Enabled bool `toml:"enabled" json:"enabled"`
TxConfirmation bool `toml:"tx_confirmation" json:"tx_confirmation"`
}

// ChainOption configures chain hermes configs.
ChainOption func(*Chain)
// ConfigOption configures hermes configs.
Expand Down Expand Up @@ -234,20 +252,41 @@ func WithTelemetryEnabled(enabled bool) ConfigOption {
}
}

// WithTelemetryHost set TelemetryHost into the Hermes config.
// WithTelemetryHost set Telemetry host into the Hermes config.
func WithTelemetryHost(host string) ConfigOption {
return func(c *Config) {
c.Telemetry.Host = host
}
}

// WithTelemetryPort set TelemetryPort into the Hermes config.
// WithTelemetryPort set Telemetry port into the Hermes config.
func WithTelemetryPort(port uint64) ConfigOption {
return func(c *Config) {
c.Telemetry.Port = port
}
}

// WithRestEnabled set Rest enable into the Hermes config.
func WithRestEnabled(enabled bool) ConfigOption {
return func(c *Config) {
c.Rest.Enabled = enabled
}
}

// WithRestHost set Rest host into the Hermes config.
func WithRestHost(host string) ConfigOption {
return func(c *Config) {
c.Rest.Host = host
}
}

// WithRestPort set Rest port into the Hermes config.
func WithRestPort(port uint64) ConfigOption {
return func(c *Config) {
c.Rest.Port = port
}
}

// WithModeChannelsEnabled set ModeChannelsEnabled into the Hermes config.
func WithModeChannelsEnabled(enabled bool) ConfigOption {
return func(c *Config) {
Expand Down Expand Up @@ -311,32 +350,44 @@ func WithModePacketsTxConfirmation(txConfirmation bool) ConfigOption {
}
}

// WithAutoRegisterCounterpartyPayee set AutoRegisterCounterpartyPayee into the Hermes config.
func WithAutoRegisterCounterpartyPayee(autoRegisterCounterpartyPayee bool) ConfigOption {
return func(c *Config) {
c.Mode.Packets.AutoRegisterCounterpartyPayee = autoRegisterCounterpartyPayee
}
}

// DefaultConfig returns a default configuration struct for Hermes.
func DefaultConfig(options ...ConfigOption) *Config {
cfg := &Config{
Chains: []Chain{},
Global: Global{
LogLevel: "error",
},
Mode: Mode{
Channels: Channels{
Enabled: true,
},
Clients: Clients{
Enabled: true,
Misbehaviour: true,
Refresh: true,
Misbehaviour: true,
},
Connections: Connections{
Enabled: true,
},
Channels: Channels{
Enabled: true,
},
Packets: Packets{
ClearInterval: 100,
ClearOnStart: true,
Enabled: true,
TxConfirmation: true,
Enabled: true,
ClearInterval: 100,
ClearOnStart: true,
TxConfirmation: false,
AutoRegisterCounterpartyPayee: false,
},
},
Rest: Rest{
Enabled: false,
Host: "127.0.0.1",
Port: 3000,
},
Telemetry: Telemetry{
Enabled: false,
Host: "127.0.0.1",
Expand Down Expand Up @@ -374,6 +425,27 @@ func WithChainAccountPrefix(prefix string) ChainOption {
}
}

// WithChainCCVConsumerChain set the chain CCVConsumerChain into the Hermes config.
func WithChainCCVConsumerChain(ccvConsumerChain bool) ChainOption {
return func(c *Chain) {
c.CCVConsumerChain = ccvConsumerChain
}
}

// WithChainTrustedNode set the chain TrustedNode into the Hermes config.
func WithChainTrustedNode(trustedNode bool) ChainOption {
return func(c *Chain) {
c.TrustedNode = trustedNode
}
}

// WithChainMemoPrefix set the chain memo prefix name into the Hermes config.
func WithChainMemoPrefix(memoPrefix string) ChainOption {
return func(c *Chain) {
c.MemoPrefix = memoPrefix
}
}

// WithChainKeyName set the chain key name into the Hermes config.
func WithChainKeyName(key string) ChainOption {
return func(c *Chain) {
Expand Down Expand Up @@ -403,12 +475,11 @@ func WithChainMaxGas(maxGas uint64) ChainOption {
}

// WithChainGasPrice set the chain gas price into the Hermes config.
func WithChainGasPrice(price sdk.Coin) ChainOption {
func WithChainGasPrice(price sdk.DecCoin) ChainOption {
return func(c *Chain) {
f, _ := price.Amount.BigInt().Float64()
c.GasPrice = GasPrice{
Denom: price.Denom,
Price: f,
Price: price.Amount.MustFloat64(),
}
}
}
Expand Down Expand Up @@ -465,8 +536,8 @@ func WithChainTrustThreshold(numerator, denominator uint64) ChainOption {
}
}

// WithChainAddressPrefix set the chain address prefix into the Hermes config.
func WithChainAddressPrefix(derivation string) ChainOption {
// WithChainAddressType set the chain address prefix into the Hermes config.
func WithChainAddressType(derivation string) ChainOption {
return func(c *Chain) {
c.AddressType = AddressType{Derivation: derivation}
}
Expand All @@ -492,8 +563,8 @@ func (c *Config) AddChain(chainID, rpcAddr, grpcAddr string, options ...ChainOpt
AccountPrefix: "cosmos",
KeyName: "wallet",
StorePrefix: "ibc",
DefaultGas: 100000,
MaxGas: 10000000,
DefaultGas: 1000,
MaxGas: 100000,
GasPrice: GasPrice{
Denom: "stake",
Price: 0.01,
Expand Down
Loading

0 comments on commit 4438ed1

Please sign in to comment.