Skip to content

Commit

Permalink
chore(data-proxy): initial module boilerplate
Browse files Browse the repository at this point in the history
Part-of: #316
  • Loading branch information
Thomasvdam committed Aug 17, 2024
1 parent ce6521a commit 456c0dc
Show file tree
Hide file tree
Showing 27 changed files with 5,139 additions and 0 deletions.
44 changes: 44 additions & 0 deletions proto/sedachain/data_proxy/v1/data_proxy.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
syntax = "proto3";
package sedachain.data_proxy.v1;

import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/sedaprotocol/seda-chain/x/data-proxy/types";

// Module parameters which can be changed through governance.
message Params {
option (gogoproto.equal) = true;

// min_fee_update_delay is the minimum number of blocks after which a fee
// update comes into effect.
uint32 min_fee_update_delay = 1;
}

// ProxyConfig defines a data-proxy entry in the registry.
message ProxyConfig {
// payout_address defines the address to which the data proxy fees should be
// transferred.
string payout_address = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

// fee defines the amount in aseda this data-proxy charges when utilised.
cosmos.base.v1beta1.Coin fee = 2;

// memo defines an optional string which is not used by the protocol.
string memo = 3;

// fee_update defines an upcoming fee change which will take effect at a
// future height.
FeeUpdate fee_update = 4 [ (gogoproto.nullable) = true ];
}

// FeeUpdate defines a new fee amount and the height at which it will take
// effect.
message FeeUpdate {
// new_fee defines the new fee for the data proxy.
cosmos.base.v1beta1.Coin new_fee = 1 [ (gogoproto.nullable) = false ];

// update_height defines the height at which the new fee comes into effect.
int64 update_height = 2;
}
32 changes: 32 additions & 0 deletions proto/sedachain/data_proxy/v1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
syntax = "proto3";
package sedachain.data_proxy.v1;

import "gogoproto/gogo.proto";
import "sedachain/data_proxy/v1/data_proxy.proto";

option go_package = "github.com/sedaprotocol/seda-chain/x/data-proxy/types";

// GenesisState defines data_proxy module's genesis state.
message GenesisState {
Params params = 1 [ (gogoproto.nullable) = false ];

repeated DataProxyConfigs data_proxy_configs = 2
[ (gogoproto.nullable) = false ];

repeated FeeUpdateQueueRecord fee_update_queue = 3
[ (gogoproto.nullable) = false ];
}

// DataProxyConfigs define the data proxy entries in the registry.
message DataProxyConfigs {
string data_proxy_pubkey = 1;

ProxyConfig config = 2;
}

// FeeUpdateQueueRecord defines an entry in the data proxy update queue.
message FeeUpdateQueueRecord {
string data_proxy_pubkey = 1;

int64 update_height = 2;
}
27 changes: 27 additions & 0 deletions proto/sedachain/data_proxy/v1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
syntax = "proto3";
package sedachain.data_proxy.v1;

import "google/api/annotations.proto";
import "sedachain/data_proxy/v1/data_proxy.proto";

option go_package = "github.com/sedaprotocol/seda-chain/x/data-proxy/types";

// Query defines the gRPC querier service.
service Query {
// DataProxyConfig returns a data proxy config when given its public key as a
// hex encoded string.
rpc DataProxyConfig(QueryDataProxyConfigRequest)
returns (QueryDataProxyConfigResponse) {
option (google.api.http).get =
"/seda-chain/data-proxy/data-proxy/{pub_key}";
}
}

// The request message for QueryDataProxyConfig RPC method.
message QueryDataProxyConfigRequest {
// A hex encoded string of the public key of the data proxy.
string pub_key = 1;
}

// The response message for QueryDataProxyConfig RPC method.
message QueryDataProxyConfigResponse { ProxyConfig config = 1; }
81 changes: 81 additions & 0 deletions proto/sedachain/data_proxy/v1/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
syntax = "proto3";
package sedachain.data_proxy.v1;

import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos/msg/v1/msg.proto";
import "sedachain/data_proxy/v1/data_proxy.proto";

option go_package = "github.com/sedaprotocol/seda-chain/x/data-proxy/types";

// Msg service defines the data-proxy tx gRPC methods.
service Msg {
// Registers a new data proxy entry in the registry.
rpc RegisterDataProxy(MsgRegisterDataProxy)
returns (MsgRegisterDataProxyResponse);

// Edits an existing data proxy.
rpc EditDataProxy(MsgEditDataProxy) returns (MsgEditDataProxyResponse);

// Used to update the modules parameters through governance.
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}

// All data required for a new data proxy.
message MsgRegisterDataProxy {
string payout_address = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

cosmos.base.v1beta1.Coin fee = 2;

string memo = 3;

// hex encoded bytes as the expected flow already uses hex encoded bytes to go
// from the CLI to the browser where the transaction is signed.
string pub_key = 4;

// hex encoded bytes as the expected flow already uses hex encoded bytes to go
// from the CLI to the browser where the transaction is signed.
string signature = 5;
}

// No response required.
message MsgRegisterDataProxyResponse {}

