Skip to content

Commit a475dec

Browse files
author
nashqueue
committed
Ignite clie scaffold message reveal-solution
1 parent 75407d1 commit a475dec

File tree

16 files changed

+778
-10
lines changed

16 files changed

+778
-10
lines changed

docs/static/openapi.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51554,6 +51554,8 @@ definitions:
5155451554
the connection handshake.
5155551555
scavenge.scavenge.MsgCommitSolutionResponse:
5155651556
type: object
51557+
scavenge.scavenge.MsgRevealSolutionResponse:
51558+
type: object
5155751559
scavenge.scavenge.MsgSubmitScavengeResponse:
5155851560
type: object
5155951561
scavenge.scavenge.Params:

proto/scavenge/tx.proto

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ option go_package = "scavenge/x/scavenge/types";
99
service Msg {
1010
rpc SubmitScavenge(MsgSubmitScavenge) returns (MsgSubmitScavengeResponse);
1111
rpc CommitSolution(MsgCommitSolution) returns (MsgCommitSolutionResponse);
12+
rpc RevealSolution(MsgRevealSolution) returns (MsgRevealSolutionResponse);
1213
// this line is used by starport scaffolding # proto/tx/rpc
1314
}
1415

@@ -31,4 +32,12 @@ message MsgCommitSolution {
3132
message MsgCommitSolutionResponse {
3233
}
3334

35+
message MsgRevealSolution {
36+
string creator = 1;
37+
string solution = 2;
38+
}
39+
40+
message MsgRevealSolutionResponse {
41+
}
42+
3443
// 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
@@ -165,6 +165,21 @@ export default {
165165
}
166166
}
167167
},
168+
async sendMsgRevealSolution({ rootGetters }, { value, fee = [], memo = '' }) {
169+
try {
170+
const txClient=await initTxClient(rootGetters)
171+
const msg = await txClient.msgRevealSolution(value)
172+
const result = await txClient.signAndBroadcast([msg], {fee: { amount: fee,
173+
gas: "200000" }, memo})
174+
return result
175+
} catch (e) {
176+
if (e == MissingWalletError) {
177+
throw new Error('TxClient:MsgRevealSolution:Init Could not initialize signing client. Wallet is required.')
178+
}else{
179+
throw new Error('TxClient:MsgRevealSolution:Send Could not broadcast Tx: '+ e.message)
180+
}
181+
}
182+
},
168183

169184
async MsgCommitSolution({ rootGetters }, { value }) {
170185
try {
@@ -192,6 +207,19 @@ export default {
192207
}
193208
}
194209
},
210+
async MsgRevealSolution({ rootGetters }, { value }) {
211+
try {
212+
const txClient=await initTxClient(rootGetters)
213+
const msg = await txClient.msgRevealSolution(value)
214+
return msg
215+
} catch (e) {
216+
if (e == MissingWalletError) {
217+
throw new Error('TxClient:MsgRevealSolution:Init Could not initialize signing client. Wallet is required.')
218+
} else{
219+
throw new Error('TxClient:MsgRevealSolution:Create Could not create message: ' + e.message)
220+
}
221+
}
222+
},
195223

196224
}
197225
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import { Registry, OfflineSigner, EncodeObject, DirectSecp256k1HdWallet } from "
66
import { Api } from "./rest";
77
import { MsgCommitSolution } from "./types/scavenge/tx";
88
import { MsgSubmitScavenge } from "./types/scavenge/tx";
9+
import { MsgRevealSolution } from "./types/scavenge/tx";
910

1011

