From 0e5f4898b5689173f241b7fc1f29381d31438f3b Mon Sep 17 00:00:00 2001 From: clearloop <26088946+clearloop@users.noreply.github.com> Date: Thu, 22 Feb 2024 12:07:32 +0100 Subject: [PATCH] feat(alpha): add alpha program (#14) * feat(alpha): alpha program * fix(alpha): build problems * feat(prog): state queries --- Cargo.lock | 28 +++++++++++++++++ Cargo.toml | 3 +- alpha/Cargo.toml | 16 ++++++++++ alpha/build.rs | 5 ++++ alpha/io/Cargo.toml | 9 ++++++ alpha/io/src/lib.rs | 68 ++++++++++++++++++++++++++++++++++++++++++ alpha/src/lib.rs | 30 +++++++++++++++++++ alpha/state/Cargo.toml | 13 ++++++++ alpha/state/build.rs | 3 ++ alpha/state/src/lib.rs | 22 ++++++++++++++ alpha/tests/main.rs | 37 +++++++++++++++++++++++ tests/tests.rs | 1 - 12 files changed, 233 insertions(+), 2 deletions(-) create mode 100644 alpha/Cargo.toml create mode 100644 alpha/build.rs create mode 100644 alpha/io/Cargo.toml create mode 100644 alpha/io/src/lib.rs create mode 100644 alpha/src/lib.rs create mode 100644 alpha/state/Cargo.toml create mode 100644 alpha/state/build.rs create mode 100644 alpha/state/src/lib.rs create mode 100644 alpha/tests/main.rs diff --git a/Cargo.lock b/Cargo.lock index 2b65df7..4aca9b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -119,6 +119,24 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" +[[package]] +name = "alpha-io" +version = "0.1.0" +dependencies = [ + "gmeta", + "gstd", +] + +[[package]] +name = "alpha-state" +version = "0.1.0" +dependencies = [ + "alpha-io", + "gear-wasm-builder", + "gmeta", + "gstd", +] + [[package]] name = "android-tzdata" version = "0.1.1" @@ -6262,6 +6280,16 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "vara-go-alpha" +version = "0.1.0" +dependencies = [ + "alpha-io", + "gear-wasm-builder", + "gstd", + "gtest", +] + [[package]] name = "version_check" version = "0.9.4" diff --git a/Cargo.toml b/Cargo.toml index 6ec346b..93e5095 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ tokio.workspace = true # It's necessary to include all metawasm crates in the workspace section, otherwise they'll be # ignored by Cargo and won't be built. [workspace] -members = ["state", "xtask", "domain", "domain/state"] +members = ["state", "xtask", "domain", "domain/state", "alpha", "alpha/state", "alpha/io"] [workspace.dependencies] gstd = "1.1.1" @@ -37,6 +37,7 @@ gear-wasm-builder = "1.1.1" gtest = "1.1.1" gclient = "1.1.1" template-io.path = "io" +alpha-io.path = "alpha/io" tokio = "1" xshell = "0.2" anyhow = "1" diff --git a/alpha/Cargo.toml b/alpha/Cargo.toml new file mode 100644 index 0000000..b022e96 --- /dev/null +++ b/alpha/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "vara-go-alpha" +version.workspace = true +edition.workspace = true +publish.workspace = true + +[dependencies] +gstd.workspace = true +alpha-io.workspace = true + +[dev-dependencies] +gtest.workspace = true + +[build-dependencies] +alpha-io.workspace = true +gear-wasm-builder.workspace = true diff --git a/alpha/build.rs b/alpha/build.rs new file mode 100644 index 0000000..00e834f --- /dev/null +++ b/alpha/build.rs @@ -0,0 +1,5 @@ +use alpha_io::ContractMetadata; + +fn main() { + gear_wasm_builder::build_with_metadata::(); +} diff --git a/alpha/io/Cargo.toml b/alpha/io/Cargo.toml new file mode 100644 index 0000000..c57b0a2 --- /dev/null +++ b/alpha/io/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "alpha-io" +version.workspace = true +edition.workspace = true +publish.workspace = true + +[dependencies] +gmeta.workspace = true +gstd.workspace = true diff --git a/alpha/io/src/lib.rs b/alpha/io/src/lib.rs new file mode 100644 index 0000000..08ef60c --- /dev/null +++ b/alpha/io/src/lib.rs @@ -0,0 +1,68 @@ +#![no_std] + +use gmeta::{In, Metadata, Out}; +use gstd::*; + +/// The contract metadata. Used by frontend apps & for describing the types of messages that can be +/// sent in contract's entry points. See also [`Metadata`]. +pub struct ContractMetadata; + +pub type State = Vec; + +#[derive(Encode, Decode, TypeInfo, PartialEq, Eq, Debug, Clone)] +#[codec(crate = gstd::codec)] +#[scale_info(crate = gstd::scale_info)] +pub enum Label { + Apple, + Banana, + Football, + Vara, +} + +impl AsRef for Label { + fn as_ref(&self) -> &str { + match self { + Label::Apple => "apple", + Label::Banana => "banana", + Label::Football => "football", + Label::Vara => "vara", + } + } +} + +impl Label { + pub fn list() -> Vec