diff --git a/proto/panacea/oracle/v2/genesis.proto b/proto/panacea/oracle/v2/genesis.proto index 25f5b2b3..7b8b0ebf 100644 --- a/proto/panacea/oracle/v2/genesis.proto +++ b/proto/panacea/oracle/v2/genesis.proto @@ -11,6 +11,7 @@ import "panacea/oracle/v2/oracle.proto"; message GenesisState { repeated Oracle oracles = 1 [(gogoproto.nullable) = false]; repeated OracleRegistration oracle_registrations = 2 [(gogoproto.nullable) = false]; + Params params = 3 [(gogoproto.nullable) = false]; } // Params defines the oracle module's params. diff --git a/x/oracle/client/cli/query.go b/x/oracle/client/cli/query.go new file mode 100644 index 00000000..043255c8 --- /dev/null +++ b/x/oracle/client/cli/query.go @@ -0,0 +1,22 @@ +package cli + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/medibloc/panacea-core/v2/x/oracle/types" + "github.com/spf13/cobra" +) + +// GetQueryCmd returns the cli query commands for this module +func GetQueryCmd(queryRoute string) *cobra.Command { + // Group oracle queries under a subcommand + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + return cmd +} diff --git a/x/oracle/client/cli/tx.go b/x/oracle/client/cli/tx.go new file mode 100644 index 00000000..bbd4017e --- /dev/null +++ b/x/oracle/client/cli/tx.go @@ -0,0 +1,22 @@ +package cli + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/medibloc/panacea-core/v2/x/oracle/types" + "github.com/spf13/cobra" +) + +// GetTxCmd returns the transaction commands for this module +func GetTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + return cmd +} diff --git a/x/oracle/genesis.go b/x/oracle/genesis.go new file mode 100644 index 00000000..ecf6eaf8 --- /dev/null +++ b/x/oracle/genesis.go @@ -0,0 +1,20 @@ +package oracle + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/medibloc/panacea-core/v2/x/oracle/keeper" + "github.com/medibloc/panacea-core/v2/x/oracle/types" +) + +// InitGenesis initializes the capability module's state from a provided genesis +// state. +func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { + //TODO implement me + panic("implement me") +} + +// ExportGenesis returns the capability module's exported genesis. +func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { + //TODO implement me + panic("implement me") +} diff --git a/x/oracle/handler.go b/x/oracle/handler.go new file mode 100644 index 00000000..5ac37fb8 --- /dev/null +++ b/x/oracle/handler.go @@ -0,0 +1,34 @@ +package oracle + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/medibloc/panacea-core/v2/x/oracle/keeper" + "github.com/medibloc/panacea-core/v2/x/oracle/types" +) + +// NewHandler ... +func NewHandler(k keeper.Keeper) sdk.Handler { + msgServer := keeper.NewMsgServerImpl(k) + + return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { + ctx = ctx.WithEventManager(sdk.NewEventManager()) + + switch msg := msg.(type) { + case *types.MsgRegisterOracle: + res, err := msgServer.RegisterOracle(sdk.WrapSDKContext(ctx), msg) + return sdk.WrapServiceResult(ctx, res, err) + //case *types.MsgApproveOracleRegistration: + // res, err := msgServer.ApproveOracleRegistration(sdk.WrapSDKContext(ctx), msg) + // return sdk.WrapServiceResult(ctx, res, err) + //case *types.MsgUpdateOracleInfo: + // res, err := msgServer.UpdateOracleInfo(sdk.WrapSDKContext(ctx), msg) + // return sdk.WrapServiceResult(ctx, res, err) + default: + errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) + return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) + } + } +} diff --git a/x/oracle/keeper/grpc_query.go b/x/oracle/keeper/grpc_query.go new file mode 100644 index 00000000..9bf6c761 --- /dev/null +++ b/x/oracle/keeper/grpc_query.go @@ -0,0 +1,5 @@ +package keeper + +import "github.com/medibloc/panacea-core/v2/x/oracle/types" + +var _ types.QueryServer = Keeper{} diff --git a/x/oracle/keeper/grpc_query_oracle.go b/x/oracle/keeper/grpc_query_oracle.go new file mode 100644 index 00000000..34b75319 --- /dev/null +++ b/x/oracle/keeper/grpc_query_oracle.go @@ -0,0 +1,32 @@ +package keeper + +import ( + "context" + + "github.com/medibloc/panacea-core/v2/x/oracle/types" +) + +func (k Keeper) Oracles(ctx context.Context, request *types.QueryOraclesRequest) (*types.QueryOraclesResponse, error) { + //TODO implement me + panic("implement me") +} + +func (k Keeper) Oracle(ctx context.Context, request *types.QueryOracleRequest) (*types.QueryOracleResponse, error) { + //TODO implement me + panic("implement me") +} + +func (k Keeper) OracleRegistrations(ctx context.Context, request *types.QueryOracleRegistrationsRequest) (*types.QueryOracleRegistrationsResponse, error) { + //TODO implement me + panic("implement me") +} + +func (k Keeper) OracleRegistration(ctx context.Context, request *types.QueryOracleRegistrationRequest) (*types.QueryOracleRegistrationResponse, error) { + //TODO implement me + panic("implement me") +} + +func (k Keeper) Params(ctx context.Context, request *types.QueryOracleParamsRequest) (*types.QueryParamsResponse, error) { + //TODO implement me + panic("implement me") +} diff --git a/x/oracle/keeper/keeper.go b/x/oracle/keeper/keeper.go new file mode 100644 index 00000000..b651643f --- /dev/null +++ b/x/oracle/keeper/keeper.go @@ -0,0 +1,37 @@ +package keeper + +import ( + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/medibloc/panacea-core/v2/x/oracle/types" + + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" +) + +type ( + Keeper struct { + cdc codec.Codec + storeKey sdk.StoreKey + memKey sdk.StoreKey + + paramSpace paramtypes.Subspace + } +) + +func NewKeeper( + cdc codec.Codec, + storeKey, + memKey sdk.StoreKey, + paramSpace paramtypes.Subspace, +) *Keeper { + if !paramSpace.HasKeyTable() { + paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable()) + } + + return &Keeper{ + cdc: cdc, + storeKey: storeKey, + memKey: memKey, + paramSpace: paramSpace, + } +} diff --git a/x/oracle/keeper/msg_server.go b/x/oracle/keeper/msg_server.go new file mode 100644 index 00000000..343409cb --- /dev/null +++ b/x/oracle/keeper/msg_server.go @@ -0,0 +1,15 @@ +package keeper + +import "github.com/medibloc/panacea-core/v2/x/oracle/types" + +type msgServer struct { + Keeper +} + +// NewMsgServerImpl returns an implementation of the MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return &msgServer{Keeper: keeper} +} + +var _ types.MsgServer = msgServer{} diff --git a/x/oracle/keeper/msg_server_oracle.go b/x/oracle/keeper/msg_server_oracle.go new file mode 100644 index 00000000..db1e12eb --- /dev/null +++ b/x/oracle/keeper/msg_server_oracle.go @@ -0,0 +1,22 @@ +package keeper + +import ( + "context" + + "github.com/medibloc/panacea-core/v2/x/oracle/types" +) + +func (m msgServer) RegisterOracle(ctx context.Context, oracle *types.MsgRegisterOracle) (*types.MsgRegisterOracleResponse, error) { + //TODO implement me + panic("implement me") +} + +func (m msgServer) ApproveOracleRegistration(ctx context.Context, registration *types.MsgApproveOracleRegistration) (*types.MsgApproveOracleRegistrationResponse, error) { + //TODO implement me + panic("implement me") +} + +func (m msgServer) UpdateOracleInfo(ctx context.Context, info *types.MsgUpdateOracleInfo) (*types.MsgUpdateOracleInfoResponse, error) { + //TODO implement me + panic("implement me") +} diff --git a/x/oracle/keeper/params.go b/x/oracle/keeper/params.go new file mode 100644 index 00000000..7c152278 --- /dev/null +++ b/x/oracle/keeper/params.go @@ -0,0 +1,16 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/medibloc/panacea-core/v2/x/oracle/types" +) + +func (k Keeper) GetParams(ctx sdk.Context) types.Params { + var params types.Params + k.paramSpace.GetParamSet(ctx, ¶ms) + return params +} + +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { + k.paramSpace.SetParamSet(ctx, ¶ms) +} diff --git a/x/oracle/module.go b/x/oracle/module.go new file mode 100644 index 00000000..40bd42e7 --- /dev/null +++ b/x/oracle/module.go @@ -0,0 +1,166 @@ +package oracle + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/gorilla/mux" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/medibloc/panacea-core/v2/x/oracle/client/cli" + "github.com/medibloc/panacea-core/v2/x/oracle/keeper" + "github.com/medibloc/panacea-core/v2/x/oracle/types" + "github.com/spf13/cobra" + abci "github.com/tendermint/tendermint/abci/types" +) + +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// ---------------------------------------------------------------------------- +// AppModuleBasic +// ---------------------------------------------------------------------------- + +// AppModuleBasic implements the AppModuleBasic interface for the capability module. +type AppModuleBasic struct { + cdc codec.Codec +} + +func NewAppModuleBasic(cdc codec.Codec) AppModuleBasic { + return AppModuleBasic{cdc: cdc} +} + +// Name returns the capability module's name. +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { + types.RegisterCodec(cdc) +} + +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterCodec(cdc) +} + +// RegisterInterfaces registers the module's interface types +func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(reg) +} + +// DefaultGenesis returns the capability module's default genesis state. +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesis()) +} + +// ValidateGenesis performs genesis state validation for the capability module. +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { + var genState types.GenesisState + if err := cdc.UnmarshalJSON(bz, &genState); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + return genState.Validate() +} + +// RegisterRESTRoutes registers the capability module's REST service handlers. +func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) { +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) + if err != nil { + panic("Error RegisterGRPCGatewayRoutes") + } +} + +// GetTxCmd returns the capability module's root tx command. +func (a AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.GetTxCmd() +} + +// GetQueryCmd returns the capability module's root query command. +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd(types.StoreKey) +} + +// ---------------------------------------------------------------------------- +// AppModule +// ---------------------------------------------------------------------------- + +// AppModule implements the AppModule interface for the capability module. +type AppModule struct { + AppModuleBasic + keeper keeper.Keeper +} + +func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule { + return AppModule{ + AppModuleBasic: NewAppModuleBasic(cdc), + keeper: keeper, + } +} + +// Name returns the capability module's name. +func (am AppModule) Name() string { + return am.AppModuleBasic.Name() +} + +// Route returns the capability module's message routing key. +func (am AppModule) Route() sdk.Route { + return sdk.NewRoute(types.RouterKey, NewHandler(am.keeper)) +} + +// QuerierRoute returns the capability module's query routing key. +func (AppModule) QuerierRoute() string { return types.QuerierRoute } + +// LegacyQuerierHandler returns the capability module's Querier. +func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier { + return nil +} + +// RegisterServices registers a GRPC query service to respond to the +// module-specific GRPC queries. +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterQueryServer(cfg.QueryServer(), am.keeper) +} + +// RegisterInvariants registers the capability module's invariants. +func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} + +// InitGenesis performs the capability module's genesis initialization It returns +// no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { + var genState types.GenesisState + // Initialize global index to index in genesis state + cdc.MustUnmarshalJSON(gs, &genState) + + InitGenesis(ctx, am.keeper, genState) + + return []abci.ValidatorUpdate{} +} + +// ExportGenesis returns the capability module's exported genesis state as raw JSON bytes. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + genState := ExportGenesis(ctx, am.keeper) + return cdc.MustMarshalJSON(genState) +} + +// BeginBlock executes all ABCI BeginBlock logic respective to the capability module. +func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} + +// EndBlock executes all ABCI EndBlock logic respective to the capability module. It +// returns no validator updates. +func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + return []abci.ValidatorUpdate{} +} + +// ConsensusVersion implements AppModule/ConsensusVersion. +func (AppModule) ConsensusVersion() uint64 { return 1 } diff --git a/x/oracle/types/codec.go b/x/oracle/types/codec.go new file mode 100644 index 00000000..efb17925 --- /dev/null +++ b/x/oracle/types/codec.go @@ -0,0 +1,28 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +func RegisterCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgRegisterOracle{}, "oracle/RegisterOracle", nil) + cdc.RegisterConcrete(&MsgApproveOracleRegistration{}, "oracle/ApproveOracleRegistration", nil) + cdc.RegisterConcrete(&MsgUpdateOracleInfo{}, "oracle/UpdateOracleInfo", nil) +} + +func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgRegisterOracle{}, + &MsgApproveOracleRegistration{}, + &MsgUpdateOracleInfo{}, + ) + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +var ( + amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewAminoCodec(amino) +) diff --git a/x/oracle/types/genesis.go b/x/oracle/types/genesis.go new file mode 100644 index 00000000..d5796be9 --- /dev/null +++ b/x/oracle/types/genesis.go @@ -0,0 +1,49 @@ +package types + +import ( + "encoding/json" + + "github.com/cosmos/cosmos-sdk/codec" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +// DefaultGenesis returns the default Capability genesis state +func DefaultGenesis() *GenesisState { + return &GenesisState{ + Oracles: []Oracle{}, + OracleRegistrations: []OracleRegistration{}, + Params: DefaultParams(), + } +} + +func GetGenesisStateFromAppState(cdc codec.Codec, appState map[string]json.RawMessage) *GenesisState { + var genesisState GenesisState + + if appState[ModuleName] != nil { + cdc.MustUnmarshalJSON(appState[ModuleName], &genesisState) + } + + return &genesisState +} + +// Validate performs basic genesis state validation returning an error upon any +// failure. +func (m GenesisState) Validate() error { + + for _, oracle := range m.Oracles { + if err := oracle.ValidateBasic(); err != nil { + return err + } + } + for _, oracleRegistration := range m.OracleRegistrations { + if err := oracleRegistration.ValidateBasic(); err != nil { + return err + } + } + + if err := m.Params.Validate(); err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, err.Error()) + } + + return nil +} diff --git a/x/oracle/types/genesis.pb.go b/x/oracle/types/genesis.pb.go index 8956d4de..e36006ed 100644 --- a/x/oracle/types/genesis.pb.go +++ b/x/oracle/types/genesis.pb.go @@ -28,6 +28,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type GenesisState struct { Oracles []Oracle `protobuf:"bytes,1,rep,name=oracles,proto3" json:"oracles"` OracleRegistrations []OracleRegistration `protobuf:"bytes,2,rep,name=oracle_registrations,json=oracleRegistrations,proto3" json:"oracle_registrations"` + Params Params `protobuf:"bytes,3,opt,name=params,proto3" json:"params"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -77,6 +78,13 @@ func (m *GenesisState) GetOracleRegistrations() []OracleRegistration { return nil } +func (m *GenesisState) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + // Params defines the oracle module's params. type Params struct { // A base64-encoded oracle public key which is paired with an oracle private key generated in SGX by the first oracle. @@ -151,30 +159,31 @@ func init() { func init() { proto.RegisterFile("panacea/oracle/v2/genesis.proto", fileDescriptor_321e5b447e46614a) } var fileDescriptor_321e5b447e46614a = []byte{ - // 357 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0xc1, 0x4a, 0xeb, 0x40, - 0x14, 0x86, 0x33, 0xed, 0xa5, 0xf7, 0x76, 0xee, 0x85, 0x4b, 0x63, 0x17, 0xb1, 0x4a, 0x5a, 0x0a, - 0x42, 0x11, 0xcc, 0x40, 0x5d, 0xb9, 0x71, 0xd1, 0x8d, 0x94, 0x2e, 0x2c, 0x71, 0xe7, 0xc2, 0x30, - 0x49, 0x8f, 0x71, 0x30, 0xc9, 0xc4, 0x99, 0x49, 0x31, 0x6f, 0xa1, 0x8f, 0xe1, 0x9b, 0x74, 0xd9, - 0xa5, 0x2b, 0x91, 0xf6, 0x45, 0xa4, 0x33, 0xa9, 0x0a, 0xc5, 0xdd, 0x99, 0xf3, 0x7f, 0xe7, 0xff, - 0x0f, 0x73, 0x70, 0x37, 0xa7, 0x19, 0x8d, 0x80, 0x12, 0x2e, 0x68, 0x94, 0x00, 0x99, 0x0f, 0x49, - 0x0c, 0x19, 0x48, 0x26, 0xbd, 0x5c, 0x70, 0xc5, 0xed, 0x56, 0x05, 0x78, 0x06, 0xf0, 0xe6, 0xc3, - 0x4e, 0x3b, 0xe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, 0xfb, 0xca, 0x45, 0x4f, 0x6b, 0xd7, 0x5a, - 0xae, 0x5d, 0xeb, 0x75, 0xed, 0x5a, 0xd7, 0x24, 0x66, 0xea, 0xae, 0x08, 0xbd, 0x88, 0xa7, 0x24, - 0x85, 0x19, 0x0b, 0x13, 0x1e, 0x91, 0xea, 0x0b, 0x4e, 0x22, 0x2e, 0x80, 0x3c, 0x6e, 0x8f, 0xa2, - 0xca, 0x1c, 0x64, 0xd8, 0xd0, 0x17, 0x39, 0xfd, 0x08, 0x00, 0x00, 0xff, 0xff, 0x90, 0xc1, 0x79, - 0x70, 0x1e, 0x02, 0x00, 0x00, + // 374 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0x41, 0x6b, 0xdb, 0x30, + 0x14, 0xc7, 0xad, 0x64, 0x64, 0x8b, 0x36, 0x18, 0xf1, 0x72, 0xf0, 0xb2, 0xe1, 0x84, 0xc0, 0x20, + 0x0c, 0x66, 0x41, 0x76, 0x18, 0xbb, 0xec, 0x90, 0xcb, 0x08, 0x39, 0x2c, 0x78, 0xb7, 0x1e, 0x6a, + 0x64, 0xe7, 0xd5, 0x15, 0xb5, 0x2d, 0x57, 0x92, 0x43, 0xfd, 0x2d, 0xda, 0x6f, 0x95, 0x63, 0x8e, + 0x3d, 0x95, 0xe2, 0x7c, 0x91, 0x12, 0x49, 0x69, 0x0b, 0x21, 0xb7, 0x27, 0xfd, 0x7f, 0xef, 0xff, + 0xfe, 0x8f, 0x87, 0x87, 0x25, 0x2d, 0x68, 0x02, 0x94, 0x70, 0x41, 0x93, 0x0c, 0xc8, 0x7a, 0x4a, + 0x52, 0x28, 0x40, 0x32, 0x19, 0x94, 0x82, 0x2b, 0xee, 0xf6, 0x2c, 0x10, 0x18, 0x20, 0x58, 0x4f, + 0x07, 0xfd, 0x94, 0xa7, 0x5c, 0xab, 0x64, 0x5f, 0x19, 0x70, 0x30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, + 0xf9, 0x6a, 0x36, 0xdf, 0x34, 0x3e, 0xda, 0x36, 0x3e, 0x7a, 0x6c, 0x7c, 0x74, 0xbb, 0xf3, 0x9d, + 0xed, 0xce, 0x77, 0xee, 0x77, 0xbe, 0x73, 0x46, 0x52, 0xa6, 0x2e, 0xab, 0x38, 0x48, 0x78, 0x4e, + 0x72, 0x58, 0xb1, 0x38, 0xe3, 0x09, 0xb1, 0x9b, 0xfe, 0x48, 0xb8, 0x00, 0x72, 0x73, 0xb8, 0xa6, + 0xaa, 0x4b, 0x90, 0x71, 0x47, 0x9f, 0xf2, 0xe7, 0x53, 0x00, 0x00, 0x00, 0xff, 0xff, 0xc6, 0x82, + 0xde, 0xcf, 0x57, 0x02, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -197,6 +206,16 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a if len(m.OracleRegistrations) > 0 { for iNdEx := len(m.OracleRegistrations) - 1; iNdEx >= 0; iNdEx-- { { @@ -301,6 +320,8 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) } } + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) return n } @@ -428,6 +449,39 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/oracle/types/keys.go b/x/oracle/types/keys.go new file mode 100644 index 00000000..28e943d6 --- /dev/null +++ b/x/oracle/types/keys.go @@ -0,0 +1,18 @@ +package types + +const ( + // ModuleName defines the module name + ModuleName = "oracle" + + // StoreKey defines the primary module store key + StoreKey = ModuleName + + // RouterKey is the message route for slashing + RouterKey = ModuleName + + // QuerierRoute defines the module's query routing key + QuerierRoute = ModuleName + + // MemStoreKey defines the in-memory store key + MemStoreKey = "mem_oracle" +) diff --git a/x/oracle/types/message_oracle.go b/x/oracle/types/message_oracle.go new file mode 100644 index 00000000..4a1c1a40 --- /dev/null +++ b/x/oracle/types/message_oracle.go @@ -0,0 +1,46 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var _ sdk.Msg = &MsgRegisterOracle{} + +func NewMsgRegisterOracle(uniqueID, oracleAddress, endpoint string, nodePubKey, nodePubKeyRemoteReport []byte, trustedBlockHeight int64, trustedBlockHash []byte, oracleCommissionRate sdk.Dec) *MsgRegisterOracle { + return &MsgRegisterOracle{ + UniqueId: uniqueID, + OracleAddress: oracleAddress, + NodePubKey: nodePubKey, + NodePubKeyRemoteReport: nodePubKeyRemoteReport, + TrustedBlockHeight: trustedBlockHeight, + TrustedBlockHash: trustedBlockHash, + Endpoint: endpoint, + OracleCommissionRate: oracleCommissionRate, + } +} + +func (m *MsgRegisterOracle) Route() string { + return RouterKey +} + +func (m *MsgRegisterOracle) Type() string { + return "RegisterOracle" +} + +func (m *MsgRegisterOracle) ValidateBasic() error { + + return nil +} + +func (m *MsgRegisterOracle) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(m) + return sdk.MustSortJSON(bz) +} + +func (m *MsgRegisterOracle) GetSigners() []sdk.AccAddress { + oracleAddress, err := sdk.AccAddressFromBech32(m.OracleAddress) + if err != nil { + panic(err) + } + return []sdk.AccAddress{oracleAddress} +} diff --git a/x/oracle/types/oracle.go b/x/oracle/types/oracle.go new file mode 100644 index 00000000..db3432b5 --- /dev/null +++ b/x/oracle/types/oracle.go @@ -0,0 +1,11 @@ +package types + +func (m Oracle) ValidateBasic() error { + //TODO implement me + panic("implement me") +} + +func (m OracleRegistration) ValidateBasic() error { + //TODO implement me + panic("implement me") +} diff --git a/x/oracle/types/params.go b/x/oracle/types/params.go new file mode 100644 index 00000000..e5fdb39b --- /dev/null +++ b/x/oracle/types/params.go @@ -0,0 +1,95 @@ +package types + +import ( + "encoding/base64" + "fmt" + + "github.com/btcsuite/btcd/btcec" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" +) + +var ( + KeyOraclePublicKey = []byte("OraclePublicKey") + KeyOraclePubKeyRemoteReport = []byte("OraclePubKeyRemoteReport") + KeyUniqueID = []byte("UniqueID") +) + +var _ paramtypes.ParamSet = (*Params)(nil) + +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) +} + +func DefaultParams() Params { + return Params{ + OraclePublicKey: "", + OraclePubKeyRemoteReport: "", + UniqueId: "", + } +} + +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(KeyOraclePublicKey, &p.OraclePublicKey, validateOraclePublicKey), + paramtypes.NewParamSetPair(KeyOraclePubKeyRemoteReport, &p.OraclePubKeyRemoteReport, validateOraclePubKeyRemoteReport), + paramtypes.NewParamSetPair(KeyUniqueID, &p.UniqueId, validateUniqueID), + } +} + +func (p Params) Validate() error { + if err := validateOraclePublicKey(p.OraclePublicKey); err != nil { + return err + } + if err := validateOraclePubKeyRemoteReport(p.OraclePubKeyRemoteReport); err != nil { + return err + } + if err := validateUniqueID(p.UniqueId); err != nil { + return err + } + + return nil +} + +func validateOraclePublicKey(i interface{}) error { + pubKeyBase64, ok := i.(string) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if pubKeyBase64 != "" { + oraclePubKeyBz, err := base64.StdEncoding.DecodeString(pubKeyBase64) + if err != nil { + return err + } + + if _, err := btcec.ParsePubKey(oraclePubKeyBz, btcec.S256()); err != nil { + return err + } + } + + return nil +} + +func validateOraclePubKeyRemoteReport(i interface{}) error { + reportBase64, ok := i.(string) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if reportBase64 != "" { + if _, err := base64.StdEncoding.DecodeString(reportBase64); err != nil { + return err + } + } + + return nil +} + +func validateUniqueID(i interface{}) error { + _, ok := i.(string) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + return nil +}