Skip to content

Commit

Permalink
Merge pull request #58 from pokt-network/refactor/shared-supplier-type
Browse files Browse the repository at this point in the history
[Supplier] refactor: supplier type to shared protobuf package
  • Loading branch information
bryanchriswhite authored Oct 13, 2023
2 parents 8be5d05 + 4603524 commit 26ffa80
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 40 deletions.
10 changes: 5 additions & 5 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75817,6 +75817,11 @@ definitions:
description: params holds all the parameters of this module.
type: object
description: QueryParamsResponse is response type for the Query/Params RPC method.
pocket.shared.Supplier:
type: object
properties:
address:
type: string
pocket.supplier.MsgStakeSupplierResponse:
type: object
pocket.supplier.MsgUnstakeSupplierResponse:
Expand Down Expand Up @@ -75875,8 +75880,3 @@ definitions:
description: params holds all the parameters of this module.
type: object
description: QueryParamsResponse is response type for the Query/Params RPC method.
pocket.supplier.Supplier:
type: object
properties:
address:
type: string
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
cosmossdk.io/api v0.3.1
github.com/cometbft/cometbft v0.37.2
github.com/cometbft/cometbft-db v0.8.0
github.com/cosmos/cosmos-proto v1.0.0-beta.2
github.com/cosmos/cosmos-sdk v0.47.3
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/ibc-go/v7 v7.1.0
Expand Down Expand Up @@ -61,7 +62,6 @@ require (
github.com/containerd/cgroups v1.1.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.2 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v0.20.0 // indirect
Expand Down
1 change: 0 additions & 1 deletion proto/pocket/service/relay.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import "cosmos_proto/cosmos.proto";
// TODO(@Olshansk): Uncomment the line below once the `service.proto` is added.
// import "pocket/service/service.proto";
import "pocket/application/application.proto";
import "pocket/supplier/supplier.proto";

// Relay contains both the RelayRequest (signed by the Application) and the RelayResponse (signed by the Supplier).
// The serialized tuple is inserted into the SMST leaves as values in the Claim/Proof lifecycle.
Expand Down
4 changes: 2 additions & 2 deletions proto/pocket/session/session.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "cosmos_proto/cosmos.proto";
// TODO(@Olshansk): Uncomment the line below once the service.proto file is added
// import "pocket/service/service.proto";
import "pocket/application/application.proto";
import "pocket/supplier/supplier.proto";
import "pocket/shared/supplier.proto";

// NOTE: Using signed integers for consistency with the cosmos SDK

Expand All @@ -32,5 +32,5 @@ message Session {
// TODO(@Olshansk): Uncomment the line below once the `Service` proto is defined
// service.Service service = 5; // A fully hydrated service object this session is for
application.Application application = 6; // A fully hydrated application object this session is for
repeated supplier.Supplier suppliers = 7; // A fully hydrated set of servicers that are serving the application
repeated shared.Supplier suppliers = 7; // A fully hydrated set of servicers that are serving the application
}
10 changes: 10 additions & 0 deletions proto/pocket/shared/supplier.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
syntax = "proto3";
package pocket.shared;

option go_package = "pocket/x/shared/types";

message Supplier {
string address = 1;

}

4 changes: 2 additions & 2 deletions proto/pocket/supplier/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ package pocket.supplier;

import "gogoproto/gogo.proto";
import "pocket/supplier/params.proto";
import "pocket/supplier/supplier.proto";
import "pocket/shared/supplier.proto";

option go_package = "pocket/x/supplier/types";

// GenesisState defines the supplier module's genesis state.
message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
repeated Supplier supplierList = 2 [(gogoproto.nullable) = false];
repeated pocket.shared.Supplier supplierList = 2 [(gogoproto.nullable) = false];
}

6 changes: 3 additions & 3 deletions proto/pocket/supplier/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "pocket/supplier/params.proto";
import "pocket/supplier/supplier.proto";
import "pocket/shared/supplier.proto";

option go_package = "pocket/x/supplier/types";

Expand Down Expand Up @@ -44,15 +44,15 @@ message QueryGetSupplierRequest {
}

message QueryGetSupplierResponse {
Supplier supplier = 1 [(gogoproto.nullable) = false];
pocket.shared.Supplier supplier = 1 [(gogoproto.nullable) = false];
}

message QueryAllSupplierRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

