Skip to content

Commit

Permalink
Add proto structures and serde tools (#8)
Browse files Browse the repository at this point in the history
* Add proto structures and serde tools

* Add burn queries for wasm interaction

* Add comments regarding proto generation

* Fixed shim proto comment

* fix proto tag

* Regenerated protos for our cosmos sdk 0.47.5 and coreum with our new protobuf generator

* Remove tendermint_proto not supported

* Adding documentation regarding protobuf generation for the types
  • Loading branch information
keyleu authored Sep 20, 2023
1 parent a034bc4 commit 0672db1
Show file tree
Hide file tree
Showing 37 changed files with 10,346 additions and 5 deletions.
17 changes: 12 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
[package]
name = "coreum-wasm-sdk"
version = "0.1.4"
version = "0.2.0"
edition = "2021"
description = "SDK for WASM coreum messages and queries."
homepage = "https://coreum.com/"
license = "Apache-2.0"

[dependencies]
cosmwasm-std = "1.2.6"
serde = { version = "1.0.164", default-features = false, features = ["derive"] }
schemars = "0.8.12"
cosmwasm-schema = "1.2.6"
cosmwasm-std = { version = "1.4.0", features = ["stargate"] }
serde = { version = "1.0.188", default-features = false, features = ["derive"] }
schemars = "0.8.13"
cosmwasm-schema = "1.4.0"
osmosis-std-derive = "0.16.2"
chrono = { version = "0.4.30", default-features = false }
prost = { version = "0.11.0", default-features = false, features = [
"prost-derive",
] }
prost-types = { version = "0.12.0", default-features = false }
serde-cw-value = "0.7.0"
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# Coreum WASM SDK

[![coreum-wasm-sdk on crates.io](https://img.shields.io/crates/v/coreum-wasm-sdk.svg)](https://crates.io/crates/coreum-wasm-sdk) [![Docs](https://docs.rs/coreum-wasm-sdk/badge.svg)](https://docs.rs/coreum-wasm-sdk)

Coreum WASM SDK contains Rust data types to be used in WASM smart contracts interacting with the Coreum blockchain.
They allow developers to issue and execute on-chain messages managing Smart Tokens.

## Proto types

The proto types are generated using [coreum-rust-protobuf](https://github.com/CoreumFoundation/coreum-rust-protobuf) according to our current version of the chain to make them compatible with tools like our [coreum-test-tube](https://github.com/CoreumFoundation/test-tube) or to interact with our chain using gRPC and Rust, they should not be manually modified. Instructions on how to use the tool are in [coreum-rust-protobuf](https://github.com/CoreumFoundation/coreum-rust-protobuf) and can be used to generate any Rust protobuf types for any version of our chain.

## Useful links

- [Coreum Website](https://coreum.com)
Expand Down
25 changes: 25 additions & 0 deletions src/assetnft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ pub struct WhitelistedAccountsForNFTResponse {
pub accounts: Vec<String>,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct BurntNFTResponse {
pub burnt: bool,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct BurntNFTsInClassResponse {
pub pagination: PageResponse,
pub nft_ids: Vec<String>,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub enum Msg {
IssueClass {
Expand Down Expand Up @@ -143,4 +156,16 @@ pub enum Query {
id: String,
class_id: String,
},

#[returns(BurntNFTResponse)]
BurntNFT {
class_id: String,
nft_id: String,
},

#[returns(BurntNFTsInClassResponse)]
BurntNFTsInClass {
pagination: Option<PageRequest>,
class_id: String,
},
}
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ pub mod assetnft;
pub mod core;
pub mod nft;
pub mod pagination;
#[allow(unused_imports, unused_variables)]
pub mod shim;
#[allow(deprecated)]
pub mod types;
mod serde;
22 changes: 22 additions & 0 deletions src/serde/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
pub mod as_str {
use serde::{de, Deserialize, Deserializer, Serializer};
use std::{fmt::Display, str::FromStr};

pub fn deserialize<'de, T, D>(deserializer: D) -> Result<T, D::Error>
where
T: FromStr,
T::Err: Display,
D: Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
T::from_str(&s).map_err(de::Error::custom)
}

pub fn serialize<S, T>(value: &T, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
T: Display,
{
serializer.serialize_str(&value.to_string())
}
}
Loading

0 comments on commit 0672db1

Please sign in to comment.