Skip to content

Commit

Permalink
updated token-reflect contract
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Aug 22, 2023
1 parent 7b9edbd commit b181937
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 51 deletions.
10 changes: 5 additions & 5 deletions x/tokenfactory/bindings/custom_msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestCreateDenomMsg(t *testing.T) {
require.NoError(t, err)

// query the denom and see if it matches
query := bindings.TokenQuery{
query := bindings.TokenFactoryQuery{
FullDenom: &bindings.FullDenom{
CreatorAddr: reflect.String(),
Subdenom: "SUN",
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestMintMsg(t *testing.T) {
require.Contains(t, coin.Denom, "factory/")

// query the denom and see if it matches
query := bindings.TokenQuery{
query := bindings.TokenFactoryQuery{
FullDenom: &bindings.FullDenom{
CreatorAddr: reflect.String(),
Subdenom: "SUN",
Expand All @@ -110,7 +110,7 @@ func TestMintMsg(t *testing.T) {
require.Contains(t, coin.Denom, "factory/")

// query the denom and see if it matches
query = bindings.TokenQuery{
query = bindings.TokenFactoryQuery{
FullDenom: &bindings.FullDenom{
CreatorAddr: reflect.String(),
Subdenom: "SUN",
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestMintMsg(t *testing.T) {
require.Contains(t, coin.Denom, "factory/")

// query the denom and see if it matches
query = bindings.TokenQuery{
query = bindings.TokenFactoryQuery{
FullDenom: &bindings.FullDenom{
CreatorAddr: reflect.String(),
Subdenom: "MOON",
Expand All @@ -163,7 +163,7 @@ func TestMintMsg(t *testing.T) {
require.Contains(t, coin.Denom, "factory/")

// query the denom and see if it matches
query = bindings.TokenQuery{
query = bindings.TokenFactoryQuery{
FullDenom: &bindings.FullDenom{
CreatorAddr: reflect.String(),
Subdenom: "SUN",
Expand Down
9 changes: 3 additions & 6 deletions x/tokenfactory/bindings/custom_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestQueryFullDenom(t *testing.T) {
require.NotEmpty(t, reflect)

// query full denom
query := bindings.TokenQuery{
query := bindings.TokenFactoryQuery{
FullDenom: &bindings.FullDenom{
CreatorAddr: reflect.String(),
Subdenom: "ustart",
Expand All @@ -47,11 +47,8 @@ type ChainResponse struct {
Data []byte `json:"data"`
}

func queryCustom(t *testing.T, ctx sdk.Context, junoapp *app.App, contract sdk.AccAddress, request bindings.TokenQuery, response interface{}) {
wrapped := bindings.TokenFactoryQuery{
Token: &request,
}
msgBz, err := json.Marshal(wrapped)
func queryCustom(t *testing.T, ctx sdk.Context, junoapp *app.App, contract sdk.AccAddress, request bindings.TokenFactoryQuery, response interface{}) {
msgBz, err := json.Marshal(request)
require.NoError(t, err)
fmt.Println("queryCustom1", string(msgBz))

Expand Down
29 changes: 14 additions & 15 deletions x/tokenfactory/bindings/query_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
errorsmod "cosmossdk.io/errors"

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

bindingstypes "github.com/CosmosContracts/juno/v17/x/tokenfactory/bindings/types"
)
Expand All @@ -21,15 +20,15 @@ func CustomQuerier(qp *QueryPlugin) func(ctx sdk.Context, request json.RawMessag
if err := json.Unmarshal(request, &contractQuery); err != nil {
return nil, errorsmod.Wrap(err, "osmosis query")
}
if contractQuery.Token == nil {
return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "nil token field")
}
tokenQuery := contractQuery.Token
// if contractQuery.Token == nil {
// return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "nil token field")
// }
// tokenQuery := contractQuery.Token

switch {
case tokenQuery.FullDenom != nil:
creator := tokenQuery.FullDenom.CreatorAddr
subdenom := tokenQuery.FullDenom.Subdenom
case contractQuery.FullDenom != nil:
creator := contractQuery.FullDenom.CreatorAddr
subdenom := contractQuery.FullDenom.Subdenom

fullDenom, err := GetFullDenom(creator, subdenom)
if err != nil {
Expand All @@ -47,8 +46,8 @@ func CustomQuerier(qp *QueryPlugin) func(ctx sdk.Context, request json.RawMessag

return bz, nil

case tokenQuery.Admin != nil:
res, err := qp.GetDenomAdmin(ctx, tokenQuery.Admin.Denom)
case contractQuery.Admin != nil:
res, err := qp.GetDenomAdmin(ctx, contractQuery.Admin.Denom)
if err != nil {
return nil, err
}
Expand All @@ -60,8 +59,8 @@ func CustomQuerier(qp *QueryPlugin) func(ctx sdk.Context, request json.RawMessag

return bz, nil

case tokenQuery.Metadata != nil:
res, err := qp.GetMetadata(ctx, tokenQuery.Metadata.Denom)
case contractQuery.Metadata != nil:
res, err := qp.GetMetadata(ctx, contractQuery.Metadata.Denom)
if err != nil {
return nil, err
}
Expand All @@ -73,8 +72,8 @@ func CustomQuerier(qp *QueryPlugin) func(ctx sdk.Context, request json.RawMessag

return bz, nil

case tokenQuery.DenomsByCreator != nil:
res, err := qp.GetDenomsByCreator(ctx, tokenQuery.DenomsByCreator.Creator)
case contractQuery.DenomsByCreator != nil:
res, err := qp.GetDenomsByCreator(ctx, contractQuery.DenomsByCreator.Creator)
if err != nil {
return nil, err
}
Expand All @@ -86,7 +85,7 @@ func CustomQuerier(qp *QueryPlugin) func(ctx sdk.Context, request json.RawMessag

return bz, nil

case tokenQuery.Params != nil:
case contractQuery.Params != nil:
res, err := qp.GetParams(ctx)
if err != nil {
return nil, err
Expand Down
5 changes: 5 additions & 0 deletions x/tokenfactory/bindings/testdata/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# token-reflect-contract

<https://github.com/CosmosContracts/token-bindings>

Commit: 834bb36573fb21c74f8e78207308d9001df127a2
19 changes: 0 additions & 19 deletions x/tokenfactory/bindings/testdata/download_releases.sh

This file was deleted.

Binary file modified x/tokenfactory/bindings/testdata/token_reflect.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion x/tokenfactory/bindings/testdata/version.txt

This file was deleted.

6 changes: 1 addition & 5 deletions x/tokenfactory/bindings/types/query.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package types

type TokenFactoryQuery struct {
Token *TokenQuery `json:"token,omitempty"`
}

// See https://github.com/CosmWasm/token-bindings/blob/main/packages/bindings/src/query.rs
type TokenQuery struct {
type TokenFactoryQuery struct {
/// Given a subdenom minted by a contract via `OsmosisMsg::MintTokens`,
/// returns the full denom as used by `BankMsg::Send`.
FullDenom *FullDenom `json:"full_denom,omitempty"`
Expand Down

0 comments on commit b181937

Please sign in to comment.