-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
10 changed files
with
519 additions
and
10 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
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use std::{ | ||
collections::HashMap, | ||
fmt::{self, Display}, | ||
}; | ||
|
||
use cosmwasm_std::{Binary, Coin, CustomQuery, Deps, DepsMut, Env, MessageInfo, Response, Uint128}; | ||
use cw_multi_test::ContractWrapper; | ||
use schemars::JsonSchema; | ||
use serde::de::DeserializeOwned; | ||
|
||
type ContractFn<T, C, E, Q> = | ||
fn(deps: DepsMut<Q>, env: Env, info: MessageInfo, msg: T) -> Result<Response<C>, E>; | ||
|
||
type QueryFn<T, E, Q> = fn(deps: Deps<Q>, env: Env, msg: T) -> Result<Binary, E>; | ||
|
||
pub fn create_code< | ||
T1: DeserializeOwned + fmt::Debug + 'static, | ||
T2: DeserializeOwned + 'static, | ||
T3: DeserializeOwned + 'static, | ||
C: Clone + fmt::Debug + PartialEq + JsonSchema + 'static, | ||
E1: Display + fmt::Debug + Send + Sync + 'static, | ||
E2: Display + fmt::Debug + Send + Sync + 'static, | ||
E3: Display + fmt::Debug + Send + Sync + 'static, | ||
Q: CustomQuery + DeserializeOwned + 'static, | ||
>( | ||
instantiate: ContractFn<T2, C, E2, Q>, | ||
execute: ContractFn<T1, C, E1, Q>, | ||
query: QueryFn<T3, E3, Q>, | ||
) -> Box<ContractWrapper<T1, T2, T3, E1, E2, E3, C, Q>> { | ||
let contract: ContractWrapper<T1, T2, T3, E1, E2, E3, C, Q> = | ||
ContractWrapper::new(execute, instantiate, query); | ||
|
||
Box::new(contract) | ||
} | ||
|
||
pub trait MergeCoin { | ||
fn merge(self) -> Vec<Coin>; | ||
} | ||
|
||
impl MergeCoin for Vec<Coin> { | ||
fn merge(self) -> Vec<Coin> { | ||
let mut map: HashMap<String, Uint128> = HashMap::new(); | ||
|
||
for i in self { | ||
if let Some(val) = map.get_mut(&i.denom) { | ||
*val += i.amount | ||
} else { | ||
map.insert(i.denom.to_string(), i.amount); | ||
} | ||
} | ||
|
||
map.into_iter() | ||
.map(|(denom, amount)| Coin::new(amount.into(), denom)) | ||
.collect() | ||
} | ||
} |
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,33 @@ | ||
use cosmwasm_std::{ | ||
entry_point, Binary, Deps, DepsMut, Empty, Env, MessageInfo, Response, StdResult, | ||
}; | ||
use cw721_base::{ContractError, Cw721Contract, ExecuteMsg, InstantiateMsg, QueryMsg}; | ||
use rhaki_cw_plus::serde_value::StdValue as Value; | ||
|
||
#[entry_point] | ||
pub fn instantiate( | ||
deps: DepsMut, | ||
env: Env, | ||
info: MessageInfo, | ||
msg: InstantiateMsg, | ||
) -> StdResult<Response> { | ||
let tract = Cw721Contract::<Value, Empty, Empty, Empty>::default(); | ||
tract.instantiate(deps, env, info, msg) | ||
} | ||
|
||
#[entry_point] | ||
pub fn execute( | ||
deps: DepsMut, | ||
env: Env, | ||
info: MessageInfo, | ||
msg: ExecuteMsg<Value, Empty>, | ||
) -> Result<Response, ContractError> { | ||
let tract = Cw721Contract::<Value, Empty, Empty, Empty>::default(); | ||
tract.execute(deps, env, info, msg) | ||
} | ||
|
||
#[entry_point] | ||
pub fn query(deps: Deps, env: Env, msg: QueryMsg<Empty>) -> StdResult<Binary> { | ||
let tract = Cw721Contract::<Value, Empty, Empty, Empty>::default(); | ||
tract.query(deps, env, msg) | ||
} |
Oops, something went wrong.