message QueryAllSupplierResponse {
repeated Supplier supplier = 1 [(gogoproto.nullable) = false];
repeated pocket.shared.Supplier supplier = 1 [(gogoproto.nullable) = false];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

10 changes: 0 additions & 10 deletions proto/pocket/supplier/supplier.proto

This file was deleted.

7 changes: 4 additions & 3 deletions x/supplier/client/cli/query_supplier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@ import (

"pocket/testutil/network"
"pocket/testutil/nullify"
sharedtypes "pocket/x/shared/types"
"pocket/x/supplier/client/cli"
"pocket/x/supplier/types"
)

// Prevent strconv unused error
var _ = strconv.IntSize

func networkWithSupplierObjects(t *testing.T, n int) (*network.Network, []types.Supplier) {
func networkWithSupplierObjects(t *testing.T, n int) (*network.Network, []sharedtypes.Supplier) {
t.Helper()
cfg := network.DefaultConfig()
state := types.GenesisState{}
for i := 0; i < n; i++ {
supplier := types.Supplier{
supplier := sharedtypes.Supplier{
Address: strconv.Itoa(i),
}
nullify.Fill(&supplier)
Expand All @@ -51,7 +52,7 @@ func TestShowSupplier(t *testing.T) {

args []string
err error
obj types.Supplier
obj sharedtypes.Supplier
}{
{
desc: "found",
Expand Down
4 changes: 3 additions & 1 deletion x/supplier/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"testing"

"github.com/stretchr/testify/require"

keepertest "pocket/testutil/keeper"
"pocket/testutil/nullify"
sharedtypes "pocket/x/shared/types"
"pocket/x/supplier"
"pocket/x/supplier/types"
)
Expand All @@ -14,7 +16,7 @@ func TestGenesis(t *testing.T) {
genesisState := types.GenesisState{
Params: types.DefaultParams(),

SupplierList: []types.Supplier{
SupplierList: []sharedtypes.Supplier{
{
Address: "0",
},
Expand Down
6 changes: 4 additions & 2 deletions x/supplier/keeper/query_supplier.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/cosmos/cosmos-sdk/types/query"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

sharedtypes "pocket/x/shared/types"
"pocket/x/supplier/types"
)

Expand All @@ -16,14 +18,14 @@ func (k Keeper) SupplierAll(goCtx context.Context, req *types.QueryAllSupplierRe
return nil, status.Error(codes.InvalidArgument, "invalid request")
}

var suppliers []types.Supplier
var suppliers []sharedtypes.Supplier
ctx := sdk.UnwrapSDKContext(goCtx)

store := ctx.KVStore(k.storeKey)
supplierStore := prefix.NewStore(store, types.KeyPrefix(types.SupplierKeyPrefix))

pageRes, err := query.Paginate(supplierStore, req.Pagination, func(key []byte, value []byte) error {
var supplier types.Supplier
var supplier sharedtypes.Supplier
if err := k.cdc.Unmarshal(value, &supplier); err != nil {
return err
}
Expand Down
10 changes: 6 additions & 4 deletions x/supplier/keeper/supplier.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package keeper
import (
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"

sharedtypes "pocket/x/shared/types"
"pocket/x/supplier/types"
)

// SetSupplier set a specific supplier in the store from its index
func (k Keeper) SetSupplier(ctx sdk.Context, supplier types.Supplier) {
func (k Keeper) SetSupplier(ctx sdk.Context, supplier sharedtypes.Supplier) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.SupplierKeyPrefix))
b := k.cdc.MustMarshal(&supplier)
store.Set(types.SupplierKey(
Expand All @@ -20,7 +22,7 @@ func (k Keeper) GetSupplier(
ctx sdk.Context,
address string,

) (val types.Supplier, found bool) {
) (val sharedtypes.Supplier, found bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.SupplierKeyPrefix))

b := store.Get(types.SupplierKey(
Expand All @@ -47,14 +49,14 @@ func (k Keeper) RemoveSupplier(
}

// GetAllSupplier returns all supplier
func (k Keeper) GetAllSupplier(ctx sdk.Context) (list []types.Supplier) {
func (k Keeper) GetAllSupplier(ctx sdk.Context) (list []sharedtypes.Supplier) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.SupplierKeyPrefix))
iterator := sdk.KVStorePrefixIterator(store, []byte{})

defer iterator.Close()

for ; iterator.Valid(); iterator.Next() {
var val types.Supplier
var val sharedtypes.Supplier
k.cdc.MustUnmarshal(iterator.Value(), &val)
list = append(list, val)
}
Expand Down
7 changes: 4 additions & 3 deletions x/supplier/keeper/supplier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"

keepertest "pocket/testutil/keeper"
"pocket/testutil/nullify"
sharedtypes "pocket/x/shared/types"
"pocket/x/supplier/keeper"
"pocket/x/supplier/types"
)

// Prevent strconv unused error
var _ = strconv.IntSize

func createNSupplier(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.Supplier {
items := make([]types.Supplier, n)
func createNSupplier(keeper *keeper.Keeper, ctx sdk.Context, n int) []sharedtypes.Supplier {
items := make([]sharedtypes.Supplier, n)
for i := range items {
items[i].Address = strconv.Itoa(i)

Expand Down
4 changes: 3 additions & 1 deletion x/supplier/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package types

import (
"fmt"

sharedtypes "pocket/x/shared/types"
)

// DefaultIndex is the default global index
Expand All @@ -10,7 +12,7 @@ const DefaultIndex uint64 = 1
// DefaultGenesis returns the default genesis state
func DefaultGenesis() *GenesisState {
return &GenesisState{
SupplierList: []Supplier{},
SupplierList: []sharedtypes.Supplier{},
// this line is used by starport scaffolding # genesis/types/default
Params: DefaultParams(),
}
Expand Down
6 changes: 4 additions & 2 deletions x/supplier/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"testing"

"github.com/stretchr/testify/require"

sharedtypes "pocket/x/shared/types"
"pocket/x/supplier/types"
)

Expand All @@ -22,7 +24,7 @@ func TestGenesisState_Validate(t *testing.T) {
desc: "valid genesis state",
genState: &types.GenesisState{

SupplierList: []types.Supplier{
SupplierList: []sharedtypes.Supplier{
{
Address: "0",
},
Expand All @@ -37,7 +39,7 @@ func TestGenesisState_Validate(t *testing.T) {
{
desc: "duplicated supplier",
genState: &types.GenesisState{
SupplierList: []types.Supplier{
SupplierList: []sharedtypes.Supplier{
{
Address: "0",
},
Expand Down

0 comments on commit 26ffa80

Please sign in to comment.