diff --git a/docs/static/openapi.yml b/docs/static/openapi.yml index dad5f09..26b5107 100644 --- a/docs/static/openapi.yml +++ b/docs/static/openapi.yml @@ -71482,6 +71482,64 @@ definitions: description: params holds all the parameters of this module. type: object description: QueryParamsResponse is response type for the Query/Params RPC method. + planetmintgo.machine.Machine: + type: object + properties: + name: + type: string + ticker: + type: string + issued: + type: string + format: uint64 + amount: + type: string + format: uint64 + precision: + type: string + format: uint64 + issuerPlanetmint: + type: string + issuerLiquid: + type: string + machineId: + type: string + metadata: + type: object + properties: + gps: + type: object + additionalProperties: + type: string + device: + type: object + additionalProperties: + type: string + assetDefinition: + type: object + additionalProperties: + type: string + additionalDataCID: + type: string + planetmintgo.machine.Metadata: + type: object + properties: + gps: + type: object + additionalProperties: + type: string + device: + type: object + additionalProperties: + type: string + assetDefinition: + type: object + additionalProperties: + type: string + additionalDataCID: + type: string + planetmintgo.machine.MsgAttestMachineResponse: + type: object planetmintgo.machine.Params: type: object description: Params defines the parameters for the module. diff --git a/proto/planetmintgo/machine/tx.proto b/proto/planetmintgo/machine/tx.proto index 3539086..49ce6ad 100644 --- a/proto/planetmintgo/machine/tx.proto +++ b/proto/planetmintgo/machine/tx.proto @@ -1,7 +1,19 @@ syntax = "proto3"; + package planetmintgo.machine; +import "planetmintgo/machine/machine.proto"; + option go_package = "planetmint-go/x/machine/types"; // Msg defines the Msg service. -service Msg {} \ No newline at end of file +service Msg { + rpc AttestMachine (MsgAttestMachine) returns (MsgAttestMachineResponse); +} +message MsgAttestMachine { + string creator = 1; + Machine machine = 2; +} + +message MsgAttestMachineResponse {} + diff --git a/x/machine/client/cli/tx.go b/x/machine/client/cli/tx.go index 67a30d2..9fea377 100644 --- a/x/machine/client/cli/tx.go +++ b/x/machine/client/cli/tx.go @@ -30,6 +30,7 @@ func GetTxCmd() *cobra.Command { RunE: client.ValidateCmd, } + cmd.AddCommand(CmdAttestMachine()) // this line is used by starport scaffolding # 1 return cmd diff --git a/x/machine/client/cli/tx_attest_machine.go b/x/machine/client/cli/tx_attest_machine.go new file mode 100644 index 0000000..860b623 --- /dev/null +++ b/x/machine/client/cli/tx_attest_machine.go @@ -0,0 +1,47 @@ +package cli + +import ( + "strconv" + + "encoding/json" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/spf13/cobra" + "planetmint-go/x/machine/types" +) + +var _ = strconv.Itoa(0) + +func CmdAttestMachine() *cobra.Command { + cmd := &cobra.Command{ + Use: "attest-machine [machine]", + Short: "Broadcast message attest-machine", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + argMachine := new(types.Machine) + err = json.Unmarshal([]byte(args[0]), argMachine) + if err != nil { + return err + } + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + msg := types.NewMsgAttestMachine( + clientCtx.GetFromAddress().String(), + argMachine, + ) + if err := msg.ValidateBasic(); err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/machine/keeper/msg_server_attest_machine.go b/x/machine/keeper/msg_server_attest_machine.go new file mode 100644 index 0000000..662badf --- /dev/null +++ b/x/machine/keeper/msg_server_attest_machine.go @@ -0,0 +1,17 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "planetmint-go/x/machine/types" +) + +func (k msgServer) AttestMachine(goCtx context.Context, msg *types.MsgAttestMachine) (*types.MsgAttestMachineResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // TODO: Handling the message + _ = ctx + + return &types.MsgAttestMachineResponse{}, nil +} diff --git a/x/machine/module_simulation.go b/x/machine/module_simulation.go index a9d1638..e8e2707 100644 --- a/x/machine/module_simulation.go +++ b/x/machine/module_simulation.go @@ -24,7 +24,11 @@ var ( ) const ( -// this line is used by starport scaffolding # simapp/module/const + opWeightMsgAttestMachine = "op_weight_msg_attest_machine" + // TODO: Determine the simulation weight value + defaultWeightMsgAttestMachine int = 100 + + // this line is used by starport scaffolding # simapp/module/const ) // GenerateGenesisState creates a randomized GenState of the module @@ -58,6 +62,17 @@ func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {} func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { operations := make([]simtypes.WeightedOperation, 0) + var weightMsgAttestMachine int + simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgAttestMachine, &weightMsgAttestMachine, nil, + func(_ *rand.Rand) { + weightMsgAttestMachine = defaultWeightMsgAttestMachine + }, + ) + operations = append(operations, simulation.NewWeightedOperation( + weightMsgAttestMachine, + machinesimulation.SimulateMsgAttestMachine(am.accountKeeper, am.bankKeeper, am.keeper), + )) + // this line is used by starport scaffolding # simapp/module/operation return operations diff --git a/x/machine/simulation/attest_machine.go b/x/machine/simulation/attest_machine.go new file mode 100644 index 0000000..5be378f --- /dev/null +++ b/x/machine/simulation/attest_machine.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" + "planetmint-go/x/machine/keeper" + "planetmint-go/x/machine/types" +) + +func SimulateMsgAttestMachine( + 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.MsgAttestMachine{ + Creator: simAccount.Address.String(), + } + + // TODO: Handling the AttestMachine simulation + + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "AttestMachine simulation not implemented"), nil, nil + } +} diff --git a/x/machine/types/codec.go b/x/machine/types/codec.go index 844157a..05b3865 100644 --- a/x/machine/types/codec.go +++ b/x/machine/types/codec.go @@ -3,15 +3,19 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - // this line is used by starport scaffolding # 1 + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" ) func RegisterCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgAttestMachine{}, "machine/AttestMachine", nil) // this line is used by starport scaffolding # 2 } func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgAttestMachine{}, + ) // this line is used by starport scaffolding # 3 msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) diff --git a/x/machine/types/machine.pb.go b/x/machine/types/machine.pb.go index acbcdc8..2d3ec34 100644 --- a/x/machine/types/machine.pb.go +++ b/x/machine/types/machine.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: proto/planetmintgo/machine/machine.proto +// source: planetmintgo/machine/machine.proto package types @@ -38,7 +38,7 @@ func (m *Machine) Reset() { *m = Machine{} } func (m *Machine) String() string { return proto.CompactTextString(m) } func (*Machine) ProtoMessage() {} func (*Machine) Descriptor() ([]byte, []int) { - return fileDescriptor_cd9f258b3d94bc1e, []int{0} + return fileDescriptor_1bb279745bef7c4b, []int{0} } func (m *Machine) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -141,7 +141,7 @@ func (m *Metadata) Reset() { *m = Metadata{} } func (m *Metadata) String() string { return proto.CompactTextString(m) } func (*Metadata) ProtoMessage() {} func (*Metadata) Descriptor() ([]byte, []int) { - return fileDescriptor_cd9f258b3d94bc1e, []int{1} + return fileDescriptor_1bb279745bef7c4b, []int{1} } func (m *Metadata) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -208,7 +208,7 @@ func (m *MachineIndex) Reset() { *m = MachineIndex{} } func (m *MachineIndex) String() string { return proto.CompactTextString(m) } func (*MachineIndex) ProtoMessage() {} func (*MachineIndex) Descriptor() ([]byte, []int) { - return fileDescriptor_cd9f258b3d94bc1e, []int{2} + return fileDescriptor_1bb279745bef7c4b, []int{2} } func (m *MachineIndex) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -268,40 +268,40 @@ func init() { } func init() { - proto.RegisterFile("proto/planetmintgo/machine/machine.proto", fileDescriptor_cd9f258b3d94bc1e) + proto.RegisterFile("planetmintgo/machine/machine.proto", fileDescriptor_1bb279745bef7c4b) } -var fileDescriptor_cd9f258b3d94bc1e = []byte{ - // 462 bytes of a gzipped FileDescriptorProto +var fileDescriptor_1bb279745bef7c4b = []byte{ + // 460 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x53, 0x41, 0x6b, 0xdb, 0x30, 0x18, 0x8d, 0xec, 0x34, 0x4d, 0xbe, 0x14, 0xd6, 0x89, 0x30, 0x44, 0xd9, 0x4c, 0xf0, 0x65, 0xa6, - 0x6c, 0x0e, 0xb4, 0xb0, 0xad, 0xbd, 0x2d, 0xf3, 0x18, 0x81, 0x15, 0x86, 0x8f, 0x83, 0x1d, 0x34, + 0x6c, 0x2e, 0xb4, 0xb0, 0xad, 0xbd, 0x2d, 0xf3, 0x18, 0x81, 0x15, 0x86, 0x8f, 0x83, 0x1d, 0x34, 0x4b, 0xcb, 0x44, 0x63, 0xd9, 0xb3, 0xe4, 0xd2, 0xc0, 0x7e, 0xc4, 0xfe, 0xc8, 0xfe, 0xc7, 0x2e, - 0x83, 0x1e, 0x77, 0x1c, 0xc9, 0x1f, 0x19, 0x96, 0x95, 0xa4, 0x69, 0xc2, 0xda, 0x9e, 0xfc, 0x7d, - 0x4f, 0xef, 0x3d, 0xf9, 0x93, 0x9e, 0x20, 0xc8, 0x8b, 0x4c, 0x67, 0x83, 0x7c, 0x42, 0x25, 0xd7, - 0xa9, 0x90, 0x7a, 0x9c, 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x9f, 0x2c, 0x6f, 0xf0, 0xf9, 0x28, + 0x3b, 0xba, 0x5a, 0x3c, 0x6a, 0x3d, 0xc9, 0xb9, 0xfa, 0xdc, 0x32, 0x6f, 0xfa, 0xe4, 0x5f, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x05, 0xe7, 0xf6, 0xc3, 0xf9, 0x03, 0x00, 0x00, } func (m *Machine) Marshal() (dAtA []byte, err error) { diff --git a/x/machine/types/message_attest_machine.go b/x/machine/types/message_attest_machine.go new file mode 100644 index 0000000..e1f4ef0 --- /dev/null +++ b/x/machine/types/message_attest_machine.go @@ -0,0 +1,46 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +const TypeMsgAttestMachine = "attest_machine" + +var _ sdk.Msg = &MsgAttestMachine{} + +func NewMsgAttestMachine(creator string, machine *Machine) *MsgAttestMachine { + return &MsgAttestMachine{ + Creator: creator, + Machine: machine, + } +} + +func (msg *MsgAttestMachine) Route() string { + return RouterKey +} + +func (msg *MsgAttestMachine) Type() string { + return TypeMsgAttestMachine +} + +func (msg *MsgAttestMachine) GetSigners() []sdk.AccAddress { + creator, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{creator} +} + +func (msg *MsgAttestMachine) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgAttestMachine) 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/machine/types/message_attest_machine_test.go b/x/machine/types/message_attest_machine_test.go new file mode 100644 index 0000000..f4e3f73 --- /dev/null +++ b/x/machine/types/message_attest_machine_test.go @@ -0,0 +1,41 @@ +package types + +import ( + "testing" + + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/stretchr/testify/require" + // "planetmint-go/testutil/sample" +) + +func TestMsgAttestMachine_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg MsgAttestMachine + err error + }{ + { + name: "invalid address", + msg: MsgAttestMachine{ + Creator: "invalid_address", + }, + err: sdkerrors.ErrInvalidAddress, + }, + // }, { + // name: "valid address", + // msg: MsgAttestMachine{ + // 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/machine/types/tx.pb.go b/x/machine/types/tx.pb.go index ba2bf76..f511560 100644 --- a/x/machine/types/tx.pb.go +++ b/x/machine/types/tx.pb.go @@ -9,7 +9,11 @@ import ( grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. @@ -23,18 +27,117 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +type MsgAttestMachine struct { + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + Machine *Machine `protobuf:"bytes,2,opt,name=machine,proto3" json:"machine,omitempty"` +} + +func (m *MsgAttestMachine) Reset() { *m = MsgAttestMachine{} } +func (m *MsgAttestMachine) String() string { return proto.CompactTextString(m) } +func (*MsgAttestMachine) ProtoMessage() {} +func (*MsgAttestMachine) Descriptor() ([]byte, []int) { + return fileDescriptor_85ac37e5c8e5251d, []int{0} +} +func (m *MsgAttestMachine) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgAttestMachine) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgAttestMachine.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 *MsgAttestMachine) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgAttestMachine.Merge(m, src) +} +func (m *MsgAttestMachine) XXX_Size() int { + return m.Size() +} +func (m *MsgAttestMachine) XXX_DiscardUnknown() { + xxx_messageInfo_MsgAttestMachine.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgAttestMachine proto.InternalMessageInfo + +func (m *MsgAttestMachine) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *MsgAttestMachine) GetMachine() *Machine { + if m != nil { + return m.Machine + } + return nil +} + +type MsgAttestMachineResponse struct { +} + +func (m *MsgAttestMachineResponse) Reset() { *m = MsgAttestMachineResponse{} } +func (m *MsgAttestMachineResponse) String() string { return proto.CompactTextString(m) } +func (*MsgAttestMachineResponse) ProtoMessage() {} +func (*MsgAttestMachineResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_85ac37e5c8e5251d, []int{1} +} +func (m *MsgAttestMachineResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgAttestMachineResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgAttestMachineResponse.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 *MsgAttestMachineResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgAttestMachineResponse.Merge(m, src) +} +func (m *MsgAttestMachineResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgAttestMachineResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgAttestMachineResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgAttestMachineResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgAttestMachine)(nil), "planetmintgo.machine.MsgAttestMachine") + proto.RegisterType((*MsgAttestMachineResponse)(nil), "planetmintgo.machine.MsgAttestMachineResponse") +} + func init() { proto.RegisterFile("planetmintgo/machine/tx.proto", fileDescriptor_85ac37e5c8e5251d) } var fileDescriptor_85ac37e5c8e5251d = []byte{ - // 116 bytes of a gzipped FileDescriptorProto + // 216 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2d, 0xc8, 0x49, 0xcc, 0x4b, 0x2d, 0xc9, 0xcd, 0xcc, 0x2b, 0x49, 0xcf, 0xd7, 0xcf, 0x4d, 0x4c, 0xce, 0xc8, 0xcc, 0x4b, 0xd5, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x41, 0x96, 0xd6, 0x83, 0x4a, - 0x1b, 0xb1, 0x72, 0x31, 0xfb, 0x16, 0xa7, 0x3b, 0x99, 0x9f, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, - 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, - 0xb1, 0x1c, 0x43, 0x14, 0x92, 0xa9, 0xba, 0xe9, 0xf9, 0xfa, 0x15, 0x08, 0x83, 0x2b, 0x0b, 0x52, - 0x8b, 0x93, 0xd8, 0xc0, 0x86, 0x1b, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x9b, 0x10, 0x38, 0x54, - 0x7d, 0x00, 0x00, 0x00, + 0x4b, 0x29, 0x61, 0xd5, 0x04, 0xa5, 0x21, 0x3a, 0x95, 0x52, 0xb9, 0x04, 0x7c, 0x8b, 0xd3, 0x1d, + 0x4b, 0x4a, 0x52, 0x8b, 0x4b, 0x7c, 0x21, 0x32, 0x42, 0x12, 0x5c, 0xec, 0xc9, 0x45, 0xa9, 0x89, + 0x25, 0xf9, 0x45, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x41, 0x30, 0xae, 0x90, 0x39, 0x17, 0x3b, + 0x54, 0xbb, 0x04, 0x93, 0x02, 0xa3, 0x06, 0xb7, 0x91, 0xac, 0x1e, 0x36, 0x9b, 0xf5, 0xa0, 0x26, + 0x05, 0xc1, 0x54, 0x2b, 0x49, 0x71, 0x49, 0xa0, 0x5b, 0x13, 0x94, 0x5a, 0x5c, 0x90, 0x9f, 0x57, + 0x9c, 0x6a, 0x94, 0xc7, 0xc5, 0xec, 0x5b, 0x9c, 0x2e, 0x94, 0xce, 0xc5, 0x8b, 0xea, 0x0c, 0x35, + 0x1c, 0x66, 0xa3, 0x99, 0x23, 0xa5, 0x47, 0x9c, 0x3a, 0x98, 0x7d, 0x4e, 0xe6, 0x27, 0x1e, 0xc9, + 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, + 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0x85, 0x14, 0xca, 0xba, 0xe9, 0xf9, 0xfa, 0x15, 0x88, + 0x80, 0xae, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0x07, 0x99, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, + 0x78, 0x82, 0x2b, 0xac, 0x8d, 0x01, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -49,6 +152,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 { + AttestMachine(ctx context.Context, in *MsgAttestMachine, opts ...grpc.CallOption) (*MsgAttestMachineResponse, error) } type msgClient struct { @@ -59,22 +163,420 @@ func NewMsgClient(cc grpc1.ClientConn) MsgClient { return &msgClient{cc} } +func (c *msgClient) AttestMachine(ctx context.Context, in *MsgAttestMachine, opts ...grpc.CallOption) (*MsgAttestMachineResponse, error) { + out := new(MsgAttestMachineResponse) + err := c.cc.Invoke(ctx, "/planetmintgo.machine.Msg/AttestMachine", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { + AttestMachine(context.Context, *MsgAttestMachine) (*MsgAttestMachineResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. type UnimplementedMsgServer struct { } +func (*UnimplementedMsgServer) AttestMachine(ctx context.Context, req *MsgAttestMachine) (*MsgAttestMachineResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method AttestMachine not implemented") +} + func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) } +func _Msg_AttestMachine_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgAttestMachine) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).AttestMachine(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/planetmintgo.machine.Msg/AttestMachine", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).AttestMachine(ctx, req.(*MsgAttestMachine)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "planetmintgo.machine.Msg", HandlerType: (*MsgServer)(nil), - Methods: []grpc.MethodDesc{}, - Streams: []grpc.StreamDesc{}, - Metadata: "planetmintgo/machine/tx.proto", + Methods: []grpc.MethodDesc{ + { + MethodName: "AttestMachine", + Handler: _Msg_AttestMachine_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "planetmintgo/machine/tx.proto", } + +func (m *MsgAttestMachine) 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 *MsgAttestMachine) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgAttestMachine) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Machine != nil { + { + size, err := m.Machine.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + 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 *MsgAttestMachineResponse) 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 *MsgAttestMachineResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgAttestMachineResponse) 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 + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgAttestMachine) 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)) + } + if m.Machine != nil { + l = m.Machine.Size() + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgAttestMachineResponse) 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 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgAttestMachine) 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: MsgAttestMachine: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgAttestMachine: 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 Machine", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Machine == nil { + m.Machine = &Machine{} + } + if err := m.Machine.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + 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 *MsgAttestMachineResponse) 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: MsgAttestMachineResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgAttestMachineResponse: 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 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + 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, ErrIntOverflowTx + } + 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, ErrIntOverflowTx + } + 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, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +)