From 4539dc2b7f6d861dd6672e7c225fbab34ae45637 Mon Sep 17 00:00:00 2001 From: Jack Zampolin Date: Wed, 29 Dec 2021 08:52:02 -0800 Subject: [PATCH 1/3] Push work --- README.md | 3 --- client/context.go | 23 +++++++++++++++++++++++ client/query.go | 3 +++ client/tx.go | 14 ++++++++++++++ cmd/modules.go | 34 ++++++++++++++++++++++++++++++++++ go.mod | 4 ++-- go.sum | 37 +++++++++++++++++++++++++++++++++---- 7 files changed, 109 insertions(+), 9 deletions(-) create mode 100644 client/context.go create mode 100644 cmd/modules.go diff --git a/README.md b/README.md index cb38cfda..502b182d 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,6 @@ Intended use cases: This is the start of ideas around how to implement the cosmos client libraries in a seperate repo -- [ ] `lens keys` to test key integration -- [ ] `lens query` to test query integration -- [ ] `lens tx` to test tx integration - [ ] Switch `lens` from using `var config *Config` as a global variable to a `lens.Config` struct pulled out `context` in a similar manner to the way the SDK works. This should allow for generic reuse of the `cmd` package to quickly build a new client. with standard functionality. - [ ] How to instantiate and use the GRPC golang client? This is not not currently obvious. - [ ] Currently we are depending on the sdk keyring libs. This is fine for now but eventually the goal is to support our own keyring implemenation that is specifically for `lens` diff --git a/client/context.go b/client/context.go new file mode 100644 index 00000000..7e777c1e --- /dev/null +++ b/client/context.go @@ -0,0 +1,23 @@ +package client + +import ( + "context" + "fmt" +) + +type contextKey string + +func newContextKey(chainid string) contextKey { + return contextKey(fmt.Sprintf("chain-client-context/%s", chainid)) +} + +func SetChainClientOnContext(ctx context.Context, chainid string, client *ChainClient) context.Context { + return context.WithValue(ctx, newContextKey(chainid), client) +} + +func GetChainClientFromContext(ctx context.Context, chainid string) (*ChainClient, error) { + if c, ok := ctx.Value(newContextKey(chainid)).(*ChainClient); ok { + return c, nil + } + return nil, fmt.Errorf("chain client not found in context") +} diff --git a/client/query.go b/client/query.go index fb032d44..ec21e83e 100644 --- a/client/query.go +++ b/client/query.go @@ -21,6 +21,7 @@ func (cc *ChainClient) QueryBalanceWithAddress(address sdk.AccAddress) (sdk.Coin return res.Balances, nil } +// QueryLatestHeight returns the latest height from the chain func (cc *ChainClient) QueryLatestHeight() (int64, error) { stat, err := cc.RPCClient.Status(context.Background()) if err != nil { @@ -37,6 +38,7 @@ func (cc *ChainClient) QueryDenomTraces(pageReq *querytypes.PageRequest, height }) } +// QueryAccount returns the account with address as input func (cc *ChainClient) QueryAccount(address sdk.AccAddress) (authtypes.AccountI, error) { addr, err := cc.EncodeBech32AccAddr(address) if err != nil { @@ -98,6 +100,7 @@ func (cc *ChainClient) QueryBalance(address sdk.AccAddress, showDenoms bool) (sd return out, nil } +// DefaultPageRequest returns a default page request func DefaultPageRequest() *querytypes.PageRequest { return &querytypes.PageRequest{ Key: []byte(""), diff --git a/client/tx.go b/client/tx.go index 9e7169c0..85ddacae 100644 --- a/client/tx.go +++ b/client/tx.go @@ -19,6 +19,8 @@ import ( "google.golang.org/grpc/status" ) +// TxFactory returns a new transaction factory based on the chain client's configuration +// and the provided message. func (cc *ChainClient) TxFactory() tx.Factory { return tx.Factory{}. WithAccountRetriever(cc). @@ -30,6 +32,7 @@ func (cc *ChainClient) TxFactory() tx.Factory { WithSignMode(cc.Config.SignMode()) } +// SignMode returns the sign mode for the chain client func (ccc *ChainClientConfig) SignMode() signing.SignMode { signMode := signing.SignMode_SIGN_MODE_UNSPECIFIED switch ccc.SignModeStr { @@ -41,6 +44,11 @@ func (ccc *ChainClientConfig) SignMode() signing.SignMode { return signMode } +// SendMsg wraps the msg in a StdTx, signs and sends it. An error is returned if there +// was an issue sending the transaction. A successfully sent, but failed transaction will +// not return an error. If a transaction is successfully sent, the result of the execution +// of that transaction will be logged. A boolean indicating if a transaction was successfully +// sent and executed successfully is returned. func (cc *ChainClient) SendMsg(ctx context.Context, msg sdk.Msg) (*sdk.TxResponse, bool, error) { return cc.SendMsgs(ctx, []sdk.Msg{msg}) } @@ -106,6 +114,8 @@ func (cc *ChainClient) SendMsgs(ctx context.Context, msgs []sdk.Msg) (*sdk.TxRes return res, true, nil } +// PrepareFactory returns a new transaction factory based on the chain client's configuration +// and the provided transaction factory. func (cc *ChainClient) PrepareFactory(txf tx.Factory) (tx.Factory, error) { from, err := cc.GetKeyAddress() if err != nil { @@ -141,6 +151,7 @@ func (cc *ChainClient) PrepareFactory(txf tx.Factory) (tx.Factory, error) { return txf, nil } +// CalculateGas estimates the gas for a transaction based on TxFactory and msgs. func (cc *ChainClient) CalculateGas(txf tx.Factory, msgs ...sdk.Msg) (txtypes.SimulateResponse, uint64, error) { txBytes, err := BuildSimTx(txf, msgs...) if err != nil { @@ -165,6 +176,8 @@ func (cc *ChainClient) CalculateGas(txf tx.Factory, msgs ...sdk.Msg) (txtypes.Si return simRes, uint64(txf.GasAdjustment() * float64(simRes.GasInfo.GasUsed)), nil } +// QueryABCI queries the ABCI server with the provided request. An error is returned +// if the query returns a non-zero code and the ABCI server returns a non-nil error. func (cc *ChainClient) QueryABCI(req abci.RequestQuery) (abci.ResponseQuery, error) { opts := rpcclient.ABCIQueryOptions{ Height: req.Height, @@ -187,6 +200,7 @@ func (cc *ChainClient) QueryABCI(req abci.RequestQuery) (abci.ResponseQuery, err return result.Response, nil } +// sdkErrorToGRPCError converts an sdk error to a grpc error. func sdkErrorToGRPCError(resp abci.ResponseQuery) error { switch resp.Code { case sdkerrors.ErrInvalidRequest.ABCICode(): diff --git a/cmd/modules.go b/cmd/modules.go new file mode 100644 index 00000000..5321fbc7 --- /dev/null +++ b/cmd/modules.go @@ -0,0 +1,34 @@ +package cmd + +import ( + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/x/auth" + authz "github.com/cosmos/cosmos-sdk/x/authz/module" + "github.com/cosmos/cosmos-sdk/x/bank" + "github.com/cosmos/cosmos-sdk/x/capability" + "github.com/cosmos/cosmos-sdk/x/crisis" + "github.com/cosmos/cosmos-sdk/x/distribution" + feegrant "github.com/cosmos/cosmos-sdk/x/feegrant/module" + "github.com/cosmos/cosmos-sdk/x/gov" + "github.com/cosmos/cosmos-sdk/x/mint" + "github.com/cosmos/cosmos-sdk/x/params" + "github.com/cosmos/cosmos-sdk/x/slashing" + "github.com/cosmos/cosmos-sdk/x/staking" + "github.com/cosmos/cosmos-sdk/x/upgrade" +) + +var ModuleBasics = []module.AppModuleBasic{ + auth.AppModuleBasic{}, + authz.AppModuleBasic{}, + bank.AppModuleBasic{}, + capability.AppModuleBasic{}, + gov.NewAppModule() + crisis.AppModuleBasic{}, + distribution.AppModuleBasic{}, + feegrant.AppModuleBasic{}, + mint.AppModuleBasic{}, + params.AppModuleBasic{}, + slashing.AppModuleBasic{}, + staking.AppModuleBasic{}, + upgrade.AppModuleBasic{}, +} diff --git a/go.mod b/go.mod index e9c1f16f..caa4dec4 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,9 @@ module github.com/strangelove-ventures/lens go 1.17 require ( - github.com/cosmos/cosmos-sdk v0.44.4 + github.com/cosmos/cosmos-sdk v0.44.3 github.com/cosmos/go-bip39 v1.0.0 - github.com/cosmos/ibc-go/v2 v2.0.1 + github.com/cosmos/ibc-go/v2 v2.0.0 github.com/gogo/protobuf v1.3.3 github.com/spf13/cobra v1.2.1 github.com/spf13/viper v1.8.1 diff --git a/go.sum b/go.sum index ffab9fca..6692a539 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,4 @@ +bazil.org/fuse v0.0.0-20160811212531-371fbbdaa898/go.mod h1:Xbm+BRKSBEpa4q4hTSxohYNQpsxXPbPry4JJWOB3LB8= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= @@ -154,10 +155,13 @@ github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:z github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= github.com/coinbase/rosetta-sdk-go v0.6.10 h1:rgHD/nHjxLh0lMEdfGDqpTtlvtSBwULqrrZ2qPdNaCM= github.com/coinbase/rosetta-sdk-go v0.6.10/go.mod h1:J/JFMsfcePrjJZkwQFLh+hJErkAmdm9Iyy3D5Y0LfXo= +github.com/confio/ics23/go v0.0.0-20200817220745-f173e6211efb/go.mod h1:E45NqnlpxGnpfTWL/xauN7MRwEE28T4Dd4uraToOaKg= +github.com/confio/ics23/go v0.6.3/go.mod h1:E45NqnlpxGnpfTWL/xauN7MRwEE28T4Dd4uraToOaKg= github.com/confio/ics23/go v0.6.6 h1:pkOy18YxxJ/r0XFDCnrl4Bjv6h4LkBSpLS6F38mrKL8= github.com/confio/ics23/go v0.6.6/go.mod h1:E45NqnlpxGnpfTWL/xauN7MRwEE28T4Dd4uraToOaKg= github.com/containerd/console v1.0.2/go.mod h1:ytZPjGgY2oeTkAONYafi2kSj0aYggsf8acV1PGKCbzQ= github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= +github.com/containerd/continuity v0.1.0/go.mod h1:ICJu0PwR54nI0yPEnJ6jcS+J7CZAUXrLh8lPo2knzsM= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= @@ -169,15 +173,19 @@ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7 github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/cosmos/cosmos-sdk v0.44.4 h1:5oJpMr0Uz6PmODDklyNmXLnuByMqonNTxi+LAyhqews= -github.com/cosmos/cosmos-sdk v0.44.4/go.mod h1:0QTCOkE8IWu5LZyfnbbjFjxYRIcV4pBOr7+zPpJwl58= +github.com/cosmos/cosmos-sdk v0.44.3 h1:F71n1jCqPi4F0wXg8AU4AUdUF8llw0x3D3o6aLt/j2A= +github.com/cosmos/cosmos-sdk v0.44.3/go.mod h1:bA3+VenaR/l/vDiYzaiwbWvRPWHMBX2jG0ygiFtiBp0= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= +github.com/cosmos/iavl v0.15.0-rc3.0.20201009144442-230e9bdf52cd/go.mod h1:3xOIaNNX19p0QrX0VqWa6voPRoJRGGYtny+DH8NEPvE= +github.com/cosmos/iavl v0.15.0-rc5/go.mod h1:WqoPL9yPTQ85QBMT45OOUzPxG/U/JcJoN7uMjgxke/I= +github.com/cosmos/iavl v0.15.3/go.mod h1:OLjQiAQ4fGD2KDZooyJG9yz+p2ao2IAYSbke8mVvSA4= +github.com/cosmos/iavl v0.17.1/go.mod h1:7aisPZK8yCpQdy3PMvKeO+bhq1NwDjUwjzxwwROUxFk= github.com/cosmos/iavl v0.17.2 h1:BT2u7DUvLLB+RYz9RItn/8n7Bt5xe5rj8QRTkk/PQU0= github.com/cosmos/iavl v0.17.2/go.mod h1:prJoErZFABYZGDHka1R6Oay4z9PrNeFFiMKHDAMOi4w= -github.com/cosmos/ibc-go/v2 v2.0.1 h1:9UqlTV/3M3JO4x71Hm26yzzYnUryMecvvX+gXyAtXic= -github.com/cosmos/ibc-go/v2 v2.0.1/go.mod h1:ZfePiHyAVzWvRafjDCI00huUnPjRgOn1FsOklO68AF0= +github.com/cosmos/ibc-go/v2 v2.0.0 h1:BMRg73JcdV9wGPI51j89ihm7VBZQsDLkqQ+tmzdeA9Y= +github.com/cosmos/ibc-go/v2 v2.0.0/go.mod h1:n53VhNSUxCtMLysvgyNhwrGHL8OW+318LMjtSmaVe9Q= github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4= github.com/cosmos/ledger-cosmos-go v0.11.1/go.mod h1:J8//BsAGTo3OC/vDLjMRFLW6q0WAaXvHnVc7ZmE8iUY= github.com/cosmos/ledger-go v0.9.2 h1:Nnao/dLwaVTk1Q5U9THldpUMMXU94BOTWPddSmVB6pI= @@ -198,6 +206,7 @@ github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea/go.mod h1:93vs github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218= github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f h1:U5y3Y5UE0w7amNe7Z5G/twsBW0KEalRQXZzf8ufSh9I= github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f/go.mod h1:xH/i4TFMt8koVQZ6WFms69WAsDWr2XsYL3Hkl7jkoLE= +github.com/dgraph-io/badger/v2 v2.2007.1/go.mod h1:26P/7fbL4kUZVEVKLAKXkBXKOydDmM2p1e+NhhnBCAE= github.com/dgraph-io/badger/v2 v2.2007.2 h1:EjjK0KqwaFMlPin1ajhP943VPENHJdEz1KLIegjaI3k= github.com/dgraph-io/badger/v2 v2.2007.2/go.mod h1:26P/7fbL4kUZVEVKLAKXkBXKOydDmM2p1e+NhhnBCAE= github.com/dgraph-io/ristretto v0.0.3-0.20200630154024-f66de99634de/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E= @@ -374,6 +383,7 @@ github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2z github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.1-0.20190629185528-ae1634f6a989/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= @@ -382,6 +392,7 @@ github.com/gotestyourself/gotestyourself v2.2.0+incompatible/go.mod h1:zZKM6oeNM github.com/graph-gophers/graphql-go v0.0.0-20191115155744-f33e81362277/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLtHm77vfxsvsIN5Vuc= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-middleware v1.2.1/go.mod h1:EaizFBKfUKtMIF5iaDEhniwNedqGo9FuLFzppDr3uwI= github.com/grpc-ecosystem/go-grpc-middleware v1.2.2/go.mod h1:EaizFBKfUKtMIF5iaDEhniwNedqGo9FuLFzppDr3uwI= github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 h1:+9834+KizmvFV7pXQGSXQTsaWhq2GjuNUt0aUU0YBYw= github.com/grpc-ecosystem/go-grpc-middleware v1.3.0/go.mod h1:z0ButlSOZa5vEBq9m2m2hlwIgKw+rp3sdCBRoJY+30Y= @@ -389,6 +400,7 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgf github.com/grpc-ecosystem/grpc-gateway v1.8.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/grpc-ecosystem/grpc-gateway v1.14.7/go.mod h1:oYZKL012gGh6LMyg/xA7Q2yq6j8bu0wa+9w14EEthWU= github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU= @@ -583,6 +595,7 @@ github.com/onsi/gomega v1.13.0 h1:7lLHu94wT9Ij0o6EWWclhu0aOh32VxhkwEJvzuWPeak= github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= +github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= github.com/opencontainers/runc v0.1.1/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U= github.com/opencontainers/runc v1.0.2/go.mod h1:aTaHFFwQXuA71CiyxOdFFIorAoemI04suvGRQFzWTD0= @@ -693,6 +706,7 @@ github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= +github.com/sasha-s/go-deadlock v0.2.0/go.mod h1:StQn567HiB1fF2yJ44N9au7wOhrPS3iZqiDbRupzT10= github.com/sasha-s/go-deadlock v0.2.1-0.20190427202633-1595213edefa h1:0U2s5loxrTy6/VgfVoLuVLFJcURKLH49ie0zSch7gh4= github.com/sasha-s/go-deadlock v0.2.1-0.20190427202633-1595213edefa/go.mod h1:F73l+cr82YSh10GxyRI6qZiCgK64VaZjwesgfQ1/iLM= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= @@ -723,6 +737,7 @@ github.com/spf13/cast v1.4.1 h1:s0hze+J0196ZfEMTs80N7UlFt0BDuQ7Q+JDnHiMWKdA= github.com/spf13/cast v1.4.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= +github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI= github.com/spf13/cobra v1.2.1 h1:+KmjbUw1hriSNMF55oPrkZcb27aECyrj8V2ytv7kWDw= github.com/spf13/cobra v1.2.1/go.mod h1:ExllRjgxM/piMAM+3tAZvg8fsklGAf3tPfi+i8t68Nk= @@ -734,6 +749,7 @@ github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnIn github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= +github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= github.com/spf13/viper v1.8.1 h1:Kq1fyeebqsBfbjZj4EL7gj2IO0mMaiyjYUWcUsl2O44= @@ -769,8 +785,14 @@ github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 h1:hqAk8riJvK4RM github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15/go.mod h1:z4YtwM70uOnk8h0pjJYlj3zdYwi9l03By6iAIF5j/Pk= github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2lyGa2E= github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME= +github.com/tendermint/tendermint v0.34.0-rc4/go.mod h1:yotsojf2C1QBOw4dZrTcxbyxmPUrT4hNuOQWX9XUwB4= +github.com/tendermint/tendermint v0.34.0-rc6/go.mod h1:ugzyZO5foutZImv0Iyx/gOFCX6mjJTgbLHTwi17VDVg= +github.com/tendermint/tendermint v0.34.0/go.mod h1:Aj3PIipBFSNO21r+Lq3TtzQ+uKESxkbA3yo/INM4QwQ= +github.com/tendermint/tendermint v0.34.13/go.mod h1:6RVVRBqwtKhA+H59APKumO+B7Nye4QXSFc6+TYxAxCI= github.com/tendermint/tendermint v0.34.14 h1:GCXmlS8Bqd2Ix3TQCpwYLUNHe+Y+QyJsm5YE+S/FkPo= github.com/tendermint/tendermint v0.34.14/go.mod h1:FrwVm3TvsVicI9Z7FlucHV6Znfd5KBc/Lpp69cCwtk0= +github.com/tendermint/tm-db v0.6.2/go.mod h1:GYtQ67SUvATOcoY8/+x6ylk8Qo02BQyLrAs+yAcLvGI= +github.com/tendermint/tm-db v0.6.3/go.mod h1:lfA1dL9/Y/Y8wwyPp2NMLyn5P5Ptr/gvDFNWtrCWSf8= github.com/tendermint/tm-db v0.6.4 h1:3N2jlnYQkXNQclQwd/eKV/NzlqPlfK21cpRRIx80XXQ= github.com/tendermint/tm-db v0.6.4/go.mod h1:dptYhIpJ2M5kUuenLr+Yyf3zQOv1SgBZcl8/BmWlMBw= github.com/tidwall/gjson v1.6.7/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI= @@ -782,6 +804,7 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1 github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs= github.com/tyler-smith/go-bip39 v1.0.2/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs= +github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= @@ -849,7 +872,9 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= +golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -905,6 +930,7 @@ golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -912,6 +938,7 @@ golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -1191,6 +1218,7 @@ google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6D google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20201109203340-2640f1f9cdfb/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201111145450-ac7456db90a6/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20201119123407-9b1e624d6bc4/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20201201144952-b05cb90ed32e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20201210142538-e3217bee35cc/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= @@ -1225,6 +1253,7 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b h1:QRR6H1YWRnHb4Y/HeNFCTJLFVxaq6wH4YuVdsUOr75U= gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= From c1cb57725fbdb7cbeeed94aafb9cc917442706fa Mon Sep 17 00:00:00 2001 From: Jack Zampolin Date: Wed, 29 Dec 2021 09:03:14 -0800 Subject: [PATCH 2/3] Add comments --- client/context.go | 2 ++ cmd/modules.go | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/client/context.go b/client/context.go index 7e777c1e..8f52a766 100644 --- a/client/context.go +++ b/client/context.go @@ -11,10 +11,12 @@ func newContextKey(chainid string) contextKey { return contextKey(fmt.Sprintf("chain-client-context/%s", chainid)) } +// SetChainClientToContext sets the chain client to the context func SetChainClientOnContext(ctx context.Context, chainid string, client *ChainClient) context.Context { return context.WithValue(ctx, newContextKey(chainid), client) } +// GetChainClientFromContext returns the chain client from the context func GetChainClientFromContext(ctx context.Context, chainid string) (*ChainClient, error) { if c, ok := ctx.Value(newContextKey(chainid)).(*ChainClient); ok { return c, nil diff --git a/cmd/modules.go b/cmd/modules.go index 5321fbc7..9ee080cc 100644 --- a/cmd/modules.go +++ b/cmd/modules.go @@ -22,7 +22,8 @@ var ModuleBasics = []module.AppModuleBasic{ authz.AppModuleBasic{}, bank.AppModuleBasic{}, capability.AppModuleBasic{}, - gov.NewAppModule() + // TODO: need to use gov.NewAppModuleBasic to get different governance proposal parsing + gov.AppModuleBasic{}, crisis.AppModuleBasic{}, distribution.AppModuleBasic{}, feegrant.AppModuleBasic{}, From 0c4d34a43f485ec1d826b71f19c7328e49052916 Mon Sep 17 00:00:00 2001 From: Jack Zampolin Date: Wed, 29 Dec 2021 12:23:49 -0800 Subject: [PATCH 3/3] First pass, incorrect use of context --- client/context.go | 19 +++++++---- cmd/config.go | 84 ++++++++++++++++++++++++++++++++--------------- cmd/keys.go | 33 +++++++++++-------- cmd/modules.go | 10 ++++-- cmd/query.go | 29 ++++++++-------- cmd/tendermint.go | 40 ++++++++++++++-------- cmd/tx.go | 14 ++++---- 7 files changed, 150 insertions(+), 79 deletions(-) diff --git a/client/context.go b/client/context.go index 8f52a766..1250dcb8 100644 --- a/client/context.go +++ b/client/context.go @@ -2,6 +2,7 @@ package client import ( "context" + "errors" "fmt" ) @@ -12,14 +13,20 @@ func newContextKey(chainid string) contextKey { } // SetChainClientToContext sets the chain client to the context -func SetChainClientOnContext(ctx context.Context, chainid string, client *ChainClient) context.Context { - return context.WithValue(ctx, newContextKey(chainid), client) +func SetChainClientOnContext(ctx context.Context, chainid string, client *ChainClient) error { + v := ctx.Value(newContextKey(chainid)) + if v == nil { + return errors.New("chain client not found in context") + } + ptr := v.(*ChainClient) + *ptr = *client + return nil } // GetChainClientFromContext returns the chain client from the context -func GetChainClientFromContext(ctx context.Context, chainid string) (*ChainClient, error) { - if c, ok := ctx.Value(newContextKey(chainid)).(*ChainClient); ok { - return c, nil +func GetChainClientFromContext(ctx context.Context, chainid string) *ChainClient { + if v, ok := ctx.Value(newContextKey(chainid)).(*ChainClient); ok { + return v } - return nil, fmt.Errorf("chain client not found in context") + return nil } diff --git a/cmd/config.go b/cmd/config.go index 282c95bf..c5a6ce04 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -84,14 +84,23 @@ func configInitCmd() *cobra.Command { // Config represents the config file for the relayer type Config struct { - Chain *client.ChainClientConfig - cl *client.ChainClient + DefaultChain string `yaml:"default_chain"` + Chains []*client.ChainClientConfig `yaml:"chains"` } // Called to initialize the relayer.Chain types on Config func validateConfig(c *Config) error { - if err := c.Chain.Validate(); err != nil { - return err + var found bool + for _, chain := range c.Chains { + if err := chain.Validate(); err != nil { + return err + } + if c.DefaultChain == chain.ChainID { + found = true + } + } + if !found { + return fmt.Errorf("default chain %s not found in chains", c.DefaultChain) } return nil } @@ -111,22 +120,42 @@ func defaultConfig(keyHome string, debug bool) []byte { modules = append(modules, v) } cfg := Config{ - Chain: &client.ChainClientConfig{ - Key: "default", - ChainID: "cosmoshub-4", - RPCAddr: "https://cosmoshub-4.technofractal.com:443", - GRPCAddr: "https://gprc.cosmoshub-4.technofractal.com:443", - AccountPrefix: "cosmos", - KeyringBackend: "test", - GasAdjustment: 1.2, - GasPrices: "0.01uatom", - KeyDirectory: keyHome, - Debug: debug, - Timeout: "20s", - OutputFormat: "json", - BroadcastMode: "block", - SignModeStr: "direct", - Modules: modules, + DefaultChain: "cosmoshub-4", + Chains: []*client.ChainClientConfig{ + { + Key: "default", + ChainID: "cosmoshub-4", + RPCAddr: "https://cosmoshub-4.technofractal.com:443", + GRPCAddr: "https://gprc.cosmoshub-4.technofractal.com:443", + AccountPrefix: "cosmos", + KeyringBackend: "test", + GasAdjustment: 1.2, + GasPrices: "0.01uatom", + KeyDirectory: keyHome, + Debug: debug, + Timeout: "20s", + OutputFormat: "json", + BroadcastMode: "block", + SignModeStr: "direct", + Modules: modules, + }, + { + Key: "default", + ChainID: "osmosis-1", + RPCAddr: "https://osmosis-1.technofractal.com:443", + GRPCAddr: "https://grpc.osmosis-1.technofractal.com:443", + AccountPrefix: "osmo", + KeyringBackend: "test", + GasAdjustment: 1.2, + GasPrices: "0.01uosmo", + KeyDirectory: keyHome, + Debug: debug, + Timeout: "20s", + OutputFormat: "json", + BroadcastMode: "block", + SignModeStr: "direct", + Modules: modules, + }, }, } return cfg.MustYAML() @@ -170,13 +199,16 @@ func initConfig(cmd *cobra.Command) error { for _, v := range simapp.ModuleBasics { modules = append(modules, v) } - config.Chain.Modules = modules - cl, err := client.NewChainClient(config.Chain, os.Stdin, os.Stdout) - if err != nil { - fmt.Println("Error creating chain client:", err) - os.Exit(1) + ctx := cmd.Context() + for _, chain := range config.Chains { + chain.Modules = modules + cl, err := client.NewChainClient(chain, os.Stdin, os.Stdout) + if err != nil { + fmt.Println("Error creating chain client:", err) + os.Exit(1) + } + client.SetChainClientOnContext(ctx, chain.ChainID, cl) } - config.cl = cl } } return nil diff --git a/cmd/keys.go b/cmd/keys.go index 8bfec24e..e4ded2bd 100644 --- a/cmd/keys.go +++ b/cmd/keys.go @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/cobra" + "github.com/strangelove-ventures/lens/client" ) const ( @@ -46,17 +47,18 @@ $ %s keys add ibc-0 $ %s keys add ibc-1 key2 $ %s k a ibc-2 testkey`, appName, appName, appName)), RunE: func(cmd *cobra.Command, args []string) error { + cl := client.GetChainClientFromContext(cmd.Context(), config.DefaultChain) var keyName string if len(args) == 0 { - keyName = config.cl.Config.Key + keyName = cl.Config.Key } else { keyName = args[0] } - if config.cl.KeyExists(keyName) { + if cl.KeyExists(keyName) { return errKeyExists(keyName) } - ko, err := config.cl.AddKey(keyName) + ko, err := cl.AddKey(keyName) if err != nil { return err } @@ -87,12 +89,13 @@ func keysRestoreCmd() *cobra.Command { $ %s keys restore ibc-0 testkey "[mnemonic-words]" $ %s k r ibc-1 faucet-key "[mnemonic-words]"`, appName, appName)), RunE: func(cmd *cobra.Command, args []string) error { + cl := client.GetChainClientFromContext(cmd.Context(), config.DefaultChain) keyName := args[1] - if config.cl.KeyExists(keyName) { + if cl.KeyExists(keyName) { return errKeyExists(keyName) } - address, err := config.cl.RestoreKey(keyName, args[2]) + address, err := cl.RestoreKey(keyName, args[2]) if err != nil { return err } @@ -118,8 +121,9 @@ $ %s keys delete ibc-0 -y $ %s keys delete ibc-1 key2 -y $ %s k d ibc-2 testkey`, appName, appName, appName)), RunE: func(cmd *cobra.Command, args []string) error { + cl := client.GetChainClientFromContext(cmd.Context(), config.DefaultChain) keyName := args[1] - if !config.cl.KeyExists(keyName) { + if !cl.KeyExists(keyName) { return errKeyDoesntExist(keyName) } @@ -130,7 +134,7 @@ $ %s k d ibc-2 testkey`, appName, appName, appName)), } } - if err := config.cl.DeleteKey(keyName); err != nil { + if err := cl.DeleteKey(keyName); err != nil { panic(err) } @@ -172,7 +176,8 @@ func keysListCmd() *cobra.Command { $ %s keys list ibc-0 $ %s k l ibc-1`, appName, appName)), RunE: func(cmd *cobra.Command, args []string) error { - info, err := config.cl.ListAddresses() + cl := client.GetChainClientFromContext(cmd.Context(), config.DefaultChain) + info, err := cl.ListAddresses() if err != nil { return err } @@ -203,17 +208,18 @@ $ %s keys show ibc-0 $ %s keys show ibc-1 key2 $ %s k s ibc-2 testkey`, appName, appName, appName)), RunE: func(cmd *cobra.Command, args []string) error { + cl := client.GetChainClientFromContext(cmd.Context(), config.DefaultChain) var keyName string if len(args) == 0 { - keyName = config.cl.Config.Key + keyName = cl.Config.Key } else { keyName = args[0] } - if !config.cl.KeyExists(keyName) { + if !cl.KeyExists(keyName) { return errKeyDoesntExist(keyName) } - address, err := config.cl.ShowAddress(keyName) + address, err := cl.ShowAddress(keyName) if err != nil { return err } @@ -237,12 +243,13 @@ func keysExportCmd() *cobra.Command { $ %s keys export ibc-0 testkey $ %s k e ibc-2 testkey`, appName, appName)), RunE: func(cmd *cobra.Command, args []string) error { + cl := client.GetChainClientFromContext(cmd.Context(), config.DefaultChain) keyName := args[1] - if !config.cl.KeyExists(keyName) { + if !cl.KeyExists(keyName) { return errKeyDoesntExist(keyName) } - info, err := config.cl.ExportPrivKeyArmor(keyName) + info, err := cl.ExportPrivKeyArmor(keyName) if err != nil { return err } diff --git a/cmd/modules.go b/cmd/modules.go index 9ee080cc..09e55bb5 100644 --- a/cmd/modules.go +++ b/cmd/modules.go @@ -8,13 +8,16 @@ import ( "github.com/cosmos/cosmos-sdk/x/capability" "github.com/cosmos/cosmos-sdk/x/crisis" "github.com/cosmos/cosmos-sdk/x/distribution" + distrclient "github.com/cosmos/cosmos-sdk/x/distribution/client" feegrant "github.com/cosmos/cosmos-sdk/x/feegrant/module" "github.com/cosmos/cosmos-sdk/x/gov" "github.com/cosmos/cosmos-sdk/x/mint" "github.com/cosmos/cosmos-sdk/x/params" + paramsclient "github.com/cosmos/cosmos-sdk/x/params/client" "github.com/cosmos/cosmos-sdk/x/slashing" "github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/upgrade" + upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" ) var ModuleBasics = []module.AppModuleBasic{ @@ -22,8 +25,11 @@ var ModuleBasics = []module.AppModuleBasic{ authz.AppModuleBasic{}, bank.AppModuleBasic{}, capability.AppModuleBasic{}, - // TODO: need to use gov.NewAppModuleBasic to get different governance proposal parsing - gov.AppModuleBasic{}, + // TODO: add osmosis governance proposal types here + // TODO: add other proposal types here + gov.NewAppModuleBasic( + paramsclient.ProposalHandler, distrclient.ProposalHandler, upgradeclient.ProposalHandler, upgradeclient.CancelProposalHandler, + ), crisis.AppModuleBasic{}, distribution.AppModuleBasic{}, feegrant.AppModuleBasic{}, diff --git a/cmd/query.go b/cmd/query.go index 1bb57615..cb0ef41b 100644 --- a/cmd/query.go +++ b/cmd/query.go @@ -6,6 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/cobra" + "github.com/strangelove-ventures/lens/client" ) // queryCmd represents the keys command @@ -31,26 +32,27 @@ func queryBalanceCmd() *cobra.Command { Short: "query the account balance for a key or address, if none is passed will query the balance of the default account", Args: cobra.RangeArgs(0, 1), RunE: func(cmd *cobra.Command, args []string) error { + cl := client.GetChainClientFromContext(cmd.Context(), config.DefaultChain) var ( keyNameOrAddress = "" address sdk.AccAddress err error ) if len(args) == 0 { - keyNameOrAddress = config.Chain.Key + keyNameOrAddress = cl.Config.Key } else { keyNameOrAddress = args[0] } - if config.cl.KeyExists(keyNameOrAddress) { - config.Chain.Key = keyNameOrAddress - address, err = config.cl.GetKeyAddress() + if cl.KeyExists(keyNameOrAddress) { + cl.Config.Key = keyNameOrAddress + address, err = cl.GetKeyAddress() } else { - address, err = config.cl.DecodeBech32AccAddr(keyNameOrAddress) + address, err = cl.DecodeBech32AccAddr(keyNameOrAddress) } if err != nil { return err } - balance, err := config.cl.QueryBalance(address, false) + balance, err := cl.QueryBalance(address, false) if err != nil { return err } @@ -72,30 +74,31 @@ func queryAccountCmd() *cobra.Command { Short: "query the account details for a key or address, if none is passed will query the balance of the default account", Args: cobra.RangeArgs(0, 1), RunE: func(cmd *cobra.Command, args []string) error { + cl := client.GetChainClientFromContext(cmd.Context(), config.DefaultChain) var ( keyNameOrAddress = "" address sdk.AccAddress err error ) if len(args) == 0 { - keyNameOrAddress = config.Chain.Key + keyNameOrAddress = cl.Config.Key } else { keyNameOrAddress = args[0] } - if config.cl.KeyExists(keyNameOrAddress) { - config.Chain.Key = keyNameOrAddress - address, err = config.cl.GetKeyAddress() + if cl.KeyExists(keyNameOrAddress) { + cl.Config.Key = keyNameOrAddress + address, err = cl.GetKeyAddress() } else { - address, err = config.cl.DecodeBech32AccAddr(keyNameOrAddress) + address, err = cl.DecodeBech32AccAddr(keyNameOrAddress) } if err != nil { return err } - account, err := config.cl.QueryAccount(address) + account, err := cl.QueryAccount(address) if err != nil { return err } - bz, err := config.cl.Codec.Marshaler.MarshalInterfaceJSON(account) + bz, err := cl.Codec.Marshaler.MarshalInterfaceJSON(account) if err != nil { return err } diff --git a/cmd/tendermint.go b/cmd/tendermint.go index 49dabf51..8da32b81 100644 --- a/cmd/tendermint.go +++ b/cmd/tendermint.go @@ -25,6 +25,7 @@ import ( "strings" "github.com/spf13/cobra" + "github.com/strangelove-ventures/lens/client" rpcclient "github.com/tendermint/tendermint/rpc/client" ) @@ -61,7 +62,8 @@ func abciInfoCmd() *cobra.Command { Short: "queries for block height, app name and app hash", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - info, err := config.cl.RPCClient.ABCIInfo(cmd.Context()) + cl := client.GetChainClientFromContext(cmd.Context(), config.DefaultChain) + info, err := cl.RPCClient.ABCIInfo(cmd.Context()) if err != nil { return err } @@ -83,6 +85,7 @@ func abciQueryCmd() *cobra.Command { Short: "query the abci interface for tendermint directly", Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) error { + cl := client.GetChainClientFromContext(cmd.Context(), config.DefaultChain) path := args[0] data := []byte(args[1]) height, err := strconv.ParseInt(args[2], 10, 64) @@ -96,7 +99,7 @@ func abciQueryCmd() *cobra.Command { Prove: false, } - info, err := config.cl.RPCClient.ABCIQueryWithOptions(cmd.Context(), path, data, opts) + info, err := cl.RPCClient.ABCIQueryWithOptions(cmd.Context(), path, data, opts) if err != nil { return err } @@ -120,11 +123,12 @@ func blockCmd() *cobra.Command { Short: "query tendermint data for a block at given height", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { + cl := client.GetChainClientFromContext(cmd.Context(), config.DefaultChain) height, err := strconv.ParseInt(args[0], 10, 64) if err != nil { return err } - block, err := config.cl.RPCClient.Block(cmd.Context(), &height) + block, err := cl.RPCClient.Block(cmd.Context(), &height) if err != nil { return err } @@ -146,11 +150,12 @@ func blockByHashCmd() *cobra.Command { Short: "query tendermint for a given block by hash", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { + cl := client.GetChainClientFromContext(cmd.Context(), config.DefaultChain) h, err := hex.DecodeString(args[0]) if err != nil { return err } - block, err := config.cl.RPCClient.BlockByHash(cmd.Context(), h) + block, err := cl.RPCClient.BlockByHash(cmd.Context(), h) if err != nil { return err } @@ -172,11 +177,12 @@ func blockResultsCmd() *cobra.Command { Short: "query tendermint tx results for a given block by height", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { + cl := client.GetChainClientFromContext(cmd.Context(), config.DefaultChain) height, err := strconv.ParseInt(args[0], 10, 64) if err != nil { return err } - block, err := config.cl.RPCClient.BlockResults(cmd.Context(), &height) + block, err := cl.RPCClient.BlockResults(cmd.Context(), &height) if err != nil { return err } @@ -216,11 +222,12 @@ func consensusParamsCmd() *cobra.Command { Short: "query tendermint consensus params at a given height", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { + cl := client.GetChainClientFromContext(cmd.Context(), config.DefaultChain) height, err := strconv.ParseInt(args[0], 10, 64) if err != nil { return err } - block, err := config.cl.RPCClient.ConsensusParams(cmd.Context(), &height) + block, err := cl.RPCClient.ConsensusParams(cmd.Context(), &height) if err != nil { return err } @@ -246,7 +253,8 @@ func consensusStateCmd() *cobra.Command { Short: "query current tendermint consensus state", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - block, err := config.cl.RPCClient.ConsensusState(cmd.Context()) + cl := client.GetChainClientFromContext(cmd.Context(), config.DefaultChain) + block, err := cl.RPCClient.ConsensusState(cmd.Context()) if err != nil { return err } @@ -268,7 +276,8 @@ func dumpConsensusStateCmd() *cobra.Command { Short: "query detailed version of current tendermint consensus state", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - block, err := config.cl.RPCClient.DumpConsensusState(cmd.Context()) + cl := client.GetChainClientFromContext(cmd.Context(), config.DefaultChain) + block, err := cl.RPCClient.DumpConsensusState(cmd.Context()) if err != nil { return err } @@ -290,7 +299,8 @@ func healthCmd() *cobra.Command { Short: "query to see if node server is online", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - block, err := config.cl.RPCClient.Health(cmd.Context()) + cl := client.GetChainClientFromContext(cmd.Context(), config.DefaultChain) + block, err := cl.RPCClient.Health(cmd.Context()) if err != nil { return err } @@ -315,11 +325,12 @@ func netInfoCmd() *cobra.Command { Short: "query for p2p network connection information", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { + cl := client.GetChainClientFromContext(cmd.Context(), config.DefaultChain) peers, err := cmd.Flags().GetBool("peers") if err != nil { return err } - block, err := config.cl.RPCClient.NetInfo(cmd.Context()) + block, err := cl.RPCClient.NetInfo(cmd.Context()) if err != nil { return err } @@ -355,11 +366,12 @@ func numUnconfirmedTxs() *cobra.Command { Short: "query for number of unconfirmed txs", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { + cl := client.GetChainClientFromContext(cmd.Context(), config.DefaultChain) limit, err := cmd.Flags().GetInt("limit") if err != nil { return err } - block, err := config.cl.RPCClient.UnconfirmedTxs(cmd.Context(), &limit) + block, err := cl.RPCClient.UnconfirmedTxs(cmd.Context(), &limit) if err != nil { return err } @@ -381,7 +393,8 @@ func statusCmd() *cobra.Command { Short: "query status of the node", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - block, err := config.cl.RPCClient.Status(cmd.Context()) + cl := client.GetChainClientFromContext(cmd.Context(), config.DefaultChain) + block, err := cl.RPCClient.Status(cmd.Context()) if err != nil { return err } @@ -402,6 +415,7 @@ func queryTxCmd() *cobra.Command { Short: "query for a transaction by hash", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { + cl := client.GetChainClientFromContext(cmd.Context(), config.DefaultChain) log, err := cmd.Flags().GetBool("log") if err != nil { return err @@ -414,7 +428,7 @@ func queryTxCmd() *cobra.Command { if err != nil { return err } - block, err := config.cl.RPCClient.Tx(cmd.Context(), h, prove) + block, err := cl.RPCClient.Tx(cmd.Context(), h, prove) if err != nil { return err } diff --git a/cmd/tx.go b/cmd/tx.go index 5cefc137..8a7b5bbf 100644 --- a/cmd/tx.go +++ b/cmd/tx.go @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/spf13/cobra" + "github.com/strangelove-ventures/lens/client" ) // queryCmd represents the keys command @@ -29,19 +30,20 @@ func bankSendCmd() *cobra.Command { Short: "send coins from one address to another", Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) error { + cl := client.GetChainClientFromContext(cmd.Context(), config.DefaultChain) var ( fromAddress sdk.AccAddress err error ) - if config.cl.KeyExists(args[0]) { - fromAddress, err = config.cl.GetKeyAddress() + if cl.KeyExists(args[0]) { + fromAddress, err = cl.GetKeyAddress() } else { - fromAddress, err = config.cl.DecodeBech32AccAddr(args[0]) + fromAddress, err = cl.DecodeBech32AccAddr(args[0]) } if err != nil { return err } - toAddr, err := config.cl.DecodeBech32AccAddr(args[1]) + toAddr, err := cl.DecodeBech32AccAddr(args[1]) if err != nil { return err } @@ -51,7 +53,7 @@ func bankSendCmd() *cobra.Command { return err } - res, ok, err := config.cl.SendMsg(cmd.Context(), types.NewMsgSend(fromAddress, toAddr, coins)) + res, ok, err := cl.SendMsg(cmd.Context(), types.NewMsgSend(fromAddress, toAddr, coins)) if err != nil || !ok { if res != nil { return fmt.Errorf("failed to send coins: code(%d) msg(%s)", res.Code, res.Logs) @@ -59,7 +61,7 @@ func bankSendCmd() *cobra.Command { return fmt.Errorf("failed to send coins: err(%w)", err) } - bz, err := config.cl.Codec.Marshaler.MarshalJSON(res) + bz, err := cl.Codec.Marshaler.MarshalJSON(res) if err != nil { return err }