Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
Add arg to set cosmos client home (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladupshot authored Feb 8, 2024
1 parent 8325728 commit 0ebc663
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
16 changes: 10 additions & 6 deletions cmd/node/appchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"encoding/json"
"errors"
"fmt"
"math"
"os"
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions cmd/node/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion cmd/node/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0ebc663

Please sign in to comment.