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

Update erc20 contract to 0.8 #68

Merged
merged 6 commits into from
May 25, 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
282 changes: 121 additions & 161 deletions erc20/Cargo.lock

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions erc20/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,17 @@ overflow-checks = true
default = ["cranelift"]
# for quicker tests, cargo test --lib
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm/backtraces", "cosmwasm-vm/backtraces"]
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]
cranelift = ["cosmwasm-vm/default-cranelift"]
singlepass = ["cosmwasm-vm/default-singlepass"]

[dependencies]
cosmwasm = { version = "0.7.0" }
cw-storage = "0.2.0"
schemars = "=0.5"
serde = { version = "=1.0.103", default-features = false, features = ["derive"] }
snafu = { version = "=0.5.0", default-features = false, features = ["rust_1_30"] }
hex = "=0.4.0"
cosmwasm-std = "0.8.0"
cosmwasm-storage = "0.8.0"
schemars = "0.7"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
hex = "0.4"

[dev-dependencies]
cosmwasm-vm = { version = "0.7.0", default-features = false }
serde_json = "1.0"
cosmwasm-vm = { version = "0.8.0", default-features = false }
cosmwasm-schema = "0.8.0"
32 changes: 3 additions & 29 deletions erc20/examples/schema.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::env::current_dir;
use std::fs::{create_dir_all, write};
use std::path::PathBuf;
use std::fs::create_dir_all;

use schemars::{schema::RootSchema, schema_for};
use cosmwasm_schema::{export_schema, remove_schemas, schema_for};

use cw_erc20::contract::Constants;
use cw_erc20::msg::{AllowanceResponse, BalanceResponse, HandleMsg, InitMsg, QueryMsg};
Expand All @@ -11,6 +10,7 @@ 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(&schema_for!(InitMsg), &out_dir);
export_schema(&schema_for!(HandleMsg), &out_dir);
Expand All @@ -19,29 +19,3 @@ fn main() {
export_schema(&schema_for!(AllowanceResponse), &out_dir);
export_schema(&schema_for!(Constants), &out_dir);
}

/// Writes schema to file. Overwrites existing file.
/// Panics on any error writing out the schema.
fn export_schema(schema: &RootSchema, out_dir: &PathBuf) -> () {
let title = schema
.schema
.metadata
.as_ref()
.map(|b| b.title.clone().unwrap_or("untitled".to_string()))
.unwrap_or("unknown".to_string());
let path = out_dir.join(format!("{}.json", to_snake_case(&title)));
let json = serde_json::to_string_pretty(schema).unwrap();
write(&path, json + "\n").unwrap();
println!("Created {}", path.to_str().unwrap());
}

fn to_snake_case(name: &str) -> String {
let mut out = String::new();
for (index, ch) in name.char_indices() {
if index != 0 && ch.is_uppercase() {
out.push('_');
}
out.push(ch.to_ascii_lowercase());
}
out
}
5 changes: 5 additions & 0 deletions erc20/schema/allowance_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
],
"properties": {
"allowance": {
"$ref": "#/definitions/Uint128"
}
},
"definitions": {
"Uint128": {
"type": "string"
}
}
Expand Down
5 changes: 5 additions & 0 deletions erc20/schema/balance_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
],
"properties": {
"balance": {
"$ref": "#/definitions/Uint128"
}
},
"definitions": {
"Uint128": {
"type": "string"
}
}
Expand Down
11 changes: 7 additions & 4 deletions erc20/schema/handle_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
],
"properties": {
"amount": {
"type": "string"
"$ref": "#/definitions/Uint128"
},
"spender": {
"$ref": "#/definitions/HumanAddr"
Expand All @@ -39,7 +39,7 @@
],
"properties": {
"amount": {
"type": "string"
"$ref": "#/definitions/Uint128"
},
"recipient": {
"$ref": "#/definitions/HumanAddr"
Expand All @@ -63,7 +63,7 @@
],
"properties": {
"amount": {
"type": "string"
"$ref": "#/definitions/Uint128"
},
"owner": {
"$ref": "#/definitions/HumanAddr"
Expand All @@ -88,7 +88,7 @@
],
"properties": {
"amount": {
"type": "string"
"$ref": "#/definitions/Uint128"
}
}
}
Expand All @@ -98,6 +98,9 @@
"definitions": {
"HumanAddr": {
"type": "string"
},
"Uint128": {
"type": "string"
}
}
}
5 changes: 4 additions & 1 deletion erc20/schema/init_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@
"$ref": "#/definitions/HumanAddr"
},
"amount": {
"type": "string"
"$ref": "#/definitions/Uint128"
}
}
},
"Uint128": {
"type": "string"
}
}
}
Loading