Skip to content

Commit 75407d1

Browse files
author
nashqueue
committed
Ignite clie scaffold message commit-scavange
1 parent 2723362 commit 75407d1

File tree

16 files changed

+862
-9
lines changed

16 files changed

+862
-9
lines changed

docs/static/openapi.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51552,6 +51552,8 @@ definitions:
5155251552
description: |-
5155351553
Version defines the versioning scheme used to negotiate the IBC verison in
5155451554
the connection handshake.
51555+
scavenge.scavenge.MsgCommitSolutionResponse:
51556+
type: object
5155551557
scavenge.scavenge.MsgSubmitScavengeResponse:
5155651558
type: object
5155751559
scavenge.scavenge.Params:

proto/scavenge/tx.proto

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ option go_package = "scavenge/x/scavenge/types";
88
// Msg defines the Msg service.
99
service Msg {
1010
rpc SubmitScavenge(MsgSubmitScavenge) returns (MsgSubmitScavengeResponse);
11+
rpc CommitSolution(MsgCommitSolution) returns (MsgCommitSolutionResponse);
1112
// this line is used by starport scaffolding # proto/tx/rpc
1213
}
1314

@@ -21,4 +22,13 @@ message MsgSubmitScavenge {
2122
message MsgSubmitScavengeResponse {
2223
}
2324

25+
message MsgCommitSolution {
26+
string creator = 1;
27+
string solutionHash = 2;
28+
string solutionScavengerHash = 3;
29+
}
30+
31+
message MsgCommitSolutionResponse {
32+
}
33+
2434
// this line is used by starport scaffolding # proto/tx/message

vue/src/store/generated/scavenge/scavenge.scavenge/index.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,21 @@ export default {
135135
},
136136

137137

138+
async sendMsgCommitSolution({ rootGetters }, { value, fee = [], memo = '' }) {
139+
try {
140+
const txClient=await initTxClient(rootGetters)
141+
const msg = await txClient.msgCommitSolution(value)
142+
const result = await txClient.signAndBroadcast([msg], {fee: { amount: fee,
143+
gas: "200000" }, memo})
144+
return result
145+
} catch (e) {
146+
if (e == MissingWalletError) {
147+
throw new Error('TxClient:MsgCommitSolution:Init Could not initialize signing client. Wallet is required.')
148+
}else{
149+
throw new Error('TxClient:MsgCommitSolution:Send Could not broadcast Tx: '+ e.message)
150+
}
151+
}
152+
},
138153
async sendMsgSubmitScavenge({ rootGetters }, { value, fee = [], memo = '' }) {
139154
try {
140155
const txClient=await initTxClient(rootGetters)
@@ -151,6 +166,19 @@ export default {
151166
}
152167
},
153168

169+
async MsgCommitSolution({ rootGetters }, { value }) {
170+
try {
171+
const txClient=await initTxClient(rootGetters)
172+
const msg = await txClient.msgCommitSolution(value)
173+
return msg
174+
} catch (e) {
175+
if (e == MissingWalletError) {
176+
throw new Error('TxClient:MsgCommitSolution:Init Could not initialize signing client. Wallet is required.')
177+
} else{
178+
throw new Error('TxClient:MsgCommitSolution:Create Could not create message: ' + e.message)
179+
}
180+
}
181+
},
154182
async MsgSubmitScavenge({ rootGetters }, { value }) {
155183
try {
156184
const txClient=await initTxClient(rootGetters)

vue/src/store/generated/scavenge/scavenge.scavenge/module/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import { StdFee } from "@cosmjs/launchpad";
44
import { SigningStargateClient } from "@cosmjs/stargate";
55
import { Registry, OfflineSigner, EncodeObject, DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
66
import { Api } from "./rest";
7+
import { MsgCommitSolution } from "./types/scavenge/tx";
78
import { MsgSubmitScavenge } from "./types/scavenge/tx";
89

910

1011
const types = [
12+
["/scavenge.scavenge.MsgCommitSolution", MsgCommitSolution],
1113
["/scavenge.scavenge.MsgSubmitScavenge", MsgSubmitScavenge],
1214

1315
];
@@ -41,6 +43,7 @@ const txClient = async (wallet: OfflineSigner, { addr: addr }: TxClientOptions =
4143

4244
return {
4345
signAndBroadcast: (msgs: EncodeObject[], { fee, memo }: SignAndBroadcastOptions = {fee: defaultFee, memo: ""}) => client.signAndBroadcast(address, msgs, fee,memo),
46+
msgCommitSolution: (data: MsgCommitSolution): EncodeObject => ({ typeUrl: "/scavenge.scavenge.MsgCommitSolution", value: MsgCommitSolution.fromPartial( data ) }),
4447
msgSubmitScavenge: (data: MsgSubmitScavenge): EncodeObject => ({ typeUrl: "/scavenge.scavenge.MsgSubmitScavenge", value: MsgSubmitScavenge.fromPartial( data ) }),
4548

4649
};

vue/src/store/generated/scavenge/scavenge.scavenge/module/rest.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export interface RpcStatus {
2020
details?: ProtobufAny[];
2121
}
2222

23+
export type ScavengeMsgCommitSolutionResponse = object;
24+
2325
export type ScavengeMsgSubmitScavengeResponse = object;
2426

2527
/**

vue/src/store/generated/scavenge/scavenge.scavenge/module/types/scavenge/tx.ts

Lines changed: 179 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ export interface MsgSubmitScavenge {
1212

1313
export interface MsgSubmitScavengeResponse {}
1414

15+
export interface MsgCommitSolution {
16+
creator: string;
17+
solutionHash: string;
18+
solutionScavengerHash: string;
19+
}
20+
21+
export interface MsgCommitSolutionResponse {}
22+
1523
const baseMsgSubmitScavenge: object = {
1624
creator: "",
1725
solutionHash: "",
@@ -177,12 +185,168 @@ export const MsgSubmitScavengeResponse = {
177185
},
178186
};
179187

188+
const baseMsgCommitSolution: object = {
189+
creator: "",
190+
solutionHash: "",
191+
solutionScavengerHash: "",
192+
};
193+
194+
export const MsgCommitSolution = {
195+
encode(message: MsgCommitSolution, writer: Writer = Writer.create()): Writer {
196+
if (message.creator !== "") {
197+
writer.uint32(10).string(message.creator);
198+
}
199+
if (message.solutionHash !== "") {
200+
writer.uint32(18).string(message.solutionHash);
201+
}
202+
if (message.solutionScavengerHash !== "") {
203+
writer.uint32(26).string(message.solutionScavengerHash);
204+
}
205+
return writer;
206+
},
207+
208+
decode(input: Reader | Uint8Array, length?: number): MsgCommitSolution {
209+
const reader = input instanceof Uint8Array ? new Reader(input) : input;
210+
let end = length === undefined ? reader.len : reader.pos + length;
211+
const message = { ...baseMsgCommitSolution } as MsgCommitSolution;
212+
while (reader.pos < end) {
213+
const tag = reader.uint32();
214+
switch (tag >>> 3) {
215+
case 1:
216+
message.creator = reader.string();
217+
break;
218+
case 2:
219+
message.solutionHash = reader.string();
220+
break;
221+
case 3:
222+
message.solutionScavengerHash = reader.string();
223+
break;
224+
default:
225+
reader.skipType(tag & 7);
226+
break;
227+
}
228+
}
229+
return message;
230+
},
231+
232+
fromJSON(object: any): MsgCommitSolution {
233+
const message = { ...baseMsgCommitSolution } as MsgCommitSolution;
234+
if (object.creator !== undefined && object.creator !== null) {
235+
message.creator = String(object.creator);
236+
} else {
237+
message.creator = "";
238+
}
239+
if (object.solutionHash !== undefined && object.solutionHash !== null) {
240+
message.solutionHash = String(object.solutionHash);
241+
} else {
242+
message.solutionHash = "";
243+
}
244+
if (
245+
object.solutionScavengerHash !== undefined &&
246+
object.solutionScavengerHash !== null
247+
) {
248+
message.solutionScavengerHash = String(object.solutionScavengerHash);
249+
} else {
250+
message.solutionScavengerHash = "";
251+
}
252+
return message;
253+
},
254+
255+
toJSON(message: MsgCommitSolution): unknown {
256+
const obj: any = {};
257+
message.creator !== undefined && (obj.creator = message.creator);
258+
message.solutionHash !== undefined &&
259+
(obj.solutionHash = message.solutionHash);
260+
message.solutionScavengerHash !== undefined &&
261+
(obj.solutionScavengerHash = message.solutionScavengerHash);
262+
return obj;
263+
},
264+
265+
fromPartial(object: DeepPartial<MsgCommitSolution>): MsgCommitSolution {
266+
const message = { ...baseMsgCommitSolution } as MsgCommitSolution;
267+
if (object.creator !== undefined && object.creator !== null) {
268+
message.creator = object.creator;
269+
} else {
270+
message.creator = "";
271+
}
272+
if (object.solutionHash !== undefined && object.solutionHash !== null) {
273+
message.solutionHash = object.solutionHash;
274+
} else {
275+
message.solutionHash = "";
276+
}
277+
if (
278+
object.solutionScavengerHash !== undefined &&
279+
object.solutionScavengerHash !== null
280+
) {
281+
message.solutionScavengerHash = object.solutionScavengerHash;
282+
} else {
283+
message.solutionScavengerHash = "";
284+
}
285+
return message;
286+
},
287+
};
288+
289+
const baseMsgCommitSolutionResponse: object = {};
290+
291+
export const MsgCommitSolutionResponse = {
292+
encode(
293+
_: MsgCommitSolutionResponse,
294+
writer: Writer = Writer.create()
295+
): Writer {
296+
return writer;
297+
},
298+
299+
decode(
300+
input: Reader | Uint8Array,
301+
length?: number
302+
): MsgCommitSolutionResponse {
303+
const reader = input instanceof Uint8Array ? new Reader(input) : input;
304+
let end = length === undefined ? reader.len : reader.pos + length;
305+
const message = {
306+
...baseMsgCommitSolutionResponse,
307+
} as MsgCommitSolutionResponse;
308+
while (reader.pos < end) {
309+
const tag = reader.uint32();
310+
switch (tag >>> 3) {
311+
default:
312+
reader.skipType(tag & 7);
313+
break;
314+
}
315+
}
316+
return message;
317+
},
318+
319+
fromJSON(_: any): MsgCommitSolutionResponse {
320+
const message = {
321+
...baseMsgCommitSolutionResponse,
322+
} as MsgCommitSolutionResponse;
323+
return message;
324+
},
325+
326+
toJSON(_: MsgCommitSolutionResponse): unknown {
327+
const obj: any = {};
328+
return obj;
329+
},
330+
331+
fromPartial(
332+
_: DeepPartial<MsgCommitSolutionResponse>
333+
): MsgCommitSolutionResponse {
334+
const message = {
335+
...baseMsgCommitSolutionResponse,
336+
} as MsgCommitSolutionResponse;
337+
return message;
338+
},
339+
};
340+
180341
/** Msg defines the Msg service. */
181342
export interface Msg {
182-
/** this line is used by starport scaffolding # proto/tx/rpc */
183343
SubmitScavenge(
184344
request: MsgSubmitScavenge
185345
): Promise<MsgSubmitScavengeResponse>;
346+
/** this line is used by starport scaffolding # proto/tx/rpc */
347+
CommitSolution(
348+
request: MsgCommitSolution
349+
): Promise<MsgCommitSolutionResponse>;
186350
}
187351

188352
export class MsgClientImpl implements Msg {
@@ -203,6 +367,20 @@ export class MsgClientImpl implements Msg {
203367
MsgSubmitScavengeResponse.decode(new Reader(data))
204368
);
205369
}
370+
371+
CommitSolution(
372+
request: MsgCommitSolution
373+
): Promise<MsgCommitSolutionResponse> {
374+
const data = MsgCommitSolution.encode(request).finish();
375+
const promise = this.rpc.request(
376+
"scavenge.scavenge.Msg",
377+
"CommitSolution",
378+
data
379+
);
380+
return promise.then((data) =>
381+
MsgCommitSolutionResponse.decode(new Reader(data))
382+
);
383+
}
206384
}
207385

208386
interface Rpc {

x/scavenge/client/cli/tx.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func GetTxCmd() *cobra.Command {
3131
}
3232

3333
cmd.AddCommand(CmdSubmitScavenge())
34+
cmd.AddCommand(CmdCommitSolution())
3435
// this line is used by starport scaffolding # 1
3536

3637
return cmd
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package cli
2+
3+
import (
4+
"strconv"
5+
6+
"github.com/cosmos/cosmos-sdk/client"
7+
"github.com/cosmos/cosmos-sdk/client/flags"
8+
"github.com/cosmos/cosmos-sdk/client/tx"
9+
"github.com/spf13/cobra"
10+
"scavenge/x/scavenge/types"
11+
)
12+
13+
var _ = strconv.Itoa(0)
14+
15+
func CmdCommitSolution() *cobra.Command {
16+
cmd := &cobra.Command{
17+
Use: "commit-solution [solution-hash] [solution-scavenger-hash]",
18+
Short: "Broadcast message commit-solution",
19+
Args: cobra.ExactArgs(2),
20+
RunE: func(cmd *cobra.Command, args []string) (err error) {
21+
argSolutionHash := args[0]
22+
argSolutionScavengerHash := args[1]
23+
24+
clientCtx, err := client.GetClientTxContext(cmd)
25+
if err != nil {
26+
return err
27+
}
28+
29+
msg := types.NewMsgCommitSolution(
30+
clientCtx.GetFromAddress().String(),
31+
argSolutionHash,
32+
argSolutionScavengerHash,
33+
)
34+
if err := msg.ValidateBasic(); err != nil {
35+
return err
36+
}
37+
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
38+
},
39+
}
40+
41+
flags.AddTxFlagsToCmd(cmd)
42+
43+
return cmd
44+
}

x/scavenge/handler.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
2020
case *types.MsgSubmitScavenge:
2121
res, err := msgServer.SubmitScavenge(sdk.WrapSDKContext(ctx), msg)
2222
return sdk.WrapServiceResult(ctx, res, err)
23+
case *types.MsgCommitSolution:
24+
res, err := msgServer.CommitSolution(sdk.WrapSDKContext(ctx), msg)
25+
return sdk.WrapServiceResult(ctx, res, err)
2326
// this line is used by starport scaffolding # 1
2427
default:
2528
errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package keeper
2+
3+
import (
4+
"context"
5+
6+
sdk "github.com/cosmos/cosmos-sdk/types"
7+
"scavenge/x/scavenge/types"
8+
)
9+
10+
func (k msgServer) CommitSolution(goCtx context.Context, msg *types.MsgCommitSolution) (*types.MsgCommitSolutionResponse, error) {
11+
ctx := sdk.UnwrapSDKContext(goCtx)
12+
13+
// TODO: Handling the message
14+
_ = ctx
15+
16+
return &types.MsgCommitSolutionResponse{}, nil
17+
}

0 commit comments

Comments
 (0)