Skip to content

Commit

Permalink
Merge pull request #282 from CosmWasm/cw20-token-in-cw4-stake
Browse files Browse the repository at this point in the history
Use Cw20 token in cw4-stake
  • Loading branch information
ethanfrey authored Apr 26, 2021
2 parents e92b6a5 + 078b7f2 commit 475d5b5
Show file tree
Hide file tree
Showing 7 changed files with 284 additions and 61 deletions.
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

0 comments on commit 475d5b5

Please sign in to comment.