From dcafdc899bfe2984f7d8153f925091b59f22957c Mon Sep 17 00:00:00 2001 From: akrem Date: Fri, 29 Sep 2023 09:23:10 -0400 Subject: [PATCH] Add commit msg & logic to subVal to reveal value --- app/app.go | 1 + proto/layer/oracle/commit_value.proto | 11 + proto/layer/oracle/reports.proto | 2 +- proto/layer/oracle/tx.proto | 13 +- x/oracle/client/cli/tx.go | 1 + x/oracle/client/cli/tx_commit_report.go | 56 +++ x/oracle/keeper/keeper.go | 3 + x/oracle/keeper/msg_server_commit_report.go | 44 ++ x/oracle/keeper/msg_server_submit_value.go | 136 ++++-- x/oracle/module_simulation.go | 23 + x/oracle/simulation/commit_report.go | 29 ++ x/oracle/types/codec.go | 4 + x/oracle/types/commit_value.pb.go | 361 +++++++++++++++ x/oracle/types/keys.go | 2 + x/oracle/types/message_commit_report.go | 47 ++ x/oracle/types/message_commit_report_test.go | 40 ++ x/oracle/types/reports.pb.go | 40 +- x/oracle/types/tx.pb.go | 448 ++++++++++++++++++- 18 files changed, 1187 insertions(+), 74 deletions(-) create mode 100644 proto/layer/oracle/commit_value.proto create mode 100644 x/oracle/client/cli/tx_commit_report.go create mode 100644 x/oracle/keeper/msg_server_commit_report.go create mode 100644 x/oracle/simulation/commit_report.go create mode 100644 x/oracle/types/commit_value.pb.go create mode 100644 x/oracle/types/message_commit_report.go create mode 100644 x/oracle/types/message_commit_report_test.go diff --git a/app/app.go b/app/app.go index ac5f6e807..5bb4be5ab 100644 --- a/app/app.go +++ b/app/app.go @@ -542,6 +542,7 @@ func New( keys[oraclemoduletypes.MemStoreKey], app.GetSubspace(oraclemoduletypes.ModuleName), + app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.RegistryKeeper, diff --git a/proto/layer/oracle/commit_value.proto b/proto/layer/oracle/commit_value.proto new file mode 100644 index 000000000..263257b31 --- /dev/null +++ b/proto/layer/oracle/commit_value.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package layer.oracle; + +import "layer/oracle/tx.proto"; +option go_package = "github.com/tellor-io/layer/x/oracle/types"; + +message CommitValue { + + MsgCommitReport report = 1; + int64 block = 2; +} diff --git a/proto/layer/oracle/reports.proto b/proto/layer/oracle/reports.proto index 61f802233..690d654fc 100644 --- a/proto/layer/oracle/reports.proto +++ b/proto/layer/oracle/reports.proto @@ -5,5 +5,5 @@ option go_package = "github.com/tellor-io/layer/x/oracle/types"; message Reports { - repeated MicroReport reports = 1; + repeated MicroReport microReports = 1; } diff --git a/proto/layer/oracle/tx.proto b/proto/layer/oracle/tx.proto index 312fe3bd0..97b51d42d 100644 --- a/proto/layer/oracle/tx.proto +++ b/proto/layer/oracle/tx.proto @@ -6,13 +6,22 @@ option go_package = "github.com/tellor-io/layer/x/oracle/types"; // Msg defines the Msg service. service Msg { - rpc SubmitValue (MsgSubmitValue) returns (MsgSubmitValueResponse); + rpc SubmitValue (MsgSubmitValue ) returns (MsgSubmitValueResponse ); + rpc CommitReport (MsgCommitReport) returns (MsgCommitReportResponse); } message MsgSubmitValue { string creator = 1; - string qid = 2; + string qid = 2; string value = 3; } message MsgSubmitValueResponse {} +message MsgCommitReport { + string creator = 1; + string queryId = 2; + string signature = 3; //signature of value in submit value +} + +message MsgCommitReportResponse {} + diff --git a/x/oracle/client/cli/tx.go b/x/oracle/client/cli/tx.go index 84cf18f80..fff67917a 100644 --- a/x/oracle/client/cli/tx.go +++ b/x/oracle/client/cli/tx.go @@ -31,6 +31,7 @@ func GetTxCmd() *cobra.Command { } cmd.AddCommand(CmdSubmitValue()) + cmd.AddCommand(CmdCommitReport()) // this line is used by starport scaffolding # 1 return cmd diff --git a/x/oracle/client/cli/tx_commit_report.go b/x/oracle/client/cli/tx_commit_report.go new file mode 100644 index 000000000..7c4ffde04 --- /dev/null +++ b/x/oracle/client/cli/tx_commit_report.go @@ -0,0 +1,56 @@ +package cli + +import ( + "encoding/hex" + "strconv" + + "github.com/cometbft/cometbft/libs/bytes" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/spf13/cobra" + "github.com/tellor-io/layer/x/oracle/types" +) + +var _ = strconv.Itoa(0) + +func CmdCommitReport() *cobra.Command { + cmd := &cobra.Command{ + Use: "commit-report [query-id] [signature]", + Short: "Broadcast message commitReport", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) (err error) { + argQueryId := args[0] + value := args[1] + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + valueDecoded, err := hex.DecodeString(value) + if err != nil { + return err + } + // leaving this here for convenience to input value thru cli + // then is signed by the keys here + data, _, err := clientCtx.Keyring.SignByAddress(clientCtx.GetFromAddress(), valueDecoded) + if err != nil { + return err + } + + msg := types.NewMsgCommitReport( + clientCtx.GetFromAddress().String(), + argQueryId, + bytes.HexBytes(data).String(), + ) + if err := msg.ValidateBasic(); err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/oracle/keeper/keeper.go b/x/oracle/keeper/keeper.go index 0a47d0255..661934bf0 100644 --- a/x/oracle/keeper/keeper.go +++ b/x/oracle/keeper/keeper.go @@ -19,6 +19,7 @@ type ( memKey storetypes.StoreKey paramstore paramtypes.Subspace + accountKeeper types.AccountKeeper bankKeeper types.BankKeeper stakingKeeper types.StakingKeeper registryKeeper types.RegistryKeeper @@ -31,6 +32,7 @@ func NewKeeper( memKey storetypes.StoreKey, ps paramtypes.Subspace, + accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper, stakingKeeper types.StakingKeeper, registryKeeper types.RegistryKeeper, @@ -46,6 +48,7 @@ func NewKeeper( memKey: memKey, paramstore: ps, + accountKeeper: accountKeeper, bankKeeper: bankKeeper, stakingKeeper: stakingKeeper, registryKeeper: registryKeeper, diff --git a/x/oracle/keeper/msg_server_commit_report.go b/x/oracle/keeper/msg_server_commit_report.go new file mode 100644 index 000000000..b6c4ea475 --- /dev/null +++ b/x/oracle/keeper/msg_server_commit_report.go @@ -0,0 +1,44 @@ +package keeper + +import ( + "context" + "encoding/hex" + + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/tellor-io/layer/x/oracle/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +func (k msgServer) CommitReport(goCtx context.Context, msg *types.MsgCommitReport) (*types.MsgCommitReportResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.CommitReportKey)) + report := types.CommitValue{ + Report: msg, + Block: ctx.BlockHeight(), + } + qIdBytes, err := hex.DecodeString(msg.QueryId) + if err != nil { + return nil, err + } + store.Set(append([]byte(msg.Creator), qIdBytes...), k.cdc.MustMarshal(&report)) + + return &types.MsgCommitReportResponse{}, nil +} + +func (k Keeper) getCommit(ctx sdk.Context, reporter, queryId string) (*types.CommitValue, error) { + + commitStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.CommitReportKey)) + qIdBytes, err := hex.DecodeString(queryId) + if err != nil { + return nil, err + } + commit := commitStore.Get(append([]byte(reporter), qIdBytes...)) + if commit == nil { + return nil, status.Error(codes.NotFound, "no commits to reveal found") + } + var commitValue types.CommitValue + k.cdc.Unmarshal(commit, &commitValue) + return &commitValue, nil +} diff --git a/x/oracle/keeper/msg_server_submit_value.go b/x/oracle/keeper/msg_server_submit_value.go index ba3d75c1d..035d22fa2 100644 --- a/x/oracle/keeper/msg_server_submit_value.go +++ b/x/oracle/keeper/msg_server_submit_value.go @@ -9,6 +9,7 @@ import ( registryKeeper "github.com/tellor-io/layer/x/registry/keeper" registryTypes "github.com/tellor-io/layer/x/registry/types" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/accounts/abi" @@ -18,45 +19,58 @@ import ( func (k msgServer) SubmitValue(goCtx context.Context, msg *types.MsgSubmitValue) (*types.MsgSubmitValueResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - if !k.IsSenderStaked(ctx, msg.Creator) { + // convert reporter address from bech32 to sdk.AccAddress + reporter, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("failed to decode reporter address: %v", err)) + } + // check if sender is bonded + if !k.IsReporterStaked(ctx, reporter) { return nil, status.Error(codes.Unauthenticated, "sender is not staked") } - // check if query id is valid + // check if query id field is valid if !registryKeeper.IsQueryIdValid(msg.Qid) { return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid query id: %s", msg.Qid)) } - // decode query id hex string to bytes - qIdBytes, err := hex.DecodeString(msg.Qid) + // get commit from store + commitValue, err := k.getCommit(ctx, msg.Creator, msg.Qid) if err != nil { - return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("failed to decode query ID string: %v", err)) + return nil, err + } + // check if value is being revealed in the one block after commit + if ctx.BlockHeight()-1 != commitValue.Block { + return nil, status.Error(codes.InvalidArgument, "missed block height to reveal") + } + // if commitValue.Block < ctx.BlockHeight()-5 || commitValue.Block > ctx.BlockHeight() { + // return nil, status.Error(codes.InvalidArgument, "missed block height window to reveal") + // } + // verify value signature + if !k.verifySignature(ctx, reporter, msg.Value, commitValue.Report.Signature) { + return nil, status.Error(codes.InvalidArgument, "unable to verify signature") } + // set value + k.setValue(ctx, msg) + return &types.MsgSubmitValueResponse{}, nil +} + +func (k Keeper) setValue(ctx sdk.Context, msg *types.MsgSubmitValue) (*types.MsgSubmitValueResponse, error) { // get query data from registry by query id queryData, err := k.registryKeeper.QueryData(ctx, msg.Qid) if err != nil { return nil, status.Error(codes.NotFound, fmt.Sprintf("query data not found: %v", err)) } - // decode query data hex to get query type - decodedQueryType, err := decodeQueryType(queryData) + // decode query data hex to get query type, returns interface array + queryType, err := decodeQueryType(queryData) if err != nil { return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("failed to decode query type: %v", err)) } - queryType := decodedQueryType[0].(string) - // get data spec from registry by query type to validate value - dataSpecBytes := k.registryKeeper.Spec(ctx, queryType) - if dataSpecBytes == nil { - return nil, status.Error(codes.NotFound, fmt.Sprintf("data spec not found for query type: %s", queryType)) - } - - var dataSpec registryTypes.DataSpec - k.cdc.Unmarshal(dataSpecBytes, &dataSpec) - decodedSpec := &dataSpec - valueType := decodedSpec.ValueType - valueBytes, err := hex.DecodeString(msg.Value) + valueType, err := getValueType(k.registryKeeper, k.cdc, ctx, queryType) if err != nil { - return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("failed to decode value string: %v", err)) + return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("failed to get value type: %v", err)) } - // decode value using value type from data spec - value, err := decodeValue(valueBytes, valueType) + // decode value using value type from data spec and check if decodes successfully + // value is not used, only used to check if it decodes successfully + value, err := decodeValue(msg.Value, valueType) ctx.Logger().Info(fmt.Sprintf("value: %v", value[0])) if err != nil { return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("failed to decode value: %v", err)) @@ -68,24 +82,69 @@ func (k msgServer) SubmitValue(goCtx context.Context, msg *types.MsgSubmitValue) Value: msg.Value, Timestamp: uint64(ctx.BlockTime().Unix()), } + // decode query id hex string to bytes + qIdBytes, err := hex.DecodeString(msg.Qid) + if err != nil { + return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("failed to decode query ID string: %v", err)) + } var reportsList types.Reports if err := k.cdc.Unmarshal(store.Get(qIdBytes), &reportsList); err != nil { return nil, fmt.Errorf("failed to unmarshal reports: %v", err) } - reportsList.Reports = append(reportsList.Reports, report) + reportsList.MicroReports = append(reportsList.MicroReports, report) store.Set(qIdBytes, k.cdc.MustMarshal(&reportsList)) return &types.MsgSubmitValueResponse{}, nil } +func getValueType(registry types.RegistryKeeper, cdc codec.BinaryCodec, ctx sdk.Context, queryType string) (string, error) { + // get data spec from registry by query type to validate value + dataSpecBytes := registry.Spec(ctx, queryType) + if dataSpecBytes == nil { + return "", status.Error(codes.NotFound, fmt.Sprintf("data spec not found for query type: %s", queryType)) + } + var dataSpec registryTypes.DataSpec + cdc.Unmarshal(dataSpecBytes, &dataSpec) + + return dataSpec.ValueType, nil +} + +func (k Keeper) IsReporterStaked(ctx sdk.Context, reporter sdk.AccAddress) bool { + delegations := k.stakingKeeper.GetAllDelegatorDelegations(ctx, reporter) -func decodeQueryType(data []byte) ([]interface{}, error) { + var totalStakedTokens sdk.Dec = sdk.ZeroDec() + for _, delegation := range delegations { + totalStakedTokens = totalStakedTokens.Add(delegation.Shares) + } + return totalStakedTokens.GT(sdk.ZeroDec()) +} + +func (k Keeper) verifySignature(ctx sdk.Context, reporter sdk.AccAddress, value, signature string) bool { + reporterAccount := k.accountKeeper.GetAccount(ctx, reporter) + pubKey := reporterAccount.GetPubKey() + sigBytes, err := hex.DecodeString(signature) + if err != nil { + return false + } + // decode value from hex string + valBytes, err := hex.DecodeString(value) + if err != nil { + return false + } + // verify signature + if !pubKey.VerifySignature(valBytes, sigBytes) { + return false + } + return true +} + +func decodeQueryType(data []byte) (string, error) { // Create an ABI arguments object based on the types strArg, err := abi.NewType("string", "string", nil) if err != nil { - return nil, fmt.Errorf("failed to create new ABI type when decoding query type: %v", err) + return "", fmt.Errorf("failed to create new ABI type when decoding query type: %v", err) } bytesArg, err := abi.NewType("bytes", "bytes", nil) if err != nil { - return nil, fmt.Errorf("failed to create new ABI type when decoding query type: %v", err) + return "", fmt.Errorf("failed to create new ABI type when decoding query type: %v", err) } args := abi.Arguments{ abi.Argument{Type: strArg}, @@ -93,12 +152,12 @@ func decodeQueryType(data []byte) ([]interface{}, error) { } result, err := args.UnpackValues(data) if err != nil { - return nil, fmt.Errorf("failed to unpack query type: %v", err) + return "", fmt.Errorf("failed to unpack query type: %v", err) } - return result, nil + return result[0].(string), nil } -func decodeValue(data []byte, dataType string) ([]interface{}, error) { +func decodeValue(value, dataType string) ([]interface{}, error) { argType, err := abi.NewType(dataType, dataType, nil) if err != nil { return nil, fmt.Errorf("failed to create new ABI type when decoding value: %v", err) @@ -107,27 +166,18 @@ func decodeValue(data []byte, dataType string) ([]interface{}, error) { Type: argType, } args := abi.Arguments{arg} + valueBytes, err := hex.DecodeString(value) + if err != nil { + return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("failed to decode value string: %v", err)) + } var result []interface{} - result, err = args.Unpack(data) + result, err = args.Unpack(valueBytes) if err != nil { return nil, fmt.Errorf("failed to unpack value: %v", err) } return result, nil } -func (k Keeper) IsSenderStaked(ctx sdk.Context, sender string) bool { - accAddr, err := sdk.AccAddressFromBech32(sender) - if err != nil { - return false - } - delegations := k.stakingKeeper.GetAllDelegatorDelegations(ctx, accAddr) - var totalStakedTokens sdk.Dec - for _, delegation := range delegations { - totalStakedTokens = totalStakedTokens.Add(delegation.GetShares()) - } - return totalStakedTokens.GT(sdk.ZeroDec()) -} - // cleanup reports list // func (k Keeper) CleanupReports(ctx sdk.Context, qid string) { // qIdBytes, err := hex.DecodeString(qid) diff --git a/x/oracle/module_simulation.go b/x/oracle/module_simulation.go index e27024340..6781c7bb7 100644 --- a/x/oracle/module_simulation.go +++ b/x/oracle/module_simulation.go @@ -27,6 +27,10 @@ const ( // TODO: Determine the simulation weight value defaultWeightMsgSubmitValue int = 100 + opWeightMsgCommitReport = "op_weight_msg_commit_report" + // TODO: Determine the simulation weight value + defaultWeightMsgCommitReport int = 100 + // this line is used by starport scaffolding # simapp/module/const ) @@ -66,6 +70,17 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp oraclesimulation.SimulateMsgSubmitValue(am.accountKeeper, am.bankKeeper, am.keeper), )) + var weightMsgCommitReport int + simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgCommitReport, &weightMsgCommitReport, nil, + func(_ *rand.Rand) { + weightMsgCommitReport = defaultWeightMsgCommitReport + }, + ) + operations = append(operations, simulation.NewWeightedOperation( + weightMsgCommitReport, + oraclesimulation.SimulateMsgCommitReport(am.accountKeeper, am.bankKeeper, am.keeper), + )) + // this line is used by starport scaffolding # simapp/module/operation return operations @@ -82,6 +97,14 @@ func (am AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.Wei return nil }, ), + simulation.NewWeightedProposalMsg( + opWeightMsgCommitReport, + defaultWeightMsgCommitReport, + func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) sdk.Msg { + oraclesimulation.SimulateMsgCommitReport(am.accountKeeper, am.bankKeeper, am.keeper) + return nil + }, + ), // this line is used by starport scaffolding # simapp/module/OpMsg } } diff --git a/x/oracle/simulation/commit_report.go b/x/oracle/simulation/commit_report.go new file mode 100644 index 000000000..39da89ecd --- /dev/null +++ b/x/oracle/simulation/commit_report.go @@ -0,0 +1,29 @@ +package simulation + +import ( + "math/rand" + + "github.com/cosmos/cosmos-sdk/baseapp" + sdk "github.com/cosmos/cosmos-sdk/types" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/tellor-io/layer/x/oracle/keeper" + "github.com/tellor-io/layer/x/oracle/types" +) + +func SimulateMsgCommitReport( + ak types.AccountKeeper, + bk types.BankKeeper, + k keeper.Keeper, +) simtypes.Operation { + return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, + ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + simAccount, _ := simtypes.RandomAcc(r, accs) + msg := &types.MsgCommitReport{ + Creator: simAccount.Address.String(), + } + + // TODO: Handling the CommitReport simulation + + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "CommitReport simulation not implemented"), nil, nil + } +} diff --git a/x/oracle/types/codec.go b/x/oracle/types/codec.go index 45d47c6b9..0f6c29405 100644 --- a/x/oracle/types/codec.go +++ b/x/oracle/types/codec.go @@ -9,6 +9,7 @@ import ( func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&MsgSubmitValue{}, "oracle/SubmitValue", nil) + cdc.RegisterConcrete(&MsgCommitReport{}, "oracle/CommitReport", nil) // this line is used by starport scaffolding # 2 } @@ -16,6 +17,9 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { registry.RegisterImplementations((*sdk.Msg)(nil), &MsgSubmitValue{}, ) + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgCommitReport{}, + ) // this line is used by starport scaffolding # 3 msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) diff --git a/x/oracle/types/commit_value.pb.go b/x/oracle/types/commit_value.pb.go new file mode 100644 index 000000000..b71c4f61b --- /dev/null +++ b/x/oracle/types/commit_value.pb.go @@ -0,0 +1,361 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: layer/oracle/commit_value.proto + +package types + +import ( + fmt "fmt" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type CommitValue struct { + Report *MsgCommitReport `protobuf:"bytes,1,opt,name=report,proto3" json:"report,omitempty"` + Block int64 `protobuf:"varint,2,opt,name=block,proto3" json:"block,omitempty"` +} + +func (m *CommitValue) Reset() { *m = CommitValue{} } +func (m *CommitValue) String() string { return proto.CompactTextString(m) } +func (*CommitValue) ProtoMessage() {} +func (*CommitValue) Descriptor() ([]byte, []int) { + return fileDescriptor_eb7c7f15ba802f2a, []int{0} +} +func (m *CommitValue) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CommitValue) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CommitValue.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *CommitValue) XXX_Merge(src proto.Message) { + xxx_messageInfo_CommitValue.Merge(m, src) +} +func (m *CommitValue) XXX_Size() int { + return m.Size() +} +func (m *CommitValue) XXX_DiscardUnknown() { + xxx_messageInfo_CommitValue.DiscardUnknown(m) +} + +var xxx_messageInfo_CommitValue proto.InternalMessageInfo + +func (m *CommitValue) GetReport() *MsgCommitReport { + if m != nil { + return m.Report + } + return nil +} + +func (m *CommitValue) GetBlock() int64 { + if m != nil { + return m.Block + } + return 0 +} + +func init() { + proto.RegisterType((*CommitValue)(nil), "layer.oracle.CommitValue") +} + +func init() { proto.RegisterFile("layer/oracle/commit_value.proto", fileDescriptor_eb7c7f15ba802f2a) } + +var fileDescriptor_eb7c7f15ba802f2a = []byte{ + // 198 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xcf, 0x49, 0xac, 0x4c, + 0x2d, 0xd2, 0xcf, 0x2f, 0x4a, 0x4c, 0xce, 0x49, 0xd5, 0x4f, 0xce, 0xcf, 0xcd, 0xcd, 0x2c, 0x89, + 0x2f, 0x4b, 0xcc, 0x29, 0x4d, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x01, 0x2b, 0xd0, + 0x83, 0x28, 0x90, 0x12, 0x45, 0x51, 0x5e, 0x52, 0x01, 0x51, 0xa4, 0x14, 0xc5, 0xc5, 0xed, 0x0c, + 0xd6, 0x1a, 0x06, 0xd2, 0x29, 0x64, 0xca, 0xc5, 0x56, 0x94, 0x5a, 0x90, 0x5f, 0x54, 0x22, 0xc1, + 0xa8, 0xc0, 0xa8, 0xc1, 0x6d, 0x24, 0xab, 0x87, 0x6c, 0x88, 0x9e, 0x6f, 0x71, 0x3a, 0x44, 0x75, + 0x10, 0x58, 0x51, 0x10, 0x54, 0xb1, 0x90, 0x08, 0x17, 0x6b, 0x52, 0x4e, 0x7e, 0x72, 0xb6, 0x04, + 0x93, 0x02, 0xa3, 0x06, 0x73, 0x10, 0x84, 0xe3, 0xe4, 0x7c, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, + 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, + 0xc7, 0x72, 0x0c, 0x51, 0x9a, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, + 0x25, 0xa9, 0x39, 0x39, 0xf9, 0x45, 0xba, 0x99, 0xf9, 0xfa, 0x10, 0x17, 0x56, 0xc0, 0xdd, 0x58, + 0x59, 0x90, 0x5a, 0x9c, 0xc4, 0x06, 0x76, 0xa7, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x9c, 0xd5, + 0xb1, 0x62, 0xef, 0x00, 0x00, 0x00, +} + +func (m *CommitValue) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *CommitValue) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CommitValue) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Block != 0 { + i = encodeVarintCommitValue(dAtA, i, uint64(m.Block)) + i-- + dAtA[i] = 0x10 + } + if m.Report != nil { + { + size, err := m.Report.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCommitValue(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintCommitValue(dAtA []byte, offset int, v uint64) int { + offset -= sovCommitValue(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *CommitValue) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Report != nil { + l = m.Report.Size() + n += 1 + l + sovCommitValue(uint64(l)) + } + if m.Block != 0 { + n += 1 + sovCommitValue(uint64(m.Block)) + } + return n +} + +func sovCommitValue(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozCommitValue(x uint64) (n int) { + return sovCommitValue(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *CommitValue) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCommitValue + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: CommitValue: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CommitValue: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Report", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCommitValue + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCommitValue + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCommitValue + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Report == nil { + m.Report = &MsgCommitReport{} + } + if err := m.Report.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Block", wireType) + } + m.Block = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCommitValue + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Block |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipCommitValue(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCommitValue + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipCommitValue(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCommitValue + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCommitValue + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCommitValue + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthCommitValue + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupCommitValue + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthCommitValue + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthCommitValue = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowCommitValue = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupCommitValue = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/oracle/types/keys.go b/x/oracle/types/keys.go index 39573c289..e59630f76 100644 --- a/x/oracle/types/keys.go +++ b/x/oracle/types/keys.go @@ -14,6 +14,8 @@ const ( MemStoreKey = "mem_oracle" ReportsKey = "Reports-value-" + + CommitReportKey = "CommitReport-value-" ) func KeyPrefix(p string) []byte { diff --git a/x/oracle/types/message_commit_report.go b/x/oracle/types/message_commit_report.go new file mode 100644 index 000000000..a06975fe2 --- /dev/null +++ b/x/oracle/types/message_commit_report.go @@ -0,0 +1,47 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +const TypeMsgCommitReport = "commit_report" + +var _ sdk.Msg = &MsgCommitReport{} + +func NewMsgCommitReport(creator string, queryId string, signature string) *MsgCommitReport { + return &MsgCommitReport{ + Creator: creator, + QueryId: queryId, + Signature: signature, + } +} + +func (msg *MsgCommitReport) Route() string { + return RouterKey +} + +func (msg *MsgCommitReport) Type() string { + return TypeMsgCommitReport +} + +func (msg *MsgCommitReport) GetSigners() []sdk.AccAddress { + creator, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{creator} +} + +func (msg *MsgCommitReport) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgCommitReport) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + } + return nil +} diff --git a/x/oracle/types/message_commit_report_test.go b/x/oracle/types/message_commit_report_test.go new file mode 100644 index 000000000..06650757f --- /dev/null +++ b/x/oracle/types/message_commit_report_test.go @@ -0,0 +1,40 @@ +package types + +import ( + "testing" + + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/stretchr/testify/require" + "github.com/tellor-io/layer/testutil/sample" +) + +func TestMsgCommitReport_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg MsgCommitReport + err error + }{ + { + name: "invalid address", + msg: MsgCommitReport{ + Creator: "invalid_address", + }, + err: sdkerrors.ErrInvalidAddress, + }, { + name: "valid address", + msg: MsgCommitReport{ + Creator: sample.AccAddress(), + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.msg.ValidateBasic() + if tt.err != nil { + require.ErrorIs(t, err, tt.err) + return + } + require.NoError(t, err) + }) + } +} diff --git a/x/oracle/types/reports.pb.go b/x/oracle/types/reports.pb.go index cb4b20e53..60b2e7835 100644 --- a/x/oracle/types/reports.pb.go +++ b/x/oracle/types/reports.pb.go @@ -23,7 +23,7 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type Reports struct { - Reports []*MicroReport `protobuf:"bytes,1,rep,name=reports,proto3" json:"reports,omitempty"` + MicroReports []*MicroReport `protobuf:"bytes,1,rep,name=microReports,proto3" json:"microReports,omitempty"` } func (m *Reports) Reset() { *m = Reports{} } @@ -59,9 +59,9 @@ func (m *Reports) XXX_DiscardUnknown() { var xxx_messageInfo_Reports proto.InternalMessageInfo -func (m *Reports) GetReports() []*MicroReport { +func (m *Reports) GetMicroReports() []*MicroReport { if m != nil { - return m.Reports + return m.MicroReports } return nil } @@ -73,18 +73,18 @@ func init() { func init() { proto.RegisterFile("layer/oracle/reports.proto", fileDescriptor_654245c0746b2b04) } var fileDescriptor_654245c0746b2b04 = []byte{ - // 173 bytes of a gzipped FileDescriptorProto + // 172 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xca, 0x49, 0xac, 0x4c, 0x2d, 0xd2, 0xcf, 0x2f, 0x4a, 0x4c, 0xce, 0x49, 0xd5, 0x2f, 0x4a, 0x2d, 0xc8, 0x2f, 0x2a, 0x29, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x01, 0xcb, 0xe9, 0x41, 0xe4, 0xa4, 0xe4, 0x51, - 0x54, 0xe6, 0x66, 0x26, 0x17, 0xe5, 0xc7, 0x43, 0xd4, 0x43, 0x94, 0x2b, 0xd9, 0x71, 0xb1, 0x07, - 0x41, 0xf4, 0x0b, 0x19, 0x73, 0xb1, 0x43, 0x8d, 0x92, 0x60, 0x54, 0x60, 0xd6, 0xe0, 0x36, 0x92, - 0xd4, 0x43, 0x36, 0x4b, 0xcf, 0x17, 0xa4, 0x1b, 0xa2, 0x38, 0x08, 0xa6, 0xd2, 0xc9, 0xf9, 0xc4, - 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, - 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x34, 0xd3, 0x33, 0x4b, 0x32, 0x4a, 0x93, - 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0x4b, 0x52, 0x73, 0x72, 0xf2, 0x8b, 0x74, 0x33, 0xf3, 0xf5, 0x21, - 0xee, 0xa9, 0x80, 0xb9, 0xa8, 0xa4, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0xec, 0x16, 0x63, 0x40, - 0x00, 0x00, 0x00, 0xff, 0xff, 0x49, 0xed, 0x0f, 0xef, 0xd8, 0x00, 0x00, 0x00, + 0x54, 0xe6, 0x66, 0x26, 0x17, 0xe5, 0xc7, 0x43, 0xd4, 0x43, 0x94, 0x2b, 0x79, 0x70, 0xb1, 0x07, + 0x41, 0xf4, 0x0b, 0xd9, 0x72, 0xf1, 0x80, 0x15, 0x40, 0xf9, 0x12, 0x8c, 0x0a, 0xcc, 0x1a, 0xdc, + 0x46, 0x92, 0x7a, 0xc8, 0x06, 0xea, 0xf9, 0x22, 0x54, 0x04, 0xa1, 0x28, 0x77, 0x72, 0x3e, 0xf1, + 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, + 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xcd, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, + 0xbd, 0xe4, 0xfc, 0x5c, 0xfd, 0x92, 0xd4, 0x9c, 0x9c, 0xfc, 0x22, 0xdd, 0xcc, 0x7c, 0x7d, 0x88, + 0xcb, 0x2a, 0x60, 0x6e, 0x2b, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0xbb, 0xca, 0x18, 0x10, + 0x00, 0x00, 0xff, 0xff, 0xa6, 0x49, 0x08, 0x1e, 0xe2, 0x00, 0x00, 0x00, } func (m *Reports) Marshal() (dAtA []byte, err error) { @@ -107,10 +107,10 @@ func (m *Reports) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.Reports) > 0 { - for iNdEx := len(m.Reports) - 1; iNdEx >= 0; iNdEx-- { + if len(m.MicroReports) > 0 { + for iNdEx := len(m.MicroReports) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.Reports[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + size, err := m.MicroReports[iNdEx].MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -141,8 +141,8 @@ func (m *Reports) Size() (n int) { } var l int _ = l - if len(m.Reports) > 0 { - for _, e := range m.Reports { + if len(m.MicroReports) > 0 { + for _, e := range m.MicroReports { l = e.Size() n += 1 + l + sovReports(uint64(l)) } @@ -187,7 +187,7 @@ func (m *Reports) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Reports", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field MicroReports", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -214,8 +214,8 @@ func (m *Reports) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Reports = append(m.Reports, &MicroReport{}) - if err := m.Reports[len(m.Reports)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.MicroReports = append(m.MicroReports, &MicroReport{}) + if err := m.MicroReports[len(m.MicroReports)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/oracle/types/tx.pb.go b/x/oracle/types/tx.pb.go index 26e5c0127..64ed37f9b 100644 --- a/x/oracle/types/tx.pb.go +++ b/x/oracle/types/tx.pb.go @@ -123,15 +123,113 @@ func (m *MsgSubmitValueResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgSubmitValueResponse proto.InternalMessageInfo +type MsgCommitReport struct { + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + QueryId string `protobuf:"bytes,2,opt,name=queryId,proto3" json:"queryId,omitempty"` + Signature string `protobuf:"bytes,3,opt,name=signature,proto3" json:"signature,omitempty"` +} + +func (m *MsgCommitReport) Reset() { *m = MsgCommitReport{} } +func (m *MsgCommitReport) String() string { return proto.CompactTextString(m) } +func (*MsgCommitReport) ProtoMessage() {} +func (*MsgCommitReport) Descriptor() ([]byte, []int) { + return fileDescriptor_85ff275c542a231a, []int{2} +} +func (m *MsgCommitReport) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCommitReport) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCommitReport.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgCommitReport) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCommitReport.Merge(m, src) +} +func (m *MsgCommitReport) XXX_Size() int { + return m.Size() +} +func (m *MsgCommitReport) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCommitReport.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCommitReport proto.InternalMessageInfo + +func (m *MsgCommitReport) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *MsgCommitReport) GetQueryId() string { + if m != nil { + return m.QueryId + } + return "" +} + +func (m *MsgCommitReport) GetSignature() string { + if m != nil { + return m.Signature + } + return "" +} + +type MsgCommitReportResponse struct { +} + +func (m *MsgCommitReportResponse) Reset() { *m = MsgCommitReportResponse{} } +func (m *MsgCommitReportResponse) String() string { return proto.CompactTextString(m) } +func (*MsgCommitReportResponse) ProtoMessage() {} +func (*MsgCommitReportResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_85ff275c542a231a, []int{3} +} +func (m *MsgCommitReportResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCommitReportResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCommitReportResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgCommitReportResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCommitReportResponse.Merge(m, src) +} +func (m *MsgCommitReportResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgCommitReportResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCommitReportResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCommitReportResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgSubmitValue)(nil), "layer.oracle.MsgSubmitValue") proto.RegisterType((*MsgSubmitValueResponse)(nil), "layer.oracle.MsgSubmitValueResponse") + proto.RegisterType((*MsgCommitReport)(nil), "layer.oracle.MsgCommitReport") + proto.RegisterType((*MsgCommitReportResponse)(nil), "layer.oracle.MsgCommitReportResponse") } func init() { proto.RegisterFile("layer/oracle/tx.proto", fileDescriptor_85ff275c542a231a) } var fileDescriptor_85ff275c542a231a = []byte{ - // 224 bytes of a gzipped FileDescriptorProto + // 302 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xcd, 0x49, 0xac, 0x4c, 0x2d, 0xd2, 0xcf, 0x2f, 0x4a, 0x4c, 0xce, 0x49, 0xd5, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x01, 0x0b, 0xeb, 0x41, 0x84, 0x95, 0x82, 0xb8, 0xf8, 0x7c, 0x8b, 0xd3, 0x83, @@ -139,13 +237,18 @@ var fileDescriptor_85ff275c542a231a = []byte{ 0x52, 0x13, 0x4b, 0xf2, 0x8b, 0x24, 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, 0x60, 0x5c, 0x21, 0x01, 0x2e, 0xe6, 0xc2, 0xcc, 0x14, 0x09, 0x26, 0xb0, 0x28, 0x88, 0x29, 0x24, 0xc2, 0xc5, 0x5a, 0x06, 0xd2, 0x24, 0xc1, 0x0c, 0x16, 0x83, 0x70, 0x94, 0x24, 0xb8, 0xc4, 0x50, 0xcd, 0x0c, 0x4a, 0x2d, - 0x2e, 0xc8, 0xcf, 0x2b, 0x4e, 0x35, 0x8a, 0xe0, 0x62, 0xf6, 0x2d, 0x4e, 0x17, 0x0a, 0xe4, 0xe2, - 0x46, 0xb6, 0x51, 0x46, 0x0f, 0xd9, 0x49, 0x7a, 0xa8, 0x7a, 0xa5, 0x54, 0xf0, 0xc9, 0xc2, 0x4c, - 0x76, 0x72, 0x3e, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, - 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xcd, 0xf4, 0xcc, - 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0xfd, 0x92, 0xd4, 0x9c, 0x9c, 0xfc, 0x22, 0xdd, - 0xcc, 0x7c, 0x7d, 0x48, 0xd8, 0x54, 0xc0, 0x43, 0xa7, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0x1c, - 0x42, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x1f, 0x41, 0x26, 0x16, 0x3a, 0x01, 0x00, 0x00, + 0x2e, 0xc8, 0xcf, 0x2b, 0x4e, 0x55, 0x4a, 0xe6, 0xe2, 0xf7, 0x2d, 0x4e, 0x77, 0xce, 0xcf, 0xcd, + 0xcd, 0x2c, 0x09, 0x4a, 0x2d, 0xc8, 0x2f, 0x2a, 0xc1, 0x63, 0x9d, 0x04, 0x17, 0x7b, 0x61, 0x69, + 0x6a, 0x51, 0xa5, 0x27, 0xcc, 0x4a, 0x18, 0x57, 0x48, 0x86, 0x8b, 0xb3, 0x38, 0x33, 0x3d, 0x2f, + 0xb1, 0xa4, 0xb4, 0x08, 0x66, 0x35, 0x42, 0x40, 0x49, 0x92, 0x4b, 0x1c, 0xcd, 0x12, 0x98, 0xfd, + 0x46, 0xeb, 0x18, 0xb9, 0x98, 0x7d, 0x8b, 0xd3, 0x85, 0x02, 0xb9, 0xb8, 0x91, 0xbd, 0x2c, 0xa3, + 0x87, 0x1c, 0x26, 0x7a, 0xa8, 0x8e, 0x97, 0x52, 0xc1, 0x27, 0x0b, 0x33, 0x5a, 0x28, 0x84, 0x8b, + 0x07, 0xc5, 0x5f, 0xb2, 0x18, 0xba, 0x90, 0xa5, 0xa5, 0x54, 0xf1, 0x4a, 0xc3, 0x4c, 0x75, 0x72, + 0x3e, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, + 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xcd, 0xf4, 0xcc, 0x92, 0x8c, + 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0xfd, 0x92, 0xd4, 0x9c, 0x9c, 0xfc, 0x22, 0xdd, 0xcc, 0x7c, + 0x7d, 0x48, 0x94, 0x57, 0xc0, 0x23, 0xbd, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0x1c, 0xf1, 0xc6, + 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x84, 0x54, 0x5f, 0x2f, 0x11, 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -161,6 +264,7 @@ const _ = grpc.SupportPackageIsVersion4 // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type MsgClient interface { SubmitValue(ctx context.Context, in *MsgSubmitValue, opts ...grpc.CallOption) (*MsgSubmitValueResponse, error) + CommitReport(ctx context.Context, in *MsgCommitReport, opts ...grpc.CallOption) (*MsgCommitReportResponse, error) } type msgClient struct { @@ -180,9 +284,19 @@ func (c *msgClient) SubmitValue(ctx context.Context, in *MsgSubmitValue, opts .. return out, nil } +func (c *msgClient) CommitReport(ctx context.Context, in *MsgCommitReport, opts ...grpc.CallOption) (*MsgCommitReportResponse, error) { + out := new(MsgCommitReportResponse) + err := c.cc.Invoke(ctx, "/layer.oracle.Msg/CommitReport", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { SubmitValue(context.Context, *MsgSubmitValue) (*MsgSubmitValueResponse, error) + CommitReport(context.Context, *MsgCommitReport) (*MsgCommitReportResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -192,6 +306,9 @@ type UnimplementedMsgServer struct { func (*UnimplementedMsgServer) SubmitValue(ctx context.Context, req *MsgSubmitValue) (*MsgSubmitValueResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method SubmitValue not implemented") } +func (*UnimplementedMsgServer) CommitReport(ctx context.Context, req *MsgCommitReport) (*MsgCommitReportResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CommitReport not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -215,6 +332,24 @@ func _Msg_SubmitValue_Handler(srv interface{}, ctx context.Context, dec func(int return interceptor(ctx, in, info, handler) } +func _Msg_CommitReport_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgCommitReport) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).CommitReport(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/layer.oracle.Msg/CommitReport", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).CommitReport(ctx, req.(*MsgCommitReport)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "layer.oracle.Msg", HandlerType: (*MsgServer)(nil), @@ -223,6 +358,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "SubmitValue", Handler: _Msg_SubmitValue_Handler, }, + { + MethodName: "CommitReport", + Handler: _Msg_CommitReport_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "layer/oracle/tx.proto", @@ -295,6 +434,73 @@ func (m *MsgSubmitValueResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) return len(dAtA) - i, nil } +func (m *MsgCommitReport) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgCommitReport) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCommitReport) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Signature) > 0 { + i -= len(m.Signature) + copy(dAtA[i:], m.Signature) + i = encodeVarintTx(dAtA, i, uint64(len(m.Signature))) + i-- + dAtA[i] = 0x1a + } + if len(m.QueryId) > 0 { + i -= len(m.QueryId) + copy(dAtA[i:], m.QueryId) + i = encodeVarintTx(dAtA, i, uint64(len(m.QueryId))) + i-- + dAtA[i] = 0x12 + } + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgCommitReportResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgCommitReportResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCommitReportResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -336,6 +542,36 @@ func (m *MsgSubmitValueResponse) Size() (n int) { return n } +func (m *MsgCommitReport) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.QueryId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Signature) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgCommitReportResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -538,6 +774,202 @@ func (m *MsgSubmitValueResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgCommitReport) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgCommitReport: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCommitReport: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field QueryId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.QueryId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signature", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signature = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgCommitReportResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgCommitReportResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCommitReportResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0