Skip to content

Commit

Permalink
Merge pull request #750 from neutron-org/feat/clean-bindings
Browse files Browse the repository at this point in the history
feat: clean bindings #ntrn-410
  • Loading branch information
pr0n00gler authored Oct 29, 2024
2 parents 3ce1b5b + 421b785 commit 99d2060
Show file tree
Hide file tree
Showing 23 changed files with 1,462 additions and 316 deletions.
6 changes: 4 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -802,8 +802,10 @@ func New(
app.TransferKeeper,
&app.AdminmoduleKeeper,
app.FeeBurnerKeeper,
app.FeeKeeper, &app.BankKeeper,
app.TokenFactoryKeeper, &app.CronKeeper,
app.FeeKeeper,
&app.BankKeeper,
app.TokenFactoryKeeper,
&app.CronKeeper,
&app.ContractManagerKeeper,
&app.DexKeeper,
app.OracleKeeper,
Expand Down
62 changes: 60 additions & 2 deletions docs/static/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19724,7 +19724,7 @@ definitions:
osmosis.tokenfactory.v1beta1.QueryBeforeSendHookAddressResponse:
description: |-
QueryBeforeSendHookAddressResponse defines the response structure for the
DenomBeforeSendHook gRPC query.
BeforeSendHookAddress gRPC query.
properties:
contract_addr:
type: string
Expand Down Expand Up @@ -19759,6 +19759,14 @@ definitions:
type: string
type: array
type: object
osmosis.tokenfactory.v1beta1.QueryFullDenomResponse:
description: |-
QueryFullDenomResponse defines the response structure for the
FullDenom 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 @@ -45519,7 +45527,7 @@ paths:
QueryBeforeSendHookAddressResponse defines the response structure
for the

DenomBeforeSendHook gRPC query.
BeforeSendHookAddress gRPC query.
properties:
contract_addr:
type: string
Expand Down Expand Up @@ -45551,6 +45559,56 @@ 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: |-
QueryFullDenomResponse defines the response structure for the
FullDenom 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
16 changes: 16 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,17 @@ 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
uint64 failure_id = 2;
}

message MsgResubmitFailureResponse {}
23 changes: 22 additions & 1 deletion 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 @@ -76,13 +82,28 @@ message QueryDenomsFromCreatorResponse {
repeated string denoms = 1 [(gogoproto.moretags) = "yaml:\"denoms\""];
}

// QueryBeforeSendHookAddressRequest defines the request structure for the
// BeforeSendHookAddress gRPC query.
message QueryBeforeSendHookAddressRequest {
string creator = 1 [(gogoproto.moretags) = "yaml:\"creator\""];
string subdenom = 2 [(gogoproto.moretags) = "yaml:\"subdenom\""];
}

// QueryBeforeSendHookAddressResponse defines the response structure for the
// DenomBeforeSendHook gRPC query.
// BeforeSendHookAddress gRPC query.
message QueryBeforeSendHookAddressResponse {
string contract_addr = 1 [(gogoproto.moretags) = "yaml:\"contract_addr\""];
}

// QueryFullDenomRequest defines the request structure for the
// FullDenom gRPC query.
message QueryFullDenomRequest {
string creator = 1 [(gogoproto.moretags) = "yaml:\"creator\""];
string subdenom = 2 [(gogoproto.moretags) = "yaml:\"subdenom\""];
}

// QueryFullDenomResponse defines the response structure for the
// FullDenom gRPC query.
message QueryFullDenomResponse {
string full_denom = 1 [(gogoproto.moretags) = "yaml:\"full_denom\""];
}
76 changes: 44 additions & 32 deletions wasmbinding/message_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"strings"
"time"

contractmanagerkeeper "github.com/neutron-org/neutron/v5/x/contractmanager/keeper"

channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"

