From 0ebc663c36983a5b2641981871093e4ae0a89361 Mon Sep 17 00:00:00 2001 From: vladupshot <154623109+vladupshot@users.noreply.github.com> Date: Thu, 8 Feb 2024 14:29:29 +1300 Subject: [PATCH] Add arg to set cosmos client home (#48) --- cmd/node/appchain.go | 16 ++++++++++------ cmd/node/flags.go | 1 + cmd/node/types.go | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/cmd/node/appchain.go b/cmd/node/appchain.go index 4aba70b..3631ad9 100644 --- a/cmd/node/appchain.go +++ b/cmd/node/appchain.go @@ -3,6 +3,7 @@ package main import ( "context" "encoding/json" + "errors" "fmt" "math" "os" @@ -24,18 +25,21 @@ import ( func NewAppChain(config AppChainConfig, log zerolog.Logger) (*AppChain, error) { ctx := context.Background() config.SubmitTx = true + userHomeDir, _ := os.UserHomeDir() + cosmosClientHome := filepath.Join(userHomeDir, ".uptd") + if config.CosmosHomeDir != "" { + cosmosClientHome = config.CosmosHomeDir + } - userHomeDir, err := os.UserHomeDir() - if err != nil { - log.Warn().Err(err).Msg("could not get home directory for app chain") + // Check that the given home folder is exist + if _, err := os.Stat(cosmosClientHome); errors.Is(err, os.ErrNotExist) { + log.Warn().Err(err).Msg("could not get home directory for cosmos client") config.SubmitTx = false return nil, err } - DefaultNodeHome := filepath.Join(userHomeDir, ".uptd") - // create a cosmos client instance - client, err := cosmosclient.New(ctx, cosmosclient.WithNodeAddress(config.NodeRPCAddress), cosmosclient.WithAddressPrefix(config.AddressPrefix), cosmosclient.WithHome(DefaultNodeHome)) + client, err := cosmosclient.New(ctx, cosmosclient.WithNodeAddress(config.NodeRPCAddress), cosmosclient.WithAddressPrefix(config.AddressPrefix), cosmosclient.WithHome(cosmosClientHome)) if err != nil { log.Warn().Err(err).Msg("unable to create an allora blockchain client") config.SubmitTx = false diff --git a/cmd/node/flags.go b/cmd/node/flags.go index ef60bf7..c4b1ac9 100644 --- a/cmd/node/flags.go +++ b/cmd/node/flags.go @@ -55,6 +55,7 @@ func parseFlags() *alloraCfg { pflag.Int64Var(&cfg.MemoryMaxKB, "memory-limit", 0, "memory limit (kB) for Blockless Functions") // Cosmos L1 configuration + pflag.StringVarP(&cfg.AppChainConfig.CosmosHomeDir, "allora-chain-home-dir", "", "", "The Home folder of the client, use the user home if not set") pflag.StringVarP(&cfg.AppChainConfig.AddressKeyName, "allora-chain-key-name", "", "", "The name of a key stored in the Allora Blockchain Wallet") pflag.StringVarP(&cfg.AppChainConfig.AddressRestoreMnemonic, "allora-chain-restore-mnemonic", "", "", "The restore mnemonic for an Allora Blockchain Wallet") pflag.StringVarP(&cfg.AppChainConfig.AddressAccountPassphrase, "allora-chain-account-password", "", "", "The password for an Allora Blockchain Wallet Key") diff --git a/cmd/node/types.go b/cmd/node/types.go index 8a90cb8..3c6ee6d 100644 --- a/cmd/node/types.go +++ b/cmd/node/types.go @@ -31,7 +31,7 @@ type AppChainConfig struct { AddressKeyName string // load a address by key from the keystore AddressRestoreMnemonic string AddressAccountPassphrase string - HomeDirectory string // home directory for the cosmos keystore + CosmosHomeDir string // home directory for the cosmos keystore StringSeperator string // string seperator used for key identifiers in cosmos LibP2PKey string // the libp2p key used to sign offchain communications SubmitTx bool // do we need to commit these to the chain, might be a reason not to