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

Stargate support #89

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
70 changes: 49 additions & 21 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::gov::Gov;
use crate::ibc::Ibc;
use crate::module::{FailingModule, Module};
use crate::staking::{Distribution, DistributionKeeper, StakeKeeper, Staking, StakingSudo};
use crate::stargate::{Stargate, StargateFailingModule, StargateMsg, StargateQuery};
use crate::transactions::transactional;
use crate::wasm::{ContractData, Wasm, WasmKeeper, WasmSudo};
use crate::{AppBuilder, GovFailingModule, IbcFailingModule};
Expand Down Expand Up @@ -36,6 +37,7 @@ pub type BasicApp<ExecC = Empty, QueryC = Empty> = App<
DistributionKeeper,
IbcFailingModule,
GovFailingModule,
StargateFailingModule,
>;

/// Router is a persisted state. You can query this.
Expand All @@ -52,15 +54,16 @@ pub struct App<
Distr = DistributionKeeper,
Ibc = IbcFailingModule,
Gov = GovFailingModule,
Stargate = StargateFailingModule,
> {
pub(crate) router: Router<Bank, Custom, Wasm, Staking, Distr, Ibc, Gov>,
pub(crate) router: Router<Bank, Custom, Wasm, Staking, Distr, Ibc, Gov, Stargate>,
pub(crate) api: Api,
pub(crate) storage: Storage,
pub(crate) block: BlockInfo,
}