1112
const types = [
1213
["/scavenge.scavenge.MsgCommitSolution", MsgCommitSolution],
1314
["/scavenge.scavenge.MsgSubmitScavenge", MsgSubmitScavenge],
15+
["/scavenge.scavenge.MsgRevealSolution", MsgRevealSolution],
1416

1517
];
1618
export const MissingWalletError = new Error("wallet is required");
@@ -45,6 +47,7 @@ const txClient = async (wallet: OfflineSigner, { addr: addr }: TxClientOptions =
4547
signAndBroadcast: (msgs: EncodeObject[], { fee, memo }: SignAndBroadcastOptions = {fee: defaultFee, memo: ""}) => client.signAndBroadcast(address, msgs, fee,memo),
4648
msgCommitSolution: (data: MsgCommitSolution): EncodeObject => ({ typeUrl: "/scavenge.scavenge.MsgCommitSolution", value: MsgCommitSolution.fromPartial( data ) }),
4749
msgSubmitScavenge: (data: MsgSubmitScavenge): EncodeObject => ({ typeUrl: "/scavenge.scavenge.MsgSubmitScavenge", value: MsgSubmitScavenge.fromPartial( data ) }),
50+
msgRevealSolution: (data: MsgRevealSolution): EncodeObject => ({ typeUrl: "/scavenge.scavenge.MsgRevealSolution", value: MsgRevealSolution.fromPartial( data ) }),
4851

4952
};
5053
};

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export interface RpcStatus {
2222

2323
export type ScavengeMsgCommitSolutionResponse = object;
2424

25+
export type ScavengeMsgRevealSolutionResponse = object;
26+
2527
export type ScavengeMsgSubmitScavengeResponse = object;
2628

2729
/**

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

Lines changed: 149 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ export interface MsgCommitSolution {
2020

2121
export interface MsgCommitSolutionResponse {}
2222

23+
export interface MsgRevealSolution {
24+
creator: string;
25+
solution: string;
26+
}
27+
28+
export interface MsgRevealSolutionResponse {}
29+
2330
const baseMsgSubmitScavenge: object = {
2431
creator: "",
2532
solutionHash: "",
@@ -338,15 +345,142 @@ export const MsgCommitSolutionResponse = {
338345
},
339346
};
340347

348+
const baseMsgRevealSolution: object = { creator: "", solution: "" };
349+
350+
export const MsgRevealSolution = {
351+
encode(message: MsgRevealSolution, writer: Writer = Writer.create()): Writer {
352+
if (message.creator !== "") {
353+
writer.uint32(10).string(message.creator);
354+
}
355+
if (message.solution !== "") {
356+
writer.uint32(18).string(message.solution);
357+
}
358+
return writer;
359+
},
360+
361+
decode(input: Reader | Uint8Array, length?: number): MsgRevealSolution {
362+
const reader = input instanceof Uint8Array ? new Reader(input) : input;
363+
let end = length === undefined ? reader.len : reader.pos + length;
364+
const message = { ...baseMsgRevealSolution } as MsgRevealSolution;
365+
while (reader.pos < end) {
366+
const tag = reader.uint32();
367+
switch (tag >>> 3) {
368+
case 1:
369+
message.creator = reader.string();
370+
break;
371+
case 2:
372+
message.solution = reader.string();
373+
break;
374+
default:
375+
reader.skipType(tag & 7);
376+
break;
377+
}
378+
}
379+
return message;
380+
},
381+
382+
fromJSON(object: any): MsgRevealSolution {
383+
const message = { ...baseMsgRevealSolution } as MsgRevealSolution;
384+
if (object.creator !== undefined && object.creator !== null) {
385+
message.creator = String(object.creator);
386+
} else {
387+
message.creator = "";
388+
}
389+
if (object.solution !== undefined && object.solution !== null) {
390+
message.solution = String(object.solution);
391+
} else {
392+
message.solution = "";
393+
}
394+
return message;
395+
},
396+
397+
toJSON(message: MsgRevealSolution): unknown {
398+
const obj: any = {};
399+
message.creator !== undefined && (obj.creator = message.creator);
400+
message.solution !== undefined && (obj.solution = message.solution);
401+
return obj;
402+
},
403+
404+
fromPartial(object: DeepPartial<MsgRevealSolution>): MsgRevealSolution {
405+
const message = { ...baseMsgRevealSolution } as MsgRevealSolution;
406+
if (object.creator !== undefined && object.creator !== null) {
407+
message.creator = object.creator;
408+
} else {
409+
message.creator = "";
410+
}
411+
if (object.solution !== undefined && object.solution !== null) {
412+
message.solution = object.solution;
413+
} else {
414+
message.solution = "";
415+
}
416+
return message;
417+
},
418+
};
419+
420+
const baseMsgRevealSolutionResponse: object = {};
421+
422+
export const MsgRevealSolutionResponse = {
423+
encode(
424+
_: MsgRevealSolutionResponse,
425+
writer: Writer = Writer.create()
426+
): Writer {
427+
return writer;
428+
},
429+
430+
decode(
431+
input: Reader | Uint8Array,
432+
length?: number
433+
): MsgRevealSolutionResponse {
434+
const reader = input instanceof Uint8Array ? new Reader(input) : input;
435+
let end = length === undefined ? reader.len : reader.pos + length;
436+
const message = {
437+
...baseMsgRevealSolutionResponse,
438+
} as MsgRevealSolutionResponse;
439+
while (reader.pos < end) {
440+
const tag = reader.uint32();
441+
switch (tag >>> 3) {
442+
default:
443+
reader.skipType(tag & 7);
444+
break;
445+
}
446+
}
447+
return message;
448+
},
449+
450+
fromJSON(_: any): MsgRevealSolutionResponse {
451+
const message = {
452+
...baseMsgRevealSolutionResponse,
453+
} as MsgRevealSolutionResponse;
454+
return message;
455+
},
456+
457+
toJSON(_: MsgRevealSolutionResponse): unknown {
458+
const obj: any = {};
459+
return obj;
460+
},
461+
462+
fromPartial(
463+
_: DeepPartial<MsgRevealSolutionResponse>
464+
): MsgRevealSolutionResponse {
465+
const message = {
466+
...baseMsgRevealSolutionResponse,
467+
} as MsgRevealSolutionResponse;
468+
return message;
469+
},
470+
};
471+
341472
/** Msg defines the Msg service. */
342473
export interface Msg {
343474
SubmitScavenge(
344475
request: MsgSubmitScavenge
345476
): Promise<MsgSubmitScavengeResponse>;
346-
/** this line is used by starport scaffolding # proto/tx/rpc */
347477
CommitSolution(
348478
request: MsgCommitSolution
349479
): Promise<MsgCommitSolutionResponse>;
480+
/** this line is used by starport scaffolding # proto/tx/rpc */
481+
RevealSolution(
482+
request: MsgRevealSolution
483+
): Promise<MsgRevealSolutionResponse>;
350484
}
351485

352486
export class MsgClientImpl implements Msg {
@@ -381,6 +515,20 @@ export class MsgClientImpl implements Msg {
381515
MsgCommitSolutionResponse.decode(new Reader(data))
382516
);
383517
}
518+
519+
RevealSolution(
520+
request: MsgRevealSolution
521+
): Promise<MsgRevealSolutionResponse> {
522+
const data = MsgRevealSolution.encode(request).finish();
523+
const promise = this.rpc.request(
524+
"scavenge.scavenge.Msg",
525+
"RevealSolution",
526+
data
527+
);
528+
return promise.then((data) =>
529+
MsgRevealSolutionResponse.decode(new Reader(data))
530+
);
531+
}
384532
}
385533

