Skip to content

Commit

Permalink
rewrite proto, fix authorities & queries
Browse files Browse the repository at this point in the history
  • Loading branch information
quasisamurai committed Sep 8, 2023
1 parent 6d36314 commit b332e03
Show file tree
Hide file tree
Showing 11 changed files with 282 additions and 100 deletions.
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ func New(
app.ContractManagerKeeper,
interchainqueriesmodulekeeper.Verifier{},
interchainqueriesmodulekeeper.TransactionVerifier{},
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
authtypes.NewModuleAddress(adminmoduletypes.ModuleName).String(),
)
app.InterchainTxsKeeper = *interchaintxskeeper.NewKeeper(
appCodec,
Expand All @@ -639,7 +639,7 @@ func New(
app.ICAControllerKeeper,
app.ContractManagerKeeper,
app.FeeKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
authtypes.NewModuleAddress(adminmoduletypes.ModuleName).String(),
)

app.CronKeeper = *cronkeeper.NewKeeper(appCodec, keys[crontypes.StoreKey], keys[crontypes.MemStoreKey], app.AccountKeeper, authtypes.NewModuleAddress(adminmoduletypes.ModuleName).String())
Expand Down
10 changes: 6 additions & 4 deletions proto/osmosis/tokenfactory/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ service Query {
rpc DenomAuthorityMetadata(QueryDenomAuthorityMetadataRequest)
returns (QueryDenomAuthorityMetadataResponse) {
option (google.api.http).get =
"/osmosis/tokenfactory/v1beta1/denoms/{denom}/authority_metadata";
"/osmosis/tokenfactory/v1beta1/denoms/factory/{creator}/{subdenom}/authority_metadata";
}

// DenomsFromCreator defines a gRPC query method for fetching all
Expand All @@ -37,7 +37,7 @@ service Query {
rpc BeforeSendHookAddress(QueryBeforeSendHookAddressRequest)
returns (QueryBeforeSendHookAddressResponse) {
option (google.api.http).get =
"/osmosis/tokenfactory/v1beta1/denoms/{denom}/before_send_hook";
"/osmosis/tokenfactory/v1beta1/denoms/factory/{creator}/{subdenom}/before_send_hook";
}
}

Expand All @@ -53,7 +53,8 @@ message QueryParamsResponse {
// QueryDenomAuthorityMetadataRequest defines the request structure for the
// DenomAuthorityMetadata gRPC query.
message QueryDenomAuthorityMetadataRequest {
string denom = 1 [ (gogoproto.moretags) = "yaml:\"denom\"" ];
string creator = 1 [ (gogoproto.moretags) = "yaml:\"creator\"" ];
string subdenom = 2 [ (gogoproto.moretags) = "yaml:\"subdenom\"" ];
}

// QueryDenomAuthorityMetadataResponse defines the response structure for the
Expand All @@ -78,7 +79,8 @@ message QueryDenomsFromCreatorResponse {
}

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

// QueryBeforeSendHookAddressResponse defines the response structure for the
Expand Down
6 changes: 3 additions & 3 deletions wasmbinding/bindings/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ type NeutronMsg struct {
/// Contracts can burn native tokens for an existing factory denom
/// that they are the admin of.
/// Currently, the burn from address must be the admin contract.
BurnTokens *BurnTokens `json:"burn_tokens,omitempty"`
SetBeforeSend *SetBeforeSend `json:"set_before_send,omitempty"`
BurnTokens *BurnTokens `json:"burn_tokens,omitempty"`
SetBeforeSendHook *SetBeforeSendHook `json:"set_before_send_hook,omitempty"`

// Cron types
AddSchedule *AddSchedule `json:"add_schedule,omitempty"`
Expand Down Expand Up @@ -180,7 +180,7 @@ type BurnTokens struct {
BurnFromAddress string `json:"burn_from_address"`
}

type SetBeforeSend struct {
type SetBeforeSendHook struct {
Denom string `json:"denom"`
CosmWasmAddr string `json:"cosm_wasm_addr"`
}
Expand Down
10 changes: 10 additions & 0 deletions wasmbinding/bindings/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type NeutronQuery struct {
FullDenom *FullDenom `json:"full_denom,omitempty"`
// Returns the admin of a denom, if the denom is a Token Factory denom.
DenomAdmin *DenomAdmin `json:"denom_admin,omitempty"`
//
BeforeSendHook *BeforeSendHook `json:"before_send_hook,omitempty"`
// Contractmanager queries
// Query all failures for address
Failures *Failures `json:"failures,omitempty"`
Expand Down Expand Up @@ -183,6 +185,14 @@ type DenomAdmin struct {
Subdenom string `json:"subdenom"`
}

type BeforeSendHook struct {
Denom string `json:"denom"`
}

type BeforeSendHookResponse struct {
CosmWasmAddr string `json:"cosm_wasm_addr"`
}

type DenomAdminResponse struct {
Admin string `json:"admin"`
}
Expand Down
13 changes: 13 additions & 0 deletions wasmbinding/custom_querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@ func CustomQuerier(qp *QueryPlugin) func(ctx sdk.Context, request json.RawMessag

return bz, nil

case contractQuery.BeforeSendHook != nil:
res, err := qp.GetBeforeSendHook(ctx, contractQuery.BeforeSendHook.Denom)
if err != nil {
return nil, errors.Wrap(err, "unable to get denom before send hook")
}

bz, err := json.Marshal(res)
if err != nil {
return nil, errors.Wrap(err, "failed to JSON marshal BeforeSendHookResponse response")
}

return bz, nil

case contractQuery.Failures != nil:
res, err := qp.GetFailures(ctx, contractQuery.Failures.Address, contractQuery.Failures.Pagination)
if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions wasmbinding/message_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ func (m *CustomMessenger) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddre
if contractMsg.MintTokens != nil {
return m.mintTokens(ctx, contractAddr, contractMsg.MintTokens)
}
if contractMsg.SetBeforeSend != nil {
return m.setBeforeSend(ctx, contractAddr, contractMsg.SetBeforeSend)
if contractMsg.SetBeforeSendHook != nil {
return m.setBeforeSendHook(ctx, contractAddr, contractMsg.SetBeforeSendHook)
}
if contractMsg.ChangeAdmin != nil {
return m.changeAdmin(ctx, contractAddr, contractMsg.ChangeAdmin)
Expand Down Expand Up @@ -499,10 +499,10 @@ func (m *CustomMessenger) mintTokens(ctx sdk.Context, contractAddr sdk.AccAddres
}

// mintTokens mints tokens of a specified denom to an address.
func (m *CustomMessenger) setBeforeSend(ctx sdk.Context, contractAddr sdk.AccAddress, set *bindings.SetBeforeSend) ([]sdk.Event, [][]byte, error) {
err := PerformSetBeforeSend(m.TokenFactory, ctx, contractAddr, set)
func (m *CustomMessenger) setBeforeSendHook(ctx sdk.Context, contractAddr sdk.AccAddress, set *bindings.SetBeforeSendHook) ([]sdk.Event, [][]byte, error) {
err := PerformSetBeforeSendHook(m.TokenFactory, ctx, contractAddr, set)
if err != nil {
return nil, nil, errors.Wrap(err, "perform mint")
return nil, nil, errors.Wrap(err, "perform set before send hook")
}
return nil, nil, nil
}
Expand Down Expand Up @@ -535,13 +535,13 @@ func PerformMint(f *tokenfactorykeeper.Keeper, b *bankkeeper.BaseKeeper, ctx sdk
return nil
}

func PerformSetBeforeSend(f *tokenfactorykeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAddress, set *bindings.SetBeforeSend) error {
func PerformSetBeforeSendHook(f *tokenfactorykeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAddress, set *bindings.SetBeforeSendHook) error {
sdkMsg := tokenfactorytypes.NewMsgSetBeforeSendHook(contractAddr.String(), set.Denom, set.CosmWasmAddr)
if err := sdkMsg.ValidateBasic(); err != nil {
return err
}

// SetBeforeSend through token factory / message server
// SetBeforeSendHook through token factory / message server
msgServer := tokenfactorykeeper.NewMsgServerImpl(*f)
_, err := msgServer.SetBeforeSendHook(sdk.WrapSDKContext(ctx), sdkMsg)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions wasmbinding/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ func (qp QueryPlugin) GetDenomAdmin(ctx sdk.Context, denom string) (*bindings.De
return &bindings.DenomAdminResponse{Admin: metadata.Admin}, nil
}

// GetBeforeSendHook is a query to get denom before send hook.
func (qp QueryPlugin) GetBeforeSendHook(ctx sdk.Context, denom string) (*bindings.BeforeSendHookResponse, error) {
cosmWasmAddr := qp.tokenFactoryKeeper.GetBeforeSendHook(ctx, denom)

return &bindings.BeforeSendHookResponse{CosmWasmAddr: cosmWasmAddr}, nil
}

func (qp *QueryPlugin) GetTotalBurnedNeutronsAmount(ctx sdk.Context, _ *bindings.QueryTotalBurnedNeutronsAmountRequest) (*bindings.QueryTotalBurnedNeutronsAmountResponse, error) {
grpcResp := qp.feeBurnerKeeper.GetTotalBurnedNeutronsAmount(ctx)
return &bindings.QueryTotalBurnedNeutronsAmountResponse{Coin: grpcResp.Coin}, nil
Expand Down
4 changes: 2 additions & 2 deletions x/tokenfactory/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func GetCmdDenomAuthorityMetadata() *cobra.Command {
}

res, err := queryClient.DenomAuthorityMetadata(cmd.Context(), &types.QueryDenomAuthorityMetadataRequest{
Denom: args[0],
Subdenom: args[0],
})
if err != nil {
return err
Expand Down Expand Up @@ -113,7 +113,7 @@ func GetCmdDenomsFromCreator() *cobra.Command {
queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.BeforeSendHookAddress(cmd.Context(), &types.QueryBeforeSendHookAddressRequest{
Denom: args[0],
Subdenom: args[0],
})
if err != nil {
return err
Expand Down
7 changes: 5 additions & 2 deletions x/tokenfactory/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"

Expand All @@ -20,7 +21,8 @@ func (k Keeper) Params(ctx context.Context, req *types.QueryParamsRequest) (*typ
func (k Keeper) DenomAuthorityMetadata(ctx context.Context, req *types.QueryDenomAuthorityMetadataRequest) (*types.QueryDenomAuthorityMetadataResponse, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)

authorityMetadata, err := k.GetAuthorityMetadata(sdkCtx, req.GetDenom())
denom := fmt.Sprintf("factory/%s/%s", req.GetCreator(), req.GetSubdenom())
authorityMetadata, err := k.GetAuthorityMetadata(sdkCtx, denom)
if err != nil {
return nil, err
}
Expand All @@ -37,7 +39,8 @@ func (k Keeper) DenomsFromCreator(ctx context.Context, req *types.QueryDenomsFro
func (k Keeper) BeforeSendHookAddress(ctx context.Context, req *types.QueryBeforeSendHookAddressRequest) (*types.QueryBeforeSendHookAddressResponse, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)

cosmwasmAddress := k.GetBeforeSendHook(sdkCtx, req.GetDenom())
denom := fmt.Sprintf("factory/%s/%s", req.GetCreator(), req.GetSubdenom())
cosmwasmAddress := k.GetBeforeSendHook(sdkCtx, denom)

return &types.QueryBeforeSendHookAddressResponse{CosmwasmAddress: cosmwasmAddress}, nil
}
Loading

0 comments on commit b332e03

Please sign in to comment.