pub fn no_init<BankT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT>(
_: &mut Router<BankT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT>,
pub fn no_init<BankT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT>(
_: &mut Router<BankT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT>,
_: &dyn Api,
_: &mut dyn Storage,
) {
Expand All @@ -85,6 +88,7 @@ impl BasicApp {
DistributionKeeper,
IbcFailingModule,
GovFailingModule,
StargateFailingModule,
>,
&dyn Api,
&mut dyn Storage,
Expand All @@ -109,6 +113,7 @@ where
DistributionKeeper,
IbcFailingModule,
GovFailingModule,
StargateFailingModule,
>,
&dyn Api,
&mut dyn Storage,
Expand All @@ -117,8 +122,8 @@ where
AppBuilder::new_custom().build(init_fn)
}

impl<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT> Querier
for App<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT>
impl<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT> Querier
for App<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT>
where
CustomT::ExecT: Clone + Debug + PartialEq + JsonSchema + DeserializeOwned + 'static,
CustomT::QueryT: CustomQuery + DeserializeOwned + 'static,
Expand All @@ -131,6 +136,7 @@ where
DistrT: Distribution,
IbcT: Ibc,
GovT: Gov,
StargateT: Stargate,
{
fn raw_query(&self, bin_request: &[u8]) -> QuerierResult {
self.router
Expand All @@ -139,8 +145,9 @@ where
}
}

impl<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT> Executor<CustomT::ExecT>
for App<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT>
impl<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT>
Executor<CustomT::ExecT>
for App<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT>
where
CustomT::ExecT: Clone + Debug + PartialEq + JsonSchema + DeserializeOwned + 'static,
CustomT::QueryT: CustomQuery + DeserializeOwned + 'static,
Expand All @@ -153,6 +160,7 @@ where
DistrT: Distribution,
IbcT: Ibc,
GovT: Gov,
StargateT: Stargate,
{
fn execute(&mut self, sender: Addr, msg: CosmosMsg<CustomT::ExecT>) -> AnyResult<AppResponse> {
let mut all = self.execute_multi(sender, vec![msg])?;
Expand All @@ -161,8 +169,8 @@ where
}
}

impl<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT>
App<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT>
impl<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT>
App<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT>
where
WasmT: Wasm<CustomT::ExecT, CustomT::QueryT>,
BankT: Bank,
Expand All @@ -173,9 +181,12 @@ where
DistrT: Distribution,
IbcT: Ibc,
GovT: Gov,
StargateT: Stargate,
{
/// Returns a shared reference to application's router.
pub fn router(&self) -> &Router<BankT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT> {
pub fn router(
&self,
) -> &Router<BankT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT> {
&self.router
}

Expand All @@ -197,7 +208,7 @@ where
pub fn init_modules<F, T>(&mut self, init_fn: F) -> T
where
F: FnOnce(
&mut Router<BankT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT>,
&mut Router<BankT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT>,
&dyn Api,
&mut dyn Storage,
) -> T,
Expand All @@ -208,7 +219,7 @@ where
pub fn read_module<F, T>(&self, query_fn: F) -> T
where
F: FnOnce(
&Router<BankT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT>,
&Router<BankT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT>,
&dyn Api,
&dyn Storage,
) -> T,
Expand All @@ -219,8 +230,8 @@ where

// Helper functions to call some custom WasmKeeper logic.
// They show how we can easily add such calls to other custom keepers (CustomT, StakingT, etc)
impl<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT>
App<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT>
impl<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT>
App<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT>
where
BankT: Bank,
ApiT: Api,
Expand All @@ -231,6 +242,7 @@ where
DistrT: Distribution,
IbcT: Ibc,
GovT: Gov,
StargateT: Stargate,
CustomT::ExecT: Clone + Debug + PartialEq + JsonSchema + DeserializeOwned + 'static,
CustomT::QueryT: CustomQuery + DeserializeOwned + 'static,
{
Expand Down Expand Up @@ -318,8 +330,8 @@ where
}
}

impl<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT>
App<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT>
impl<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT>
App<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT>
where
CustomT::ExecT: Debug + PartialEq + Clone + JsonSchema + DeserializeOwned + 'static,
CustomT::QueryT: CustomQuery + DeserializeOwned + 'static,
Expand All @@ -332,6 +344,7 @@ where
DistrT: Distribution,
IbcT: Ibc,
GovT: Gov,
StargateT: Stargate,
{
pub fn set_block(&mut self, block: BlockInfo) {
self.router
Expand Down Expand Up @@ -432,7 +445,7 @@ where
}

#[derive(Clone)]
pub struct Router<Bank, Custom, Wasm, Staking, Distr, Ibc, Gov> {
pub struct Router<Bank, Custom, Wasm, Staking, Distr, Ibc, Gov, Stargate> {
// this can remain crate-only as all special functions are wired up to app currently
// we need to figure out another format for wasm, as some like sudo need to be called after init
pub(crate) wasm: Wasm,
Expand All @@ -443,10 +456,11 @@ pub struct Router<Bank, Custom, Wasm, Staking, Distr, Ibc, Gov> {
pub distribution: Distr,
pub ibc: Ibc,
pub gov: Gov,
pub stargate: Stargate,
}

impl<BankT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT>
Router<BankT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT>
impl<BankT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT>
Router<BankT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT>
where
CustomT::ExecT: Clone + Debug + PartialEq + JsonSchema + DeserializeOwned + 'static,
CustomT::QueryT: CustomQuery + DeserializeOwned + 'static,
Expand All @@ -457,6 +471,7 @@ where
DistrT: Distribution,
IbcT: Ibc,
GovT: Gov,
StargateT: Stargate,
{
pub fn querier<'a>(
&'a self,
Expand Down Expand Up @@ -530,8 +545,8 @@ pub trait CosmosRouter {
) -> AnyResult<AppResponse>;
}

impl<BankT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT> CosmosRouter
for Router<BankT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT>
impl<BankT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT> CosmosRouter
for Router<BankT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT>
where
CustomT::ExecT: Debug + Clone + PartialEq + JsonSchema + DeserializeOwned + 'static,
CustomT::QueryT: CustomQuery + DeserializeOwned + 'static,
Expand All @@ -542,6 +557,7 @@ where
DistrT: Distribution,
IbcT: Ibc,
GovT: Gov,
StargateT: Stargate,
{
type ExecC = CustomT::ExecT;
type QueryC = CustomT::QueryT;
Expand All @@ -564,6 +580,14 @@ where
.execute(api, storage, self, block, sender, msg),
CosmosMsg::Ibc(msg) => self.ibc.execute(api, storage, self, block, sender, msg),
CosmosMsg::Gov(msg) => self.gov.execute(api, storage, self, block, sender, msg),
CosmosMsg::Stargate { type_url, value } => self.stargate.execute(
api,
storage,
self,
block,
sender,
StargateMsg { type_url, value },
),
_ => bail!("Cannot execute {:?}", msg),
}
}
Expand All @@ -585,6 +609,10 @@ where
QueryRequest::Custom(req) => self.custom.query(api, storage, &querier, block, req),
QueryRequest::Staking(req) => self.staking.query(api, storage, &querier, block, req),
QueryRequest::Ibc(req) => self.ibc.query(api, storage, &querier, block, req),
QueryRequest::Stargate { path, data } => {
self.stargate
.query(api, storage, &querier, block, StargateQuery { path, data })
}
_ => unimplemented!(),
}
}
Expand Down
Loading