Skip to content

Commit

Permalink
feat(logic): introduce logic module bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Feb 7, 2023
1 parent 22f4089 commit 465a4fe
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 1 deletion.
9 changes: 9 additions & 0 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["contracts/*"]
members = ["contracts/*", "packages/*"]

[workspace.dependencies]
cosmwasm-schema = "1.2.1"
Expand Down
10 changes: 10 additions & 0 deletions packages/logic-bindings/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
authors = ["OKP4"]
edition = "2021"
name = "logic-bindings"
version = "0.2.0"

[dependencies]
cosmwasm-std.workspace = true
schemars.workspace = true
serde.workspace = true
3 changes: 3 additions & 0 deletions packages/logic-bindings/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# CW Logic Sample

Sample contract to query the okp4 logic module.
3 changes: 3 additions & 0 deletions packages/logic-bindings/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod query;

pub use query::{LogicCustomQuery, AskResponse, Answer, Result, Substitution, Term};
51 changes: 51 additions & 0 deletions packages/logic-bindings/src/query.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use cosmwasm_std::CustomQuery;
use serde::{Deserialize, Serialize};
use schemars::JsonSchema;

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum LogicCustomQuery {
Ask {
program: String,
query: String,
},
}

impl CustomQuery for LogicCustomQuery {}

#[derive(Serialize, Deserialize, Default, Clone, PartialEq, Eq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub struct AskResponse {
pub height: u64,
pub gas_used: u64,
pub answer: Option<Answer>,
}

#[derive(Serialize, Deserialize, Default, Clone, PartialEq, Eq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub struct Answer {
pub success: bool,
pub has_more: bool,
pub variables: Vec<String>,
pub results: Vec<Result>,
}

#[derive(Serialize, Deserialize, Default, Clone, PartialEq, Eq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub struct Result {
pub substitutions: Vec<Substitution>,
}

#[derive(Serialize, Deserialize, Default, Clone, PartialEq, Eq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub struct Substitution {
pub variable: String,
pub term: Term,
}

#[derive(Serialize, Deserialize, Default, Clone, PartialEq, Eq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub struct Term {
pub name: String,
pub arguments: Vec<Term>,
}

0 comments on commit 465a4fe

Please sign in to comment.