Skip to content

Commit

Permalink
fix: add interface registry for auth module interaction
Browse files Browse the repository at this point in the history
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
  • Loading branch information
LaurentMontBlanc committed May 23, 2024
1 parent 1f43644 commit 75b2a88
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
9 changes: 1 addition & 8 deletions cmd/ta/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ import (
"log"
"os"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/rddl-network/ta_attest/config"
"github.com/rddl-network/ta_attest/service"
"github.com/syndtr/goleveldb/leveldb"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

"github.com/spf13/viper"
)
Expand Down Expand Up @@ -75,11 +72,7 @@ func main() {
log.Fatalf("fatal error opening db %s", err)
}

grpcConn, err := grpc.Dial(
cfg.PlanetmintRPCHost,
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithDefaultCallOptions(grpc.ForceCodec(codec.NewProtoCodec(nil).GRPCCodec())),
)
grpcConn, err := service.SetupGRPCConnection(cfg)
if err != nil {
log.Fatalf("fatal error opening grpc connection %s", err)
}
Expand Down
20 changes: 20 additions & 0 deletions service/planetmint_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ import (
"encoding/hex"
"strings"

"github.com/cosmos/cosmos-sdk/codec"
ctypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/decred/dcrd/dcrec/secp256k1/v4"
"github.com/planetmint/planetmint-go/app"
"github.com/planetmint/planetmint-go/lib"
machinetypes "github.com/planetmint/planetmint-go/x/machine/types"
"github.com/rddl-network/ta_attest/config"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
)

type IPlanetmintClient interface {
Expand All @@ -36,6 +40,22 @@ func NewPlanetmintClient(actor string, conn *grpc.ClientConn) *PlanetmintClient
}
}

func SetupGRPCConnection(cfg *config.Config) (conn *grpc.ClientConn, err error) {
interfaceRegistry := ctypes.NewInterfaceRegistry()
interfaceRegistry.RegisterInterface(
"cosmos.auth.IAccount",
(*authtypes.AccountI)(nil),
&authtypes.BaseAccount{},
&authtypes.ModuleAccount{},
)

return grpc.Dial(
cfg.PlanetmintRPCHost,
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithDefaultCallOptions(grpc.ForceCodec(codec.NewProtoCodec(interfaceRegistry).GRPCCodec())),
)
}

var libConfig *lib.Config

func init() {
Expand Down
16 changes: 5 additions & 11 deletions service/planetmint_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,22 @@ import (
"log"
"testing"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/rddl-network/ta_attest/config"
"github.com/rddl-network/ta_attest/service"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)

func TestPlanetmintQueryAccount(t *testing.T) {
// skipped because test is just to showcase interfaceRegistry fix
t.SkipNow()
cfg := config.DefaultConfig()
grpcConn, err := grpc.Dial(
cfg.PlanetmintRPCHost,
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithDefaultCallOptions(grpc.ForceCodec(codec.NewProtoCodec(nil).GRPCCodec())),
)
grpcConn, err := service.SetupGRPCConnection(cfg)
if err != nil {
log.Fatalf("fatal error opening grpc connection %s", err)
}
cfg.PlanetmintActor = "plmnt1rmgh77rsnfz2vk2tn3j0uqczw97znpy0lxp4sm"
cfg.PlanetmintActor = "plmnt1p445cz0hfg4yg3dgrq5n3e9wdr8rwpt9qfcz2y"
pmc := service.NewPlanetmintClient(cfg.PlanetmintActor, grpcConn)
res, err := pmc.GetAccount("plmnt199zf0vkmehhr2hhdt3e425r5dx4749dmenm35w")
res, err := pmc.GetAccount("plmnt1u8awp62tsp68fed7ezasdh98rch6wyansg8dzs")
assert.NoError(t, err)
assert.NotNil(t, res)

}

0 comments on commit 75b2a88

Please sign in to comment.