-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ran ignite scaffold message stake-supplier --module supplier --signer…
… address --yes
- Loading branch information
Showing
10 changed files
with
213 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
syntax = "proto3"; | ||
|
||
package pocket.supplier; | ||
|
||
option go_package = "pocket/x/supplier/types"; | ||
|
||
// Msg defines the Msg service. | ||
service Msg {} | ||
service Msg { | ||
rpc StakeSupplier (MsgStakeSupplier) returns (MsgStakeSupplierResponse); | ||
} | ||
message MsgStakeSupplier { | ||
string address = 1; | ||
} | ||
|
||
message MsgStakeSupplierResponse {} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package cli | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
"github.com/spf13/cobra" | ||
"pocket/x/supplier/types" | ||
) | ||
|
||
var _ = strconv.Itoa(0) | ||
|
||
func CmdStakeSupplier() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "stake-supplier", | ||
Short: "Broadcast message stake-supplier", | ||
Args: cobra.ExactArgs(0), | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
|
||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
msg := types.NewMsgStakeSupplier( | ||
clientCtx.GetFromAddress().String(), | ||
) | ||
if err := msg.ValidateBasic(); err != nil { | ||
return err | ||
} | ||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) | ||
}, | ||
} | ||
|
||
flags.AddTxFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"pocket/x/supplier/types" | ||
) | ||
|
||
func (k msgServer) StakeSupplier(goCtx context.Context, msg *types.MsgStakeSupplier) (*types.MsgStakeSupplierResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
// TODO: Handling the message | ||
_ = ctx | ||
|
||
return &types.MsgStakeSupplierResponse{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
"pocket/x/supplier/keeper" | ||
"pocket/x/supplier/types" | ||
) | ||
|
||
func SimulateMsgStakeSupplier( | ||
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.MsgStakeSupplier{ | ||
Address: simAccount.Address.String(), | ||
} | ||
|
||
// TODO: Handling the StakeSupplier simulation | ||
|
||
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "StakeSupplier simulation not implemented"), nil, nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package types | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
const TypeMsgStakeSupplier = "stake_supplier" | ||
|
||
var _ sdk.Msg = &MsgStakeSupplier{} | ||
|
||
func NewMsgStakeSupplier(address string) *MsgStakeSupplier { | ||
return &MsgStakeSupplier{ | ||
Address: address, | ||
} | ||
} | ||
|
||
func (msg *MsgStakeSupplier) Route() string { | ||
return RouterKey | ||
} | ||
|
||
func (msg *MsgStakeSupplier) Type() string { | ||
return TypeMsgStakeSupplier | ||
} | ||
|
||
func (msg *MsgStakeSupplier) GetSigners() []sdk.AccAddress { | ||
address, err := sdk.AccAddressFromBech32(msg.Address) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return []sdk.AccAddress{address} | ||
} | ||
|
||
func (msg *MsgStakeSupplier) GetSignBytes() []byte { | ||
bz := ModuleCdc.MustMarshalJSON(msg) | ||
return sdk.MustSortJSON(bz) | ||
} | ||
|
||
func (msg *MsgStakeSupplier) ValidateBasic() error { | ||
_, err := sdk.AccAddressFromBech32(msg.Address) | ||
if err != nil { | ||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid address address (%s)", err) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package types | ||
|
||
import ( | ||
"testing" | ||
|
||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/stretchr/testify/require" | ||
"pocket/testutil/sample" | ||
) | ||
|
||
func TestMsgStakeSupplier_ValidateBasic(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
msg MsgStakeSupplier | ||
err error | ||
}{ | ||
{ | ||
name: "invalid address", | ||
msg: MsgStakeSupplier{ | ||
Address: "invalid_address", | ||
}, | ||
err: sdkerrors.ErrInvalidAddress, | ||
}, { | ||
name: "valid address", | ||
msg: MsgStakeSupplier{ | ||
Address: 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) | ||
}) | ||
} | ||
} |