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

fix: refining ext and test contract #35

Merged
merged 18 commits into from
Dec 29, 2020
Merged
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions contracts/collection-tester/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 25 additions & 2 deletions contracts/collection-tester/schema/query_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@
{
"type": "object",
"required": [
"get_nft"
"get_nft_count"
],
"properties": {
"get_nft": {
"get_nft_count": {
"type": "object",
"required": [
"contract_id",
Expand Down Expand Up @@ -262,6 +262,29 @@
}
}
}
},
{
"type": "object",
"required": [
"get_approvers"
],
"properties": {
"get_approvers": {
"type": "object",
"required": [
"contract_id",
"proxy"
],
"properties": {
"contract_id": {
"type": "string"
},
"proxy": {
"$ref": "#/definitions/HumanAddr"
}
}
}
}
}
],
"definitions": {
Expand Down
50 changes: 39 additions & 11 deletions contracts/collection-tester/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,11 @@ pub fn query<S: Storage, A: Api, Q: Querier>(
token_id,
} => query_token(deps, contract_id, token_id),
QueryMsg::GetTokens { contract_id } => query_tokens(deps, contract_id),
QueryMsg::GetNft {
QueryMsg::GetNftCount {
contract_id,
token_id,
target,
} => query_nft(deps, contract_id, token_id, target),
} => query_nft_count(deps, contract_id, token_id, target),
QueryMsg::GetTotal {
contract_id,
token_id,
Expand All @@ -233,7 +233,8 @@ pub fn query<S: Storage, A: Api, Q: Querier>(
contract_id,
proxy,
approver,
} => query_approved(deps, contract_id, proxy, approver),
} => query_is_approved(deps, contract_id, proxy, approver),
QueryMsg::GetApprovers { proxy, contract_id } => query_approvers(deps, proxy, contract_id),
}
}

Expand Down Expand Up @@ -1048,7 +1049,7 @@ fn query_tokens<S: Storage, A: Api, Q: Querier>(
Ok(out)
}

