Skip to content

Commit

Permalink
Update schema
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed Jul 28, 2020
1 parent 34f23c9 commit e89d9e6
Show file tree
Hide file tree
Showing 4 changed files with 262 additions and 3 deletions.
5 changes: 4 additions & 1 deletion contracts/cw1-subkeys/examples/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use std::fs::create_dir_all;

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

use cw1_subkeys::msg::{ConfigResponse, HandleMsg, InitMsg, QueryMsg};
use cw1_subkeys::msg::{HandleMsg, QueryMsg};
use cw1_subkeys::state::Allowance;
use cw1_whitelist::msg::{ConfigResponse, InitMsg};

fn main() {
let mut out_dir = current_dir().unwrap();
Expand All @@ -14,5 +16,6 @@ fn main() {
export_schema(&schema_for!(InitMsg), &out_dir);
export_schema(&schema_for!(HandleMsg), &out_dir);
export_schema(&schema_for!(QueryMsg), &out_dir);
export_schema(&schema_for!(Allowance), &out_dir);
export_schema(&schema_for!(ConfigResponse), &out_dir);
}
103 changes: 103 additions & 0 deletions contracts/cw1-subkeys/schema/allowance.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Allowance",
"type": "object",
"required": [
"balance",
"expires"
],
"properties": {
"balance": {
"$ref": "#/definitions/Balance"
},
"expires": {
"$ref": "#/definitions/Expiration"
}
},
"definitions": {
"Balance": {
"type": "array",
"items": {
"$ref": "#/definitions/Coin"
}
},
"Coin": {
"type": "object",
"required": [
"amount",
"denom"
],
"properties": {
"amount": {
"$ref": "#/definitions/Uint128"
},
"denom": {
"type": "string"
}
}
},
"Expiration": {
"anyOf": [
{
"description": "AtHeight will expire when `env.block.height` >= height",
"type": "object",
"required": [
"at_height"
],
"properties": {
"at_height": {
"type": "object",
"required": [
"height"
],
"properties": {
"height": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
}
}
}
},
{
"description": "AtTime will expire when `env.block.time` >= time",
"type": "object",
"required": [
"at_time"
],
"properties": {
"at_time": {
"type": "object",
"required": [
"time"
],
"properties": {
"time": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
}
}
}
},
{
"description": "Never will never expire. Used to distinguish None from Some(Expiration::Never)",
"type": "object",
"required": [
"never"
],
"properties": {
"never": {
"type": "object"
}
}
}
]
},
"Uint128": {
"type": "string"
}
}
}
128 changes: 128 additions & 0 deletions contracts/cw1-subkeys/schema/handle_msg_for__empty.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,74 @@
}
}
}
},
{
"description": "Add an allowance to a given subkey (subkey must not be admin)",
"type": "object",
"required": [
"increase_allowance"
],
"properties": {
"increase_allowance": {
"type": "object",
"required": [
"amount",
"spender"
],
"properties": {
"amount": {
"$ref": "#/definitions/Coin"
},
"expires": {
"anyOf": [
{
"$ref": "#/definitions/Expiration"
},
{
"type": "null"
}
]
},
"spender": {
"$ref": "#/definitions/HumanAddr"
}
}
}
}
},
{
"description": "Decreases an allowance for a given subkey (subkey must not be admin)",
"type": "object",
"required": [
"decrease_allowance"
],
"properties": {
"decrease_allowance": {
"type": "object",
"required": [
"amount",
"spender"
],
"properties": {
"amount": {
"$ref": "#/definitions/Coin"
},
"expires": {
"anyOf": [
{
"$ref": "#/definitions/Expiration"
},
{
"type": "null"
}
]
},
"spender": {
"$ref": "#/definitions/HumanAddr"
}
}
}
}
}
],
"definitions": {
Expand Down Expand Up @@ -167,6 +235,66 @@
"description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)",
"type": "object"
},
"Expiration": {
"anyOf": [
{
"description": "AtHeight will expire when `env.block.height` >= height",
"type": "object",
"required": [
"at_height"
],
"properties": {
"at_height": {
"type": "object",
"required": [
"height"
],
"properties": {
"height": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
}
}
}
},
{
"description": "AtTime will expire when `env.block.time` >= time",
"type": "object",
"required": [
"at_time"
],
"properties": {
"at_time": {
"type": "object",
"required": [
"time"
],
"properties": {
"time": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
}
}
}
},
{
"description": "Never will never expire. Used to distinguish None from Some(Expiration::Never)",
"type": "object",
"required": [
"never"
],
"properties": {
"never": {
"type": "object"
}
}
}
]
},
"HumanAddr": {
"type": "string"
},
Expand Down
29 changes: 27 additions & 2 deletions contracts/cw1-subkeys/schema/query_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"title": "QueryMsg",
"anyOf": [
{
"description": "Shows all admins and whether or not it is mutable",
"description": "Shows all admins and whether or not it is mutable Returns cw1-whitelist::ConfigResponse",
"type": "object",
"required": [
"config"
Expand All @@ -13,6 +13,31 @@
"type": "object"
}
}
},
{
"description": "Get the current allowance for the given subkey (how much it can spend) Returns crate::state::Allowance",
"type": "object",
"required": [
"allowance"
],
"properties": {
"allowance": {
"type": "object",
"required": [
"spender"
],
"properties": {
"spender": {
"$ref": "#/definitions/HumanAddr"
}
}
}
}
}
],
"definitions": {
"HumanAddr": {
"type": "string"
}
]
}
}

0 comments on commit e89d9e6

Please sign in to comment.