386534
interface Rpc {

x/scavenge/client/cli/tx.go

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

3333
cmd.AddCommand(CmdSubmitScavenge())
3434
cmd.AddCommand(CmdCommitSolution())
35+
cmd.AddCommand(CmdRevealSolution())
3536
// this line is used by starport scaffolding # 1
3637

3738
return cmd
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 CmdRevealSolution() *cobra.Command {
16+
cmd := &cobra.Command{
17+
Use: "reveal-solution [solution]",
18+
Short: "Broadcast message reveal-solution",
19+
Args: cobra.ExactArgs(1),
20+
RunE: func(cmd *cobra.Command, args []string) (err error) {
21+
argSolution := args[0]
22+
23+
clientCtx, err := client.GetClientTxContext(cmd)
24+
if err != nil {
25+
return err
26+
}
27+
28+
msg := types.NewMsgRevealSolution(
29+
clientCtx.GetFromAddress().String(),
30+
argSolution,
31+
)
32+
if err := msg.ValidateBasic(); err != nil {
33+
return err
34+
}
35+
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
36+
},
37+
}
38+
39+
flags.AddTxFlagsToCmd(cmd)
40+
41+
return cmd
42+
}

x/scavenge/handler.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
2323
case *types.MsgCommitSolution:
2424
res, err := msgServer.CommitSolution(sdk.WrapSDKContext(ctx), msg)
2525
return sdk.WrapServiceResult(ctx, res, err)
26+
case *types.MsgRevealSolution:
27+
res, err := msgServer.RevealSolution(sdk.WrapSDKContext(ctx), msg)
28+
return sdk.WrapServiceResult(ctx, res, err)
2629
// this line is used by starport scaffolding # 1
2730
default:
2831
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) RevealSolution(goCtx context.Context, msg *types.MsgRevealSolution) (*types.MsgRevealSolutionResponse, error) {
11+
ctx := sdk.UnwrapSDKContext(goCtx)
12+
13+
// TODO: Handling the message
14+
_ = ctx
15+
16+
return &types.MsgRevealSolutionResponse{}, nil
17+
}

0 commit comments

Comments
 (0)