-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9765caa
commit da0231c
Showing
7 changed files
with
67 additions
and
65 deletions.
There are no files selected for viewing
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,52 @@ | ||
package custom_queriers | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/CosmWasm/wasmd/x/wasm" | ||
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" | ||
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" | ||
alliancebindings "github.com/terra-money/alliance/x/alliance/bindings" | ||
alliancekeeper "github.com/terra-money/alliance/x/alliance/keeper" | ||
tokenfactorybindings "github.com/terra-money/core/v2/x/tokenfactory/bindings" | ||
tokenfactorykeeper "github.com/terra-money/core/v2/x/tokenfactory/keeper" | ||
"strings" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
type Querier func(ctx sdk.Context, request json.RawMessage) ([]byte, error) | ||
|
||
func CustomQueriers(queriers ...Querier) func(ctx sdk.Context, request json.RawMessage) ([]byte, error) { | ||
return func(ctx sdk.Context, request json.RawMessage) ([]byte, error) { | ||
for _, querier := range queriers { | ||
res, err := querier(ctx, request) | ||
if err == nil || !strings.Contains(err.Error(), "unknown query") { | ||
return res, err | ||
} | ||
} | ||
return nil, fmt.Errorf("unknown query") | ||
} | ||
} | ||
|
||
func RegisterCustomPlugins( | ||
bank *bankkeeper.BaseKeeper, | ||
tokenFactory *tokenfactorykeeper.Keeper, | ||
allianceKeeper *alliancekeeper.Keeper, | ||
) []wasmkeeper.Option { | ||
tfQuerier := tokenfactorybindings.CustomQuerier(tokenfactorybindings.NewQueryPlugin(bank, tokenFactory)) | ||
allianceQuerier := alliancebindings.CustomQuerier(alliancebindings.NewAllianceQueryPlugin(allianceKeeper)) | ||
queriers := CustomQueriers(tfQuerier, allianceQuerier) | ||
|
||
queryPluginOpt := wasmkeeper.WithQueryPlugins(&wasmkeeper.QueryPlugins{ | ||
Custom: queriers, | ||
}) | ||
messengerDecoratorOpt := wasmkeeper.WithMessageHandlerDecorator( | ||
tokenfactorybindings.CustomMessageDecorator(bank, tokenFactory), | ||
) | ||
|
||
return []wasm.Option{ | ||
queryPluginOpt, | ||
messengerDecoratorOpt, | ||
} | ||
} |
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 |
---|---|---|
@@ -1,34 +1,2 @@ | ||
package bindings | ||
|
||
import ( | ||
"github.com/CosmWasm/wasmd/x/wasm" | ||
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" | ||
alliancebindings "github.com/terra-money/alliance/x/alliance/bindings" | ||
alliancekeeper "github.com/terra-money/alliance/x/alliance/keeper" | ||
tokenfactorykeeper "github.com/terra-money/core/v2/x/tokenfactory/keeper" | ||
wasm2 "github.com/terra-money/core/v2/x/wasm" | ||
|
||
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" | ||
) | ||
|
||
func RegisterCustomPlugins( | ||
bank *bankkeeper.BaseKeeper, | ||
tokenFactory *tokenfactorykeeper.Keeper, | ||
allianceKeeper *alliancekeeper.Keeper, | ||
) []wasmkeeper.Option { | ||
tfQuerier := CustomQuerier(NewQueryPlugin(bank, tokenFactory)) | ||
allianceQuerier := alliancebindings.CustomQuerier(alliancebindings.NewAllianceQueryPlugin(allianceKeeper)) | ||
queriers := wasm2.CustomQueriers(tfQuerier, allianceQuerier) | ||
|
||
queryPluginOpt := wasmkeeper.WithQueryPlugins(&wasmkeeper.QueryPlugins{ | ||
Custom: queriers, | ||
}) | ||
messengerDecoratorOpt := wasmkeeper.WithMessageHandlerDecorator( | ||
CustomMessageDecorator(bank, tokenFactory), | ||
) | ||
|
||
return []wasm.Option{ | ||
queryPluginOpt, | ||
messengerDecoratorOpt, | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.