Skip to content

Commit e6fc6c2

Browse files
committed
refactor gitopia client integration
1 parent 1d90d42 commit e6fc6c2

File tree

3 files changed

+3
-62
lines changed

3 files changed

+3
-62
lines changed

core/wallet/os_keyring.go

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import (
55
"fmt"
66
"os"
77

8-
"github.com/cosmos/cosmos-sdk/client"
9-
"github.com/cosmos/cosmos-sdk/client/flags"
108
"github.com/cosmos/cosmos-sdk/client/tx"
119
"github.com/cosmos/cosmos-sdk/codec"
1210
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
@@ -15,7 +13,6 @@ import (
1513
sdkkeyring "github.com/cosmos/cosmos-sdk/crypto/keyring"
1614
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
1715
sdk "github.com/cosmos/cosmos-sdk/types"
18-
"github.com/cosmos/cosmos-sdk/version"
1916
"github.com/gitopia/git-remote-gitopia/config"
2017
glib "github.com/gitopia/gitopia-go"
2118
"github.com/gitopia/gitopia-go/logger"
@@ -25,13 +22,6 @@ import (
2522
"github.com/sirupsen/logrus"
2623
"github.com/spf13/pflag"
2724

28-
"github.com/cosmos/cosmos-sdk/std"
29-
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
30-
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
31-
gtypes "github.com/gitopia/gitopia/v2/x/gitopia/types"
32-
otypes "github.com/gitopia/gitopia/v2/x/offchain/types"
33-
rtypes "github.com/gitopia/gitopia/v2/x/rewards/types"
34-
3525
"github.com/pkg/errors"
3626
"google.golang.org/grpc"
3727
)
@@ -96,7 +86,7 @@ func InitOSKeyringWallet() (Wallet, error) {
9686
ctx := logger.ContextWithValue(context.Background(), l)
9787
glib.WithGitopiaAddr(config.GRPCHost)
9888
glib.WithGasPrices(config.GasPrices)
99-
cc, err := NewContext(key)
89+
cc, err := glib.GetClientContextWithOptions(AppName, key, backend)
10090
if err != nil {
10191
return nil, errors.Wrap(err, "error creating cosmos client context")
10292
}
@@ -116,55 +106,6 @@ func InitOSKeyringWallet() (Wallet, error) {
116106
return o, nil
117107
}
118108

119-
func NewContext(from string) (client.Context, error) {
120-
version.Name = AppName
121-
clientCtx := client.Context{}
122-
123-
interfaceRegistry := codectypes.NewInterfaceRegistry()
124-
std.RegisterInterfaces(interfaceRegistry)
125-
cryptocodec.RegisterInterfaces(interfaceRegistry)
126-
authtypes.RegisterInterfaces(interfaceRegistry)
127-
gtypes.RegisterInterfaces(interfaceRegistry)
128-
rtypes.RegisterInterfaces(interfaceRegistry)
129-
otypes.RegisterInterfaces(interfaceRegistry)
130-
131-
marshaler := codec.NewProtoCodec(interfaceRegistry)
132-
txCfg := authtx.NewTxConfig(marshaler, authtx.DefaultSignModes)
133-
clientCtx = clientCtx.
134-
WithCodec(marshaler).
135-
WithInterfaceRegistry(interfaceRegistry).
136-
WithAccountRetriever(authtypes.AccountRetriever{}).
137-
WithTxConfig(txCfg).
138-
WithInput(os.Stdin)
139-
140-
clientCtx = clientCtx.WithChainID(config.ChainId)
141-
clientCtx = clientCtx.WithNodeURI(config.TmAddr)
142-
c, err := client.NewClientFromNode(clientCtx.NodeURI)
143-
if err != nil {
144-
return clientCtx, errors.Wrap(err, "error creatig tm client")
145-
}
146-
clientCtx = clientCtx.WithClient(c)
147-
clientCtx = clientCtx.WithBroadcastMode(flags.BroadcastSync)
148-
clientCtx = clientCtx.WithSkipConfirmation(true)
149-
150-
kr, err := client.NewKeyringFromBackend(clientCtx, keyring.BackendOS)
151-
if err != nil {
152-
return clientCtx, errors.Wrap(err, "error creating keyring backend")
153-
}
154-
clientCtx = clientCtx.WithKeyring(kr)
155-
156-
fromAddr, fromName, _, err := client.GetFromFields(clientCtx, kr, from)
157-
if err != nil {
158-
return clientCtx, errors.Wrap(err, "error parsing from Addr")
159-
}
160-
161-
clientCtx = clientCtx.WithFrom(from).WithFromAddress(fromAddr).WithFromName(fromName)
162-
163-
feeGranterAddr := sdk.MustAccAddressFromBech32(config.FeeGranterAddr)
164-
clientCtx = clientCtx.WithFeeGranterAddress(feeGranterAddr)
165-
return clientCtx, nil
166-
}
167-
168109
func (o OSKeyring) SignData(data []byte) (string, error) {
169110
var privKey offchaintypes.SignatureProvider
170111

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,5 @@ require (
176176
replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
177177

178178
replace github.com/tendermint/tendermint => github.com/cometbft/cometbft v0.34.27
179+
180+
replace github.com/gitopia/gitopia-go => /users/jananianbarasan/go/src/github.com/gitopia/gitopia-go

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,6 @@ github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4
204204
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
205205
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
206206
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
207-
github.com/gitopia/gitopia-go v0.4.0 h1:vuKVlUDKqUlK6wz5n/Lbn6q0H7+4v0PzI1DBnxKFpbE=
208-
github.com/gitopia/gitopia-go v0.4.0/go.mod h1:1in+bQqP/CFduTIvJbB8WowPGRBhvyFkp+ZhBddutt0=
209207
github.com/gitopia/gitopia/v2 v2.0.1 h1:SeHwKkUkA+bqEzsgVimsOb5v6A1wL6O0zqQg/PSSl5c=
210208
github.com/gitopia/gitopia/v2 v2.0.1/go.mod h1:ZEEo2wHSxjJL3tcGg+ZenFlYMhfqFzwJkGkNMkgA9lE=
211209
github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY=

0 commit comments

Comments
 (0)