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

Use Cw20 token in cw4-stake #282

Merged
merged 6 commits into from
Apr 26, 2021
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
14 changes: 9 additions & 5 deletions contracts/cw4-stake/examples/schema.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
use std::env::current_dir;
use std::fs::create_dir_all;

use cosmwasm_schema::{export_schema, export_schema_with_title, remove_schemas, schema_for};
use cosmwasm_schema::{export_schema, remove_schemas, schema_for};

pub use cw4::{AdminResponse, MemberListResponse, MemberResponse, TotalWeightResponse};
pub use cw4_stake::msg::{ClaimsResponse, ExecuteMsg, InstantiateMsg, QueryMsg, StakedResponse};
pub use cw4_stake::msg::{
ClaimsResponse, ExecuteMsg, InstantiateMsg, QueryMsg, ReceiveMsg, StakedResponse,
};

fn main() {
let mut out_dir = current_dir().unwrap();
out_dir.push("schema");
create_dir_all(&out_dir).unwrap();
remove_schemas(&out_dir).unwrap();

export_schema_with_title(&mut schema_for!(InstantiateMsg), &out_dir, "InstantiateMsg");
export_schema_with_title(&mut schema_for!(ExecuteMsg), &out_dir, "ExecuteMsg");
export_schema_with_title(&mut schema_for!(QueryMsg), &out_dir, "QueryMsg");
export_schema(&schema_for!(InstantiateMsg), &out_dir);
export_schema(&schema_for!(ExecuteMsg), &out_dir);
export_schema(&schema_for!(QueryMsg), &out_dir);
export_schema(&schema_for!(ReceiveMsg), &out_dir);

export_schema(&schema_for!(AdminResponse), &out_dir);
export_schema(&schema_for!(MemberListResponse), &out_dir);
export_schema(&schema_for!(MemberResponse), &out_dir);
Expand Down
37 changes: 37 additions & 0 deletions contracts/cw4-stake/schema/execute_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,46 @@
}
},
"additionalProperties": false
},
{
"description": "This accepts a properly-encoded ReceiveMsg from a cw20 contract",
"type": "object",
"required": [
"receive"
],
"properties": {
"receive": {
"$ref": "#/definitions/Cw20ReceiveMsg"
}
},
"additionalProperties": false
}
],
"definitions": {
"Binary": {
"description": "Binary is a wrapper around Vec<u8> to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec<u8>",
"type": "string"
},
"Cw20ReceiveMsg": {
"description": "Cw20ReceiveMsg should be de/serialized under `Receive()` variant in a ExecuteMsg",
"type": "object",
"required": [
"amount",
"msg",
"sender"
],
"properties": {
"amount": {
"$ref": "#/definitions/Uint128"
},
"msg": {
"$ref": "#/definitions/Binary"
},
"sender": {
"type": "string"
}
}
},
"Uint128": {
"type": "string"
}
Expand Down
19 changes: 19 additions & 0 deletions contracts/cw4-stake/schema/receive_msg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "ReceiveMsg",
"anyOf": [
{
"description": "Only valid cw20 message is to bond the tokens",
"type": "object",
"required": [
"bond"
],
"properties": {
"bond": {
"type": "object"
}
},
"additionalProperties": false
}
]
}
47 changes: 34 additions & 13 deletions contracts/cw4-stake/schema/staked_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,49 @@
"title": "StakedResponse",
"type": "object",
"required": [
"denom",
"stake"
],
"properties": {
"denom": {
"$ref": "#/definitions/Denom"
},
"stake": {
"$ref": "#/definitions/Coin"
"$ref": "#/definitions/Uint128"
}
},
"definitions": {
"Coin": {
"type": "object",
"required": [
"amount",
"denom"
],
"properties": {
"amount": {
"$ref": "#/definitions/Uint128"
"Addr": {
"description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.",
"type": "string"
},
"Denom": {
"anyOf": [
{
"type": "object",
"required": [
"native"
],
"properties": {
"native": {
"type": "string"
}
},
"additionalProperties": false
},
"denom": {
"type": "string"
{
"type": "object",
"required": [
"cw20"
],
"properties": {
"cw20": {
"$ref": "#/definitions/Addr"
}
},
"additionalProperties": false
}
}
]
},
"Uint128": {
"type": "string"
Expand Down
Loading