generated from okp4/template-oss
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: scaffold trigger-service message
- Loading branch information
Showing
14 changed files
with
40,558 additions
and
12,906 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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,42 @@ | ||
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/okp4/okp4d/x/knowledge/types" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var _ = strconv.Itoa(0) | ||
|
||
func CmdTriggerService() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "trigger-service [uri]", | ||
Short: "Trigger a service execution from an invocation URI", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
argUri := args[0] | ||
|
||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
msg := types.NewMsgTriggerService( | ||
clientCtx.GetFromAddress().String(), | ||
argUri, | ||
) | ||
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
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" | ||
"github.com/okp4/okp4d/x/knowledge/types" | ||
) | ||
|
||
func (k msgServer) TriggerService(goCtx context.Context, msg *types.MsgTriggerService) (*types.MsgTriggerServiceResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
// TODO: Handling the message | ||
_ = ctx | ||
|
||
return &types.MsgTriggerServiceResponse{}, 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" | ||
"github.com/okp4/okp4d/x/knowledge/keeper" | ||
"github.com/okp4/okp4d/x/knowledge/types" | ||
) | ||
|
||
func SimulateMsgTriggerService( | ||
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.MsgTriggerService{ | ||
Creator: simAccount.Address.String(), | ||
} | ||
|
||
// TODO: Handling the TriggerService simulation | ||
|
||
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "TriggerService 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,46 @@ | ||
package types | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
const TypeMsgTriggerService = "trigger_service" | ||
|
||
var _ sdk.Msg = &MsgTriggerService{} | ||
|
||
func NewMsgTriggerService(creator string, uri string) *MsgTriggerService { | ||
return &MsgTriggerService{ | ||
Creator: creator, | ||
Uri: uri, | ||
} | ||
} | ||
|
||
func (msg *MsgTriggerService) Route() string { | ||
return RouterKey | ||
} | ||
|
||
func (msg *MsgTriggerService) Type() string { | ||
return TypeMsgTriggerService | ||
} | ||
|
||
func (msg *MsgTriggerService) GetSigners() []sdk.AccAddress { | ||
creator, err := sdk.AccAddressFromBech32(msg.Creator) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return []sdk.AccAddress{creator} | ||
} | ||
|
||
func (msg *MsgTriggerService) GetSignBytes() []byte { | ||
bz := ModuleCdc.MustMarshalJSON(msg) | ||
return sdk.MustSortJSON(bz) | ||
} | ||
|
||
func (msg *MsgTriggerService) ValidateBasic() error { | ||
_, err := sdk.AccAddressFromBech32(msg.Creator) | ||
if err != nil { | ||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator 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/okp4/okp4d/testutil/sample" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestMsgTriggerService_ValidateBasic(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
msg MsgTriggerService | ||
err error | ||
}{ | ||
{ | ||
name: "invalid address", | ||
msg: MsgTriggerService{ | ||
Creator: "invalid_address", | ||
}, | ||
err: sdkerrors.ErrInvalidAddress, | ||
}, { | ||
name: "valid address", | ||
msg: MsgTriggerService{ | ||
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) | ||
}) | ||
} | ||
} |
Oops, something went wrong.