-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New
ModuleCallJsonSchema
macro to generate JSON Schemas via `schema…
…rs` (#517) * Introduce `ModuleCallJsonSchema` trait * Refactor `get_generics_type_param` * Add `ModuleInfo` test * Allow `#[derive(ModuleCallJsonSchema)]` * Impl `ModuleCallJsonSchema` for `Bank` * New crate `sov-module-schemas` * `#![deny(missing_docs)]` for `sov_modules_macros` * Improve macro hygiene * Clearer docs on module type generics * ci: run coverage on bigger machine
- Loading branch information
1 parent
836253b
commit 0e35f53
Showing
25 changed files
with
493 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "sov-module-schemas" | ||
description = "A dummy crate that stores as files the JSON Schemas for all Sovereign modules" | ||
authors = { workspace = true } | ||
edition = { workspace = true } | ||
homepage = { workspace = true } | ||
license = { workspace = true } | ||
repository = { workspace = true } | ||
rust-version = { workspace = true } | ||
version = { workspace = true } | ||
readme = "README.md" | ||
resolver = "2" | ||
|
||
[build-dependencies] | ||
sov-modules-api = { path = "../sov-modules-api" } | ||
sov-bank = { path = "../module-implementations/sov-bank" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# `sov-module-schemas` | ||
|
||
This crate is not intended to be used directly, but serves as generated documentation in the form of JSON Schemas for modules built-in into the SDK. The schemas are tracked by `git` to make them linkable and searchable on GitHub. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use std::fs::File; | ||
use std::io::{self, Write}; | ||
|
||
use sov_modules_api::default_context::DefaultContext as C; | ||
use sov_modules_api::ModuleCallJsonSchema; | ||
|
||
fn main() -> io::Result<()> { | ||
store_json_schema::<sov_bank::Bank<C>>("sov-bank.json")?; | ||
Ok(()) | ||
} | ||
|
||
fn store_json_schema<M: ModuleCallJsonSchema>(filename: &str) -> io::Result<()> { | ||
let mut file = File::create(format!("schemas/{}", filename))?; | ||
file.write_all(M::json_schema().as_bytes())?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "CallMessage", | ||
"description": "This enumeration represents the available call messages for interacting with the sov-bank module.", | ||
"oneOf": [ | ||
{ | ||
"description": "Creates a new token with the specified name and initial balance.", | ||
"type": "object", | ||
"required": [ | ||
"CreateToken" | ||
], | ||
"properties": { | ||
"CreateToken": { | ||
"type": "object", | ||
"required": [ | ||
"authorized_minters", | ||
"initial_balance", | ||
"minter_address", | ||
"salt", | ||
"token_name" | ||
], | ||
"properties": { | ||
"authorized_minters": { | ||
"description": "Authorized minter list.", | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/Address" | ||
} | ||
}, | ||
"initial_balance": { | ||
"description": "The initial balance of the new token.", | ||
"type": "integer", | ||
"format": "uint64", | ||
"minimum": 0.0 | ||
}, | ||
"minter_address": { | ||
"description": "The address of the account that the new tokens are minted to.", | ||
"allOf": [ | ||
{ | ||
"$ref": "#/definitions/Address" | ||
} | ||
] | ||
}, | ||
"salt": { | ||
"description": "Random value use to create a unique token address.", | ||
"type": "integer", | ||
"format": "uint64", | ||
"minimum": 0.0 | ||
}, | ||
"token_name": { | ||
"description": "The name of the new token.", | ||
"type": "string" | ||
} | ||
} | ||
} | ||
}, | ||
"additionalProperties": false | ||
}, | ||
{ | ||
"description": "Transfers a specified amount of tokens to the specified address.", | ||
"type": "object", | ||
"required": [ | ||
"Transfer" | ||
], | ||
"properties": { | ||
"Transfer": { | ||
"type": "object", | ||
"required": [ | ||
"coins", | ||
"to" | ||
], | ||
"properties": { | ||
"coins": { | ||
"description": "The amount of tokens to transfer.", | ||
"allOf": [ | ||
{ | ||
"$ref": "#/definitions/Coins" | ||
} | ||
] | ||
}, | ||
"to": { | ||
"description": "The address to which the tokens will be transferred.", | ||
"allOf": [ | ||
{ | ||
"$ref": "#/definitions/Address" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"additionalProperties": false | ||
}, | ||
{ | ||
"description": "Burns a specified amount of tokens.", | ||
"type": "object", | ||
"required": [ | ||
"Burn" | ||
], | ||
"properties": { | ||
"Burn": { | ||
"type": "object", | ||
"required": [ | ||
"coins" | ||
], | ||
"properties": { | ||
"coins": { | ||
"description": "The amount of tokens to burn.", | ||
"allOf": [ | ||
{ | ||
"$ref": "#/definitions/Coins" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"additionalProperties": false | ||
}, | ||
{ | ||
"description": "Mints a specified amount of tokens.", | ||
"type": "object", | ||
"required": [ | ||
"Mint" | ||
], | ||
"properties": { | ||
"Mint": { | ||
"type": "object", | ||
"required": [ | ||
"coins", | ||
"minter_address" | ||
], | ||
"properties": { | ||
"coins": { | ||
"description": "The amount of tokens to mint.", | ||
"allOf": [ | ||
{ | ||
"$ref": "#/definitions/Coins" | ||
} | ||
] | ||
}, | ||
"minter_address": { | ||
"description": "Address to mint tokens to", | ||
"allOf": [ | ||
{ | ||
"$ref": "#/definitions/Address" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"additionalProperties": false | ||
}, | ||
{ | ||
"description": "Freeze a token so that the supply is frozen", | ||
"type": "object", | ||
"required": [ | ||
"Freeze" | ||
], | ||
"properties": { | ||
"Freeze": { | ||
"type": "object", | ||
"required": [ | ||
"token_address" | ||
], | ||
"properties": { | ||
"token_address": { | ||
"description": "Address of the token to be frozen", | ||
"allOf": [ | ||
{ | ||
"$ref": "#/definitions/Address" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"additionalProperties": false | ||
} | ||
], | ||
"definitions": { | ||
"Address": { | ||
"type": "object", | ||
"required": [ | ||
"addr" | ||
], | ||
"properties": { | ||
"addr": { | ||
"type": "array", | ||
"items": { | ||
"type": "integer", | ||
"format": "uint8", | ||
"minimum": 0.0 | ||
}, | ||
"maxItems": 32, | ||
"minItems": 32 | ||
} | ||
} | ||
}, | ||
"Coins": { | ||
"type": "object", | ||
"required": [ | ||
"amount", | ||
"token_address" | ||
], | ||
"properties": { | ||
"amount": { | ||
"type": "integer", | ||
"format": "uint64", | ||
"minimum": 0.0 | ||
}, | ||
"token_address": { | ||
"$ref": "#/definitions/Address" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.