Skip to content

Commit c08f663

Browse files
author
nashqueue
committed
added keeper commit solution
1 parent aed75c4 commit c08f663

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed
Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,35 @@
1+
// x/scavenge/keeper/msg_server_commit_solution.go
2+
13
package keeper
24

35
import (
46
"context"
57

68
sdk "github.com/cosmos/cosmos-sdk/types"
9+
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
10+
711
"scavenge/x/scavenge/types"
812
)
913

1014
func (k msgServer) CommitSolution(goCtx context.Context, msg *types.MsgCommitSolution) (*types.MsgCommitSolutionResponse, error) {
1115
ctx := sdk.UnwrapSDKContext(goCtx)
1216

13-
// TODO: Handling the message
14-
_ = ctx
17+
// create a new commit from the information in the MsgCommitSolution message
18+
var commit = types.Commit{
19+
Index: msg.SolutionScavengerHash,
20+
SolutionHash: msg.SolutionHash,
21+
SolutionScavengerHash: msg.SolutionScavengerHash,
22+
}
23+
24+
// try getting a commit from the store using the solution+scavenger hash as the key
25+
_, isFound := k.GetCommit(ctx, commit.SolutionScavengerHash)
26+
27+
// return an error if a commit already exists in the store
28+
if isFound {
29+
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Commit with that hash already exists")
30+
}
1531

32+
// write commit to the store
33+
k.SetCommit(ctx, commit)
1634
return &types.MsgCommitSolutionResponse{}, nil
1735
}

0 commit comments

Comments
 (0)