Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: clean bindings #ntrn-410 #750

Merged
merged 20 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions docs/static/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19759,6 +19759,14 @@ definitions:
type: string
type: array
type: object
osmosis.tokenfactory.v1beta1.QueryFullDenomResponse:
description: |-
QueryBeforeSendHookAddressResponse defines the response structure for the
DenomBeforeSendHook gRPC query.
properties:
full_denom:
type: string
type: object
osmosis.tokenfactory.v1beta1.QueryParamsResponse:
description: QueryParamsResponse is the response type for the Query/Params RPC method.
properties:
Expand Down Expand Up @@ -45411,6 +45419,58 @@ paths:
getting the address registered for the before send hook.
tags:
- Query
/osmosis/tokenfactory/v1beta1/denoms/factory/{creator}/{subdenom}/full_denom:
get:
operationId: FullDenom
parameters:
- in: path
name: creator
required: true
type: string
- in: path
name: subdenom
required: true
type: string
responses:
'200':
description: A successful response.
schema:
description: >-
QueryBeforeSendHookAddressResponse defines the response structure
for the

DenomBeforeSendHook gRPC query.
properties:
full_denom:
type: string
type: object
default:
description: An unexpected error response.
schema:
properties:
code:
format: int32
type: integer
details:
items:
properties:
type_url:
type: string
value:
format: byte
type: string
type: object
type: array
error:
type: string
message:
type: string
type: object
summary: |-
FullDenom defines a gRPC query method for getting full denom name
from the creator and subdenom strings.
tags:
- Query
/osmosis/tokenfactory/v1beta1/denoms_from_creator/{creator}:
get:
operationId: DenomsFromCreator
Expand Down
18 changes: 18 additions & 0 deletions proto/neutron/contractmanager/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ service Msg {
option (cosmos.msg.v1.service) = true;

rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
rpc ResubmitFailure(MsgResubmitFailure) returns (MsgResubmitFailureResponse);

// this line is used by starport scaffolding # proto/tx/rpc
}

Expand Down Expand Up @@ -43,3 +45,19 @@ message MsgUpdateParams {
//
// Since: 0.47
message MsgUpdateParamsResponse {}

// MsgResubmitFailure - contract that has failed acknowledgement can resubmit its failure
message MsgResubmitFailure {
option (amino.name) = "contractmanager/MsgResubmitFailure";
option (cosmos.msg.v1.signer) = "sender";

// sender is the contract which failure to acknowledge is resubmitted.
string sender = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// failure_id is id of failure to resubmit
//
// NOTE: All parameters must be supplied.
swelf19 marked this conversation as resolved.
Show resolved Hide resolved
uint64 failure_id = 2;
}

message MsgResubmitFailureResponse {}
17 changes: 17 additions & 0 deletions proto/osmosis/tokenfactory/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ service Query {
"/osmosis/tokenfactory/v1beta1/denoms/factory/{creator}/{subdenom}/"
"before_send_hook";
}

// FullDenom defines a gRPC query method for getting full denom name
// from the creator and subdenom strings.
rpc FullDenom(QueryFullDenomRequest) returns (QueryFullDenomResponse) {
option (google.api.http).get = "/osmosis/tokenfactory/v1beta1/denoms/factory/{creator}/{subdenom}/full_denom";
}
}