fn query_nft<S: Storage, A: Api, Q: Querier>(
fn query_nft_count<S: Storage, A: Api, Q: Querier>(
deps: &Extern<S, A, Q>,
contract_id: String,
token_id: String,
Expand Down Expand Up @@ -1077,11 +1078,25 @@ fn query_total<S: Storage, A: Api, Q: Querier>(
target_str: String,
) -> StdResult<Binary> {
let target = Target::from_str(&target_str).unwrap();
let res = LinkCollectionQuerier::new(&deps.querier)
.query_supply(contract_id, token_id, target)
.unwrap();
let out = to_binary(&res)?;
Ok(out)
if Target::Supply == target {
let res = LinkCollectionQuerier::new(&deps.querier)
.query_supply(contract_id, token_id)
.unwrap();
let out = to_binary(&res)?;
Ok(out)
} else if Target::Mint == target {
let res = LinkCollectionQuerier::new(&deps.querier)
.query_mint(contract_id, token_id)
.unwrap();
let out = to_binary(&res)?;
Ok(out)
} else {
let res = LinkCollectionQuerier::new(&deps.querier)
.query_burn(contract_id, token_id)
.unwrap();
let out = to_binary(&res)?;
Ok(out)
}
}

fn query_root_or_parent_or_children<S: Storage, A: Api, Q: Querier>(
Expand Down Expand Up @@ -1123,15 +1138,28 @@ fn query_perms<S: Storage, A: Api, Q: Querier>(
Ok(out)
}

fn query_approved<S: Storage, A: Api, Q: Querier>(
fn query_is_approved<S: Storage, A: Api, Q: Querier>(
deps: &Extern<S, A, Q>,
contract_id: String,
proxy: HumanAddr,
approver: HumanAddr,
) -> StdResult<Binary> {
let res = LinkCollectionQuerier::new(&deps.querier)
.query_approved(contract_id, proxy, approver)
.query_is_approved(contract_id, proxy, approver)
.unwrap();
let out = to_binary(&res)?;
Ok(out)
}

fn query_approvers<S: Storage, A: Api, Q: Querier>(
deps: &Extern<S, A, Q>,
proxy: HumanAddr,
contract_id: String,
) -> StdResult<Binary> {
let res = match LinkCollectionQuerier::new(&deps.querier).query_approvers(proxy, contract_id)? {
Some(approvers) => approvers,
None => return to_binary(&None::<Box<Vec<HumanAddr>>>),
};
let out = to_binary(&res)?;
Ok(out)
}
6 changes: 5 additions & 1 deletion contracts/collection-tester/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ pub enum QueryMsg {
GetTokens {
contract_id: String,
},
GetNft {
GetNftCount {
contract_id: String,
token_id: String,
target: String,
Expand All @@ -196,4 +196,8 @@ pub enum QueryMsg {
proxy: HumanAddr,
approver: HumanAddr,
},
GetApprovers {
proxy: HumanAddr,
contract_id: String,
},
}
1 change: 1 addition & 0 deletions contracts/token-tester/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion contracts/token-tester/schema/handle_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,22 @@
"type": "object",
"required": [
"contract_id",
"owner"
"key",
"owner",
"value"
],
"properties": {
"contract_id": {
"type": "string"
},
"key": {
"type": "string"
},
"owner": {
"$ref": "#/definitions/HumanAddr"
},
"value": {
"type": "string"
}
}
}
Expand Down
39 changes: 30 additions & 9 deletions contracts/token-tester/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ pub fn handle<S: Storage, A: Api, Q: Querier>(
contract_id,
permission,
} => try_revoke_perm(deps, env, from, contract_id, permission),
HandleMsg::Modify { owner, contract_id } => try_modify(deps, env, owner, contract_id),
HandleMsg::Modify {
owner,
contract_id,
key,
value,
} => try_modify(deps, env, owner, contract_id, key, value),
HandleMsg::Approve {
approver,
contract_id,
Expand All @@ -109,7 +114,7 @@ pub fn query<S: Storage, A: Api, Q: Querier>(
QueryMsg::GetTotal {
contract_id,
target,
} => query_supply(deps, contract_id, target),
} => query_total(deps, contract_id, target),
QueryMsg::GetPerm {
contract_id,
address,
Expand Down Expand Up @@ -384,8 +389,10 @@ pub fn try_modify<S: Storage, A: Api, Q: Querier>(
_env: Env,
owner: HumanAddr,
contract_id: String,
key: String,
value: String,
) -> HandleResult<LinkMsgWrapper<TokenRoute, TokenMsg>> {
let change = Change::new("meta".to_string(), "update_token_meta".to_string());
let change = Change::new(key, value);
let msg: CosmosMsg<LinkMsgWrapper<TokenRoute, TokenMsg>> = LinkMsgWrapper {
module: Module::Tokenencode,
msg_data: MsgData {
Expand Down Expand Up @@ -459,17 +466,31 @@ fn query_balance<S: Storage, A: Api, Q: Querier>(
Ok(out)
}

fn query_supply<S: Storage, A: Api, Q: Querier>(
fn query_total<S: Storage, A: Api, Q: Querier>(
deps: &Extern<S, A, Q>,
contract_id: String,
target_str: String,
) -> StdResult<Binary> {
let target = Target::from_str(&target_str).unwrap();
let res = LinkTokenQuerier::new(&deps.querier)
.query_supply(contract_id, target)
.unwrap();
let out = to_binary(&res)?;
Ok(out)
if Target::Supply == target {
let res = LinkTokenQuerier::new(&deps.querier)
.query_supply(contract_id)
.unwrap();
let out = to_binary(&res)?;
Ok(out)
} else if Target::Mint == target {
let res = LinkTokenQuerier::new(&deps.querier)
.query_mint(contract_id)
.unwrap();
let out = to_binary(&res)?;
Ok(out)
} else {
let res = LinkTokenQuerier::new(&deps.querier)
.query_burn(contract_id)
.unwrap();
let out = to_binary(&res)?;
Ok(out)
}
}

fn query_perm<S: Storage, A: Api, Q: Querier>(
Expand Down
2 changes: 2 additions & 0 deletions contracts/token-tester/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ pub enum HandleMsg {
Modify {
owner: HumanAddr,
contract_id: String,
key: String,
value: String,
},
Approve {
approver: HumanAddr,
Expand Down
1 change: 1 addition & 0 deletions packages/ext/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ readme = "README.md"
cosmwasm-std = { path = "../std", version = "0.10.0" }
schemars = "0.7"
serde = { version = "1.0.103", default-features = false, features = ["derive", "alloc"] }
serde_json = "1.0"

[dev-dependencies]
cosmwasm-schema = { path = "../schema" }
Original file line number Diff line number Diff line change
Expand Up @@ -670,10 +670,10 @@
},
"permission": {
"enum": [
"Mint",
"Burn",
"Issue",
"Modify"
"mint",
"burn",
"issue",
"modify"
]
}
}
Expand Down
Loading