"github.com/cosmos/gogoproto/proto"
Expand All @@ -17,8 +19,6 @@ import (
dextypes "github.com/neutron-org/neutron/v5/x/dex/types"
dexutils "github.com/neutron-org/neutron/v5/x/dex/utils"

contractmanagerkeeper "github.com/neutron-org/neutron/v5/x/contractmanager/keeper"

"cosmossdk.io/errors"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

Expand All @@ -37,6 +37,8 @@ import (
adminmodulekeeper "github.com/cosmos/admin-module/v2/x/adminmodule/keeper"
admintypes "github.com/cosmos/admin-module/v2/x/adminmodule/types"

contractmanagertypes "github.com/neutron-org/neutron/v5/x/contractmanager/types"

bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
//nolint:staticcheck

Expand Down Expand Up @@ -65,37 +67,39 @@ func CustomMessageDecorator(
) func(messenger wasmkeeper.Messenger) wasmkeeper.Messenger {
return func(old wasmkeeper.Messenger) wasmkeeper.Messenger {
return &CustomMessenger{
Keeper: *ictx,
Wrapped: old,
Ictxmsgserver: ictxkeeper.NewMsgServerImpl(*ictx),
Icqmsgserver: icqkeeper.NewMsgServerImpl(*icq),
transferKeeper: transferKeeper,
Adminserver: adminmodulekeeper.NewMsgServerImpl(*adminKeeper),
Bank: bankKeeper,
TokenFactory: tokenFactoryKeeper,
CronMsgServer: cronkeeper.NewMsgServerImpl(*cronKeeper),
CronQueryServer: cronKeeper,
AdminKeeper: adminKeeper,
ContractmanagerKeeper: contractmanagerKeeper,
DexMsgServer: dexkeeper.NewMsgServerImpl(*dexKeeper),
Keeper: *ictx,
Wrapped: old,
Ictxmsgserver: ictxkeeper.NewMsgServerImpl(*ictx),
Icqmsgserver: icqkeeper.NewMsgServerImpl(*icq),
transferKeeper: transferKeeper,
Adminserver: adminmodulekeeper.NewMsgServerImpl(*adminKeeper),
Bank: bankKeeper,
TokenFactory: tokenFactoryKeeper,
CronMsgServer: cronkeeper.NewMsgServerImpl(*cronKeeper),
CronQueryServer: cronKeeper,
AdminKeeper: adminKeeper,
ContractmanagerMsgServer: contractmanagerkeeper.NewMsgServerImpl(*contractmanagerKeeper),
ContractmanagerQueryServer: contractmanagerkeeper.NewQueryServerImpl(*contractmanagerKeeper),
DexMsgServer: dexkeeper.NewMsgServerImpl(*dexKeeper),
}
}
}

type CustomMessenger struct {
Keeper ictxkeeper.Keeper
Wrapped wasmkeeper.Messenger
Ictxmsgserver ictxtypes.MsgServer
Icqmsgserver icqtypes.MsgServer
transferKeeper transferwrapperkeeper.KeeperTransferWrapper
Adminserver admintypes.MsgServer
Bank *bankkeeper.BaseKeeper
TokenFactory *tokenfactorykeeper.Keeper
CronMsgServer crontypes.MsgServer
CronQueryServer crontypes.QueryServer
AdminKeeper *adminmodulekeeper.Keeper
ContractmanagerKeeper *contractmanagerkeeper.Keeper
DexMsgServer dextypes.MsgServer
Keeper ictxkeeper.Keeper
Wrapped wasmkeeper.Messenger
Ictxmsgserver ictxtypes.MsgServer
Icqmsgserver icqtypes.MsgServer
transferKeeper transferwrapperkeeper.KeeperTransferWrapper
Adminserver admintypes.MsgServer
Bank *bankkeeper.BaseKeeper
TokenFactory *tokenfactorykeeper.Keeper
CronMsgServer crontypes.MsgServer
CronQueryServer crontypes.QueryServer
AdminKeeper *adminmodulekeeper.Keeper
ContractmanagerMsgServer contractmanagertypes.MsgServer
ContractmanagerQueryServer contractmanagertypes.QueryServer
DexMsgServer dextypes.MsgServer
}

var _ wasmkeeper.Messenger = (*CustomMessenger)(nil)
Expand Down Expand Up @@ -1060,12 +1064,18 @@ func (m *CustomMessenger) removeSchedule(ctx sdk.Context, contractAddr sdk.AccAd
}

func (m *CustomMessenger) resubmitFailure(ctx sdk.Context, contractAddr sdk.AccAddress, resubmitFailure *bindings.ResubmitFailure) ([]sdk.Event, [][]byte, [][]*types.Any, error) {
failure, err := m.ContractmanagerKeeper.GetFailure(ctx, contractAddr, resubmitFailure.FailureId)
failure, err := m.ContractmanagerQueryServer.AddressFailure(ctx, &contractmanagertypes.QueryFailureRequest{
Address: contractAddr.String(),
FailureId: resubmitFailure.FailureId,
})
if err != nil {
return nil, nil, nil, errors.Wrap(sdkerrors.ErrNotFound, "no failure found to resubmit")
return nil, nil, nil, errors.Wrapf(err, "no failure with given FailureId found to resubmit")
}

err = m.ContractmanagerKeeper.ResubmitFailure(ctx, contractAddr, failure)
_, err = m.ContractmanagerMsgServer.ResubmitFailure(ctx, &contractmanagertypes.MsgResubmitFailure{
Sender: contractAddr.String(),
FailureId: resubmitFailure.FailureId,
})
if err != nil {
ctx.Logger().Error("failed to resubmitFailure",
"from_address", contractAddr.String(),
Expand All @@ -1074,7 +1084,7 @@ func (m *CustomMessenger) resubmitFailure(ctx sdk.Context, contractAddr sdk.AccA
return nil, nil, nil, errors.Wrap(err, "failed to resubmitFailure")
}

resp := bindings.ResubmitFailureResponse{FailureId: failure.Id}
resp := bindings.ResubmitFailureResponse{FailureId: resubmitFailure.FailureId}
data, err := json.Marshal(&resp)
if err != nil {
ctx.Logger().Error("json.Marshal: failed to marshal remove resubmitFailure response to JSON",
Expand All @@ -1084,6 +1094,8 @@ func (m *CustomMessenger) resubmitFailure(ctx sdk.Context, contractAddr sdk.AccA
return nil, nil, nil, errors.Wrap(err, "marshal json failed")
}

// Return failure for reverse compatibility purposes.
// Maybe it'll be removed in the future because it was already deleted after resubmit before returning here.
anyResp, err := types.NewAnyWithValue(failure)
if err != nil {
return nil, nil, nil, errors.Wrapf(err, "failed to convert {%T} to Any", failure)
Expand Down
2 changes: 1 addition & 1 deletion wasmbinding/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (qp *QueryPlugin) GetMinIbcFee(ctx sdk.Context, _ *bindings.QueryMinIbcFeeR
}

func (qp *QueryPlugin) GetFailures(ctx sdk.Context, address string, pagination *sdkquery.PageRequest) (*bindings.FailuresResponse, error) {
res, err := qp.contractmanagerKeeper.AddressFailures(ctx, &contractmanagertypes.QueryFailuresRequest{
res, err := qp.contractmanagerQueryServer.AddressFailures(ctx, &contractmanagertypes.QueryFailuresRequest{
Address: address,
Pagination: pagination,
})
Expand Down
37 changes: 19 additions & 18 deletions wasmbinding/query_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package wasmbinding

import (
contractmanagerkeeper "github.com/neutron-org/neutron/v5/x/contractmanager/keeper"
contractmanagertypes "github.com/neutron-org/neutron/v5/x/contractmanager/types"
dexkeeper "github.com/neutron-org/neutron/v5/x/dex/keeper"
feeburnerkeeper "github.com/neutron-org/neutron/v5/x/feeburner/keeper"
feerefunderkeeper "github.com/neutron-org/neutron/v5/x/feerefunder/keeper"
Expand All @@ -15,28 +16,28 @@ import (
)

type QueryPlugin struct {
icaControllerKeeper *icacontrollerkeeper.Keeper
icqKeeper *icqkeeper.Keeper
feeBurnerKeeper *feeburnerkeeper.Keeper
feeRefunderKeeper *feerefunderkeeper.Keeper
tokenFactoryKeeper *tokenfactorykeeper.Keeper
contractmanagerKeeper *contractmanagerkeeper.Keeper
dexKeeper *dexkeeper.Keeper
oracleKeeper *oraclekeeper.Keeper
marketmapKeeper *marketmapkeeper.Keeper
icaControllerKeeper *icacontrollerkeeper.Keeper
icqKeeper *icqkeeper.Keeper
feeBurnerKeeper *feeburnerkeeper.Keeper
feeRefunderKeeper *feerefunderkeeper.Keeper
tokenFactoryKeeper *tokenfactorykeeper.Keeper
contractmanagerQueryServer contractmanagertypes.QueryServer
dexKeeper *dexkeeper.Keeper
oracleKeeper *oraclekeeper.Keeper
marketmapKeeper *marketmapkeeper.Keeper
}

// NewQueryPlugin returns a reference to a new QueryPlugin.
func NewQueryPlugin(icaControllerKeeper *icacontrollerkeeper.Keeper, icqKeeper *icqkeeper.Keeper, feeBurnerKeeper *feeburnerkeeper.Keeper, feeRefunderKeeper *feerefunderkeeper.Keeper, tfk *tokenfactorykeeper.Keeper, contractmanagerKeeper *contractmanagerkeeper.Keeper, dexKeeper *dexkeeper.Keeper, oracleKeeper *oraclekeeper.Keeper, marketmapKeeper *marketmapkeeper.Keeper) *QueryPlugin {
return &QueryPlugin{
icaControllerKeeper: icaControllerKeeper,
icqKeeper: icqKeeper,
feeBurnerKeeper: feeBurnerKeeper,
feeRefunderKeeper: feeRefunderKeeper,
tokenFactoryKeeper: tfk,
contractmanagerKeeper: contractmanagerKeeper,
dexKeeper: dexKeeper,
oracleKeeper: oracleKeeper,
marketmapKeeper: marketmapKeeper,
icaControllerKeeper: icaControllerKeeper,
icqKeeper: icqKeeper,
feeBurnerKeeper: feeBurnerKeeper,
feeRefunderKeeper: feeRefunderKeeper,
tokenFactoryKeeper: tfk,
contractmanagerQueryServer: contractmanagerkeeper.NewQueryServerImpl(*contractmanagerKeeper),
dexKeeper: dexKeeper,
oracleKeeper: oracleKeeper,
marketmapKeeper: marketmapKeeper,
}
}
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
Loading

0 comments on commit 99d2060

Please sign in to comment.