99 "strings"
1010
1111 "github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
12- "github.com/cosmos/cosmos-sdk/codec"
1312 codectypes "github.com/cosmos/cosmos-sdk/codec/types"
1413 cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
1514 sdk "github.com/cosmos/cosmos-sdk/types"
@@ -19,9 +18,10 @@ import (
1918 "github.com/cosmos/cosmos-sdk/x/feegrant"
2019 "github.com/gitopia/git-remote-gitopia/config"
2120 core "github.com/gitopia/git-remote-gitopia/core"
21+ "github.com/gitopia/git-remote-gitopia/core/api"
2222 "github.com/gitopia/git-remote-gitopia/core/wallet"
23- gitopiatypes "github.com/gitopia/gitopia/v2 /x/gitopia/types"
24- "github.com/gitopia/gitopia/v2 /x/gitopia/utils"
23+ gitopiatypes "github.com/gitopia/gitopia/v4 /x/gitopia/types"
24+ "github.com/gitopia/gitopia/v4 /x/gitopia/utils"
2525 "github.com/go-git/go-git/v5/plumbing"
2626 "github.com/pkg/errors"
2727 "google.golang.org/grpc"
@@ -55,32 +55,39 @@ type GitopiaHandler struct {
5555func (h * GitopiaHandler ) Initialize (remote * core.Remote ) error {
5656 var err error
5757
58- interfaceRegistry := codectypes .NewInterfaceRegistry ()
59- authtypes .RegisterInterfaces (interfaceRegistry )
60- cryptocodec .RegisterInterfaces (interfaceRegistry )
58+ grpcHost , _ := config .GitConfigGet (config .GitopiaConfigGRPCHostOption )
59+ tmAddr , _ := config .GitConfigGet (config .GitopiaConfigTmAddrOption )
60+ if grpcHost == "" || tmAddr == "" || ! api .CheckGRPCHostLiveness (grpcHost ) || ! api .CheckRPCHostLiveness (tmAddr ) {
61+ provider := api .GetBestApiProvider ()
62+ grpcHost = provider .GRPCHost
63+ if err := api .SetConfiguredGRPCHost (provider .GRPCHost ); err != nil {
64+ return err
65+ }
66+ if err := api .SetConfiguredTmAddr (provider .TMAddr ); err != nil {
67+ return err
68+ }
69+ }
6170
62- h .grpcConn , err = grpc .Dial (config .GRPCHost ,
63- grpc .WithTransportCredentials (insecure .NewCredentials ()),
64- grpc .WithDefaultCallOptions (grpc .ForceCodec (codec .NewProtoCodec (interfaceRegistry ).GRPCCodec ())),
65- )
71+ h .grpcConn , err = grpc .Dial (grpcHost , grpc .WithTransportCredentials (insecure .NewCredentials ()))
6672 if err != nil {
6773 return err
6874 }
69- // defer grpcConn.Close()
75+
76+ interfaceRegistry := codectypes .NewInterfaceRegistry ()
77+ authtypes .RegisterInterfaces (interfaceRegistry )
78+ cryptocodec .RegisterInterfaces (interfaceRegistry )
7079
7180 h .queryClient = gitopiatypes .NewQueryClient (h .grpcConn )
7281 serviceClient := tmservice .NewServiceClient (h .grpcConn )
7382 h .feegrantClient = feegrant .NewQueryClient (h .grpcConn )
7483 h .bankClient = banktypes .NewQueryClient (h .grpcConn )
7584
76- // Get chain id for signing transaction
7785 nodeInfoRes , err := serviceClient .GetNodeInfo (context .Background (), & tmservice.GetNodeInfoRequest {})
7886 if err != nil {
7987 return err
8088 }
8189 h .chainId = nodeInfoRes .DefaultNodeInfo .Network
8290
83- // Get RepositoryId
8491 res , err := h .queryClient .AnyRepository (context .Background (), & gitopiatypes.QueryGetAnyRepositoryRequest {
8592 Id : h .remoteUserId ,
8693 RepositoryName : h .remoteRepositoryName ,
@@ -336,6 +343,10 @@ func (h *GitopiaHandler) Push(remote *core.Remote, refsToPush []core.RefToPush)
336343 }, deleteTags ))
337344 }
338345
346+ if h .wallet .Type () == wallet .LEDGER {
347+ remote .Logger .Println ("Please sign the gitopia transaction on your ledger device." )
348+ }
349+
339350 if err := h .wallet .SignAndBroadcast (h .grpcConn , msg ); err != nil {
340351 return nil , err
341352 }
0 commit comments