// QueryParamsRequest is the request type for the Query/Params RPC method.
Expand Down Expand Up @@ -86,3 +92,14 @@ message QueryBeforeSendHookAddressRequest {
message QueryBeforeSendHookAddressResponse {
string contract_addr = 1 [(gogoproto.moretags) = "yaml:\"contract_addr\""];
}

message QueryFullDenomRequest {
string creator = 1 [(gogoproto.moretags) = "yaml:\"creator\""];
string subdenom = 2 [(gogoproto.moretags) = "yaml:\"subdenom\""];
}

// QueryBeforeSendHookAddressResponse defines the response structure for the
swelf19 marked this conversation as resolved.
Show resolved Hide resolved
// DenomBeforeSendHook gRPC query.
message QueryFullDenomResponse {
string full_denom = 1 [(gogoproto.moretags) = "yaml:\"full_denom\""];
}
2 changes: 1 addition & 1 deletion wasmbinding/message_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ func (m *CustomMessenger) resubmitFailure(ctx sdk.Context, contractAddr sdk.AccA
return nil, nil, nil, errors.Wrap(sdkerrors.ErrNotFound, "no failure found to resubmit")
}

err = m.ContractmanagerKeeper.ResubmitFailure(ctx, contractAddr, failure)
err = m.ContractmanagerKeeper.DoResubmitFailure(ctx, contractAddr, failure)
pr0n00gler marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
ctx.Logger().Error("failed to resubmitFailure",
"from_address", contractAddr.String(),
Expand Down
1 change: 1 addition & 0 deletions wasmbinding/stargate_allowlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func AcceptedStargateQueries() wasmkeeper.AcceptedQueries {
"/osmosis.tokenfactory.v1beta1.Query/DenomAuthorityMetadata": &tokenfactorytypes.QueryDenomAuthorityMetadataResponse{},
"/osmosis.tokenfactory.v1beta1.Query/DenomsFromCreator": &tokenfactorytypes.QueryDenomsFromCreatorResponse{},
"/osmosis.tokenfactory.v1beta1.Query/BeforeSendHookAddress": &tokenfactorytypes.QueryBeforeSendHookAddressResponse{},
"/osmosis.tokenfactory.v1beta1.Query/FullDenom": &tokenfactorytypes.QueryFullDenomResponse{},

// interchain accounts
"/ibc.applications.interchain_accounts.controller.v1.Query/InterchainAccount": &icacontrollertypes.QueryInterchainAccountResponse{},
Expand Down
4 changes: 2 additions & 2 deletions x/contractmanager/keeper/failure.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ func (k Keeper) GetFailure(ctx sdk.Context, contractAddr sdk.AccAddress, id uint
return &res, nil
}

// ResubmitFailure tries to call sudo handler for contract with same parameters as initially.
func (k Keeper) ResubmitFailure(ctx sdk.Context, contractAddr sdk.AccAddress, failure *types.Failure) error {
// DoResubmitFailure tries to call sudo handler for contract with same parameters as initially.
func (k Keeper) DoResubmitFailure(ctx sdk.Context, contractAddr sdk.AccAddress, failure *types.Failure) error {
if failure.SudoPayload == nil {
return errorsmod.Wrapf(types.ErrIncorrectFailureToResubmit, "cannot resubmit failure without sudo payload; failureId = %d", failure.Id)
}
Expand Down
12 changes: 6 additions & 6 deletions x/contractmanager/keeper/failure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func TestResubmitFailure(t *testing.T) {

failure, err := k.GetFailure(ctx, contractAddr, failureID)
require.NoError(t, err)
err = k.ResubmitFailure(ctx, contractAddr, failure)
err = k.DoResubmitFailure(ctx, contractAddr, failure)
require.NoError(t, err)
// failure should be deleted
_, err = k.GetFailure(ctx, contractAddr, failureID)
Expand All @@ -169,7 +169,7 @@ func TestResubmitFailure(t *testing.T) {

failure2, err := k.GetFailure(ctx, contractAddr, failureID2)
require.NoError(t, err)
err = k.ResubmitFailure(ctx, contractAddr, failure2)
err = k.DoResubmitFailure(ctx, contractAddr, failure2)
require.ErrorContains(t, err, "cannot resubmit failure")
// failure is still there
failureAfter2, err := k.GetFailure(ctx, contractAddr, failureID2)
Expand All @@ -187,7 +187,7 @@ func TestResubmitFailure(t *testing.T) {

failure3, err := k.GetFailure(ctx, contractAddr, failureID3)
require.NoError(t, err)
err = k.ResubmitFailure(ctx, contractAddr, failure3)
err = k.DoResubmitFailure(ctx, contractAddr, failure3)
require.NoError(t, err)
// failure should be deleted
_, err = k.GetFailure(ctx, contractAddr, failureID3)
Expand All @@ -203,7 +203,7 @@ func TestResubmitFailure(t *testing.T) {

failure4, err := k.GetFailure(ctx, contractAddr, failureID4)
require.NoError(t, err)
err = k.ResubmitFailure(ctx, contractAddr, failure4)
err = k.DoResubmitFailure(ctx, contractAddr, failure4)
require.ErrorContains(t, err, "cannot resubmit failure")
// failure is still there
failureAfter4, err := k.GetFailure(ctx, contractAddr, failureID4)
Expand All @@ -221,7 +221,7 @@ func TestResubmitFailure(t *testing.T) {

failure5, err := k.GetFailure(ctx, contractAddr, failureID5)
require.NoError(t, err)
err = k.ResubmitFailure(ctx, contractAddr, failure5)
err = k.DoResubmitFailure(ctx, contractAddr, failure5)
require.NoError(t, err)
// failure should be deleted
_, err = k.GetFailure(ctx, contractAddr, failureID5)
Expand All @@ -237,7 +237,7 @@ func TestResubmitFailure(t *testing.T) {

failure6, err := k.GetFailure(ctx, contractAddr, failureID6)
require.NoError(t, err)
err = k.ResubmitFailure(ctx, contractAddr, failure6)
err = k.DoResubmitFailure(ctx, contractAddr, failure6)
require.ErrorContains(t, err, "cannot resubmit failure")
// failure is still there
failureAfter6, err := k.GetFailure(ctx, contractAddr, failureID6)
Expand Down
29 changes: 29 additions & 0 deletions x/contractmanager/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,32 @@ func (k Keeper) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams)

return &types.MsgUpdateParamsResponse{}, nil
}

// ResubmitFailure resubmits the failure after contract acknowledgement failed
func (k Keeper) ResubmitFailure(goCtx context.Context, req *types.MsgResubmitFailure) (*types.MsgResubmitFailureResponse, error) {
Comment on lines +44 to +45
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we have ResubmitFailure and DoResubmitFailure? what's the difference between them? can we unify so there's only one Keeper's method for failures resubmission?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed DoResubmitFailure to resubmitFailure to avoid clashing. This function is keeper function and a little bit lower level dealing with store

if err := req.Validate(); err != nil {
return nil, errors.Wrap(err, "failed to validate MsgUpdateParams")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

failed to validate MsgUpdateParams?

}

ctx := sdk.UnwrapSDKContext(goCtx)

sender, err := sdk.AccAddressFromBech32(req.Sender)
if err != nil {
return nil, errors.Wrap(sdkerrors.ErrInvalidAddress, "sender in resubmit request is not in correct address format")
pr0n00gler marked this conversation as resolved.
Show resolved Hide resolved
}

if !k.wasmKeeper.HasContractInfo(ctx, sender) {
return nil, errors.Wrap(sdkerrors.ErrNotFound, "not a contract address tried to resubmit")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the error would look like "not a contract address tried to resubmit: not found" with codespace and code referring to sdk.

I think this way it would be more clear. wdyt about something like this?

ErrNotContractResubmission = errors.Register(ModuleName, 1104, "failures resubmission is only allowed to be called by a smart contract")

...
return nil, errors.Wrap(ErrNotContractResubmission, "sender is not a smart contract")

would be "sender is not a smart contract: failures resubmission is only allowed to be called by a smart contract" with codespace and code referring to the contractmanager module.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like it!

}

failure, err := k.GetFailure(ctx, sender, req.FailureId)
if err != nil {
return nil, errors.Wrap(sdkerrors.ErrNotFound, "no failure found to resubmit")
}

if err := k.DoResubmitFailure(ctx, sender, failure); err != nil {
return nil, err
}

return &types.MsgResubmitFailureResponse{}, nil
}
2 changes: 2 additions & 0 deletions x/contractmanager/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import (

func RegisterCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgUpdateParams{}, "neutron.contractmanager.v1.MsgUpdateParams", nil)
cdc.RegisterConcrete(&MsgResubmitFailure{}, "neutron.contractmanager.v1.MsgResubmitFailure", nil)
}

func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
registry.RegisterImplementations(
(*sdk.Msg)(nil),
&MsgUpdateParams{},
&MsgResubmitFailure{},
)
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}
Expand Down
29 changes: 29 additions & 0 deletions x/contractmanager/types/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,32 @@ func (msg *MsgUpdateParams) Validate() error {
}
return nil
}

var _ sdk.Msg = &MsgResubmitFailure{}

func (msg *MsgResubmitFailure) Route() string {
return RouterKey
}

func (msg *MsgResubmitFailure) Type() string {
return "resubmit-failure"
}

func (msg *MsgResubmitFailure) GetSigners() []sdk.AccAddress {
sender, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil { // should never happen as valid basic rejects invalid addresses
panic(err.Error())
}
return []sdk.AccAddress{sender}
}

func (msg *MsgResubmitFailure) GetSignBytes() []byte {
return ModuleCdc.MustMarshalJSON(msg)
}

func (msg *MsgResubmitFailure) Validate() error {
if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil {
return errorsmod.Wrap(err, "sender is invalid")
}
return nil
}
Loading
Loading