Skip to content

Commit

Permalink
Merge pull request #1339 from CosmWasm/idl-ux
Browse files Browse the repository at this point in the history
Better UX for defining query response types and schema generation
  • Loading branch information
uint authored Jul 11, 2022
2 parents 0f90b99 + 4e0985a commit c42ded7
Show file tree
Hide file tree
Showing 33 changed files with 894 additions and 498 deletions.
32 changes: 32 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ workflows:
- arm64
- package_crypto
- package_schema
- package_schema_derive
- package_std
- package_storage
- package_vm
Expand Down Expand Up @@ -186,6 +187,33 @@ jobs:
- target/debug/deps
key: cargocache-v2-package_schema-rust:1.56.1-{{ checksum "Cargo.lock" }}

package_schema_derive:
docker:
- image: rust:1.56.1
steps:
- checkout
- run:
name: Version information
command: rustc --version; cargo --version; rustup --version; rustup target list --installed
- restore_cache:
keys:
- cargocache-v2-package_schema_derive-rust:1.56.1-{{ checksum "Cargo.lock" }}
- run:
name: Build
working_directory: ~/project/packages/schema-derive
command: cargo build --locked
- run:
name: Run tests
working_directory: ~/project/packages/schema-derive
command: cargo test --locked
- save_cache:
paths:
- /usr/local/cargo/registry
- target/debug/.fingerprint
- target/debug/build
- target/debug/deps
key: cargocache-v2-package_schema_derive-rust:1.56.1-{{ checksum "Cargo.lock" }}

package_std:
docker:
- image: rust:1.56.1
Expand Down Expand Up @@ -938,6 +966,10 @@ jobs:
name: Clippy linting on schema
working_directory: ~/project/packages/schema
command: cargo clippy --all-targets -- -D warnings
- run:
name: Clippy linting on schema-derive
working_directory: ~/project/packages/schema-derive
command: cargo clippy --all-targets -- -D warnings
- run:
name: Clippy linting on std (no feature flags)
working_directory: ~/project/packages/std
Expand Down
11 changes: 11 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ flags:
cosmwasm-schema:
paths:
- packages/schema/
cosmwasm-schema-derive:
paths:
- packages/schema-derive/
cosmwasm-std:
paths:
- packages/std/
Expand Down
10 changes: 10 additions & 0 deletions contracts/burner/Cargo.lock

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

10 changes: 10 additions & 0 deletions contracts/crypto-verify/Cargo.lock

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

10 changes: 10 additions & 0 deletions contracts/floaty/Cargo.lock

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

10 changes: 10 additions & 0 deletions contracts/hackatom/Cargo.lock

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

2 changes: 1 addition & 1 deletion contracts/hackatom/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ cranelift = ["cosmwasm-vm/cranelift"]
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]

[dependencies]
cosmwasm-schema = { path = "../../packages/schema" }
cosmwasm-std = { path = "../../packages/std", default-features = false, features = ["abort"] }
rust-argon2 = "0.8"
schemars = "0.8.1"
Expand All @@ -39,6 +40,5 @@ sha2 = "0.9.1"
thiserror = "1.0"

[dev-dependencies]
cosmwasm-schema = { path = "../../packages/schema" }
cosmwasm-storage = { path = "../../packages/storage", default-features = false }
cosmwasm-vm = { path = "../../packages/vm", default-features = false }
59 changes: 8 additions & 51 deletions contracts/hackatom/examples/schema.rs
Original file line number Diff line number Diff line change
@@ -1,56 +1,13 @@
use std::collections::BTreeMap;
use std::env::current_dir;
use std::fs::{create_dir_all, write};
use cosmwasm_schema::write_api;

use cosmwasm_schema::{export_schema, remove_schemas, schema_for, Api};
use cosmwasm_std::{AllBalanceResponse, BalanceResponse};

use hackatom::msg::{
ExecuteMsg, InstantiateMsg, IntResponse, MigrateMsg, QueryMsg, RecurseResponse, SudoMsg,
VerifierResponse,
};
use hackatom::state::State;
use hackatom::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, SudoMsg};

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

// messages
export_schema(&schema_for!(InstantiateMsg), &out_dir);
export_schema(&schema_for!(ExecuteMsg), &out_dir);
export_schema(&schema_for!(MigrateMsg), &out_dir);
export_schema(&schema_for!(SudoMsg), &out_dir);
export_schema(&schema_for!(QueryMsg), &out_dir);
export_schema(&schema_for!(VerifierResponse), &out_dir);
export_schema(&schema_for!(BalanceResponse), &out_dir);

// state
export_schema(&schema_for!(State), &out_dir);

let contract_name = env!("CARGO_PKG_NAME");
let contract_version = env!("CARGO_PKG_VERSION");

// The new IDL
let path = out_dir.join(format!("{}.json", contract_name));
let api = Api {
contract_name: contract_name.to_string(),
contract_version: contract_version.to_string(),
instantiate: schema_for!(InstantiateMsg),
execute: Some(schema_for!(ExecuteMsg)),
query: Some(schema_for!(QueryMsg)),
migrate: Some(schema_for!(MigrateMsg)),
sudo: Some(schema_for!(SudoMsg)),
responses: BTreeMap::from([
("verifier".to_string(), schema_for!(VerifierResponse)),
("other_balance".to_string(), schema_for!(AllBalanceResponse)),
("recurse".to_string(), schema_for!(RecurseResponse)),
("get_int".to_string(), schema_for!(IntResponse)),
]),
write_api! {
instantiate: InstantiateMsg,
query: QueryMsg,
execute: ExecuteMsg,
sudo: SudoMsg,
migrate: MigrateMsg,
}
.render();
let json = api.to_string().unwrap();
write(&path, json + "\n").unwrap();
println!("Exported the full API as {}", path.to_str().unwrap());
}
39 changes: 0 additions & 39 deletions contracts/hackatom/schema/balance_response.json

This file was deleted.

Loading

0 comments on commit c42ded7

Please sign in to comment.