// Allow updating memo and payout address instantly and/or scheduling a fee
// update.
message MsgEditDataProxy {
string new_payout_address = 1
[ (cosmos_proto.scalar) = "cosmos.AddressString" ];

string new_memo = 2 [ (gogoproto.nullable) = true ];

cosmos.base.v1beta1.Coin new_fee = 3 [ (gogoproto.nullable) = true ];

uint32 fee_update_delay = 4 [ (gogoproto.nullable) = true ];

// hex encoded bytes as the expected flow already uses hex encoded bytes to go
// from the CLI to the browser where the transaction is signed.
string pub_key = 5;

// hex encoded bytes as the expected flow already uses hex encoded bytes to go
// from the CLI to the browser where the transaction is signed.
string signature = 6;
}

// Returns the height at which the fee update will go into effect.
message MsgEditDataProxyResponse { int64 update_height = 1; }

// The request message for the UpdateParams method.
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";

// authority is the address that controls the module (defaults to x/gov unless
// overwritten).
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

Params params = 2 [ (gogoproto.nullable) = false ];
}

// No response required.
message MsgUpdateParamsResponse {}
55 changes: 55 additions & 0 deletions x/data-proxy/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package cli

import (
"fmt"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"

"github.com/sedaprotocol/seda-chain/x/data-proxy/types"
)

// GetQueryCmd returns the CLI query commands for this module
func GetQueryCmd(_ string) *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName),
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}

cmd.AddCommand(
GetDataProxyConfig(),
)
return cmd
}

// GetDataProxyConfig returns the command for querying the config of a given data proxy.
func GetDataProxyConfig() *cobra.Command {
cmd := &cobra.Command{
Use: "data-proxy-config <data_proxy_pubkey>",
Short: "Query a data proxy config by its hex encoded public key",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

req := &types.QueryDataProxyConfigRequest{
PubKey: args[0],
}
res, err := queryClient.DataProxyConfig(cmd.Context(), req)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)
return cmd
}
53 changes: 53 additions & 0 deletions x/data-proxy/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package cli

import (
"fmt"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"

"github.com/sedaprotocol/seda-chain/x/data-proxy/types"
)

// GetTxCmd returns the CLI transaction commands for this module
func GetTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName),
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
cmd.AddCommand(
RegisterDataProxy(),
)
return cmd
}

// AddKey returns the command for adding a new key and uploading its
// public key on chain at a given index.
func RegisterDataProxy() *cobra.Command {
// TODO
cmd := &cobra.Command{
Use: "register [thing]",
Short: "Register a data proxy using a signed message generated with the data-proxy cli",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

// TODO
msg := &types.MsgRegisterDataProxy{}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)
return cmd
}

// TODO Edit tx
26 changes: 26 additions & 0 deletions x/data-proxy/keeper/common_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package keeper_test

import (
"testing"

"github.com/stretchr/testify/suite"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/sedaprotocol/seda-chain/x/data-proxy/keeper"
)

type KeeperTestSuite struct {
suite.Suite
ctx sdk.Context
keeper *keeper.Keeper
}

func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(KeeperTestSuite))
}

func (s *KeeperTestSuite) SetupTest() {
t := s.T()
t.Helper()
}
21 changes: 21 additions & 0 deletions x/data-proxy/keeper/genesis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/sedaprotocol/seda-chain/x/data-proxy/types"
)

// InitGenesis initializes the store based on the given genesis state.
func (k Keeper) InitGenesis(_ sdk.Context, _ types.GenesisState) {
// TODO
}

// ExportGenesis extracts all data from store to genesis state.
func (k Keeper) ExportGenesis(_ sdk.Context) types.GenesisState {
var gs types.GenesisState

// TODO

return gs
}
13 changes: 13 additions & 0 deletions x/data-proxy/keeper/genesis_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package keeper_test

import (
"github.com/sedaprotocol/seda-chain/x/data-proxy/types"
)

func (s *KeeperTestSuite) TestImportExportGenesis() {
genState := types.GenesisState{}

s.keeper.InitGenesis(s.ctx, genState)
// exportedGenState := s.keeper.ExportGenesis(s.ctx)
// TODO
}
21 changes: 21 additions & 0 deletions x/data-proxy/keeper/grpc_query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package keeper

import (
"context"

"github.com/sedaprotocol/seda-chain/x/data-proxy/types"
)

var _ types.QueryServer = Querier{}

type Querier struct {
Keeper
}

func (q Querier) DataProxyConfig(ctx context.Context, req *types.QueryDataProxyConfigRequest) (*types.QueryDataProxyConfigResponse, error) {
result, err := q.GetDataProxyConfig(ctx, req.PubKey)
if err != nil {
return nil, err
}
return &types.QueryDataProxyConfigResponse{Config: &result}, nil
}
5 changes: 5 additions & 0 deletions x/data-proxy/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package keeper_test

func (s *KeeperTestSuite) TestQuerier_ProxyConfig() {
// TODO
}
Loading

0 comments on commit 456c0dc

Please sign in to comment.