From c57847f9871b848c8b4d287da888aef24ab5b7d4 Mon Sep 17 00:00:00 2001 From: Shamil <66209982+shamilsan@users.noreply.github.com> Date: Tue, 22 Aug 2023 11:57:08 +0400 Subject: [PATCH 1/5] chore: clean up example manifests --- examples/async-custom-entry/Cargo.toml | 7 +- examples/async-init/Cargo.toml | 1 - examples/async-recursion/Cargo.toml | 1 - examples/async-signal-entry/Cargo.toml | 7 +- examples/async-tester/Cargo.toml | 5 +- examples/async/Cargo.toml | 1 - examples/calc-hash/Cargo.toml | 5 +- examples/calc-hash/in-one-block/Cargo.toml | 5 +- examples/calc-hash/over-blocks/Cargo.toml | 5 +- examples/compose/Cargo.toml | 7 +- examples/constructor/Cargo.toml | 1 - examples/custom/Cargo.toml | 1 - examples/delayed-sender/Cargo.toml | 5 +- examples/distributor/Cargo.toml | 7 +- examples/fungible-token/Cargo.toml | 1 - examples/fungible-token/io/Cargo.toml | 1 - examples/futures-unordered/Cargo.toml | 1 - examples/gas-burned/Cargo.toml | 5 +- examples/incomplete-async-payloads/Cargo.toml | 1 - examples/init-fail-sender/Cargo.toml | 7 +- examples/init-wait-reply-exit/Cargo.toml | 7 +- examples/init-wait/Cargo.toml | 7 +- examples/messager/Cargo.toml | 3 +- examples/mul-by-const/Cargo.toml | 7 +- examples/ncompose/Cargo.toml | 7 +- examples/new-meta/Cargo.toml | 5 +- examples/new-meta/io/Cargo.toml | 1 - examples/new-meta/state-v1/Cargo.toml | 1 - examples/new-meta/state-v2/Cargo.toml | 1 - examples/new-meta/state-v3/Cargo.toml | 1 - examples/node/Cargo.toml | 7 +- examples/out-of-memory/Cargo.toml | 5 +- examples/piggy-bank/Cargo.toml | 1 - examples/ping/Cargo.toml | 1 - examples/program-factory/Cargo.toml | 7 +- examples/program-generator/Cargo.toml | 1 - examples/proxy-relay/Cargo.toml | 7 +- .../proxy-reservation-with-gas/Cargo.toml | 7 +- examples/proxy/Cargo.toml | 7 +- examples/read-big-state/Cargo.toml | 1 - examples/reservation-manager/Cargo.toml | 1 - examples/reserve-gas/Cargo.toml | 1 - examples/rwlock/Cargo.toml | 1 - examples/send-from-reservation/Cargo.toml | 7 +- examples/signal-entry/Cargo.toml | 7 +- examples/stack-allocations/Cargo.toml | 1 - examples/state-rollback/Cargo.toml | 1 - examples/sync-duplicate/Cargo.toml | 1 - examples/sys-calls/Cargo.toml | 7 +- examples/syscall-error/Cargo.toml | 7 +- examples/vec/Cargo.toml | 1 - examples/wait-timeout/Cargo.toml | 9 +- examples/wait/Cargo.toml | 1 - examples/wait_wake/Cargo.toml | 1 - examples/waiter/Cargo.toml | 7 +- examples/waiting-proxy/Cargo.toml | 7 +- examples/wat/Cargo.toml | 1 - tomls.txt | 1075 +++++++++++++++++ 58 files changed, 1134 insertions(+), 160 deletions(-) create mode 100644 tomls.txt diff --git a/examples/async-custom-entry/Cargo.toml b/examples/async-custom-entry/Cargo.toml index 7a059c0d776..d01a744a8b7 100644 --- a/examples/async-custom-entry/Cargo.toml +++ b/examples/async-custom-entry/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-async-custom-entry" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../" +edition.workspace = true +license.workspace = true [dependencies] parity-scale-codec = { workspace = true, features = ["derive"] } @@ -16,8 +15,6 @@ gear-wasm-builder.workspace = true [dev-dependencies] gtest.workspace = true -[lib] - [features] debug = ["gstd/debug"] std = ["parity-scale-codec/std"] diff --git a/examples/async-init/Cargo.toml b/examples/async-init/Cargo.toml index 950e247e59d..fde0965c821 100644 --- a/examples/async-init/Cargo.toml +++ b/examples/async-init/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true -workspace = "../../" [dependencies] gstd.workspace = true diff --git a/examples/async-recursion/Cargo.toml b/examples/async-recursion/Cargo.toml index 8bdf01eb582..437490c3a54 100644 --- a/examples/async-recursion/Cargo.toml +++ b/examples/async-recursion/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true -workspace = "../../" [dependencies] gstd.workspace = true diff --git a/examples/async-signal-entry/Cargo.toml b/examples/async-signal-entry/Cargo.toml index e60c5baaceb..ee5f1f51b62 100644 --- a/examples/async-signal-entry/Cargo.toml +++ b/examples/async-signal-entry/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-async-signal-entry" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../" +edition.workspace = true +license.workspace = true [dependencies] parity-scale-codec = { workspace = true, features = ["derive"] } @@ -16,8 +15,6 @@ gear-wasm-builder.workspace = true [dev-dependencies] gtest.workspace = true -[lib] - [features] debug = ["gstd/debug"] std = ["parity-scale-codec/std"] diff --git a/examples/async-tester/Cargo.toml b/examples/async-tester/Cargo.toml index 114ec3a62a3..bc1c8db4ad8 100644 --- a/examples/async-tester/Cargo.toml +++ b/examples/async-tester/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-async-tester" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../" +edition.workspace = true +license.workspace = true [dependencies] parity-scale-codec = { workspace = true, features = ["derive"] } diff --git a/examples/async/Cargo.toml b/examples/async/Cargo.toml index be01a96165c..47678ca0437 100644 --- a/examples/async/Cargo.toml +++ b/examples/async/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true -workspace = "../../" [dependencies] gstd.workspace = true diff --git a/examples/calc-hash/Cargo.toml b/examples/calc-hash/Cargo.toml index b61fb33ecf3..fec4610bc79 100644 --- a/examples/calc-hash/Cargo.toml +++ b/examples/calc-hash/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-calc-hash" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../" +edition.workspace = true +license.workspace = true [dependencies] parity-scale-codec = { workspace = true, features = ["derive"]} diff --git a/examples/calc-hash/in-one-block/Cargo.toml b/examples/calc-hash/in-one-block/Cargo.toml index fcd0da368bb..59c1af47555 100644 --- a/examples/calc-hash/in-one-block/Cargo.toml +++ b/examples/calc-hash/in-one-block/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-calc-hash-in-one-block" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../../" +edition.workspace = true +license.workspace = true [dependencies] parity-scale-codec = { workspace = true, features = ["derive"]} diff --git a/examples/calc-hash/over-blocks/Cargo.toml b/examples/calc-hash/over-blocks/Cargo.toml index f3795a7d0b0..95ed3387da6 100644 --- a/examples/calc-hash/over-blocks/Cargo.toml +++ b/examples/calc-hash/over-blocks/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-calc-hash-over-blocks" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../../" +edition.workspace = true +license.workspace = true [dependencies] parity-scale-codec = { workspace = true, features = ["derive"]} diff --git a/examples/compose/Cargo.toml b/examples/compose/Cargo.toml index ed7edbd9bda..ea7dc3ce8d2 100644 --- a/examples/compose/Cargo.toml +++ b/examples/compose/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-compose" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../" +edition.workspace = true +license.workspace = true [dependencies] gstd.workspace = true @@ -13,8 +12,6 @@ hex = { version = "0.4.3", default-features = false, features = ["alloc"] } [build-dependencies] gear-wasm-builder.workspace = true -[lib] - [features] debug = ["gstd/debug"] std = [] diff --git a/examples/constructor/Cargo.toml b/examples/constructor/Cargo.toml index 10782f0558e..90bd70352b0 100644 --- a/examples/constructor/Cargo.toml +++ b/examples/constructor/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true -workspace = "../../" [dependencies] gstd.workspace = true diff --git a/examples/custom/Cargo.toml b/examples/custom/Cargo.toml index 164f8415084..fc80e7aabb8 100644 --- a/examples/custom/Cargo.toml +++ b/examples/custom/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true -workspace = "../../" [dependencies] gstd.workspace = true diff --git a/examples/delayed-sender/Cargo.toml b/examples/delayed-sender/Cargo.toml index e23c5e2f310..fadf31febda 100644 --- a/examples/delayed-sender/Cargo.toml +++ b/examples/delayed-sender/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-delayed-sender" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../" +edition.workspace = true +license.workspace = true [dependencies] gstd.workspace = true diff --git a/examples/distributor/Cargo.toml b/examples/distributor/Cargo.toml index 00d2f03613f..e1e8085020b 100644 --- a/examples/distributor/Cargo.toml +++ b/examples/distributor/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-distributor" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../" +edition.workspace = true +license.workspace = true [dependencies] parity-scale-codec = { workspace = true, features = ["derive"] } @@ -17,8 +16,6 @@ gear-wasm-builder.workspace = true gstd = { workspace = true, features = ["debug"] } gtest.workspace = true -[lib] - [features] debug = ["gstd/debug"] std = ["parity-scale-codec/std"] diff --git a/examples/fungible-token/Cargo.toml b/examples/fungible-token/Cargo.toml index 11d3a446136..000959e208c 100644 --- a/examples/fungible-token/Cargo.toml +++ b/examples/fungible-token/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.4" authors.workspace = true edition.workspace = true license.workspace = true -workspace = "../../" [dependencies] gstd = { workspace = true } diff --git a/examples/fungible-token/io/Cargo.toml b/examples/fungible-token/io/Cargo.toml index 2f7fefeaa90..59d80d83486 100644 --- a/examples/fungible-token/io/Cargo.toml +++ b/examples/fungible-token/io/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.4" authors.workspace = true edition.workspace = true license.workspace = true -workspace = "../../../" [dependencies] gstd = { workspace = true } diff --git a/examples/futures-unordered/Cargo.toml b/examples/futures-unordered/Cargo.toml index df6d483f4a6..10fd6a80804 100644 --- a/examples/futures-unordered/Cargo.toml +++ b/examples/futures-unordered/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true -workspace = "../../" [dependencies] gstd.workspace = true diff --git a/examples/gas-burned/Cargo.toml b/examples/gas-burned/Cargo.toml index 656a5b96c4c..c3bcbfb9aab 100644 --- a/examples/gas-burned/Cargo.toml +++ b/examples/gas-burned/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-gas-burned" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../" +edition.workspace = true +license.workspace = true [dependencies] gstd.workspace = true diff --git a/examples/incomplete-async-payloads/Cargo.toml b/examples/incomplete-async-payloads/Cargo.toml index 10dd073012e..733fb5b4f7d 100644 --- a/examples/incomplete-async-payloads/Cargo.toml +++ b/examples/incomplete-async-payloads/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true -workspace = "../../" [dependencies] gstd.workspace = true diff --git a/examples/init-fail-sender/Cargo.toml b/examples/init-fail-sender/Cargo.toml index 7406dd2fd2d..5b1aa98a3c6 100644 --- a/examples/init-fail-sender/Cargo.toml +++ b/examples/init-fail-sender/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-init-fail-sender" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../" +edition.workspace = true +license.workspace = true [dependencies] gstd.workspace = true @@ -12,8 +11,6 @@ gstd.workspace = true [build-dependencies] gear-wasm-builder.workspace = true -[lib] - [features] debug = ["gstd/debug"] std = [] diff --git a/examples/init-wait-reply-exit/Cargo.toml b/examples/init-wait-reply-exit/Cargo.toml index 52f98b3149b..234a5e0178f 100644 --- a/examples/init-wait-reply-exit/Cargo.toml +++ b/examples/init-wait-reply-exit/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-init-wait-reply-exit" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../" +edition.workspace = true +license.workspace = true [dependencies] gstd.workspace = true @@ -12,8 +11,6 @@ gstd.workspace = true [build-dependencies] gear-wasm-builder.workspace = true -[lib] - [features] debug = ["gstd/debug"] std = [] diff --git a/examples/init-wait/Cargo.toml b/examples/init-wait/Cargo.toml index 8b0d9b0b238..05f2d67d4d3 100644 --- a/examples/init-wait/Cargo.toml +++ b/examples/init-wait/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-init-wait" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../" +edition.workspace = true +license.workspace = true [dependencies] gstd.workspace = true @@ -12,8 +11,6 @@ gstd.workspace = true [build-dependencies] gear-wasm-builder.workspace = true -[lib] - [features] debug = ["gstd/debug"] std = [] diff --git a/examples/messager/Cargo.toml b/examples/messager/Cargo.toml index cc570e340ab..884b045bec8 100644 --- a/examples/messager/Cargo.toml +++ b/examples/messager/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-messager" version = "0.1.0" authors.workspace = true -license = "GPL-3.0" +license.workspace = true edition.workspace = true -workspace = "../../" [dependencies] gstd.workspace = true diff --git a/examples/mul-by-const/Cargo.toml b/examples/mul-by-const/Cargo.toml index adbd0248877..57e2d376d0f 100644 --- a/examples/mul-by-const/Cargo.toml +++ b/examples/mul-by-const/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-mul-by-const" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../" +edition.workspace = true +license.workspace = true [dependencies] gstd.workspace = true @@ -13,8 +12,6 @@ hex = { version = "0.4.3", default-features = false, features = ["alloc"] } [build-dependencies] gear-wasm-builder.workspace = true -[lib] - [features] debug = ["gstd/debug"] std = [] diff --git a/examples/ncompose/Cargo.toml b/examples/ncompose/Cargo.toml index c5ae98c9182..846db8f57f9 100644 --- a/examples/ncompose/Cargo.toml +++ b/examples/ncompose/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-ncompose" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../" +edition.workspace = true +license.workspace = true [dependencies] gstd.workspace = true @@ -13,8 +12,6 @@ hex = { version = "0.4.3", default-features = false, features = ["alloc"] } [build-dependencies] gear-wasm-builder.workspace = true -[lib] - [features] debug = ["gstd/debug"] std = [] diff --git a/examples/new-meta/Cargo.toml b/examples/new-meta/Cargo.toml index fb1bb189f7c..1d7ae947885 100644 --- a/examples/new-meta/Cargo.toml +++ b/examples/new-meta/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-new-meta" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../" +edition.workspace = true +license.workspace = true [dependencies] parity-scale-codec.workspace = true diff --git a/examples/new-meta/io/Cargo.toml b/examples/new-meta/io/Cargo.toml index 071bf9c8993..b4a3affb0ee 100644 --- a/examples/new-meta/io/Cargo.toml +++ b/examples/new-meta/io/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true -workspace = "../../../" [dependencies] gmeta = { workspace = true } diff --git a/examples/new-meta/state-v1/Cargo.toml b/examples/new-meta/state-v1/Cargo.toml index 901bd45dde5..915bcfdf07f 100644 --- a/examples/new-meta/state-v1/Cargo.toml +++ b/examples/new-meta/state-v1/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true -workspace = "../../../" [dependencies] gstd.workspace = true diff --git a/examples/new-meta/state-v2/Cargo.toml b/examples/new-meta/state-v2/Cargo.toml index b5c0becefb6..da84f0b246b 100644 --- a/examples/new-meta/state-v2/Cargo.toml +++ b/examples/new-meta/state-v2/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true -workspace = "../../../" [dependencies] gstd.workspace = true diff --git a/examples/new-meta/state-v3/Cargo.toml b/examples/new-meta/state-v3/Cargo.toml index 379155bff3f..4e49d593ed0 100644 --- a/examples/new-meta/state-v3/Cargo.toml +++ b/examples/new-meta/state-v3/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true -workspace = "../../../" [dependencies] gstd.workspace = true diff --git a/examples/node/Cargo.toml b/examples/node/Cargo.toml index 097453824e4..80b859cde36 100644 --- a/examples/node/Cargo.toml +++ b/examples/node/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-node" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../" +edition.workspace = true +license.workspace = true [dependencies] parity-scale-codec = { workspace = true, features = ["derive"] } @@ -17,8 +16,6 @@ gear-wasm-builder.workspace = true gstd = { workspace = true, features = ["debug"] } gtest.workspace = true -[lib] - [features] debug = ["gstd/debug"] std = ["parity-scale-codec/std"] diff --git a/examples/out-of-memory/Cargo.toml b/examples/out-of-memory/Cargo.toml index ac2f3feaa37..e8b49e1699f 100644 --- a/examples/out-of-memory/Cargo.toml +++ b/examples/out-of-memory/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-out-of-memory" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../" +edition.workspace = true +license.workspace = true [dependencies] gstd.workspace = true diff --git a/examples/piggy-bank/Cargo.toml b/examples/piggy-bank/Cargo.toml index 77e2791deae..4a1cee16d5f 100644 --- a/examples/piggy-bank/Cargo.toml +++ b/examples/piggy-bank/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true -workspace = "../../" [dependencies] gstd.workspace = true diff --git a/examples/ping/Cargo.toml b/examples/ping/Cargo.toml index fa79445e23f..46cabcd31e3 100644 --- a/examples/ping/Cargo.toml +++ b/examples/ping/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true -workspace = "../../" [dependencies] gstd.workspace = true diff --git a/examples/program-factory/Cargo.toml b/examples/program-factory/Cargo.toml index 09539fd458c..e9af75b8c6f 100644 --- a/examples/program-factory/Cargo.toml +++ b/examples/program-factory/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-program-factory" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../" +edition.workspace = true +license.workspace = true [dependencies] parity-scale-codec = { workspace = true, features = ["derive"] } @@ -17,8 +16,6 @@ gear-wasm-builder.workspace = true [dev-dependencies] gtest.workspace = true -[lib] - [features] debug = ["gstd/debug"] std = ["parity-scale-codec/std"] diff --git a/examples/program-generator/Cargo.toml b/examples/program-generator/Cargo.toml index d3c686e1030..e3bd5a7049a 100644 --- a/examples/program-generator/Cargo.toml +++ b/examples/program-generator/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true -workspace = "../../" [dependencies] gstd.workspace = true diff --git a/examples/proxy-relay/Cargo.toml b/examples/proxy-relay/Cargo.toml index b12547ba515..b009ba681b1 100644 --- a/examples/proxy-relay/Cargo.toml +++ b/examples/proxy-relay/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-proxy-relay" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../" +edition.workspace = true +license.workspace = true [dependencies] parity-scale-codec = { workspace = true, features = ["derive"] } @@ -14,8 +13,6 @@ scale-info = { workspace = true, features = ["derive"] } [build-dependencies] gear-wasm-builder.workspace = true -[lib] - [features] debug = ["gstd/debug"] std = ["parity-scale-codec/std", "scale-info/std"] diff --git a/examples/proxy-reservation-with-gas/Cargo.toml b/examples/proxy-reservation-with-gas/Cargo.toml index 4371dac5811..700c2ca6d32 100644 --- a/examples/proxy-reservation-with-gas/Cargo.toml +++ b/examples/proxy-reservation-with-gas/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-proxy-reservation-with-gas" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../" +edition.workspace = true +license.workspace = true [dependencies] parity-scale-codec = { workspace = true, features = ["derive"] } @@ -14,8 +13,6 @@ scale-info = { workspace = true, features = ["derive"] } [build-dependencies] gear-wasm-builder.workspace = true -[lib] - [features] debug = ["gstd/debug"] std = ["parity-scale-codec/std", "scale-info/std"] diff --git a/examples/proxy/Cargo.toml b/examples/proxy/Cargo.toml index e3603c7e609..2cde888e83d 100644 --- a/examples/proxy/Cargo.toml +++ b/examples/proxy/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-proxy" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../" +edition.workspace = true +license.workspace = true [dependencies] gstd = { workspace = true } @@ -14,8 +13,6 @@ scale-info = { workspace = true, features = ["derive"] } [build-dependencies] gear-wasm-builder.workspace = true -[lib] - [features] debug = ["gstd/debug"] wasm-wrapper = [] diff --git a/examples/read-big-state/Cargo.toml b/examples/read-big-state/Cargo.toml index 8468f7fcadd..956d2c7c54b 100644 --- a/examples/read-big-state/Cargo.toml +++ b/examples/read-big-state/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true -workspace = "../../" [dependencies] gstd.workspace = true diff --git a/examples/reservation-manager/Cargo.toml b/examples/reservation-manager/Cargo.toml index df7f282d5ff..9e7cf0d5186 100644 --- a/examples/reservation-manager/Cargo.toml +++ b/examples/reservation-manager/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true -workspace = "../../" [dependencies] gstd.workspace = true diff --git a/examples/reserve-gas/Cargo.toml b/examples/reserve-gas/Cargo.toml index aef27afb79c..4ebc3e193b2 100644 --- a/examples/reserve-gas/Cargo.toml +++ b/examples/reserve-gas/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true -workspace = "../../" [dependencies] gstd.workspace = true diff --git a/examples/rwlock/Cargo.toml b/examples/rwlock/Cargo.toml index 2d9f2e5bf74..f82785132ca 100644 --- a/examples/rwlock/Cargo.toml +++ b/examples/rwlock/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true -workspace = "../../" [dependencies] gstd = { workspace = true, features = ["debug"] } diff --git a/examples/send-from-reservation/Cargo.toml b/examples/send-from-reservation/Cargo.toml index 0cfee5b00e8..b095b852fe5 100644 --- a/examples/send-from-reservation/Cargo.toml +++ b/examples/send-from-reservation/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-send-from-reservation" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../" +edition.workspace = true +license.workspace = true [dependencies] parity-scale-codec = { workspace = true, features = ["derive"] } @@ -16,8 +15,6 @@ gear-wasm-builder.workspace = true [dev-dependencies] gtest.workspace = true -[lib] - [features] debug = ["gstd/debug"] std = ["parity-scale-codec/std"] diff --git a/examples/signal-entry/Cargo.toml b/examples/signal-entry/Cargo.toml index 4216fab2909..708b63893c9 100644 --- a/examples/signal-entry/Cargo.toml +++ b/examples/signal-entry/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-signal-entry" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../" +edition.workspace = true +license.workspace = true [dependencies] gstd.workspace = true @@ -16,8 +15,6 @@ gear-wasm-builder.workspace = true [dev-dependencies] gtest.workspace = true -[lib] - [features] debug = ["gstd/debug"] std = [] diff --git a/examples/stack-allocations/Cargo.toml b/examples/stack-allocations/Cargo.toml index 5cf923ff1e8..d3ec7a51e95 100644 --- a/examples/stack-allocations/Cargo.toml +++ b/examples/stack-allocations/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true -workspace = "../../" [dependencies] gstd.workspace = true diff --git a/examples/state-rollback/Cargo.toml b/examples/state-rollback/Cargo.toml index 99d46e405c5..df652d9f995 100644 --- a/examples/state-rollback/Cargo.toml +++ b/examples/state-rollback/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true -workspace = "../../" [dependencies] gstd.workspace = true diff --git a/examples/sync-duplicate/Cargo.toml b/examples/sync-duplicate/Cargo.toml index 8f9ae9d0e87..9d95387d7e1 100644 --- a/examples/sync-duplicate/Cargo.toml +++ b/examples/sync-duplicate/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true -workspace = "../../" [dependencies] gstd.workspace = true diff --git a/examples/sys-calls/Cargo.toml b/examples/sys-calls/Cargo.toml index ba8908b4021..6ab1914d0fa 100644 --- a/examples/sys-calls/Cargo.toml +++ b/examples/sys-calls/Cargo.toml @@ -2,9 +2,8 @@ name = "test-syscalls" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../" +edition.workspace = true +license.workspace = true [dependencies] gstd = { workspace = true } @@ -13,8 +12,6 @@ parity-scale-codec = { workspace = true, features = ["derive"] } [build-dependencies] gear-wasm-builder.workspace = true -[lib] - [features] debug = ["gstd/debug"] wasm-wrapper = [] diff --git a/examples/syscall-error/Cargo.toml b/examples/syscall-error/Cargo.toml index 885b3139f81..5c7155134f4 100644 --- a/examples/syscall-error/Cargo.toml +++ b/examples/syscall-error/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-syscall-error" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../" +edition.workspace = true +license.workspace = true [dependencies] parity-scale-codec = { workspace = true, features = ["derive"] } @@ -17,8 +16,6 @@ gear-wasm-builder.workspace = true [dev-dependencies] gtest.workspace = true -[lib] - [features] debug = ["gstd/debug"] std = ["parity-scale-codec/std"] diff --git a/examples/vec/Cargo.toml b/examples/vec/Cargo.toml index 1d9d8417fba..d428636ee9f 100644 --- a/examples/vec/Cargo.toml +++ b/examples/vec/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true -workspace = "../../" [dependencies] gstd = { workspace = true, features = ["debug"] } diff --git a/examples/wait-timeout/Cargo.toml b/examples/wait-timeout/Cargo.toml index dcd5f2521bd..1650a625443 100644 --- a/examples/wait-timeout/Cargo.toml +++ b/examples/wait-timeout/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-wait-timeout" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../" +edition.workspace = true +license.workspace = true [dependencies] parity-scale-codec = { workspace = true, features = ["derive"] } @@ -14,10 +13,6 @@ futures = { version = "0.3", default-features = false, features = ["alloc"] } [build-dependencies] gear-wasm-builder.workspace = true -[dev-dependencies] - -[lib] - [features] debug = ["gstd/debug"] std = ["parity-scale-codec/std"] diff --git a/examples/wait/Cargo.toml b/examples/wait/Cargo.toml index 172e9f4cc06..c45a661cddc 100644 --- a/examples/wait/Cargo.toml +++ b/examples/wait/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true -workspace = "../../" [dependencies] gstd.workspace = true diff --git a/examples/wait_wake/Cargo.toml b/examples/wait_wake/Cargo.toml index 0f23aad78dc..adf86e08c8f 100644 --- a/examples/wait_wake/Cargo.toml +++ b/examples/wait_wake/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true -workspace = "../../" [dependencies] gstd.workspace = true diff --git a/examples/waiter/Cargo.toml b/examples/waiter/Cargo.toml index a72ef94b3a5..f978e3d2fda 100644 --- a/examples/waiter/Cargo.toml +++ b/examples/waiter/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-waiter" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../" +edition.workspace = true +license.workspace = true [dependencies] parity-scale-codec = { workspace = true, features = ["derive"] } @@ -19,8 +18,6 @@ gtest.workspace = true gear-core.workspace = true demo-waiter = { path = ".", features = ["debug"] } -[lib] - [features] debug = ["gstd/debug"] std = ["parity-scale-codec/std"] diff --git a/examples/waiting-proxy/Cargo.toml b/examples/waiting-proxy/Cargo.toml index 9ae7ce44ea6..381cc50e7e0 100644 --- a/examples/waiting-proxy/Cargo.toml +++ b/examples/waiting-proxy/Cargo.toml @@ -2,9 +2,8 @@ name = "demo-waiting-proxy" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" -workspace = "../../" +edition.workspace = true +license.workspace = true [dependencies] gstd.workspace = true @@ -12,8 +11,6 @@ gstd.workspace = true [build-dependencies] gear-wasm-builder.workspace = true -[lib] - [features] debug = ["gstd/debug"] std = [] diff --git a/examples/wat/Cargo.toml b/examples/wat/Cargo.toml index 9ea0380a9bb..c87112a7f83 100644 --- a/examples/wat/Cargo.toml +++ b/examples/wat/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true -workspace = "../../" [dependencies] hex = { workspace = true, features = ["alloc"] } diff --git a/tomls.txt b/tomls.txt new file mode 100644 index 00000000000..bf859419e7e --- /dev/null +++ b/tomls.txt @@ -0,0 +1,1075 @@ +[package] +name = "demo-read-big-state" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true +parity-scale-codec = { workspace = true, features = ["derive"] } + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +default = ["std"] +std = [] +[package] +name = "demo-wait" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true +gcore.workspace = true + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug", "gcore/debug"] +default = ["std"] +std = [] +[package] +name = "demo-ping" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +default = ["std"] +std = [] +[package] +name = "demo-program-generator" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true +hex-literal.workspace = true + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +default = ["std"] +std = [] +[package] +name = "demo-calc-hash" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +parity-scale-codec = { workspace = true, features = ["derive"]} +sha2 = { version = "0.10.6", default-features = false } + +[build-dependencies] +gear-wasm-builder.workspace = true +[package] +name = "demo-calc-hash-over-blocks" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +parity-scale-codec = { workspace = true, features = ["derive"]} +gstd.workspace = true +shared = { path = "../", package = "demo-calc-hash" } + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +std = [] +default = ["std"] +[package] +name = "demo-calc-hash-in-one-block" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +parity-scale-codec = { workspace = true, features = ["derive"]} +gstd.workspace = true +shared = { path = "..", package = "demo-calc-hash" } + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +std = [] +default = [ "std" ] +[package] +name = "demo-init-wait-reply-exit" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +std = [] +default = ["std"] +[package] +name = "demo-proxy" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd = { workspace = true } +parity-scale-codec = { workspace = true, features = ["derive"] } +scale-info = { workspace = true, features = ["derive"] } + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +wasm-wrapper = [] +std = ["wasm-wrapper", "parity-scale-codec/std", "scale-info/std"] +default = ["std"] +[package] +name = "demo-messager" +version = "0.1.0" +authors.workspace = true +license.workspace = true +edition.workspace = true + +[dependencies] +gstd.workspace = true + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +std = [] +default = ["std"] +[package] +name = "demo-sync-duplicate" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +default = ["std"] +std = [] +[package] +name = "demo-ncompose" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true +hex = { version = "0.4.3", default-features = false, features = ["alloc"] } + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +std = [] +default = ["std"] +[package] +name = "demo-init-wait" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +std = [] +default = ["std"] +[package] +name = "demo-async-tester" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +parity-scale-codec = { workspace = true, features = ["derive"] } +gstd.workspace = true + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +std = [] +default = ["std"] +[package] +name = "demo-rwlock" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd = { workspace = true, features = ["debug"] } +parity-scale-codec = { workspace = true, features = ["derive"] } + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +default = ["std"] +std = [] +[package] +name = "demo-mul-by-const" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true +hex = { version = "0.4.3", default-features = false, features = ["alloc"] } + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +std = [] +default = ["std"] +[package] +name = "demo-async-custom-entry" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +parity-scale-codec = { workspace = true, features = ["derive"] } +gstd.workspace = true + +[build-dependencies] +gear-wasm-builder.workspace = true + +[dev-dependencies] +gtest.workspace = true + +[features] +debug = ["gstd/debug"] +std = ["parity-scale-codec/std"] +default = ["std"] +[package] +name = "demo-piggy-bank" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +default = ["std"] +std = [] +[package] +name = "demo-compose" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true +hex = { version = "0.4.3", default-features = false, features = ["alloc"] } + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +std = [] +default = ["std"] +[package] +name = "demo-send-from-reservation" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +parity-scale-codec = { workspace = true, features = ["derive"] } +gstd.workspace = true + +[build-dependencies] +gear-wasm-builder.workspace = true + +[dev-dependencies] +gtest.workspace = true + +[features] +debug = ["gstd/debug"] +std = ["parity-scale-codec/std"] +default = ["std"] +[package] +name = "demo-async" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true +parity-scale-codec = { workspace = true, features = ["derive"] } + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +default = ["std"] +std = [] +[package] +name = "demo-state-rollback" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +default = ["std"] +std = [] +[package] +name = "demo-async-init" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true +parity-scale-codec = { workspace = true, features = ["derive"] } +futures = { workspace = true, features = ["alloc"] } + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +default = ["std"] +std = [] +[package] +name = "demo-reserve-gas" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true +parity-scale-codec = { workspace = true, features = ["derive"] } + +[build-dependencies] +gear-wasm-builder.workspace = true + +[dev-dependencies] +gtest.workspace = true + +[features] +debug = ["gstd/debug"] +std = [] +default = ["std"] +[package] +name = "demo-proxy-reservation-with-gas" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +parity-scale-codec = { workspace = true, features = ["derive"] } +gstd.workspace = true +scale-info = { workspace = true, features = ["derive"] } + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +std = ["parity-scale-codec/std", "scale-info/std"] +default = ["std"] +[package] +name = "demo-gas-burned" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true + +[build-dependencies] +gear-wasm-builder.workspace = true + +[dev-dependencies] +gtest.workspace = true +log.workspace = true + +[features] +std = [] +default = ["std"] +[package] +name = "demo-reservation-manager" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true +parity-scale-codec = { workspace = true, features = ["derive"] } + +[build-dependencies] +gear-wasm-builder.workspace = true + +[dev-dependencies] +gtest.workspace = true + +[features] +std = ["parity-scale-codec/std"] +default = ["std"] +[package] +name = "demo-vec" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd = { workspace = true, features = ["debug"] } + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +default = ["std"] +std = [] +[package] +name = "demo-wait-wake" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true +parity-scale-codec = { workspace = true, features = ["derive"] } + +[build-dependencies] +gear-wasm-builder.workspace = true + +[dev-dependencies] +gtest.workspace = true + +[features] +debug = ["gstd/debug"] +std = [] +default = ["std"] +[package] +name = "demo-wait-timeout" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +parity-scale-codec = { workspace = true, features = ["derive"] } +gstd.workspace = true +futures = { version = "0.3", default-features = false, features = ["alloc"] } + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +std = ["parity-scale-codec/std"] +default = ["std"] +[package] +name = "demo-waiter" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +parity-scale-codec = { workspace = true, features = ["derive"] } +futures.workspace = true +gstd.workspace = true + +[build-dependencies] +gear-wasm-builder.workspace = true + +[dev-dependencies] +gtest.workspace = true +gear-core.workspace = true +demo-waiter = { path = ".", features = ["debug"] } + +[features] +debug = ["gstd/debug"] +std = ["parity-scale-codec/std"] +default = ["std"] +[package] +name = "demo-init-fail-sender" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +std = [] +default = ["std"] +[package] +name = "test-syscalls" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd = { workspace = true } +parity-scale-codec = { workspace = true, features = ["derive"] } + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +wasm-wrapper = [] +std = ["wasm-wrapper", "parity-scale-codec/std"] +default = ["std"] +[package] +name = "demo-waiting-proxy" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +std = [] +default = ["std"] +[package] +name = "demo-out-of-memory" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +std = [] +default = ["std"] +[package] +name = "demo-distributor" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +parity-scale-codec = { workspace = true, features = ["derive"] } +gstd.workspace = true + +[build-dependencies] +gear-wasm-builder.workspace = true + +[dev-dependencies] +gstd = { workspace = true, features = ["debug"] } +gtest.workspace = true + +[features] +debug = ["gstd/debug"] +std = ["parity-scale-codec/std"] +default = ["std"] +[package] +name = "demo-delayed-sender" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +std = [ ] +default = ["std"] +[package] +name = "demo-syscall-error" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +parity-scale-codec = { workspace = true, features = ["derive"] } +gstd.workspace = true +gsys.workspace = true + +[build-dependencies] +gear-wasm-builder.workspace = true + +[dev-dependencies] +gtest.workspace = true + +[features] +debug = ["gstd/debug"] +std = ["parity-scale-codec/std"] +default = ["std"] +[package] +name = "demo-wat" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +hex = { workspace = true, features = ["alloc"] } +wabt.workspace = true +[package] +name = "demo-proxy-relay" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +parity-scale-codec = { workspace = true, features = ["derive"] } +gstd.workspace = true +scale-info = { workspace = true, features = ["derive"] } + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +std = ["parity-scale-codec/std", "scale-info/std"] +default = ["std"] +[package] +name = "demo-stack-allocations" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true +parity-scale-codec = { workspace = true, features = ["derive"] } + +[dev-dependencies] +gtest.workspace = true +rand_pcg = { workspace = true } +rand = "0.8" +static_assertions.workspace = true + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +std = [] +default = ["std"] +[package] +name = "demo-signal-entry" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true +parity-scale-codec = { workspace = true, features = ["derive"] } + +[build-dependencies] +gear-wasm-builder.workspace = true + +[dev-dependencies] +gtest.workspace = true + +[features] +debug = ["gstd/debug"] +std = [] +default = ["std"] +[package] +name = "demo-node" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +parity-scale-codec = { workspace = true, features = ["derive"] } +gstd.workspace = true + +[build-dependencies] +gear-wasm-builder.workspace = true + +[dev-dependencies] +gstd = { workspace = true, features = ["debug"] } +gtest.workspace = true + +[features] +debug = ["gstd/debug"] +std = ["parity-scale-codec/std"] +default = ["std"] +[package] +name = "demo-custom" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true +gsys.workspace = true +parity-scale-codec.workspace = true + +[dev-dependencies] +gtest.workspace = true + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +default = ["std"] +std = [] +[package] +name = "demo-incomplete-async-payloads" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true +parity-scale-codec = { workspace = true, features = ["derive"] } + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +default = ["std"] +std = [] +[package] +name = "demo-async-recursion" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true +async-recursion.workspace = true + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +default = ["std"] +std = [] +[package] +name = "demo-async-signal-entry" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +parity-scale-codec = { workspace = true, features = ["derive"] } +gstd.workspace = true + +[build-dependencies] +gear-wasm-builder.workspace = true + +[dev-dependencies] +gtest.workspace = true + +[features] +debug = ["gstd/debug"] +std = ["parity-scale-codec/std"] +default = ["std"] +[package] +name = "demo-program-factory" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +parity-scale-codec = { workspace = true, features = ["derive"] } +gstd.workspace = true +hex-literal = "*" + +[build-dependencies] +gear-wasm-builder.workspace = true + +[dev-dependencies] +gtest.workspace = true + +[features] +debug = ["gstd/debug"] +std = ["parity-scale-codec/std"] +default = ["std"] +[package] +name = "demo-new-meta" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +parity-scale-codec.workspace = true +demo-meta-io = { path = "io" } +demo-meta-state-v1 = { path = "state-v1", default-features = false, optional = true } +demo-meta-state-v2 = { path = "state-v2", default-features = false, optional = true } +demo-meta-state-v3 = { path = "state-v3", default-features = false, optional = true } +gstd.workspace = true + +[build-dependencies] +demo-meta-io = { path = "io" } +gear-wasm-builder.workspace = true + +[dev-dependencies] +gtest.workspace = true + +[features] +debug = ["gstd/debug"] +default = ["std"] +std = [ + "demo-meta-state-v1/std", + "demo-meta-state-v2/std", + "demo-meta-state-v3/std", + "parity-scale-codec/std", +] +[package] +name = "demo-meta-state-v2" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true +# workspace = "../../../" + +[dependencies] +gstd.workspace = true +gmeta = { workspace = true, features = ["codegen"] } +demo-meta-io = { path = "../io" } + +[build-dependencies] +gear-wasm-builder = { workspace = true, features = ["metawasm"] } + +[features] +default = ["std"] +std = [] +[package] +name = "demo-meta-state-v3" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true +# workspace = "../../../" + +[dependencies] +gstd.workspace = true +gmeta = { workspace = true, features = ["codegen"] } +demo-meta-io = { path = "../io" } + +[build-dependencies] +gear-wasm-builder = { workspace = true, features = ["metawasm"] } + +[features] +default = ["std"] +std = [] +[package] +name = "demo-meta-io" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gmeta = { workspace = true } +scale-info = { workspace = true, features = ["derive"] } +parity-scale-codec = { workspace = true, features = ["derive"] } +[package] +name = "demo-meta-state-v1" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true +# workspace = "../../../" + +[dependencies] +gstd.workspace = true +gmeta = { workspace = true, features = ["codegen"] } +demo-meta-io = { path = "../io" } + +[build-dependencies] +gear-wasm-builder = { workspace = true, features = ["metawasm"] } + +[features] +default = ["std"] +std = [] +[package] +name = "demo-constructor" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true +parity-scale-codec = { workspace = true, features = ["derive"] } +hex.workspace = true + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +std = [] +default = ["std"] +[package] +name = "demo-fungible-token" +version = "0.1.4" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd = { workspace = true } +hashbrown = { workspace = true } +gmeta = { workspace = true } +ft-io = { path = "io" } + +[dev-dependencies] +gstd = { workspace = true, features = ["debug"] } +gear-core.workspace = true +tokio = { workspace = true, features = ["full", "test-util"] } +gclient = { workspace = true } +futures = "0.3" +rand = { version = "0.8" } +statrs = "0.16" + +[build-dependencies] +gear-wasm-builder = { workspace = true } + +[features] +debug = ["gstd/debug"] +std = [] +default = ["std"] +[package] +name = "ft-io" +version = "0.1.4" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd = { workspace = true } +gmeta = { workspace = true } +[package] +name = "demo-futures-unordered" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +gstd.workspace = true +parity-scale-codec = { workspace = true, features = ["derive"] } +futures = { workspace = true, features = ["alloc", "async-await"] } + +[build-dependencies] +gear-wasm-builder.workspace = true + +[features] +debug = ["gstd/debug"] +default = ["std"] +std = [] From 60901f40a68acd273a31aab0d1f897ba8c573e1d Mon Sep 17 00:00:00 2001 From: Shamil <66209982+shamilsan@users.noreply.github.com> Date: Tue, 22 Aug 2023 11:58:48 +0400 Subject: [PATCH 2/5] chore: remove crap --- tomls.txt | 1075 ----------------------------------------------------- 1 file changed, 1075 deletions(-) delete mode 100644 tomls.txt diff --git a/tomls.txt b/tomls.txt deleted file mode 100644 index bf859419e7e..00000000000 --- a/tomls.txt +++ /dev/null @@ -1,1075 +0,0 @@ -[package] -name = "demo-read-big-state" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true -parity-scale-codec = { workspace = true, features = ["derive"] } - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -default = ["std"] -std = [] -[package] -name = "demo-wait" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true -gcore.workspace = true - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug", "gcore/debug"] -default = ["std"] -std = [] -[package] -name = "demo-ping" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -default = ["std"] -std = [] -[package] -name = "demo-program-generator" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true -hex-literal.workspace = true - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -default = ["std"] -std = [] -[package] -name = "demo-calc-hash" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -parity-scale-codec = { workspace = true, features = ["derive"]} -sha2 = { version = "0.10.6", default-features = false } - -[build-dependencies] -gear-wasm-builder.workspace = true -[package] -name = "demo-calc-hash-over-blocks" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -parity-scale-codec = { workspace = true, features = ["derive"]} -gstd.workspace = true -shared = { path = "../", package = "demo-calc-hash" } - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -std = [] -default = ["std"] -[package] -name = "demo-calc-hash-in-one-block" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -parity-scale-codec = { workspace = true, features = ["derive"]} -gstd.workspace = true -shared = { path = "..", package = "demo-calc-hash" } - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -std = [] -default = [ "std" ] -[package] -name = "demo-init-wait-reply-exit" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -std = [] -default = ["std"] -[package] -name = "demo-proxy" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd = { workspace = true } -parity-scale-codec = { workspace = true, features = ["derive"] } -scale-info = { workspace = true, features = ["derive"] } - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -wasm-wrapper = [] -std = ["wasm-wrapper", "parity-scale-codec/std", "scale-info/std"] -default = ["std"] -[package] -name = "demo-messager" -version = "0.1.0" -authors.workspace = true -license.workspace = true -edition.workspace = true - -[dependencies] -gstd.workspace = true - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -std = [] -default = ["std"] -[package] -name = "demo-sync-duplicate" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -default = ["std"] -std = [] -[package] -name = "demo-ncompose" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true -hex = { version = "0.4.3", default-features = false, features = ["alloc"] } - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -std = [] -default = ["std"] -[package] -name = "demo-init-wait" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -std = [] -default = ["std"] -[package] -name = "demo-async-tester" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -parity-scale-codec = { workspace = true, features = ["derive"] } -gstd.workspace = true - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -std = [] -default = ["std"] -[package] -name = "demo-rwlock" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd = { workspace = true, features = ["debug"] } -parity-scale-codec = { workspace = true, features = ["derive"] } - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -default = ["std"] -std = [] -[package] -name = "demo-mul-by-const" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true -hex = { version = "0.4.3", default-features = false, features = ["alloc"] } - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -std = [] -default = ["std"] -[package] -name = "demo-async-custom-entry" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -parity-scale-codec = { workspace = true, features = ["derive"] } -gstd.workspace = true - -[build-dependencies] -gear-wasm-builder.workspace = true - -[dev-dependencies] -gtest.workspace = true - -[features] -debug = ["gstd/debug"] -std = ["parity-scale-codec/std"] -default = ["std"] -[package] -name = "demo-piggy-bank" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -default = ["std"] -std = [] -[package] -name = "demo-compose" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true -hex = { version = "0.4.3", default-features = false, features = ["alloc"] } - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -std = [] -default = ["std"] -[package] -name = "demo-send-from-reservation" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -parity-scale-codec = { workspace = true, features = ["derive"] } -gstd.workspace = true - -[build-dependencies] -gear-wasm-builder.workspace = true - -[dev-dependencies] -gtest.workspace = true - -[features] -debug = ["gstd/debug"] -std = ["parity-scale-codec/std"] -default = ["std"] -[package] -name = "demo-async" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true -parity-scale-codec = { workspace = true, features = ["derive"] } - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -default = ["std"] -std = [] -[package] -name = "demo-state-rollback" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -default = ["std"] -std = [] -[package] -name = "demo-async-init" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true -parity-scale-codec = { workspace = true, features = ["derive"] } -futures = { workspace = true, features = ["alloc"] } - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -default = ["std"] -std = [] -[package] -name = "demo-reserve-gas" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true -parity-scale-codec = { workspace = true, features = ["derive"] } - -[build-dependencies] -gear-wasm-builder.workspace = true - -[dev-dependencies] -gtest.workspace = true - -[features] -debug = ["gstd/debug"] -std = [] -default = ["std"] -[package] -name = "demo-proxy-reservation-with-gas" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -parity-scale-codec = { workspace = true, features = ["derive"] } -gstd.workspace = true -scale-info = { workspace = true, features = ["derive"] } - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -std = ["parity-scale-codec/std", "scale-info/std"] -default = ["std"] -[package] -name = "demo-gas-burned" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true - -[build-dependencies] -gear-wasm-builder.workspace = true - -[dev-dependencies] -gtest.workspace = true -log.workspace = true - -[features] -std = [] -default = ["std"] -[package] -name = "demo-reservation-manager" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true -parity-scale-codec = { workspace = true, features = ["derive"] } - -[build-dependencies] -gear-wasm-builder.workspace = true - -[dev-dependencies] -gtest.workspace = true - -[features] -std = ["parity-scale-codec/std"] -default = ["std"] -[package] -name = "demo-vec" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd = { workspace = true, features = ["debug"] } - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -default = ["std"] -std = [] -[package] -name = "demo-wait-wake" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true -parity-scale-codec = { workspace = true, features = ["derive"] } - -[build-dependencies] -gear-wasm-builder.workspace = true - -[dev-dependencies] -gtest.workspace = true - -[features] -debug = ["gstd/debug"] -std = [] -default = ["std"] -[package] -name = "demo-wait-timeout" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -parity-scale-codec = { workspace = true, features = ["derive"] } -gstd.workspace = true -futures = { version = "0.3", default-features = false, features = ["alloc"] } - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -std = ["parity-scale-codec/std"] -default = ["std"] -[package] -name = "demo-waiter" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -parity-scale-codec = { workspace = true, features = ["derive"] } -futures.workspace = true -gstd.workspace = true - -[build-dependencies] -gear-wasm-builder.workspace = true - -[dev-dependencies] -gtest.workspace = true -gear-core.workspace = true -demo-waiter = { path = ".", features = ["debug"] } - -[features] -debug = ["gstd/debug"] -std = ["parity-scale-codec/std"] -default = ["std"] -[package] -name = "demo-init-fail-sender" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -std = [] -default = ["std"] -[package] -name = "test-syscalls" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd = { workspace = true } -parity-scale-codec = { workspace = true, features = ["derive"] } - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -wasm-wrapper = [] -std = ["wasm-wrapper", "parity-scale-codec/std"] -default = ["std"] -[package] -name = "demo-waiting-proxy" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -std = [] -default = ["std"] -[package] -name = "demo-out-of-memory" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -std = [] -default = ["std"] -[package] -name = "demo-distributor" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -parity-scale-codec = { workspace = true, features = ["derive"] } -gstd.workspace = true - -[build-dependencies] -gear-wasm-builder.workspace = true - -[dev-dependencies] -gstd = { workspace = true, features = ["debug"] } -gtest.workspace = true - -[features] -debug = ["gstd/debug"] -std = ["parity-scale-codec/std"] -default = ["std"] -[package] -name = "demo-delayed-sender" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -std = [ ] -default = ["std"] -[package] -name = "demo-syscall-error" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -parity-scale-codec = { workspace = true, features = ["derive"] } -gstd.workspace = true -gsys.workspace = true - -[build-dependencies] -gear-wasm-builder.workspace = true - -[dev-dependencies] -gtest.workspace = true - -[features] -debug = ["gstd/debug"] -std = ["parity-scale-codec/std"] -default = ["std"] -[package] -name = "demo-wat" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -hex = { workspace = true, features = ["alloc"] } -wabt.workspace = true -[package] -name = "demo-proxy-relay" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -parity-scale-codec = { workspace = true, features = ["derive"] } -gstd.workspace = true -scale-info = { workspace = true, features = ["derive"] } - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -std = ["parity-scale-codec/std", "scale-info/std"] -default = ["std"] -[package] -name = "demo-stack-allocations" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true -parity-scale-codec = { workspace = true, features = ["derive"] } - -[dev-dependencies] -gtest.workspace = true -rand_pcg = { workspace = true } -rand = "0.8" -static_assertions.workspace = true - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -std = [] -default = ["std"] -[package] -name = "demo-signal-entry" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true -parity-scale-codec = { workspace = true, features = ["derive"] } - -[build-dependencies] -gear-wasm-builder.workspace = true - -[dev-dependencies] -gtest.workspace = true - -[features] -debug = ["gstd/debug"] -std = [] -default = ["std"] -[package] -name = "demo-node" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -parity-scale-codec = { workspace = true, features = ["derive"] } -gstd.workspace = true - -[build-dependencies] -gear-wasm-builder.workspace = true - -[dev-dependencies] -gstd = { workspace = true, features = ["debug"] } -gtest.workspace = true - -[features] -debug = ["gstd/debug"] -std = ["parity-scale-codec/std"] -default = ["std"] -[package] -name = "demo-custom" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true -gsys.workspace = true -parity-scale-codec.workspace = true - -[dev-dependencies] -gtest.workspace = true - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -default = ["std"] -std = [] -[package] -name = "demo-incomplete-async-payloads" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true -parity-scale-codec = { workspace = true, features = ["derive"] } - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -default = ["std"] -std = [] -[package] -name = "demo-async-recursion" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true -async-recursion.workspace = true - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -default = ["std"] -std = [] -[package] -name = "demo-async-signal-entry" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -parity-scale-codec = { workspace = true, features = ["derive"] } -gstd.workspace = true - -[build-dependencies] -gear-wasm-builder.workspace = true - -[dev-dependencies] -gtest.workspace = true - -[features] -debug = ["gstd/debug"] -std = ["parity-scale-codec/std"] -default = ["std"] -[package] -name = "demo-program-factory" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -parity-scale-codec = { workspace = true, features = ["derive"] } -gstd.workspace = true -hex-literal = "*" - -[build-dependencies] -gear-wasm-builder.workspace = true - -[dev-dependencies] -gtest.workspace = true - -[features] -debug = ["gstd/debug"] -std = ["parity-scale-codec/std"] -default = ["std"] -[package] -name = "demo-new-meta" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -parity-scale-codec.workspace = true -demo-meta-io = { path = "io" } -demo-meta-state-v1 = { path = "state-v1", default-features = false, optional = true } -demo-meta-state-v2 = { path = "state-v2", default-features = false, optional = true } -demo-meta-state-v3 = { path = "state-v3", default-features = false, optional = true } -gstd.workspace = true - -[build-dependencies] -demo-meta-io = { path = "io" } -gear-wasm-builder.workspace = true - -[dev-dependencies] -gtest.workspace = true - -[features] -debug = ["gstd/debug"] -default = ["std"] -std = [ - "demo-meta-state-v1/std", - "demo-meta-state-v2/std", - "demo-meta-state-v3/std", - "parity-scale-codec/std", -] -[package] -name = "demo-meta-state-v2" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true -# workspace = "../../../" - -[dependencies] -gstd.workspace = true -gmeta = { workspace = true, features = ["codegen"] } -demo-meta-io = { path = "../io" } - -[build-dependencies] -gear-wasm-builder = { workspace = true, features = ["metawasm"] } - -[features] -default = ["std"] -std = [] -[package] -name = "demo-meta-state-v3" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true -# workspace = "../../../" - -[dependencies] -gstd.workspace = true -gmeta = { workspace = true, features = ["codegen"] } -demo-meta-io = { path = "../io" } - -[build-dependencies] -gear-wasm-builder = { workspace = true, features = ["metawasm"] } - -[features] -default = ["std"] -std = [] -[package] -name = "demo-meta-io" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gmeta = { workspace = true } -scale-info = { workspace = true, features = ["derive"] } -parity-scale-codec = { workspace = true, features = ["derive"] } -[package] -name = "demo-meta-state-v1" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true -# workspace = "../../../" - -[dependencies] -gstd.workspace = true -gmeta = { workspace = true, features = ["codegen"] } -demo-meta-io = { path = "../io" } - -[build-dependencies] -gear-wasm-builder = { workspace = true, features = ["metawasm"] } - -[features] -default = ["std"] -std = [] -[package] -name = "demo-constructor" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true -parity-scale-codec = { workspace = true, features = ["derive"] } -hex.workspace = true - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -std = [] -default = ["std"] -[package] -name = "demo-fungible-token" -version = "0.1.4" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd = { workspace = true } -hashbrown = { workspace = true } -gmeta = { workspace = true } -ft-io = { path = "io" } - -[dev-dependencies] -gstd = { workspace = true, features = ["debug"] } -gear-core.workspace = true -tokio = { workspace = true, features = ["full", "test-util"] } -gclient = { workspace = true } -futures = "0.3" -rand = { version = "0.8" } -statrs = "0.16" - -[build-dependencies] -gear-wasm-builder = { workspace = true } - -[features] -debug = ["gstd/debug"] -std = [] -default = ["std"] -[package] -name = "ft-io" -version = "0.1.4" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd = { workspace = true } -gmeta = { workspace = true } -[package] -name = "demo-futures-unordered" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -gstd.workspace = true -parity-scale-codec = { workspace = true, features = ["derive"] } -futures = { workspace = true, features = ["alloc", "async-await"] } - -[build-dependencies] -gear-wasm-builder.workspace = true - -[features] -debug = ["gstd/debug"] -default = ["std"] -std = [] From a63211659bc1ea3b304e6589dde05a3d89e86871 Mon Sep 17 00:00:00 2001 From: Shamil <66209982+shamilsan@users.noreply.github.com> Date: Tue, 22 Aug 2023 13:54:01 +0400 Subject: [PATCH 3/5] chore: address comments --- examples/async-custom-entry/Cargo.toml | 4 +++- examples/async-init/Cargo.toml | 6 ++++-- examples/async-recursion/Cargo.toml | 2 ++ examples/async-signal-entry/Cargo.toml | 4 +++- examples/async-tester/Cargo.toml | 4 +++- examples/async/Cargo.toml | 4 +++- examples/calc-hash/Cargo.toml | 4 +++- examples/calc-hash/in-one-block/Cargo.toml | 4 +++- examples/calc-hash/over-blocks/Cargo.toml | 4 +++- examples/compose/Cargo.toml | 4 +++- examples/constructor/Cargo.toml | 4 +++- examples/custom/Cargo.toml | 2 ++ examples/delayed-sender/Cargo.toml | 2 ++ examples/distributor/Cargo.toml | 4 +++- examples/fungible-token/Cargo.toml | 18 ++++++++++-------- examples/fungible-token/io/Cargo.toml | 6 ++++-- examples/futures-unordered/Cargo.toml | 6 ++++-- examples/gas-burned/Cargo.toml | 2 ++ examples/incomplete-async-payloads/Cargo.toml | 4 +++- examples/init-fail-sender/Cargo.toml | 2 ++ examples/init-wait-reply-exit/Cargo.toml | 2 ++ examples/init-wait/Cargo.toml | 2 ++ examples/mul-by-const/Cargo.toml | 4 +++- examples/ncompose/Cargo.toml | 4 +++- examples/new-meta/Cargo.toml | 4 +++- examples/new-meta/io/Cargo.toml | 8 +++++--- examples/new-meta/state-v1/Cargo.toml | 2 ++ examples/new-meta/state-v2/Cargo.toml | 2 ++ examples/new-meta/state-v3/Cargo.toml | 2 ++ examples/node/Cargo.toml | 4 +++- examples/out-of-memory/Cargo.toml | 2 ++ examples/piggy-bank/Cargo.toml | 2 ++ examples/ping/Cargo.toml | 2 ++ examples/program-factory/Cargo.toml | 6 ++++-- examples/program-generator/Cargo.toml | 2 ++ examples/proxy-relay/Cargo.toml | 6 ++++-- examples/proxy-reservation-with-gas/Cargo.toml | 6 ++++-- examples/proxy/Cargo.toml | 8 +++++--- examples/read-big-state/Cargo.toml | 4 +++- examples/reservation-manager/Cargo.toml | 4 +++- examples/reserve-gas/Cargo.toml | 4 +++- examples/rwlock/Cargo.toml | 4 +++- examples/send-from-reservation/Cargo.toml | 4 +++- examples/signal-entry/Cargo.toml | 4 +++- examples/stack-allocations/Cargo.toml | 8 +++++--- examples/state-rollback/Cargo.toml | 2 ++ examples/sync-duplicate/Cargo.toml | 2 ++ examples/sys-calls/Cargo.toml | 6 ++++-- examples/syscall-error/Cargo.toml | 4 +++- examples/vec/Cargo.toml | 2 ++ examples/wait-timeout/Cargo.toml | 6 ++++-- examples/wait/Cargo.toml | 2 ++ examples/wait_wake/Cargo.toml | 4 +++- examples/waiter/Cargo.toml | 8 +++++--- examples/waiting-proxy/Cargo.toml | 2 ++ examples/wat/Cargo.toml | 4 +++- 56 files changed, 172 insertions(+), 60 deletions(-) diff --git a/examples/async-custom-entry/Cargo.toml b/examples/async-custom-entry/Cargo.toml index d01a744a8b7..ce820c11930 100644 --- a/examples/async-custom-entry/Cargo.toml +++ b/examples/async-custom-entry/Cargo.toml @@ -4,10 +4,12 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] -parity-scale-codec = { workspace = true, features = ["derive"] } gstd.workspace = true +parity-scale-codec.workspace = true [build-dependencies] gear-wasm-builder.workspace = true diff --git a/examples/async-init/Cargo.toml b/examples/async-init/Cargo.toml index fde0965c821..eb2eb78d4b6 100644 --- a/examples/async-init/Cargo.toml +++ b/examples/async-init/Cargo.toml @@ -4,11 +4,13 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true -parity-scale-codec = { workspace = true, features = ["derive"] } -futures = { workspace = true, features = ["alloc"] } +parity-scale-codec.workspace = true +futures.workspace = true [build-dependencies] gear-wasm-builder.workspace = true diff --git a/examples/async-recursion/Cargo.toml b/examples/async-recursion/Cargo.toml index 437490c3a54..99fc3c4f579 100644 --- a/examples/async-recursion/Cargo.toml +++ b/examples/async-recursion/Cargo.toml @@ -4,6 +4,8 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true diff --git a/examples/async-signal-entry/Cargo.toml b/examples/async-signal-entry/Cargo.toml index ee5f1f51b62..66067c35b43 100644 --- a/examples/async-signal-entry/Cargo.toml +++ b/examples/async-signal-entry/Cargo.toml @@ -4,10 +4,12 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] -parity-scale-codec = { workspace = true, features = ["derive"] } gstd.workspace = true +parity-scale-codec.workspace = true [build-dependencies] gear-wasm-builder.workspace = true diff --git a/examples/async-tester/Cargo.toml b/examples/async-tester/Cargo.toml index bc1c8db4ad8..4e75128315a 100644 --- a/examples/async-tester/Cargo.toml +++ b/examples/async-tester/Cargo.toml @@ -4,10 +4,12 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] -parity-scale-codec = { workspace = true, features = ["derive"] } gstd.workspace = true +parity-scale-codec.workspace = true [build-dependencies] gear-wasm-builder.workspace = true diff --git a/examples/async/Cargo.toml b/examples/async/Cargo.toml index 47678ca0437..45a6b2ddb94 100644 --- a/examples/async/Cargo.toml +++ b/examples/async/Cargo.toml @@ -4,10 +4,12 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true -parity-scale-codec = { workspace = true, features = ["derive"] } +parity-scale-codec.workspace = true [build-dependencies] gear-wasm-builder.workspace = true diff --git a/examples/calc-hash/Cargo.toml b/examples/calc-hash/Cargo.toml index fec4610bc79..41a8bd8947a 100644 --- a/examples/calc-hash/Cargo.toml +++ b/examples/calc-hash/Cargo.toml @@ -4,9 +4,11 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] -parity-scale-codec = { workspace = true, features = ["derive"]} +parity-scale-codec.workspace = true sha2 = { version = "0.10.6", default-features = false } [build-dependencies] diff --git a/examples/calc-hash/in-one-block/Cargo.toml b/examples/calc-hash/in-one-block/Cargo.toml index 59c1af47555..7192e5baca9 100644 --- a/examples/calc-hash/in-one-block/Cargo.toml +++ b/examples/calc-hash/in-one-block/Cargo.toml @@ -4,10 +4,12 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] -parity-scale-codec = { workspace = true, features = ["derive"]} gstd.workspace = true +parity-scale-codec.workspace = true shared = { path = "..", package = "demo-calc-hash" } [build-dependencies] diff --git a/examples/calc-hash/over-blocks/Cargo.toml b/examples/calc-hash/over-blocks/Cargo.toml index 95ed3387da6..5d93098fe37 100644 --- a/examples/calc-hash/over-blocks/Cargo.toml +++ b/examples/calc-hash/over-blocks/Cargo.toml @@ -4,10 +4,12 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] -parity-scale-codec = { workspace = true, features = ["derive"]} gstd.workspace = true +parity-scale-codec.workspace = true shared = { path = "../", package = "demo-calc-hash" } [build-dependencies] diff --git a/examples/compose/Cargo.toml b/examples/compose/Cargo.toml index ea7dc3ce8d2..bd4a1891822 100644 --- a/examples/compose/Cargo.toml +++ b/examples/compose/Cargo.toml @@ -4,10 +4,12 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true -hex = { version = "0.4.3", default-features = false, features = ["alloc"] } +hex.workspace = true [build-dependencies] gear-wasm-builder.workspace = true diff --git a/examples/constructor/Cargo.toml b/examples/constructor/Cargo.toml index 90bd70352b0..e1dc39d3567 100644 --- a/examples/constructor/Cargo.toml +++ b/examples/constructor/Cargo.toml @@ -4,11 +4,13 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true -parity-scale-codec = { workspace = true, features = ["derive"] } hex.workspace = true +parity-scale-codec.workspace = true [build-dependencies] gear-wasm-builder.workspace = true diff --git a/examples/custom/Cargo.toml b/examples/custom/Cargo.toml index fc80e7aabb8..bcf618a3c63 100644 --- a/examples/custom/Cargo.toml +++ b/examples/custom/Cargo.toml @@ -4,6 +4,8 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true diff --git a/examples/delayed-sender/Cargo.toml b/examples/delayed-sender/Cargo.toml index fadf31febda..c07ea044711 100644 --- a/examples/delayed-sender/Cargo.toml +++ b/examples/delayed-sender/Cargo.toml @@ -4,6 +4,8 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true diff --git a/examples/distributor/Cargo.toml b/examples/distributor/Cargo.toml index e1e8085020b..73887d6fd87 100644 --- a/examples/distributor/Cargo.toml +++ b/examples/distributor/Cargo.toml @@ -4,10 +4,12 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] -parity-scale-codec = { workspace = true, features = ["derive"] } gstd.workspace = true +parity-scale-codec.workspace = true [build-dependencies] gear-wasm-builder.workspace = true diff --git a/examples/fungible-token/Cargo.toml b/examples/fungible-token/Cargo.toml index 000959e208c..18d977de144 100644 --- a/examples/fungible-token/Cargo.toml +++ b/examples/fungible-token/Cargo.toml @@ -4,24 +4,26 @@ version = "0.1.4" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] -gstd = { workspace = true } -hashbrown = { workspace = true } -gmeta = { workspace = true } +gstd.workspace = true +hashbrown.workspace = true +gmeta.workspace = true ft-io = { path = "io" } [dev-dependencies] gstd = { workspace = true, features = ["debug"] } gear-core.workspace = true -tokio = { workspace = true, features = ["full", "test-util"] } -gclient = { workspace = true } -futures = "0.3" -rand = { version = "0.8" } +tokio.workspace = true +gclient.workspace = true +futures.workspace = true +rand.workspace = true statrs = "0.16" [build-dependencies] -gear-wasm-builder = { workspace = true } +gear-wasm-builder.workspace = true [features] debug = ["gstd/debug"] diff --git a/examples/fungible-token/io/Cargo.toml b/examples/fungible-token/io/Cargo.toml index 59d80d83486..7fd0537bf5c 100644 --- a/examples/fungible-token/io/Cargo.toml +++ b/examples/fungible-token/io/Cargo.toml @@ -4,7 +4,9 @@ version = "0.1.4" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] -gstd = { workspace = true } -gmeta = { workspace = true } +gstd.workspace = true +gmeta.workspace = true diff --git a/examples/futures-unordered/Cargo.toml b/examples/futures-unordered/Cargo.toml index 10fd6a80804..b20a78af317 100644 --- a/examples/futures-unordered/Cargo.toml +++ b/examples/futures-unordered/Cargo.toml @@ -4,11 +4,13 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true -parity-scale-codec = { workspace = true, features = ["derive"] } -futures = { workspace = true, features = ["alloc", "async-await"] } +parity-scale-codec.workspace = true +futures = { workspace = true, features = ["async-await"] } [build-dependencies] gear-wasm-builder.workspace = true diff --git a/examples/gas-burned/Cargo.toml b/examples/gas-burned/Cargo.toml index c3bcbfb9aab..9ad1445febf 100644 --- a/examples/gas-burned/Cargo.toml +++ b/examples/gas-burned/Cargo.toml @@ -4,6 +4,8 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true diff --git a/examples/incomplete-async-payloads/Cargo.toml b/examples/incomplete-async-payloads/Cargo.toml index 733fb5b4f7d..1c4ef56a519 100644 --- a/examples/incomplete-async-payloads/Cargo.toml +++ b/examples/incomplete-async-payloads/Cargo.toml @@ -4,10 +4,12 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true -parity-scale-codec = { workspace = true, features = ["derive"] } +parity-scale-codec.workspace = true [build-dependencies] gear-wasm-builder.workspace = true diff --git a/examples/init-fail-sender/Cargo.toml b/examples/init-fail-sender/Cargo.toml index 5b1aa98a3c6..34611c8f1fb 100644 --- a/examples/init-fail-sender/Cargo.toml +++ b/examples/init-fail-sender/Cargo.toml @@ -4,6 +4,8 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true diff --git a/examples/init-wait-reply-exit/Cargo.toml b/examples/init-wait-reply-exit/Cargo.toml index 234a5e0178f..71b6321fe47 100644 --- a/examples/init-wait-reply-exit/Cargo.toml +++ b/examples/init-wait-reply-exit/Cargo.toml @@ -4,6 +4,8 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true diff --git a/examples/init-wait/Cargo.toml b/examples/init-wait/Cargo.toml index 05f2d67d4d3..560c4e37019 100644 --- a/examples/init-wait/Cargo.toml +++ b/examples/init-wait/Cargo.toml @@ -4,6 +4,8 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true diff --git a/examples/mul-by-const/Cargo.toml b/examples/mul-by-const/Cargo.toml index 57e2d376d0f..64e2f97f889 100644 --- a/examples/mul-by-const/Cargo.toml +++ b/examples/mul-by-const/Cargo.toml @@ -4,10 +4,12 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true -hex = { version = "0.4.3", default-features = false, features = ["alloc"] } +hex.workspace = true [build-dependencies] gear-wasm-builder.workspace = true diff --git a/examples/ncompose/Cargo.toml b/examples/ncompose/Cargo.toml index 846db8f57f9..9cb597e461a 100644 --- a/examples/ncompose/Cargo.toml +++ b/examples/ncompose/Cargo.toml @@ -4,10 +4,12 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true -hex = { version = "0.4.3", default-features = false, features = ["alloc"] } +hex.workspace = true [build-dependencies] gear-wasm-builder.workspace = true diff --git a/examples/new-meta/Cargo.toml b/examples/new-meta/Cargo.toml index 1d7ae947885..f78115c3251 100644 --- a/examples/new-meta/Cargo.toml +++ b/examples/new-meta/Cargo.toml @@ -4,14 +4,16 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] +gstd.workspace = true parity-scale-codec.workspace = true demo-meta-io = { path = "io" } demo-meta-state-v1 = { path = "state-v1", default-features = false, optional = true } demo-meta-state-v2 = { path = "state-v2", default-features = false, optional = true } demo-meta-state-v3 = { path = "state-v3", default-features = false, optional = true } -gstd.workspace = true [build-dependencies] demo-meta-io = { path = "io" } diff --git a/examples/new-meta/io/Cargo.toml b/examples/new-meta/io/Cargo.toml index b4a3affb0ee..6bd4fedeaed 100644 --- a/examples/new-meta/io/Cargo.toml +++ b/examples/new-meta/io/Cargo.toml @@ -4,8 +4,10 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] -gmeta = { workspace = true } -scale-info = { workspace = true, features = ["derive"] } -parity-scale-codec = { workspace = true, features = ["derive"] } +gmeta.workspace = true +scale-info.workspace = true +parity-scale-codec.workspace = true diff --git a/examples/new-meta/state-v1/Cargo.toml b/examples/new-meta/state-v1/Cargo.toml index 915bcfdf07f..df273f240cf 100644 --- a/examples/new-meta/state-v1/Cargo.toml +++ b/examples/new-meta/state-v1/Cargo.toml @@ -4,6 +4,8 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true diff --git a/examples/new-meta/state-v2/Cargo.toml b/examples/new-meta/state-v2/Cargo.toml index da84f0b246b..b63c6aec983 100644 --- a/examples/new-meta/state-v2/Cargo.toml +++ b/examples/new-meta/state-v2/Cargo.toml @@ -4,6 +4,8 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true diff --git a/examples/new-meta/state-v3/Cargo.toml b/examples/new-meta/state-v3/Cargo.toml index 4e49d593ed0..7724c477251 100644 --- a/examples/new-meta/state-v3/Cargo.toml +++ b/examples/new-meta/state-v3/Cargo.toml @@ -4,6 +4,8 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true diff --git a/examples/node/Cargo.toml b/examples/node/Cargo.toml index 80b859cde36..d0e5078b4f4 100644 --- a/examples/node/Cargo.toml +++ b/examples/node/Cargo.toml @@ -4,10 +4,12 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] -parity-scale-codec = { workspace = true, features = ["derive"] } gstd.workspace = true +parity-scale-codec.workspace = true [build-dependencies] gear-wasm-builder.workspace = true diff --git a/examples/out-of-memory/Cargo.toml b/examples/out-of-memory/Cargo.toml index e8b49e1699f..3b039d61913 100644 --- a/examples/out-of-memory/Cargo.toml +++ b/examples/out-of-memory/Cargo.toml @@ -4,6 +4,8 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true diff --git a/examples/piggy-bank/Cargo.toml b/examples/piggy-bank/Cargo.toml index 4a1cee16d5f..12e17ebc57b 100644 --- a/examples/piggy-bank/Cargo.toml +++ b/examples/piggy-bank/Cargo.toml @@ -4,6 +4,8 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true diff --git a/examples/ping/Cargo.toml b/examples/ping/Cargo.toml index 46cabcd31e3..50dd1ce8605 100644 --- a/examples/ping/Cargo.toml +++ b/examples/ping/Cargo.toml @@ -4,6 +4,8 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true diff --git a/examples/program-factory/Cargo.toml b/examples/program-factory/Cargo.toml index e9af75b8c6f..104d6b64ff3 100644 --- a/examples/program-factory/Cargo.toml +++ b/examples/program-factory/Cargo.toml @@ -4,11 +4,13 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] -parity-scale-codec = { workspace = true, features = ["derive"] } gstd.workspace = true -hex-literal = "*" +parity-scale-codec.workspace = true +hex-literal.workspace = true [build-dependencies] gear-wasm-builder.workspace = true diff --git a/examples/program-generator/Cargo.toml b/examples/program-generator/Cargo.toml index e3bd5a7049a..9782f2a468f 100644 --- a/examples/program-generator/Cargo.toml +++ b/examples/program-generator/Cargo.toml @@ -4,6 +4,8 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true diff --git a/examples/proxy-relay/Cargo.toml b/examples/proxy-relay/Cargo.toml index b009ba681b1..4378c75e4e3 100644 --- a/examples/proxy-relay/Cargo.toml +++ b/examples/proxy-relay/Cargo.toml @@ -4,11 +4,13 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] -parity-scale-codec = { workspace = true, features = ["derive"] } gstd.workspace = true -scale-info = { workspace = true, features = ["derive"] } +parity-scale-codec.workspace = true +scale-info.workspace = true [build-dependencies] gear-wasm-builder.workspace = true diff --git a/examples/proxy-reservation-with-gas/Cargo.toml b/examples/proxy-reservation-with-gas/Cargo.toml index 700c2ca6d32..c8e775cdf43 100644 --- a/examples/proxy-reservation-with-gas/Cargo.toml +++ b/examples/proxy-reservation-with-gas/Cargo.toml @@ -4,11 +4,13 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] -parity-scale-codec = { workspace = true, features = ["derive"] } gstd.workspace = true -scale-info = { workspace = true, features = ["derive"] } +parity-scale-codec.workspace = true +scale-info.workspace = true [build-dependencies] gear-wasm-builder.workspace = true diff --git a/examples/proxy/Cargo.toml b/examples/proxy/Cargo.toml index 2cde888e83d..f679ca89cd5 100644 --- a/examples/proxy/Cargo.toml +++ b/examples/proxy/Cargo.toml @@ -4,11 +4,13 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] -gstd = { workspace = true } -parity-scale-codec = { workspace = true, features = ["derive"] } -scale-info = { workspace = true, features = ["derive"] } +gstd.workspace = true +parity-scale-codec.workspace = true +scale-info.workspace = true [build-dependencies] gear-wasm-builder.workspace = true diff --git a/examples/read-big-state/Cargo.toml b/examples/read-big-state/Cargo.toml index 956d2c7c54b..c7ce1f683e4 100644 --- a/examples/read-big-state/Cargo.toml +++ b/examples/read-big-state/Cargo.toml @@ -4,10 +4,12 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true -parity-scale-codec = { workspace = true, features = ["derive"] } +parity-scale-codec.workspace = true [build-dependencies] gear-wasm-builder.workspace = true diff --git a/examples/reservation-manager/Cargo.toml b/examples/reservation-manager/Cargo.toml index 9e7cf0d5186..372ecdbd5aa 100644 --- a/examples/reservation-manager/Cargo.toml +++ b/examples/reservation-manager/Cargo.toml @@ -4,10 +4,12 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true -parity-scale-codec = { workspace = true, features = ["derive"] } +parity-scale-codec.workspace = true [build-dependencies] gear-wasm-builder.workspace = true diff --git a/examples/reserve-gas/Cargo.toml b/examples/reserve-gas/Cargo.toml index 4ebc3e193b2..4aef7faa035 100644 --- a/examples/reserve-gas/Cargo.toml +++ b/examples/reserve-gas/Cargo.toml @@ -4,10 +4,12 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true -parity-scale-codec = { workspace = true, features = ["derive"] } +parity-scale-codec.workspace = true [build-dependencies] gear-wasm-builder.workspace = true diff --git a/examples/rwlock/Cargo.toml b/examples/rwlock/Cargo.toml index f82785132ca..b7a8621cb12 100644 --- a/examples/rwlock/Cargo.toml +++ b/examples/rwlock/Cargo.toml @@ -4,10 +4,12 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd = { workspace = true, features = ["debug"] } -parity-scale-codec = { workspace = true, features = ["derive"] } +parity-scale-codec.workspace = true [build-dependencies] gear-wasm-builder.workspace = true diff --git a/examples/send-from-reservation/Cargo.toml b/examples/send-from-reservation/Cargo.toml index b095b852fe5..cbde057d74b 100644 --- a/examples/send-from-reservation/Cargo.toml +++ b/examples/send-from-reservation/Cargo.toml @@ -4,10 +4,12 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] -parity-scale-codec = { workspace = true, features = ["derive"] } gstd.workspace = true +parity-scale-codec.workspace = true [build-dependencies] gear-wasm-builder.workspace = true diff --git a/examples/signal-entry/Cargo.toml b/examples/signal-entry/Cargo.toml index 708b63893c9..9edebd56afe 100644 --- a/examples/signal-entry/Cargo.toml +++ b/examples/signal-entry/Cargo.toml @@ -4,10 +4,12 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true -parity-scale-codec = { workspace = true, features = ["derive"] } +parity-scale-codec.workspace = true [build-dependencies] gear-wasm-builder.workspace = true diff --git a/examples/stack-allocations/Cargo.toml b/examples/stack-allocations/Cargo.toml index d3ec7a51e95..e6b8fe0c32e 100644 --- a/examples/stack-allocations/Cargo.toml +++ b/examples/stack-allocations/Cargo.toml @@ -4,15 +4,17 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true -parity-scale-codec = { workspace = true, features = ["derive"] } +parity-scale-codec.workspace = true [dev-dependencies] gtest.workspace = true -rand_pcg = { workspace = true } -rand = "0.8" +rand_pcg.workspace = true +rand.workspace = true static_assertions.workspace = true [build-dependencies] diff --git a/examples/state-rollback/Cargo.toml b/examples/state-rollback/Cargo.toml index df652d9f995..c4d156bc250 100644 --- a/examples/state-rollback/Cargo.toml +++ b/examples/state-rollback/Cargo.toml @@ -4,6 +4,8 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true diff --git a/examples/sync-duplicate/Cargo.toml b/examples/sync-duplicate/Cargo.toml index 9d95387d7e1..f0d0a3adf96 100644 --- a/examples/sync-duplicate/Cargo.toml +++ b/examples/sync-duplicate/Cargo.toml @@ -4,6 +4,8 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true diff --git a/examples/sys-calls/Cargo.toml b/examples/sys-calls/Cargo.toml index 6ab1914d0fa..1e0e64155bd 100644 --- a/examples/sys-calls/Cargo.toml +++ b/examples/sys-calls/Cargo.toml @@ -4,10 +4,12 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] -gstd = { workspace = true } -parity-scale-codec = { workspace = true, features = ["derive"] } +gstd.workspace = true +parity-scale-codec.workspace = true [build-dependencies] gear-wasm-builder.workspace = true diff --git a/examples/syscall-error/Cargo.toml b/examples/syscall-error/Cargo.toml index 5c7155134f4..b454bad67bc 100644 --- a/examples/syscall-error/Cargo.toml +++ b/examples/syscall-error/Cargo.toml @@ -4,9 +4,11 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] -parity-scale-codec = { workspace = true, features = ["derive"] } +parity-scale-codec.workspace = true gstd.workspace = true gsys.workspace = true diff --git a/examples/vec/Cargo.toml b/examples/vec/Cargo.toml index d428636ee9f..176929ad803 100644 --- a/examples/vec/Cargo.toml +++ b/examples/vec/Cargo.toml @@ -4,6 +4,8 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd = { workspace = true, features = ["debug"] } diff --git a/examples/wait-timeout/Cargo.toml b/examples/wait-timeout/Cargo.toml index 1650a625443..c1e7c4e47a0 100644 --- a/examples/wait-timeout/Cargo.toml +++ b/examples/wait-timeout/Cargo.toml @@ -4,11 +4,13 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] -parity-scale-codec = { workspace = true, features = ["derive"] } gstd.workspace = true -futures = { version = "0.3", default-features = false, features = ["alloc"] } +futures.workspace = true +parity-scale-codec.workspace = true [build-dependencies] gear-wasm-builder.workspace = true diff --git a/examples/wait/Cargo.toml b/examples/wait/Cargo.toml index c45a661cddc..1ef9502fc9c 100644 --- a/examples/wait/Cargo.toml +++ b/examples/wait/Cargo.toml @@ -4,6 +4,8 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true diff --git a/examples/wait_wake/Cargo.toml b/examples/wait_wake/Cargo.toml index adf86e08c8f..b92655788c4 100644 --- a/examples/wait_wake/Cargo.toml +++ b/examples/wait_wake/Cargo.toml @@ -4,10 +4,12 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true -parity-scale-codec = { workspace = true, features = ["derive"] } +parity-scale-codec.workspace = true [build-dependencies] gear-wasm-builder.workspace = true diff --git a/examples/waiter/Cargo.toml b/examples/waiter/Cargo.toml index f978e3d2fda..4b6dc2e8400 100644 --- a/examples/waiter/Cargo.toml +++ b/examples/waiter/Cargo.toml @@ -4,11 +4,13 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] -parity-scale-codec = { workspace = true, features = ["derive"] } -futures.workspace = true gstd.workspace = true +futures.workspace = true +parity-scale-codec.workspace = true [build-dependencies] gear-wasm-builder.workspace = true @@ -16,7 +18,7 @@ gear-wasm-builder.workspace = true [dev-dependencies] gtest.workspace = true gear-core.workspace = true -demo-waiter = { path = ".", features = ["debug"] } +demo-waiter = { workspace = true, features = ["debug"] } [features] debug = ["gstd/debug"] diff --git a/examples/waiting-proxy/Cargo.toml b/examples/waiting-proxy/Cargo.toml index 381cc50e7e0..076c2520096 100644 --- a/examples/waiting-proxy/Cargo.toml +++ b/examples/waiting-proxy/Cargo.toml @@ -4,6 +4,8 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] gstd.workspace = true diff --git a/examples/wat/Cargo.toml b/examples/wat/Cargo.toml index c87112a7f83..f4cfbee18e0 100644 --- a/examples/wat/Cargo.toml +++ b/examples/wat/Cargo.toml @@ -4,7 +4,9 @@ version = "0.1.0" authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] -hex = { workspace = true, features = ["alloc"] } +hex.workspace = true wabt.workspace = true From 7e5552afde793c3091808d5d2db3d19979dab82a Mon Sep 17 00:00:00 2001 From: Shamil <66209982+shamilsan@users.noreply.github.com> Date: Wed, 23 Aug 2023 10:04:43 +0400 Subject: [PATCH 4/5] chore: split source code into `lib` + `wasm` --- examples/async-custom-entry/src/lib.rs | 31 +- examples/async-custom-entry/src/wasm.rs | 46 ++ examples/async-init/src/lib.rs | 72 +-- examples/async-init/src/wasm.rs | 82 ++++ examples/async-recursion/src/lib.rs | 37 +- examples/async-recursion/src/wasm.rs | 52 +++ examples/async-signal-entry/src/lib.rs | 26 +- examples/async-signal-entry/src/wasm.rs | 41 ++ examples/async-tester/src/lib.rs | 4 +- .../async-tester/src/{code.rs => wasm.rs} | 6 +- examples/async/src/lib.rs | 48 +- examples/async/src/wasm.rs | 63 +++ examples/calc-hash/in-one-block/src/lib.rs | 4 +- .../in-one-block/src/{code.rs => wasm.rs} | 0 examples/calc-hash/over-blocks/src/lib.rs | 4 +- .../over-blocks/src/{code.rs => wasm.rs} | 4 +- examples/compose/src/lib.rs | 109 +---- examples/compose/src/wasm.rs | 131 ++++++ examples/delayed-sender/src/lib.rs | 4 +- .../delayed-sender/src/{code.rs => wasm.rs} | 10 +- examples/distributor/src/lib.rs | 169 +------ examples/distributor/src/wasm.rs | 183 ++++++++ examples/fungible-token/src/lib.rs | 2 +- .../src/{contract.rs => wasm.rs} | 0 examples/futures-unordered/src/lib.rs | 111 +---- examples/futures-unordered/src/wasm.rs | 126 +++++ examples/gas-burned/src/lib.rs | 24 +- examples/gas-burned/src/wasm.rs | 58 +++ examples/incomplete-async-payloads/src/lib.rs | 58 +-- .../incomplete-async-payloads/src/wasm.rs | 73 +++ examples/init-fail-sender/src/lib.rs | 18 +- examples/init-fail-sender/src/wasm.rs | 15 + examples/init-wait-reply-exit/src/lib.rs | 4 +- .../src/{code.rs => wasm.rs} | 0 examples/init-wait/src/lib.rs | 4 +- examples/init-wait/src/{code.rs => wasm.rs} | 0 examples/messager/src/lib.rs | 4 +- examples/messager/src/{code.rs => wasm.rs} | 0 examples/mul-by-const/src/lib.rs | 58 +-- examples/mul-by-const/src/wasm.rs | 80 ++++ examples/ncompose/src/lib.rs | 132 +----- examples/ncompose/src/wasm.rs | 154 +++++++ examples/node/src/lib.rs | 232 +--------- examples/node/src/wasm.rs | 248 ++++++++++ examples/out-of-memory/src/lib.rs | 15 +- examples/out-of-memory/src/wasm.rs | 28 ++ examples/piggy-bank/src/lib.rs | 18 +- examples/piggy-bank/src/wasm.rs | 33 ++ examples/ping/src/lib.rs | 13 +- examples/ping/src/wasm.rs | 28 ++ examples/program-factory/src/lib.rs | 55 +-- examples/program-factory/src/wasm.rs | 71 +++ examples/program-generator/src/lib.rs | 31 +- examples/program-generator/src/wasm.rs | 41 ++ examples/proxy-relay/src/lib.rs | 82 +--- examples/proxy-relay/src/wasm.rs | 97 ++++ .../proxy-reservation-with-gas/src/lib.rs | 33 +- .../proxy-reservation-with-gas/src/wasm.rs | 48 ++ examples/proxy/src/lib.rs | 26 +- examples/proxy/src/wasm.rs | 40 ++ examples/read-big-state/src/lib.rs | 22 +- examples/read-big-state/src/wasm.rs | 37 ++ examples/reservation-manager/src/lib.rs | 31 +- examples/reservation-manager/src/wasm.rs | 46 ++ examples/reserve-gas/src/lib.rs | 190 +------- examples/reserve-gas/src/wasm.rs | 199 ++++++++ examples/rwlock/src/lib.rs | 109 +---- examples/rwlock/src/wasm.rs | 124 +++++ examples/send-from-reservation/src/lib.rs | 82 +--- examples/send-from-reservation/src/wasm.rs | 92 ++++ examples/signal-entry/src/lib.rs | 182 +------- examples/signal-entry/src/wasm.rs | 197 ++++++++ examples/stack-allocations/src/lib.rs | 42 +- examples/stack-allocations/src/wasm.rs | 62 +++ examples/state-rollback/src/lib.rs | 29 +- examples/state-rollback/src/wasm.rs | 44 ++ examples/sync-duplicate/src/lib.rs | 31 +- examples/sync-duplicate/src/wasm.rs | 46 ++ examples/sys-calls/src/lib.rs | 427 +---------------- examples/sys-calls/src/wasm.rs | 432 ++++++++++++++++++ examples/syscall-error/src/lib.rs | 17 +- examples/syscall-error/src/wasm.rs | 35 ++ examples/vec/src/lib.rs | 37 +- examples/vec/src/wasm.rs | 52 +++ examples/wait-timeout/src/lib.rs | 4 +- .../wait-timeout/src/{code.rs => wasm.rs} | 19 +- examples/wait/src/lib.rs | 38 +- examples/wait/src/wasm.rs | 53 +++ examples/wait_wake/src/lib.rs | 36 +- examples/wait_wake/src/wasm.rs | 50 ++ examples/waiter/src/lib.rs | 5 +- examples/waiter/src/{code.rs => wasm.rs} | 18 + examples/waiting-proxy/src/lib.rs | 29 +- examples/waiting-proxy/src/wasm.rs | 44 ++ 94 files changed, 3354 insertions(+), 2693 deletions(-) create mode 100644 examples/async-custom-entry/src/wasm.rs create mode 100644 examples/async-init/src/wasm.rs create mode 100644 examples/async-recursion/src/wasm.rs create mode 100644 examples/async-signal-entry/src/wasm.rs rename examples/async-tester/src/{code.rs => wasm.rs} (91%) create mode 100644 examples/async/src/wasm.rs rename examples/calc-hash/in-one-block/src/{code.rs => wasm.rs} (100%) rename examples/calc-hash/over-blocks/src/{code.rs => wasm.rs} (96%) create mode 100644 examples/compose/src/wasm.rs rename examples/delayed-sender/src/{code.rs => wasm.rs} (77%) create mode 100644 examples/distributor/src/wasm.rs rename examples/fungible-token/src/{contract.rs => wasm.rs} (100%) create mode 100644 examples/futures-unordered/src/wasm.rs create mode 100644 examples/gas-burned/src/wasm.rs create mode 100644 examples/incomplete-async-payloads/src/wasm.rs create mode 100644 examples/init-fail-sender/src/wasm.rs rename examples/init-wait-reply-exit/src/{code.rs => wasm.rs} (100%) rename examples/init-wait/src/{code.rs => wasm.rs} (100%) rename examples/messager/src/{code.rs => wasm.rs} (100%) create mode 100644 examples/mul-by-const/src/wasm.rs create mode 100644 examples/ncompose/src/wasm.rs create mode 100644 examples/node/src/wasm.rs create mode 100644 examples/out-of-memory/src/wasm.rs create mode 100644 examples/piggy-bank/src/wasm.rs create mode 100644 examples/ping/src/wasm.rs create mode 100644 examples/program-factory/src/wasm.rs create mode 100644 examples/program-generator/src/wasm.rs create mode 100644 examples/proxy-relay/src/wasm.rs create mode 100644 examples/proxy-reservation-with-gas/src/wasm.rs create mode 100644 examples/proxy/src/wasm.rs create mode 100644 examples/read-big-state/src/wasm.rs create mode 100644 examples/reservation-manager/src/wasm.rs create mode 100644 examples/reserve-gas/src/wasm.rs create mode 100644 examples/rwlock/src/wasm.rs create mode 100644 examples/send-from-reservation/src/wasm.rs create mode 100644 examples/signal-entry/src/wasm.rs create mode 100644 examples/stack-allocations/src/wasm.rs create mode 100644 examples/state-rollback/src/wasm.rs create mode 100644 examples/sync-duplicate/src/wasm.rs create mode 100644 examples/sys-calls/src/wasm.rs create mode 100644 examples/syscall-error/src/wasm.rs create mode 100644 examples/vec/src/wasm.rs rename examples/wait-timeout/src/{code.rs => wasm.rs} (84%) create mode 100644 examples/wait/src/wasm.rs create mode 100644 examples/wait_wake/src/wasm.rs rename examples/waiter/src/{code.rs => wasm.rs} (90%) create mode 100644 examples/waiting-proxy/src/wasm.rs diff --git a/examples/async-custom-entry/src/lib.rs b/examples/async-custom-entry/src/lib.rs index 6a7b7d54ea0..b20b99554f5 100644 --- a/examples/async-custom-entry/src/lib.rs +++ b/examples/async-custom-entry/src/lib.rs @@ -27,33 +27,4 @@ mod code { pub use code::WASM_BINARY_OPT as WASM_BINARY; #[cfg(not(feature = "std"))] -mod wasm { - use gstd::{msg, ActorId}; - - static mut USER: ActorId = ActorId::zero(); - - #[gstd::async_init(handle_reply = my_handle_reply, handle_signal = my_handle_signal)] - async fn init() { - gstd::Config::set_system_reserve(10_000_000_000).expect("Failed to set system reserve"); - - unsafe { USER = msg::source() } - } - - #[gstd::async_main] - async fn main() { - #[allow(clippy::empty_loop)] - loop {} - } - - fn my_handle_reply() { - unsafe { - msg::send_bytes(USER, b"my_handle_reply", 0).unwrap(); - } - } - - fn my_handle_signal() { - unsafe { - msg::send_bytes(USER, b"my_handle_signal", 0).unwrap(); - } - } -} +mod wasm; diff --git a/examples/async-custom-entry/src/wasm.rs b/examples/async-custom-entry/src/wasm.rs new file mode 100644 index 00000000000..a8f110f5bb2 --- /dev/null +++ b/examples/async-custom-entry/src/wasm.rs @@ -0,0 +1,46 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use gstd::{msg, ActorId}; + +static mut USER: ActorId = ActorId::zero(); + +#[gstd::async_init(handle_reply = my_handle_reply, handle_signal = my_handle_signal)] +async fn init() { + gstd::Config::set_system_reserve(10_000_000_000).expect("Failed to set system reserve"); + + unsafe { USER = msg::source() } +} + +#[gstd::async_main] +async fn main() { + #[allow(clippy::empty_loop)] + loop {} +} + +fn my_handle_reply() { + unsafe { + msg::send_bytes(USER, b"my_handle_reply", 0).unwrap(); + } +} + +fn my_handle_signal() { + unsafe { + msg::send_bytes(USER, b"my_handle_signal", 0).unwrap(); + } +} diff --git a/examples/async-init/src/lib.rs b/examples/async-init/src/lib.rs index d5111c026cd..f58aab75c33 100644 --- a/examples/async-init/src/lib.rs +++ b/examples/async-init/src/lib.rs @@ -57,74 +57,4 @@ impl InputArgs { } #[cfg(not(feature = "std"))] -mod wasm { - /* The program demonstrates asynchronous execution and - * how to use macros `gstd::async_init`/`gstd::async_main`. - * - * `Init` method gets three addresses, sends "PING" messages - * to them and waits for at least two replies with any payload ("approvals"). - * - * `Handle` processes only "PING" messages. When `handle` gets such message - * it sends empty requests to the three addresses and waits for just one approval. - * If an approval is obtained the method replies with "PONG". - */ - - use crate::InputArgs; - use futures::future; - use gstd::{msg, prelude::*, ActorId}; - - // One of the addresses supposed to be non-program. - static mut ARGUMENTS: InputArgs = InputArgs { - approver_first: ActorId::zero(), - approver_second: ActorId::zero(), - approver_third: ActorId::zero(), - }; - - static mut RESPONSES: u8 = 0; - - #[gstd::async_init] - async fn init() { - let arguments: InputArgs = msg::load().expect("Failed to load arguments"); - - let mut requests = arguments - .iter() - .map(|&addr| { - msg::send_bytes_for_reply(addr, "PING", 0, 0).expect("Failed to send message") - }) - .collect::>(); - - unsafe { - ARGUMENTS = arguments; - } - - while !requests.is_empty() { - let (.., remaining) = future::select_all(requests).await; - unsafe { - RESPONSES += 1; - } - - if unsafe { RESPONSES } >= 2 { - break; - } - - requests = remaining; - } - } - - #[gstd::async_main] - async fn main() { - let message = msg::load_bytes().expect("Failed to load bytes"); - - assert_eq!(message, b"PING"); - - let requests = unsafe { ARGUMENTS.iter() } - .map(|&addr| { - msg::send_bytes_for_reply(addr, "PING", 0, 0).expect("Failed to send message") - }) - .collect::>(); - - let _ = future::select_all(requests).await; - - msg::reply(unsafe { RESPONSES }, 0).expect("Failed to send reply"); - } -} +mod wasm; diff --git a/examples/async-init/src/wasm.rs b/examples/async-init/src/wasm.rs new file mode 100644 index 00000000000..0b12705ca91 --- /dev/null +++ b/examples/async-init/src/wasm.rs @@ -0,0 +1,82 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +//! The program demonstrates asynchronous execution and +//! how to use macros `gstd::async_init`/`gstd::async_main`. +//! +//! `Init` method gets three addresses, sends "PING" messages +//! to them and waits for at least two replies with any payload ("approvals"). +//! +//! `Handle` processes only "PING" messages. When `handle` gets such message +//! it sends empty requests to the three addresses and waits for just one approval. +//! If an approval is obtained the method replies with "PONG". + +use crate::InputArgs; +use futures::future; +use gstd::{msg, prelude::*, ActorId}; + +// One of the addresses supposed to be non-program. +static mut ARGUMENTS: InputArgs = InputArgs { + approver_first: ActorId::zero(), + approver_second: ActorId::zero(), + approver_third: ActorId::zero(), +}; + +static mut RESPONSES: u8 = 0; + +#[gstd::async_init] +async fn init() { + let arguments: InputArgs = msg::load().expect("Failed to load arguments"); + + let mut requests = arguments + .iter() + .map(|&addr| msg::send_bytes_for_reply(addr, "PING", 0, 0).expect("Failed to send message")) + .collect::>(); + + unsafe { + ARGUMENTS = arguments; + } + + while !requests.is_empty() { + let (.., remaining) = future::select_all(requests).await; + unsafe { + RESPONSES += 1; + } + + if unsafe { RESPONSES } >= 2 { + break; + } + + requests = remaining; + } +} + +#[gstd::async_main] +async fn main() { + let message = msg::load_bytes().expect("Failed to load bytes"); + + assert_eq!(message, b"PING"); + + let requests = unsafe { ARGUMENTS.iter() } + .map(|&addr| msg::send_bytes_for_reply(addr, "PING", 0, 0).expect("Failed to send message")) + .collect::>(); + + let _ = future::select_all(requests).await; + + msg::reply(unsafe { RESPONSES }, 0).expect("Failed to send reply"); +} diff --git a/examples/async-recursion/src/lib.rs b/examples/async-recursion/src/lib.rs index 7d32db1717b..fbc08d47a0b 100644 --- a/examples/async-recursion/src/lib.rs +++ b/examples/async-recursion/src/lib.rs @@ -27,39 +27,4 @@ mod code { pub use code::WASM_BINARY_OPT as WASM_BINARY; #[cfg(not(feature = "std"))] -mod wasm { - use async_recursion::async_recursion; - use gstd::{msg, prelude::*, ActorId}; - - static mut DESTINATION: ActorId = ActorId::zero(); - - #[no_mangle] - extern "C" fn init() { - let destination = msg::load().expect("Failed to load destination"); - unsafe { DESTINATION = destination }; - } - - /// Send message "PING" and wait for a reply, then recursively - /// repeat with `val` decreased by reply len while `val` > reply len. - #[async_recursion] - async fn rec_func(val: i32) { - let reply = msg::send_bytes_for_reply(unsafe { DESTINATION }, "PING", 0, 0) - .expect("Failed to send message") - .await - .expect("Received error reply"); - - msg::send(msg::source(), val, 0).expect("Failed to send message"); - - let reply_len = reply.len() as i32; - - if val - reply_len > 0 { - rec_func(val - reply_len).await; - } - } - - #[gstd::async_main] - async fn main() { - let arg = msg::load().expect("Failed to load argument"); - rec_func(arg).await; - } -} +mod wasm; diff --git a/examples/async-recursion/src/wasm.rs b/examples/async-recursion/src/wasm.rs new file mode 100644 index 00000000000..40648a95b08 --- /dev/null +++ b/examples/async-recursion/src/wasm.rs @@ -0,0 +1,52 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use async_recursion::async_recursion; +use gstd::{msg, prelude::*, ActorId}; + +static mut DESTINATION: ActorId = ActorId::zero(); + +#[no_mangle] +extern "C" fn init() { + let destination = msg::load().expect("Failed to load destination"); + unsafe { DESTINATION = destination }; +} + +/// Send message "PING" and wait for a reply, then recursively +/// repeat with `val` decreased by reply len while `val` > reply len. +#[async_recursion] +async fn rec_func(val: i32) { + let reply = msg::send_bytes_for_reply(unsafe { DESTINATION }, "PING", 0, 0) + .expect("Failed to send message") + .await + .expect("Received error reply"); + + msg::send(msg::source(), val, 0).expect("Failed to send message"); + + let reply_len = reply.len() as i32; + + if val - reply_len > 0 { + rec_func(val - reply_len).await; + } +} + +#[gstd::async_main] +async fn main() { + let arg = msg::load().expect("Failed to load argument"); + rec_func(arg).await; +} diff --git a/examples/async-signal-entry/src/lib.rs b/examples/async-signal-entry/src/lib.rs index 921725da3ef..a6e3c737ab1 100644 --- a/examples/async-signal-entry/src/lib.rs +++ b/examples/async-signal-entry/src/lib.rs @@ -35,28 +35,4 @@ pub enum InitAction { } #[cfg(not(feature = "std"))] -mod wasm { - use super::*; - use gstd::{exec, msg}; - - #[gstd::async_init] - async fn init() { - let action = msg::load().unwrap(); - match action { - InitAction::None => {} - InitAction::Panic => { - let _bytes = msg::send_for_reply(msg::source(), b"init", 0, 0) - .unwrap() - .await - .unwrap(); - panic!(); - } - } - } - - #[gstd::async_main] - async fn main() { - msg::send(msg::source(), b"handle_signal", 0).unwrap(); - exec::wait(); - } -} +mod wasm; diff --git a/examples/async-signal-entry/src/wasm.rs b/examples/async-signal-entry/src/wasm.rs new file mode 100644 index 00000000000..a9192d60fd4 --- /dev/null +++ b/examples/async-signal-entry/src/wasm.rs @@ -0,0 +1,41 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use crate::InitAction; +use gstd::{exec, msg}; + +#[gstd::async_init] +async fn init() { + let action = msg::load().unwrap(); + match action { + InitAction::None => {} + InitAction::Panic => { + let _bytes = msg::send_for_reply(msg::source(), b"init", 0, 0) + .unwrap() + .await + .unwrap(); + panic!(); + } + } +} + +#[gstd::async_main] +async fn main() { + msg::send(msg::source(), b"handle_signal", 0).unwrap(); + exec::wait(); +} diff --git a/examples/async-tester/src/lib.rs b/examples/async-tester/src/lib.rs index 41822dd4176..d752d462007 100644 --- a/examples/async-tester/src/lib.rs +++ b/examples/async-tester/src/lib.rs @@ -10,9 +10,7 @@ mod code { pub use code::WASM_BINARY_OPT as WASM_BINARY; #[cfg(not(feature = "std"))] -mod wasm { - include! {"./code.rs"} -} +mod wasm; #[derive(Clone, Copy, Debug, Decode, Encode, PartialEq, Eq)] pub enum Kind { diff --git a/examples/async-tester/src/code.rs b/examples/async-tester/src/wasm.rs similarity index 91% rename from examples/async-tester/src/code.rs rename to examples/async-tester/src/wasm.rs index 3cad9d5052f..fe32ce5f66e 100644 --- a/examples/async-tester/src/code.rs +++ b/examples/async-tester/src/wasm.rs @@ -36,14 +36,16 @@ async fn main() { Kind::SendCommit => { let handle = MessageHandle::init().expect("init message failed"); handle.push(&encoded_kind).expect("push payload failed"); - handle.commit_for_reply(msg::source(), 0, 0) + handle + .commit_for_reply(msg::source(), 0, 0) .expect("send message failed") .await } Kind::SendCommitWithGas(gas) => { let handle = MessageHandle::init().expect("init message failed"); handle.push(&encoded_kind).expect("push payload failed"); - handle.commit_with_gas_for_reply(msg::source(), gas, 0, 0) + handle + .commit_with_gas_for_reply(msg::source(), gas, 0, 0) .expect("send message failed") .await } diff --git a/examples/async/src/lib.rs b/examples/async/src/lib.rs index 46759ad8d4b..113fcda6c27 100644 --- a/examples/async/src/lib.rs +++ b/examples/async/src/lib.rs @@ -35,50 +35,4 @@ pub enum Command { } #[cfg(not(feature = "std"))] -mod wasm { - use crate::Command; - use gstd::{lock::Mutex, msg, prelude::*, ActorId}; - - static mut DESTINATION: ActorId = ActorId::zero(); - static MUTEX: Mutex = Mutex::new(0); - - #[no_mangle] - extern "C" fn init() { - let destination = msg::load().expect("Failed to load destination"); - unsafe { DESTINATION = destination }; - } - - async fn ping() -> Vec { - msg::send_bytes_for_reply(unsafe { DESTINATION }, "PING", 0, 0) - .expect("Failed to send message") - .await - .expect("Received error reply") - } - - #[gstd::async_main] - async fn main() { - let command = msg::load().expect("Failed to load command"); - - match command { - Command::Common => { - let r1 = ping().await; - let r2 = ping().await; - let r3 = ping().await; - - assert_eq!(r1, b"PONG"); - assert_eq!(r1, r2); - assert_eq!(r2, r3); - } - Command::Mutex => { - let _val = MUTEX.lock().await; - - msg::send(msg::source(), msg::id(), 0).expect("Failed to send message"); - let r = ping().await; - - assert_eq!(r, b"PONG"); - } - } - - msg::reply(msg::id(), 0).expect("Failed to send reply"); - } -} +mod wasm; diff --git a/examples/async/src/wasm.rs b/examples/async/src/wasm.rs new file mode 100644 index 00000000000..ca9da74e670 --- /dev/null +++ b/examples/async/src/wasm.rs @@ -0,0 +1,63 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use crate::Command; +use gstd::{lock::Mutex, msg, prelude::*, ActorId}; + +static mut DESTINATION: ActorId = ActorId::zero(); +static MUTEX: Mutex = Mutex::new(0); + +#[no_mangle] +extern "C" fn init() { + let destination = msg::load().expect("Failed to load destination"); + unsafe { DESTINATION = destination }; +} + +async fn ping() -> Vec { + msg::send_bytes_for_reply(unsafe { DESTINATION }, "PING", 0, 0) + .expect("Failed to send message") + .await + .expect("Received error reply") +} + +#[gstd::async_main] +async fn main() { + let command = msg::load().expect("Failed to load command"); + + match command { + Command::Common => { + let r1 = ping().await; + let r2 = ping().await; + let r3 = ping().await; + + assert_eq!(r1, b"PONG"); + assert_eq!(r1, r2); + assert_eq!(r2, r3); + } + Command::Mutex => { + let _val = MUTEX.lock().await; + + msg::send(msg::source(), msg::id(), 0).expect("Failed to send message"); + let r = ping().await; + + assert_eq!(r, b"PONG"); + } + } + + msg::reply(msg::id(), 0).expect("Failed to send reply"); +} diff --git a/examples/calc-hash/in-one-block/src/lib.rs b/examples/calc-hash/in-one-block/src/lib.rs index fafd39d6b22..1d609b29753 100644 --- a/examples/calc-hash/in-one-block/src/lib.rs +++ b/examples/calc-hash/in-one-block/src/lib.rs @@ -27,9 +27,7 @@ mod code { pub use code::WASM_BINARY_OPT as WASM_BINARY; #[cfg(not(feature = "std"))] -mod wasm { - include! {"./code.rs"} -} +mod wasm; /// Package with expected #[derive(Encode, Decode)] diff --git a/examples/calc-hash/in-one-block/src/code.rs b/examples/calc-hash/in-one-block/src/wasm.rs similarity index 100% rename from examples/calc-hash/in-one-block/src/code.rs rename to examples/calc-hash/in-one-block/src/wasm.rs diff --git a/examples/calc-hash/over-blocks/src/lib.rs b/examples/calc-hash/over-blocks/src/lib.rs index 7c0054dd056..ab716fcd2da 100644 --- a/examples/calc-hash/over-blocks/src/lib.rs +++ b/examples/calc-hash/over-blocks/src/lib.rs @@ -29,9 +29,7 @@ mod code { pub use code::WASM_BINARY_OPT as WASM_BINARY; #[cfg(not(feature = "std"))] -mod wasm { - include! {"./code.rs"} -} +mod wasm; /// Program methods. #[derive(Debug, Encode, Decode)] diff --git a/examples/calc-hash/over-blocks/src/code.rs b/examples/calc-hash/over-blocks/src/wasm.rs similarity index 96% rename from examples/calc-hash/over-blocks/src/code.rs rename to examples/calc-hash/over-blocks/src/wasm.rs index b266a98c05b..bcb501e2701 100644 --- a/examples/calc-hash/over-blocks/src/code.rs +++ b/examples/calc-hash/over-blocks/src/wasm.rs @@ -15,7 +15,9 @@ extern "C" fn handle() { match method { Method::Start { expected, id, src } => { - registry.entry(id).or_insert_with(|| Package::new(expected, src)); + registry + .entry(id) + .or_insert_with(|| Package::new(expected, src)); let pkg = registry.get(&id).expect("Calculation not found."); diff --git a/examples/compose/src/lib.rs b/examples/compose/src/lib.rs index 442e6d7ea0f..cc2e84c6fc0 100644 --- a/examples/compose/src/lib.rs +++ b/examples/compose/src/lib.rs @@ -34,111 +34,4 @@ mod code { pub use code::WASM_BINARY_OPT as WASM_BINARY; #[cfg(not(feature = "std"))] -mod wasm { - extern crate alloc; - - use gstd::{debug, exec, msg, prelude::*, ActorId}; - - static mut STATE: State = State { - contract_a: Program { - handle: ActorId::new([0u8; 32]), - }, - contract_b: Program { - handle: ActorId::new([0u8; 32]), - }, - }; - - struct State { - contract_a: Program, - contract_b: Program, - } - - impl State { - fn new(actor_a: impl Into, actor_b: impl Into) -> Self { - Self { - contract_a: Program::new(actor_a), - contract_b: Program::new(actor_b), - } - } - - async fn compose(&mut self, input: Vec) -> Result, &'static str> { - debug!( - "[0x{} compose::compose] Composing programs 0x{} and 0x{} on input {input:?}", - hex::encode(exec::program_id()), - hex::encode(self.contract_a.handle), - hex::encode(self.contract_b.handle), - ); - debug!( - "[0x{} compose::compose] Calling contract #1 at 0x{}", - hex::encode(exec::program_id()), - hex::encode(self.contract_a.handle) - ); - let output_a = self.contract_a.call(input).await?; - debug!( - "[0x{} compose::compose] Calling contract #2 at 0x{}", - hex::encode(exec::program_id()), - hex::encode(self.contract_b.handle) - ); - let output = self.contract_b.call(output_a).await?; - debug!( - "[0x{} compose::compose] Composition output: {output:?}", - hex::encode(exec::program_id()), - ); - - Ok(output) - } - } - - #[derive(Eq, Ord, PartialEq, PartialOrd)] - struct Program { - handle: ActorId, - } - - impl Program { - fn new(handle: impl Into) -> Self { - Self { - handle: handle.into(), - } - } - - async fn call(&self, input: Vec) -> Result, &'static str> { - let reply_bytes = msg::send_bytes_for_reply(self.handle, &input[..], 0, 0) - .expect("Error sending message") - .await - .map_err(|_| "Error in async message processing")?; - debug!( - "[0x{} compose::Program::call] Received reply from remote contract: {}", - hex::encode(exec::program_id()), - hex::encode(&reply_bytes) - ); - - Ok(reply_bytes) - } - } - - #[gstd::async_main] - async fn main() { - let input = msg::load_bytes().expect("Failed to load payload bytes"); - debug!( - "[0x{} compose::handle] input = {input:?}, gas_available = {}", - hex::encode(exec::program_id()), - exec::gas_available() - ); - - if let Ok(outcome) = (unsafe { STATE.compose(input) }).await { - debug!( - "[0x{} compose::handle] Composition output: {outcome:?}", - hex::encode(exec::program_id()), - ); - msg::reply(outcome, 0).unwrap(); - } - } - - #[no_mangle] - extern "C" fn init() { - let (contract_a, contract_b): (ActorId, ActorId) = - msg::load().expect("Expecting two contract addresses"); - unsafe { STATE = State::new(contract_a, contract_b) }; - msg::reply_bytes([], 0).unwrap(); - } -} +mod wasm; diff --git a/examples/compose/src/wasm.rs b/examples/compose/src/wasm.rs new file mode 100644 index 00000000000..bee23607499 --- /dev/null +++ b/examples/compose/src/wasm.rs @@ -0,0 +1,131 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// This contract recursively composes itself with another contract (the other contract +// being applied to the input data first): `c(f) = (c(f) . f) x`. +// Every call to the auto_composer contract increments the internal `ITER` counter. +// As soon as the counter reaches the `MAX_ITER`, the recursion stops. +// Effectively, this procedure executes a composition of `MAX_ITER` contracts `f` +// where the output of the previous call is fed to the input of the next call. + +extern crate alloc; + +use gstd::{debug, exec, msg, prelude::*, ActorId}; + +static mut STATE: State = State { + contract_a: Program { + handle: ActorId::new([0u8; 32]), + }, + contract_b: Program { + handle: ActorId::new([0u8; 32]), + }, +}; + +struct State { + contract_a: Program, + contract_b: Program, +} + +impl State { + fn new(actor_a: impl Into, actor_b: impl Into) -> Self { + Self { + contract_a: Program::new(actor_a), + contract_b: Program::new(actor_b), + } + } + + async fn compose(&mut self, input: Vec) -> Result, &'static str> { + debug!( + "[0x{} compose::compose] Composing programs 0x{} and 0x{} on input {input:?}", + hex::encode(exec::program_id()), + hex::encode(self.contract_a.handle), + hex::encode(self.contract_b.handle), + ); + debug!( + "[0x{} compose::compose] Calling contract #1 at 0x{}", + hex::encode(exec::program_id()), + hex::encode(self.contract_a.handle) + ); + let output_a = self.contract_a.call(input).await?; + debug!( + "[0x{} compose::compose] Calling contract #2 at 0x{}", + hex::encode(exec::program_id()), + hex::encode(self.contract_b.handle) + ); + let output = self.contract_b.call(output_a).await?; + debug!( + "[0x{} compose::compose] Composition output: {output:?}", + hex::encode(exec::program_id()), + ); + + Ok(output) + } +} + +#[derive(Eq, Ord, PartialEq, PartialOrd)] +struct Program { + handle: ActorId, +} + +impl Program { + fn new(handle: impl Into) -> Self { + Self { + handle: handle.into(), + } + } + + async fn call(&self, input: Vec) -> Result, &'static str> { + let reply_bytes = msg::send_bytes_for_reply(self.handle, &input[..], 0, 0) + .expect("Error sending message") + .await + .map_err(|_| "Error in async message processing")?; + debug!( + "[0x{} compose::Program::call] Received reply from remote contract: {}", + hex::encode(exec::program_id()), + hex::encode(&reply_bytes) + ); + + Ok(reply_bytes) + } +} + +#[gstd::async_main] +async fn main() { + let input = msg::load_bytes().expect("Failed to load payload bytes"); + debug!( + "[0x{} compose::handle] input = {input:?}, gas_available = {}", + hex::encode(exec::program_id()), + exec::gas_available() + ); + + if let Ok(outcome) = (unsafe { STATE.compose(input) }).await { + debug!( + "[0x{} compose::handle] Composition output: {outcome:?}", + hex::encode(exec::program_id()), + ); + msg::reply(outcome, 0).unwrap(); + } +} + +#[no_mangle] +extern "C" fn init() { + let (contract_a, contract_b): (ActorId, ActorId) = + msg::load().expect("Expecting two contract addresses"); + unsafe { STATE = State::new(contract_a, contract_b) }; + msg::reply_bytes([], 0).unwrap(); +} diff --git a/examples/delayed-sender/src/lib.rs b/examples/delayed-sender/src/lib.rs index 9348dfb7a52..8be54f89785 100644 --- a/examples/delayed-sender/src/lib.rs +++ b/examples/delayed-sender/src/lib.rs @@ -26,6 +26,4 @@ mod code { pub use code::WASM_BINARY_OPT as WASM_BINARY; #[cfg(not(feature = "std"))] -mod wasm { - include! {"./code.rs"} -} +mod wasm; diff --git a/examples/delayed-sender/src/code.rs b/examples/delayed-sender/src/wasm.rs similarity index 77% rename from examples/delayed-sender/src/code.rs rename to examples/delayed-sender/src/wasm.rs index 3107b539988..6cdbb78b74f 100644 --- a/examples/delayed-sender/src/code.rs +++ b/examples/delayed-sender/src/wasm.rs @@ -1,4 +1,4 @@ -use gstd::{msg, MessageId, exec}; +use gstd::{exec, msg, MessageId}; static mut MID: Option = None; static mut DONE: bool = false; @@ -15,11 +15,15 @@ extern "C" fn handle() { if let Some(message_id) = unsafe { MID.take() } { let delay: u32 = msg::load().unwrap(); - unsafe { DONE = true; } + unsafe { + DONE = true; + } exec::wake_delayed(message_id, delay).expect("Failed to wake message"); } else if unsafe { !DONE } { - unsafe { MID = Some(msg::id()); } + unsafe { + MID = Some(msg::id()); + } exec::wait(); } diff --git a/examples/distributor/src/lib.rs b/examples/distributor/src/lib.rs index 15ee3f38c2b..53fd344ee84 100644 --- a/examples/distributor/src/lib.rs +++ b/examples/distributor/src/lib.rs @@ -52,174 +52,7 @@ struct Program { } #[cfg(not(feature = "std"))] -mod wasm { - use super::*; - - use alloc::collections::BTreeSet; - use core::future::Future; - use gstd::{debug, lock::Mutex, msg}; - - static mut STATE: Option = None; - - struct ProgramState { - nodes: Mutex>, - amount: u64, - } - - impl Default for ProgramState { - fn default() -> Self { - Self { - nodes: Mutex::new(BTreeSet::default()), - amount: 0, - } - } - } - - impl Program { - fn new(handle: impl Into) -> Self { - Self { - handle: handle.into(), - } - } - - fn do_request( - &self, - request: Req, - ) -> impl Future> { - let encoded_request: Vec = request.encode(); - - let program_handle = self.handle; - async move { - let reply_bytes = - msg::send_bytes_for_reply(program_handle, &encoded_request[..], 0, 0) - .expect("Error in message sending") - .await - .expect("Error in async message processing"); - - Rep::decode(&mut &reply_bytes[..]).map_err(|_| "Failed to decode reply") - } - } - - async fn do_send(&self, amount: u64) -> Result<(), &'static str> { - match self.do_request(Request::Receive(amount)).await? { - Reply::Success => Ok(()), - _ => Err("Unexpected send reply"), - } - } - - async fn do_report(&self) -> Result { - match self.do_request(Request::Report).await? { - Reply::Amount(amount) => Ok(amount), - _ => Err("Unexpected send reply"), - } - } - - fn nodes() -> &'static Mutex> { - unsafe { &mut STATE.as_mut().expect("STATE UNINITIALIZED!").nodes } - } - - fn amount() -> &'static mut u64 { - unsafe { &mut STATE.as_mut().expect("STATE UNINITIALIZED!").amount } - } - - async fn handle_request() { - let reply = match msg::load::() { - Ok(request) => match request { - Request::Receive(amount) => Self::handle_receive(amount).await, - Request::Join(program_id) => Self::handle_join(program_id).await, - Request::Report => Self::handle_report().await, - }, - Err(e) => { - debug!("Error processing request: {e:?}"); - Reply::Failure - } - }; - - debug!("Handle request finished"); - msg::reply(reply, 0).unwrap(); - } - - async fn handle_receive(amount: u64) -> Reply { - debug!("Handling receive {amount}"); - - let nodes = Program::nodes().lock().await; - let subnodes_count = nodes.as_ref().len() as u64; - - if subnodes_count > 0 { - let distributed_per_node = amount / subnodes_count; - let distributed_total = distributed_per_node * subnodes_count; - let mut left_over = amount - distributed_total; - - if distributed_per_node > 0 { - for program in nodes.as_ref().iter() { - if program.do_send(distributed_per_node).await.is_err() { - // reclaiming amount from nodes that fail! - left_over += distributed_per_node; - } - } - } - - debug!("Set own amount to: {left_over}"); - *Self::amount() = *Self::amount() + left_over; - } else { - debug!("Set own amount to: {amount}"); - *Self::amount() = *Self::amount() + amount; - } - - Reply::Success - } - - async fn handle_join(program_id: ActorId) -> Reply { - let mut nodes = Self::nodes().lock().await; - debug!("Inserting into nodes"); - nodes.as_mut().insert(Program::new(program_id)); - Reply::Success - } - - async fn handle_report() -> Reply { - let mut amount = *Program::amount(); - debug!("Own amount: {amount}"); - - let nodes = Program::nodes().lock().await; - - for program in nodes.as_ref().iter() { - debug!("Querying next node"); - amount += match program.do_report().await { - Ok(amount) => { - debug!("Sub-node result: {amount}"); - amount - } - Err(_) => { - // skipping erroneous sub-nodes! - debug!("Skipping erroneous node"); - 0 - } - } - } - - Reply::Amount(amount) - } - } - - #[no_mangle] - extern "C" fn handle() { - debug!("Handling sequence started"); - gstd::message_loop(Program::handle_request()); - debug!("Handling sequence terminated"); - } - - #[no_mangle] - extern "C" fn handle_reply() { - gstd::record_reply(); - } - - #[no_mangle] - extern "C" fn init() { - unsafe { STATE = Some(Default::default()) }; - msg::reply((), 0).unwrap(); - debug!("Program initialized"); - } -} +mod wasm; #[cfg(test)] mod tests { diff --git a/examples/distributor/src/wasm.rs b/examples/distributor/src/wasm.rs new file mode 100644 index 00000000000..1aa264a9921 --- /dev/null +++ b/examples/distributor/src/wasm.rs @@ -0,0 +1,183 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use crate::{Program, Reply, Request}; +use alloc::{collections::BTreeSet, vec::Vec}; +use core::future::Future; +use gstd::{debug, lock::Mutex, msg, ActorId}; +use parity_scale_codec::{Decode, Encode}; + +static mut STATE: Option = None; + +struct ProgramState { + nodes: Mutex>, + amount: u64, +} + +impl Default for ProgramState { + fn default() -> Self { + Self { + nodes: Mutex::new(BTreeSet::default()), + amount: 0, + } + } +} + +impl Program { + fn new(handle: impl Into) -> Self { + Self { + handle: handle.into(), + } + } + + fn do_request( + &self, + request: Req, + ) -> impl Future> { + let encoded_request: Vec = request.encode(); + + let program_handle = self.handle; + async move { + let reply_bytes = msg::send_bytes_for_reply(program_handle, &encoded_request[..], 0, 0) + .expect("Error in message sending") + .await + .expect("Error in async message processing"); + + Rep::decode(&mut &reply_bytes[..]).map_err(|_| "Failed to decode reply") + } + } + + async fn do_send(&self, amount: u64) -> Result<(), &'static str> { + match self.do_request(Request::Receive(amount)).await? { + Reply::Success => Ok(()), + _ => Err("Unexpected send reply"), + } + } + + async fn do_report(&self) -> Result { + match self.do_request(Request::Report).await? { + Reply::Amount(amount) => Ok(amount), + _ => Err("Unexpected send reply"), + } + } + + fn nodes() -> &'static Mutex> { + unsafe { &mut STATE.as_mut().expect("STATE UNINITIALIZED!").nodes } + } + + fn amount() -> &'static mut u64 { + unsafe { &mut STATE.as_mut().expect("STATE UNINITIALIZED!").amount } + } + + async fn handle_request() { + let reply = match msg::load::() { + Ok(request) => match request { + Request::Receive(amount) => Self::handle_receive(amount).await, + Request::Join(program_id) => Self::handle_join(program_id).await, + Request::Report => Self::handle_report().await, + }, + Err(e) => { + debug!("Error processing request: {e:?}"); + Reply::Failure + } + }; + + debug!("Handle request finished"); + msg::reply(reply, 0).unwrap(); + } + + async fn handle_receive(amount: u64) -> Reply { + debug!("Handling receive {amount}"); + + let nodes = Program::nodes().lock().await; + let subnodes_count = nodes.as_ref().len() as u64; + + if subnodes_count > 0 { + let distributed_per_node = amount / subnodes_count; + let distributed_total = distributed_per_node * subnodes_count; + let mut left_over = amount - distributed_total; + + if distributed_per_node > 0 { + for program in nodes.as_ref().iter() { + if program.do_send(distributed_per_node).await.is_err() { + // reclaiming amount from nodes that fail! + left_over += distributed_per_node; + } + } + } + + debug!("Set own amount to: {left_over}"); + *Self::amount() = *Self::amount() + left_over; + } else { + debug!("Set own amount to: {amount}"); + *Self::amount() = *Self::amount() + amount; + } + + Reply::Success + } + + async fn handle_join(program_id: ActorId) -> Reply { + let mut nodes = Self::nodes().lock().await; + debug!("Inserting into nodes"); + nodes.as_mut().insert(Program::new(program_id)); + Reply::Success + } + + async fn handle_report() -> Reply { + let mut amount = *Program::amount(); + debug!("Own amount: {amount}"); + + let nodes = Program::nodes().lock().await; + + for program in nodes.as_ref().iter() { + debug!("Querying next node"); + amount += match program.do_report().await { + Ok(amount) => { + debug!("Sub-node result: {amount}"); + amount + } + Err(_) => { + // skipping erroneous sub-nodes! + debug!("Skipping erroneous node"); + 0 + } + } + } + + Reply::Amount(amount) + } +} + +#[no_mangle] +extern "C" fn handle() { + debug!("Handling sequence started"); + gstd::message_loop(Program::handle_request()); + debug!("Handling sequence terminated"); +} + +#[no_mangle] +extern "C" fn handle_reply() { + gstd::record_reply(); +} + +#[no_mangle] +extern "C" fn init() { + unsafe { STATE = Some(Default::default()) }; + msg::reply((), 0).unwrap(); + debug!("Program initialized"); +} diff --git a/examples/fungible-token/src/lib.rs b/examples/fungible-token/src/lib.rs index f135d5bfcd3..3c6944afdde 100644 --- a/examples/fungible-token/src/lib.rs +++ b/examples/fungible-token/src/lib.rs @@ -30,4 +30,4 @@ pub use code::WASM_BINARY_OPT as WASM_BINARY; pub const WASM_BINARY: &[u8] = &[]; #[cfg(not(feature = "std"))] -pub mod contract; +pub mod wasm; diff --git a/examples/fungible-token/src/contract.rs b/examples/fungible-token/src/wasm.rs similarity index 100% rename from examples/fungible-token/src/contract.rs rename to examples/fungible-token/src/wasm.rs diff --git a/examples/futures-unordered/src/lib.rs b/examples/futures-unordered/src/lib.rs index 0144a88f59a..aafc99aa7fd 100644 --- a/examples/futures-unordered/src/lib.rs +++ b/examples/futures-unordered/src/lib.rs @@ -36,113 +36,4 @@ pub enum Command { } #[cfg(not(feature = "std"))] -mod wasm { - use crate::Command; - use futures::{ - join, select_biased, - stream::{FuturesUnordered, StreamExt}, - }; - use gstd::{debug, msg, prelude::*, ActorId}; - - static mut DEMO_ASYNC: ActorId = ActorId::new([0u8; 32]); - static mut DEMO_PING: ActorId = ActorId::new([0u8; 32]); - - #[no_mangle] - extern "C" fn init() { - let (demo_async, demo_ping) = msg::load().expect("Failed to load destination"); - unsafe { - DEMO_ASYNC = demo_async; - DEMO_PING = demo_ping; - } - } - - enum Dest { - Async, - Ping, - } - - #[gstd::async_main] - async fn main() { - let command = msg::load().expect("Failed to load command"); - let source = msg::source(); - - let send_fut = |dest: Dest| { - let (destination, payload) = match dest { - Dest::Async => (unsafe { DEMO_ASYNC }, vec![0]), // demo_async::Command::Common - Dest::Ping => (unsafe { DEMO_PING }, b"PING".to_vec()), - }; - - msg::send_bytes_for_reply(destination, payload, 0, 0).expect("Failed to send message") - }; - - match command { - // Directly using stream from futures unordered - // to step through each future ready - Command::Unordered => { - debug!("UNORDERED: Before any sending"); - - let requests = vec![send_fut(Dest::Async), send_fut(Dest::Ping)]; - let mut unordered: FuturesUnordered<_> = requests.into_iter().collect(); - - debug!("Before any polls"); - - let first = unordered.next().await; - msg::send_bytes( - source, - first.expect("Infallible").expect("Received error reply"), - 0, - ) - .expect("Failed to send message"); - - debug!("First (from demo_ping) done"); - - let second = unordered.next().await; - msg::send_bytes( - source, - second.expect("Infallible").expect("Received error reply"), - 0, - ) - .expect("Failed to send message"); - - debug!("Second (from demo_async) done"); - } - // Using select! macro to wait for first future ready - Command::Select => { - debug!("SELECT: Before any sending"); - - select_biased! { - res = send_fut(Dest::Async) => { - debug!("Received msg from demo_async"); - msg::send_bytes(source, res.expect("Received error reply"), 0).expect("Failed to send message"); - }, - res = send_fut(Dest::Ping) => { - debug!("Received msg from demo_ping"); - msg::send_bytes(source, res.expect("Received error reply"), 0).expect("Failed to send message"); - }, - }; - - debug!("Finish after select"); - } - // Using join! macros to wait all features ready - Command::Join => { - debug!("JOIN: Before any sending"); - - let res = join!(send_fut(Dest::Async), send_fut(Dest::Ping)); - - debug!("Finish after join"); - - let mut r1 = res.0.expect("Received error reply"); - let mut r2 = res.1.expect("Received error reply"); - - let mut res = Vec::with_capacity(r1.len() + r2.len()); - - res.append(&mut r1); - res.append(&mut r2); - - msg::send_bytes(source, res, 0).expect("Failed to send message"); - } - } - - msg::reply_bytes(msg::id(), 0).expect("Failed to send reply"); - } -} +mod wasm; diff --git a/examples/futures-unordered/src/wasm.rs b/examples/futures-unordered/src/wasm.rs new file mode 100644 index 00000000000..dcc301caaf2 --- /dev/null +++ b/examples/futures-unordered/src/wasm.rs @@ -0,0 +1,126 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use crate::Command; +use futures::{ + join, select_biased, + stream::{FuturesUnordered, StreamExt}, +}; +use gstd::{debug, msg, prelude::*, ActorId}; + +static mut DEMO_ASYNC: ActorId = ActorId::new([0u8; 32]); +static mut DEMO_PING: ActorId = ActorId::new([0u8; 32]); + +#[no_mangle] +extern "C" fn init() { + let (demo_async, demo_ping) = msg::load().expect("Failed to load destination"); + unsafe { + DEMO_ASYNC = demo_async; + DEMO_PING = demo_ping; + } +} + +enum Dest { + Async, + Ping, +} + +#[gstd::async_main] +async fn main() { + let command = msg::load().expect("Failed to load command"); + let source = msg::source(); + + let send_fut = |dest: Dest| { + let (destination, payload) = match dest { + Dest::Async => (unsafe { DEMO_ASYNC }, vec![0]), // demo_async::Command::Common + Dest::Ping => (unsafe { DEMO_PING }, b"PING".to_vec()), + }; + + msg::send_bytes_for_reply(destination, payload, 0, 0).expect("Failed to send message") + }; + + match command { + // Directly using stream from futures unordered + // to step through each future ready + Command::Unordered => { + debug!("UNORDERED: Before any sending"); + + let requests = vec![send_fut(Dest::Async), send_fut(Dest::Ping)]; + let mut unordered: FuturesUnordered<_> = requests.into_iter().collect(); + + debug!("Before any polls"); + + let first = unordered.next().await; + msg::send_bytes( + source, + first.expect("Infallible").expect("Received error reply"), + 0, + ) + .expect("Failed to send message"); + + debug!("First (from demo_ping) done"); + + let second = unordered.next().await; + msg::send_bytes( + source, + second.expect("Infallible").expect("Received error reply"), + 0, + ) + .expect("Failed to send message"); + + debug!("Second (from demo_async) done"); + } + // Using select! macro to wait for first future ready + Command::Select => { + debug!("SELECT: Before any sending"); + + select_biased! { + res = send_fut(Dest::Async) => { + debug!("Received msg from demo_async"); + msg::send_bytes(source, res.expect("Received error reply"), 0).expect("Failed to send message"); + }, + res = send_fut(Dest::Ping) => { + debug!("Received msg from demo_ping"); + msg::send_bytes(source, res.expect("Received error reply"), 0).expect("Failed to send message"); + }, + }; + + debug!("Finish after select"); + } + // Using join! macros to wait all features ready + Command::Join => { + debug!("JOIN: Before any sending"); + + let res = join!(send_fut(Dest::Async), send_fut(Dest::Ping)); + + debug!("Finish after join"); + + let mut r1 = res.0.expect("Received error reply"); + let mut r2 = res.1.expect("Received error reply"); + + let mut res = Vec::with_capacity(r1.len() + r2.len()); + + res.append(&mut r1); + res.append(&mut r2); + + msg::send_bytes(source, res, 0).expect("Failed to send message"); + } + } + + msg::reply_bytes(msg::id(), 0).expect("Failed to send reply"); +} diff --git a/examples/gas-burned/src/lib.rs b/examples/gas-burned/src/lib.rs index 85514ae9dbb..45e628fea74 100644 --- a/examples/gas-burned/src/lib.rs +++ b/examples/gas-burned/src/lib.rs @@ -9,29 +9,7 @@ mod code { pub use code::WASM_BINARY_OPT as WASM_BINARY; #[cfg(not(feature = "std"))] -mod wasm { - use gstd::{msg, prelude::*}; - - const SHORT: usize = 100; - const LONG: usize = 10000; - - #[no_mangle] - extern "C" fn init() { - let mut v = vec![0; SHORT]; - for (i, item) in v.iter_mut().enumerate() { - *item = i * i; - } - msg::reply_bytes(format!("init: {}", v.into_iter().sum::()), 0).unwrap(); - } - - #[no_mangle] - extern "C" fn handle() { - let mut v = vec![0; LONG]; - for (i, item) in v.iter_mut().enumerate() { - *item = i * i; - } - } -} +mod wasm; #[cfg(test)] mod tests { diff --git a/examples/gas-burned/src/wasm.rs b/examples/gas-burned/src/wasm.rs new file mode 100644 index 00000000000..85514ae9dbb --- /dev/null +++ b/examples/gas-burned/src/wasm.rs @@ -0,0 +1,58 @@ +#![cfg_attr(not(feature = "std"), no_std)] + +#[cfg(feature = "std")] +mod code { + include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); +} + +#[cfg(feature = "std")] +pub use code::WASM_BINARY_OPT as WASM_BINARY; + +#[cfg(not(feature = "std"))] +mod wasm { + use gstd::{msg, prelude::*}; + + const SHORT: usize = 100; + const LONG: usize = 10000; + + #[no_mangle] + extern "C" fn init() { + let mut v = vec![0; SHORT]; + for (i, item) in v.iter_mut().enumerate() { + *item = i * i; + } + msg::reply_bytes(format!("init: {}", v.into_iter().sum::()), 0).unwrap(); + } + + #[no_mangle] + extern "C" fn handle() { + let mut v = vec![0; LONG]; + for (i, item) in v.iter_mut().enumerate() { + *item = i * i; + } + } +} + +#[cfg(test)] +mod tests { + use gtest::{Gas, Program, System}; + + #[test] + fn gas_burned() { + let system = System::new(); + system.init_logger(); + + let from = 42; + + let program = Program::current(&system); + let res = program.send_bytes(from, "init"); + let init_gas_burned = res.main_gas_burned(); + log::debug!("Init gas burned: {init_gas_burned}"); + assert!(init_gas_burned > Gas::zero()); + + let res = program.send_bytes(from, "handle"); + let handle_gas_burned = res.main_gas_burned(); + log::debug!("Handle gas burned: {handle_gas_burned}"); + assert!(handle_gas_burned > init_gas_burned); + } +} diff --git a/examples/incomplete-async-payloads/src/lib.rs b/examples/incomplete-async-payloads/src/lib.rs index eb8cc63eb20..4e40051df18 100644 --- a/examples/incomplete-async-payloads/src/lib.rs +++ b/examples/incomplete-async-payloads/src/lib.rs @@ -37,60 +37,4 @@ pub enum Command { } #[cfg(not(feature = "std"))] -mod wasm { - use crate::Command; - use gstd::{ - msg::{self, MessageHandle}, - prelude::*, - ActorId, - }; - - static mut DESTINATION: ActorId = ActorId::zero(); - - #[no_mangle] - extern "C" fn init() { - let destination = msg::load().expect("Failed to load destination"); - unsafe { DESTINATION = destination }; - } - - async fn ping() { - msg::send_bytes_for_reply(unsafe { DESTINATION }, "PING", 0, 0) - .expect("Failed to send message") - .await - .expect("Received error reply"); - } - - #[gstd::async_main] - async fn main() { - let command = msg::load().expect("Failed to load command"); - - match command { - Command::HandleStore => { - let handle = MessageHandle::init().expect("Failed to init message"); - handle.push(b"STORED ").expect("Failed to push payload"); - ping().await; - handle.push("COMMON").expect("Failed to push payload"); - handle - .commit(msg::source(), 0) - .expect("Failed to commit message"); - } - Command::ReplyStore => { - msg::reply_push(b"STORED ").expect("Failed to push reply payload"); - ping().await; - msg::reply_push(b"REPLY").expect("Failed to push reply payload"); - msg::reply_commit(0).expect("Failed to commit reply"); - } - Command::Handle => { - let handle = MessageHandle::init().expect("Failed to init message"); - handle.push(b"OK PING").expect("Failed to push payload"); - handle - .commit(msg::source(), 0) - .expect("Failed to commit message"); - } - Command::Reply => { - msg::reply_push(b"OK REPLY").expect("Failed to push reply payload"); - msg::reply_commit(0).expect("Failed to commit reply"); - } - } - } -} +mod wasm; diff --git a/examples/incomplete-async-payloads/src/wasm.rs b/examples/incomplete-async-payloads/src/wasm.rs new file mode 100644 index 00000000000..987f22ff05d --- /dev/null +++ b/examples/incomplete-async-payloads/src/wasm.rs @@ -0,0 +1,73 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use crate::Command; +use gstd::{ + msg::{self, MessageHandle}, + prelude::*, + ActorId, +}; + +static mut DESTINATION: ActorId = ActorId::zero(); + +#[no_mangle] +extern "C" fn init() { + let destination = msg::load().expect("Failed to load destination"); + unsafe { DESTINATION = destination }; +} + +async fn ping() { + msg::send_bytes_for_reply(unsafe { DESTINATION }, "PING", 0, 0) + .expect("Failed to send message") + .await + .expect("Received error reply"); +} + +#[gstd::async_main] +async fn main() { + let command = msg::load().expect("Failed to load command"); + + match command { + Command::HandleStore => { + let handle = MessageHandle::init().expect("Failed to init message"); + handle.push(b"STORED ").expect("Failed to push payload"); + ping().await; + handle.push("COMMON").expect("Failed to push payload"); + handle + .commit(msg::source(), 0) + .expect("Failed to commit message"); + } + Command::ReplyStore => { + msg::reply_push(b"STORED ").expect("Failed to push reply payload"); + ping().await; + msg::reply_push(b"REPLY").expect("Failed to push reply payload"); + msg::reply_commit(0).expect("Failed to commit reply"); + } + Command::Handle => { + let handle = MessageHandle::init().expect("Failed to init message"); + handle.push(b"OK PING").expect("Failed to push payload"); + handle + .commit(msg::source(), 0) + .expect("Failed to commit message"); + } + Command::Reply => { + msg::reply_push(b"OK REPLY").expect("Failed to push reply payload"); + msg::reply_commit(0).expect("Failed to commit reply"); + } + } +} diff --git a/examples/init-fail-sender/src/lib.rs b/examples/init-fail-sender/src/lib.rs index 81a7e8ec5a3..a9c048cd09d 100644 --- a/examples/init-fail-sender/src/lib.rs +++ b/examples/init-fail-sender/src/lib.rs @@ -17,20 +17,4 @@ pub fn reply_duration() -> u32 { } #[cfg(not(feature = "std"))] -mod wasm { - use gstd::{msg, ActorId}; - - #[gstd::async_init] - async fn init() { - let value_receiver: ActorId = msg::load().unwrap(); - - msg::send_bytes_with_gas(value_receiver, [], 50_000, 1_000).unwrap(); - msg::send_bytes_with_gas_for_reply(msg::source(), [], 30_000, 0, 0) - .unwrap() - .exactly(Some(super::reply_duration())) - .unwrap() - .await - .expect("Failed to send message"); - panic!(); - } -} +mod wasm; diff --git a/examples/init-fail-sender/src/wasm.rs b/examples/init-fail-sender/src/wasm.rs new file mode 100644 index 00000000000..4bca976c3bb --- /dev/null +++ b/examples/init-fail-sender/src/wasm.rs @@ -0,0 +1,15 @@ +use gstd::{msg, ActorId}; + +#[gstd::async_init] +async fn init() { + let value_receiver: ActorId = msg::load().unwrap(); + + msg::send_bytes_with_gas(value_receiver, [], 50_000, 1_000).unwrap(); + msg::send_bytes_with_gas_for_reply(msg::source(), [], 30_000, 0, 0) + .unwrap() + .exactly(Some(super::reply_duration())) + .unwrap() + .await + .expect("Failed to send message"); + panic!(); +} diff --git a/examples/init-wait-reply-exit/src/lib.rs b/examples/init-wait-reply-exit/src/lib.rs index e5e4ef17484..813a4f3ed30 100644 --- a/examples/init-wait-reply-exit/src/lib.rs +++ b/examples/init-wait-reply-exit/src/lib.rs @@ -9,6 +9,4 @@ mod code { pub use code::WASM_BINARY_OPT as WASM_BINARY; #[cfg(not(feature = "std"))] -mod wasm { - include! {"./code.rs"} -} +mod wasm; diff --git a/examples/init-wait-reply-exit/src/code.rs b/examples/init-wait-reply-exit/src/wasm.rs similarity index 100% rename from examples/init-wait-reply-exit/src/code.rs rename to examples/init-wait-reply-exit/src/wasm.rs diff --git a/examples/init-wait/src/lib.rs b/examples/init-wait/src/lib.rs index e5e4ef17484..813a4f3ed30 100644 --- a/examples/init-wait/src/lib.rs +++ b/examples/init-wait/src/lib.rs @@ -9,6 +9,4 @@ mod code { pub use code::WASM_BINARY_OPT as WASM_BINARY; #[cfg(not(feature = "std"))] -mod wasm { - include! {"./code.rs"} -} +mod wasm; diff --git a/examples/init-wait/src/code.rs b/examples/init-wait/src/wasm.rs similarity index 100% rename from examples/init-wait/src/code.rs rename to examples/init-wait/src/wasm.rs diff --git a/examples/messager/src/lib.rs b/examples/messager/src/lib.rs index 3616ca8a492..fd16790cf82 100644 --- a/examples/messager/src/lib.rs +++ b/examples/messager/src/lib.rs @@ -27,9 +27,7 @@ mod code { pub use code::WASM_BINARY_OPT as WASM_BINARY; #[cfg(not(feature = "std"))] -mod wasm { - include! {"./code.rs"} -} +mod wasm; pub const SEND_REPLY: &[u8] = b"send"; pub const REPLY_REPLY: &[u8] = b"reply"; diff --git a/examples/messager/src/code.rs b/examples/messager/src/wasm.rs similarity index 100% rename from examples/messager/src/code.rs rename to examples/messager/src/wasm.rs diff --git a/examples/mul-by-const/src/lib.rs b/examples/mul-by-const/src/lib.rs index 0076d711649..cc2e84c6fc0 100644 --- a/examples/mul-by-const/src/lib.rs +++ b/examples/mul-by-const/src/lib.rs @@ -34,60 +34,4 @@ mod code { pub use code::WASM_BINARY_OPT as WASM_BINARY; #[cfg(not(feature = "std"))] -mod wasm { - extern crate alloc; - - use gstd::{debug, exec, msg, String}; - - static mut DEBUG: DebugInfo = DebugInfo { me: String::new() }; - static mut STATE: State = State { intrinsic: 0 }; - - struct DebugInfo { - me: String, - } - - struct State { - intrinsic: u64, - } - - impl State { - fn new(value: u64) -> Self { - Self { intrinsic: value } - } - - unsafe fn unchecked_mul(&mut self, other: u64) -> u64 { - let z: u64 = self - .intrinsic - .checked_mul(other) - .expect("Multiplication overflow"); - debug!( - "[0x{} mul_by_const::unchecked_mul] Calculated {} x {other} == {z}", - DEBUG.me, self.intrinsic - ); - z - } - } - - #[no_mangle] - extern "C" fn handle() { - let x: u64 = msg::load().expect("Expecting a u64 number"); - - msg::reply(unsafe { STATE.unchecked_mul(x) }, 0).unwrap(); - } - - #[no_mangle] - extern "C" fn init() { - let val: u64 = msg::load().expect("Expecting a u64 number"); - unsafe { - STATE = State::new(val); - DEBUG = DebugInfo { - me: hex::encode(exec::program_id()), - }; - } - msg::reply_bytes([], 0).unwrap(); - debug!( - "[0x{} mul_by_const::init] Program initialized with input {val}", - unsafe { &DEBUG.me }, - ); - } -} +mod wasm; diff --git a/examples/mul-by-const/src/wasm.rs b/examples/mul-by-const/src/wasm.rs new file mode 100644 index 00000000000..15dfeb404c8 --- /dev/null +++ b/examples/mul-by-const/src/wasm.rs @@ -0,0 +1,80 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// This contract recursively composes itself with another contract (the other contract +// being applied to the input data first): `c(f) = (c(f) . f) x`. +// Every call to the auto_composer contract increments the internal `ITER` counter. +// As soon as the counter reaches the `MAX_ITER`, the recursion stops. +// Effectively, this procedure executes a composition of `MAX_ITER` contracts `f` +// where the output of the previous call is fed to the input of the next call. + +extern crate alloc; + +use gstd::{debug, exec, msg, String}; + +static mut DEBUG: DebugInfo = DebugInfo { me: String::new() }; +static mut STATE: State = State { intrinsic: 0 }; + +struct DebugInfo { + me: String, +} + +struct State { + intrinsic: u64, +} + +impl State { + fn new(value: u64) -> Self { + Self { intrinsic: value } + } + + unsafe fn unchecked_mul(&mut self, other: u64) -> u64 { + let z: u64 = self + .intrinsic + .checked_mul(other) + .expect("Multiplication overflow"); + debug!( + "[0x{} mul_by_const::unchecked_mul] Calculated {} x {other} == {z}", + DEBUG.me, self.intrinsic + ); + z + } +} + +#[no_mangle] +extern "C" fn handle() { + let x: u64 = msg::load().expect("Expecting a u64 number"); + + msg::reply(unsafe { STATE.unchecked_mul(x) }, 0).unwrap(); +} + +#[no_mangle] +extern "C" fn init() { + let val: u64 = msg::load().expect("Expecting a u64 number"); + unsafe { + STATE = State::new(val); + DEBUG = DebugInfo { + me: hex::encode(exec::program_id()), + }; + } + msg::reply_bytes([], 0).unwrap(); + debug!( + "[0x{} mul_by_const::init] Program initialized with input {val}", + unsafe { &DEBUG.me }, + ); +} diff --git a/examples/ncompose/src/lib.rs b/examples/ncompose/src/lib.rs index 5aa2d603784..cc2e84c6fc0 100644 --- a/examples/ncompose/src/lib.rs +++ b/examples/ncompose/src/lib.rs @@ -34,134 +34,4 @@ mod code { pub use code::WASM_BINARY_OPT as WASM_BINARY; #[cfg(not(feature = "std"))] -mod wasm { - extern crate alloc; - - use gstd::{debug, exec, msg, prelude::*, ActorId}; - - static mut STATE: State = State { - iter: 0, - max_iter: 0, - me: Program { - handle: ActorId::new([0u8; 32]), - }, - other: Program { - handle: ActorId::new([0u8; 32]), - }, - }; - - struct State { - iter: u16, - max_iter: u16, - me: Program, - other: Program, - } - - impl State { - fn new(max_iter: u16, actor: impl Into) -> Self { - Self { - iter: 0, - max_iter, - me: Program::new(exec::program_id()), - other: Program::new(actor), - } - } - - fn inc(&mut self) { - self.iter += 1; - } - - async fn compose_with_self(&mut self, input: Vec) -> Result, &'static str> { - if self.iter >= self.max_iter { - debug!( - "[0x{} ncompose::compose_with_self] Max number of iterations {} reached; no further progress is possible", - hex::encode(self.me.handle), - self.max_iter - ); - return Err("Max iteration reached"); - } - // Increase iter - self.inc(); - - debug!( - "[ncompose::compose_with_self] Iter: {} out of {}", - self.iter, self.max_iter - ); - - // Pass the input to the `other` contract first - debug!( - "[0x{} ncompose::compose_with_self] Calling contract 0x{}", - hex::encode(self.me.handle), - hex::encode(self.other.handle) - ); - let output_other = self.other.call(input).await?; - debug!( - "[0x{} ncompose::compose_with_self] Calling self", - hex::encode(exec::program_id()) - ); - let output = self.me.call(output_other).await?; - debug!( - "[0x{} ncompose::compose_with_self] Composition output: {output:?}", - hex::encode(exec::program_id()), - ); - - Ok(output) - } - } - - #[derive(Eq, Ord, PartialEq, PartialOrd)] - struct Program { - handle: ActorId, - } - - impl Program { - fn new(handle: impl Into) -> Self { - Self { - handle: handle.into(), - } - } - - async fn call(&self, input: Vec) -> Result, &'static str> { - let reply_bytes = msg::send_bytes_for_reply(self.handle, &input[..], 0, 0) - .expect("Error sending message") - .await - .map_err(|_| "Error in async message processing")?; - debug!( - "[0x{} ncompose::Program::call] Received reply from remote contract: {:?}", - hex::encode(exec::program_id()), - hex::encode(&reply_bytes) - ); - - Ok(reply_bytes) - } - } - - #[gstd::async_main] - async fn main() { - let input = msg::load_bytes().expect("Failed to load payload bytes"); - debug!( - "[0x{} ncompose::handle] input = {input:?}", - hex::encode(unsafe { STATE.me.handle }), - ); - - if let Ok(outcome) = (unsafe { STATE.compose_with_self(input) }).await { - debug!( - "[0x{} ncompose::handle] Composition output: {outcome:?}", - hex::encode(exec::program_id()), - ); - msg::reply(outcome, 0).unwrap(); - } - } - - #[no_mangle] - extern "C" fn init() { - let (actor, max_iter): (ActorId, u16) = - msg::load().expect("Malformed input: expecting a program ID and a number"); - unsafe { STATE = State::new(max_iter, actor) }; - msg::reply_bytes([], 0).unwrap(); - debug!( - "[0x{} ncompose::init] Program initialized", - hex::encode(exec::program_id()) - ); - } -} +mod wasm; diff --git a/examples/ncompose/src/wasm.rs b/examples/ncompose/src/wasm.rs new file mode 100644 index 00000000000..1b4c1276c5e --- /dev/null +++ b/examples/ncompose/src/wasm.rs @@ -0,0 +1,154 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// This contract recursively composes itself with another contract (the other contract +// being applied to the input data first): `c(f) = (c(f) . f) x`. +// Every call to the auto_composer contract increments the internal `ITER` counter. +// As soon as the counter reaches the `MAX_ITER`, the recursion stops. +// Effectively, this procedure executes a composition of `MAX_ITER` contracts `f` +// where the output of the previous call is fed to the input of the next call. + +extern crate alloc; + +use gstd::{debug, exec, msg, prelude::*, ActorId}; + +static mut STATE: State = State { + iter: 0, + max_iter: 0, + me: Program { + handle: ActorId::new([0u8; 32]), + }, + other: Program { + handle: ActorId::new([0u8; 32]), + }, +}; + +struct State { + iter: u16, + max_iter: u16, + me: Program, + other: Program, +} + +impl State { + fn new(max_iter: u16, actor: impl Into) -> Self { + Self { + iter: 0, + max_iter, + me: Program::new(exec::program_id()), + other: Program::new(actor), + } + } + + fn inc(&mut self) { + self.iter += 1; + } + + async fn compose_with_self(&mut self, input: Vec) -> Result, &'static str> { + if self.iter >= self.max_iter { + debug!( + "[0x{} ncompose::compose_with_self] Max number of iterations {} reached; no further progress is possible", + hex::encode(self.me.handle), + self.max_iter + ); + return Err("Max iteration reached"); + } + // Increase iter + self.inc(); + + debug!( + "[ncompose::compose_with_self] Iter: {} out of {}", + self.iter, self.max_iter + ); + + // Pass the input to the `other` contract first + debug!( + "[0x{} ncompose::compose_with_self] Calling contract 0x{}", + hex::encode(self.me.handle), + hex::encode(self.other.handle) + ); + let output_other = self.other.call(input).await?; + debug!( + "[0x{} ncompose::compose_with_self] Calling self", + hex::encode(exec::program_id()) + ); + let output = self.me.call(output_other).await?; + debug!( + "[0x{} ncompose::compose_with_self] Composition output: {output:?}", + hex::encode(exec::program_id()), + ); + + Ok(output) + } +} + +#[derive(Eq, Ord, PartialEq, PartialOrd)] +struct Program { + handle: ActorId, +} + +impl Program { + fn new(handle: impl Into) -> Self { + Self { + handle: handle.into(), + } + } + + async fn call(&self, input: Vec) -> Result, &'static str> { + let reply_bytes = msg::send_bytes_for_reply(self.handle, &input[..], 0, 0) + .expect("Error sending message") + .await + .map_err(|_| "Error in async message processing")?; + debug!( + "[0x{} ncompose::Program::call] Received reply from remote contract: {:?}", + hex::encode(exec::program_id()), + hex::encode(&reply_bytes) + ); + + Ok(reply_bytes) + } +} + +#[gstd::async_main] +async fn main() { + let input = msg::load_bytes().expect("Failed to load payload bytes"); + debug!( + "[0x{} ncompose::handle] input = {input:?}", + hex::encode(unsafe { STATE.me.handle }), + ); + + if let Ok(outcome) = (unsafe { STATE.compose_with_self(input) }).await { + debug!( + "[0x{} ncompose::handle] Composition output: {outcome:?}", + hex::encode(exec::program_id()), + ); + msg::reply(outcome, 0).unwrap(); + } +} + +#[no_mangle] +extern "C" fn init() { + let (actor, max_iter): (ActorId, u16) = + msg::load().expect("Malformed input: expecting a program ID and a number"); + unsafe { STATE = State::new(max_iter, actor) }; + msg::reply_bytes([], 0).unwrap(); + debug!( + "[0x{} ncompose::init] Program initialized", + hex::encode(exec::program_id()) + ); +} diff --git a/examples/node/src/lib.rs b/examples/node/src/lib.rs index ee8ff58f89e..1b64af59594 100644 --- a/examples/node/src/lib.rs +++ b/examples/node/src/lib.rs @@ -20,8 +20,7 @@ extern crate alloc; -use alloc::collections::BTreeSet; -use gstd::{debug, exec, msg, prelude::*, ActorId, MessageId}; +use gstd::ActorId; use parity_scale_codec::{Decode, Encode}; #[cfg(feature = "std")] @@ -56,233 +55,8 @@ pub enum Reply { Failure, } -enum TransitionState { - Ready, - NotReady, - Failed, -} - -struct Transition { - #[allow(dead_code)] - to_status: u32, - origin: ActorId, - query_list: Vec, - message_id: MessageId, - last_sent_message_id: MessageId, - query_index: usize, - state: TransitionState, -} - -struct NodeState { - #[allow(dead_code)] - status: u32, - sub_nodes: BTreeSet, - transition: Option, -} - -static mut STATE: Option = None; - -#[no_mangle] -extern "C" fn handle() { - let reply = match msg::load() { - Ok(request) => process(request), - Err(e) => { - debug!("Error processing request: {e:?}"); - Reply::Failure - } - }; - - msg::reply(reply, 0).unwrap(); -} - -fn state() -> &'static mut NodeState { - unsafe { STATE.as_mut().unwrap() } -} - -fn process(request: Request) -> Reply { - if let Some(mut transition) = state().transition.take() { - if transition.message_id == msg::id() { - // one of the answers has set failed state - if let TransitionState::Failed = transition.state { - return Reply::Failure; - } - - // this means that we received replies from all subnodes - if transition.query_index == transition.query_list.len() { - match transition.state { - TransitionState::NotReady => { - transition.state = TransitionState::Ready; - - debug!("Returning final ready signal"); - - // this is ready to further process with committing - state().transition = Some(transition); - return Reply::Success; - } - TransitionState::Ready => { - // this means we successfully committed and we can - // drop the transition returning success - debug!("Returning final commit signal"); - - return Reply::Success; - } - _ => { - // this is some invalid state already - return Reply::Failure; - } - } - } - - // this means we need to send another sub-node query - let next_sub_node = transition - .query_list - .get(transition.query_index) - .expect("Checked above that it has that number of elements; qed"); - - transition.last_sent_message_id = msg::send(*next_sub_node, request, 0).unwrap(); - - state().transition = Some(transition); - - exec::wait(); - } else { - // this is just a new message that should be processed normally, without continuation. - state().transition = Some(transition); - } - } - - match request { - Request::IsReady => { - if state().transition.is_none() { - Reply::Yes - } else { - Reply::No - } - } - Request::Begin(Operation { to_status }) => { - if state().transition.is_some() { - Reply::Failure - } else { - let mut transition = Transition { - to_status, - origin: msg::source(), - query_index: 0, - query_list: vec![], - state: TransitionState::NotReady, - message_id: msg::id(), - last_sent_message_id: MessageId::default(), - }; - - debug!("Transition started"); - - if !state().sub_nodes.is_empty() { - debug!("Transition started is complex"); - - transition.query_list = state().sub_nodes.iter().cloned().collect(); - let first_sub_node = *transition - .query_list - .get(0) - .expect("Checked above that sub_nodes is not empty; qed"); - transition.last_sent_message_id = - msg::send(first_sub_node, request, 0).unwrap(); - state().transition = Some(transition); - exec::wait() - } else { - transition.state = TransitionState::Ready; - state().transition = Some(transition); - Reply::Success - } - } - } - Request::Commit => { - if state().sub_nodes.is_empty() { - let (transition, reply) = match state().transition.take() { - Some(transition) => { - if transition.origin != msg::source() { - (Some(transition), Reply::Failure) - } else { - (None, Reply::Success) - } - } - None => (None, Reply::Failure), - }; - - state().transition = transition; - - reply - } else if let Some(mut transition) = state().transition.take() { - if let TransitionState::Ready = transition.state { - let first_sub_node = *transition - .query_list - .get(0) - .expect("Checked above that sub_nodes is not empty; qed"); - - transition.query_index = 0; - - transition.message_id = msg::id(); - - transition.last_sent_message_id = - msg::send(first_sub_node, request, 0).unwrap(); - - state().transition = Some(transition); - - exec::wait() - } else { - debug!("Returning failure because current state is not READY"); - Reply::Failure - } - } else { - debug!("Returning failure because there is no transition in process"); - Reply::Failure - } - } - Request::Add(sub_node) => { - state().sub_nodes.insert(sub_node); - Reply::Success - } - } -} - -#[no_mangle] -extern "C" fn handle_reply() { - if let Some(ref mut transition) = state().transition { - if msg::reply_to().unwrap() != transition.last_sent_message_id { - return; - } - - match msg::load() { - Ok(reply) => { - transition.query_index += 1; - if let Reply::Success = reply { - } else { - transition.state = TransitionState::Failed; - } - exec::wake(transition.message_id).unwrap(); - } - Err(e) => { - transition.state = TransitionState::Failed; - debug!("Error processing reply: {e:?}"); - exec::wake(transition.message_id).unwrap(); - } - } - } else { - debug!("Got some reply that can not be processed"); - } -} - -#[no_mangle] -extern "C" fn init() { - let init: Initialization = msg::load().expect("Failed to decode init"); - - unsafe { - STATE = Some(NodeState { - status: init.status, - sub_nodes: BTreeSet::default(), - transition: None, - }); - } - - msg::reply((), 0).unwrap(); -} +#[cfg(not(feature = "std"))] +mod wasm; #[cfg(test)] mod tests { diff --git a/examples/node/src/wasm.rs b/examples/node/src/wasm.rs new file mode 100644 index 00000000000..b3eecb340be --- /dev/null +++ b/examples/node/src/wasm.rs @@ -0,0 +1,248 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use crate::{Initialization, Operation, Reply, Request}; +use gstd::{debug, exec, msg, prelude::*, ActorId, MessageId}; + +static mut STATE: Option = None; + +enum TransitionState { + Ready, + NotReady, + Failed, +} + +struct Transition { + #[allow(dead_code)] + to_status: u32, + origin: ActorId, + query_list: Vec, + message_id: MessageId, + last_sent_message_id: MessageId, + query_index: usize, + state: TransitionState, +} + +struct NodeState { + #[allow(dead_code)] + status: u32, + sub_nodes: BTreeSet, + transition: Option, +} + +#[no_mangle] +extern "C" fn handle() { + let reply = match msg::load() { + Ok(request) => process(request), + Err(e) => { + debug!("Error processing request: {e:?}"); + Reply::Failure + } + }; + + msg::reply(reply, 0).unwrap(); +} + +fn state() -> &'static mut NodeState { + unsafe { STATE.as_mut().unwrap() } +} + +fn process(request: Request) -> Reply { + if let Some(mut transition) = state().transition.take() { + if transition.message_id == msg::id() { + // one of the answers has set failed state + if let TransitionState::Failed = transition.state { + return Reply::Failure; + } + + // this means that we received replies from all subnodes + if transition.query_index == transition.query_list.len() { + match transition.state { + TransitionState::NotReady => { + transition.state = TransitionState::Ready; + + debug!("Returning final ready signal"); + + // this is ready to further process with committing + state().transition = Some(transition); + return Reply::Success; + } + TransitionState::Ready => { + // this means we successfully committed and we can + // drop the transition returning success + debug!("Returning final commit signal"); + + return Reply::Success; + } + _ => { + // this is some invalid state already + return Reply::Failure; + } + } + } + + // this means we need to send another sub-node query + let next_sub_node = transition + .query_list + .get(transition.query_index) + .expect("Checked above that it has that number of elements; qed"); + + transition.last_sent_message_id = msg::send(*next_sub_node, request, 0).unwrap(); + + state().transition = Some(transition); + + exec::wait(); + } else { + // this is just a new message that should be processed normally, without continuation. + state().transition = Some(transition); + } + } + + match request { + Request::IsReady => { + if state().transition.is_none() { + Reply::Yes + } else { + Reply::No + } + } + Request::Begin(Operation { to_status }) => { + if state().transition.is_some() { + Reply::Failure + } else { + let mut transition = Transition { + to_status, + origin: msg::source(), + query_index: 0, + query_list: vec![], + state: TransitionState::NotReady, + message_id: msg::id(), + last_sent_message_id: MessageId::default(), + }; + + debug!("Transition started"); + + if !state().sub_nodes.is_empty() { + debug!("Transition started is complex"); + + transition.query_list = state().sub_nodes.iter().cloned().collect(); + let first_sub_node = *transition + .query_list + .get(0) + .expect("Checked above that sub_nodes is not empty; qed"); + transition.last_sent_message_id = + msg::send(first_sub_node, request, 0).unwrap(); + state().transition = Some(transition); + exec::wait() + } else { + transition.state = TransitionState::Ready; + state().transition = Some(transition); + Reply::Success + } + } + } + Request::Commit => { + if state().sub_nodes.is_empty() { + let (transition, reply) = match state().transition.take() { + Some(transition) => { + if transition.origin != msg::source() { + (Some(transition), Reply::Failure) + } else { + (None, Reply::Success) + } + } + None => (None, Reply::Failure), + }; + + state().transition = transition; + + reply + } else if let Some(mut transition) = state().transition.take() { + if let TransitionState::Ready = transition.state { + let first_sub_node = *transition + .query_list + .get(0) + .expect("Checked above that sub_nodes is not empty; qed"); + + transition.query_index = 0; + + transition.message_id = msg::id(); + + transition.last_sent_message_id = + msg::send(first_sub_node, request, 0).unwrap(); + + state().transition = Some(transition); + + exec::wait() + } else { + debug!("Returning failure because current state is not READY"); + Reply::Failure + } + } else { + debug!("Returning failure because there is no transition in process"); + Reply::Failure + } + } + Request::Add(sub_node) => { + state().sub_nodes.insert(sub_node); + Reply::Success + } + } +} + +#[no_mangle] +extern "C" fn handle_reply() { + if let Some(ref mut transition) = state().transition { + if msg::reply_to().unwrap() != transition.last_sent_message_id { + return; + } + + match msg::load() { + Ok(reply) => { + transition.query_index += 1; + if let Reply::Success = reply { + } else { + transition.state = TransitionState::Failed; + } + exec::wake(transition.message_id).unwrap(); + } + Err(e) => { + transition.state = TransitionState::Failed; + debug!("Error processing reply: {e:?}"); + exec::wake(transition.message_id).unwrap(); + } + } + } else { + debug!("Got some reply that can not be processed"); + } +} + +#[no_mangle] +extern "C" fn init() { + let init: Initialization = msg::load().expect("Failed to decode init"); + + unsafe { + STATE = Some(NodeState { + status: init.status, + sub_nodes: BTreeSet::default(), + transition: None, + }); + } + + msg::reply((), 0).unwrap(); +} diff --git a/examples/out-of-memory/src/lib.rs b/examples/out-of-memory/src/lib.rs index ca12845c8fc..b64f1e21f2f 100644 --- a/examples/out-of-memory/src/lib.rs +++ b/examples/out-of-memory/src/lib.rs @@ -29,16 +29,5 @@ mod code { #[cfg(feature = "std")] pub use code::WASM_BINARY_OPT as WASM_BINARY; -#[cfg(target_arch = "wasm32")] -mod wasm { - use alloc::alloc::Layout; - - #[no_mangle] - extern "C" fn init() { - unsafe { - // Force rustc not to remove memory import - *(10usize as *mut u8) = 10; - } - alloc::alloc::handle_alloc_error(Layout::new::<[u8; 64 * 1024]>()); - } -} +#[cfg(not(feature = "std"))] +mod wasm; diff --git a/examples/out-of-memory/src/wasm.rs b/examples/out-of-memory/src/wasm.rs new file mode 100644 index 00000000000..6ac5382b67a --- /dev/null +++ b/examples/out-of-memory/src/wasm.rs @@ -0,0 +1,28 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use alloc::alloc::Layout; + +#[no_mangle] +extern "C" fn init() { + unsafe { + // Force rustc not to remove memory import + *(10usize as *mut u8) = 10; + } + alloc::alloc::handle_alloc_error(Layout::new::<[u8; 64 * 1024]>()); +} diff --git a/examples/piggy-bank/src/lib.rs b/examples/piggy-bank/src/lib.rs index 4ddfa5a7498..fbc08d47a0b 100644 --- a/examples/piggy-bank/src/lib.rs +++ b/examples/piggy-bank/src/lib.rs @@ -27,20 +27,4 @@ mod code { pub use code::WASM_BINARY_OPT as WASM_BINARY; #[cfg(not(feature = "std"))] -mod wasm { - use gstd::{debug, exec, msg}; - - #[no_mangle] - extern "C" fn handle() { - msg::with_read_on_stack(|msg| { - let available_value = exec::value_available(); - let value = msg::value(); - debug!("inserted: {value}, total: {available_value}"); - - if msg.expect("Failed to load payload bytes") == b"smash" { - debug!("smashing, total: {available_value}"); - msg::reply_bytes(b"send", available_value).unwrap(); - } - }); - } -} +mod wasm; diff --git a/examples/piggy-bank/src/wasm.rs b/examples/piggy-bank/src/wasm.rs new file mode 100644 index 00000000000..cc8ea523c1c --- /dev/null +++ b/examples/piggy-bank/src/wasm.rs @@ -0,0 +1,33 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use gstd::{debug, exec, msg}; + +#[no_mangle] +extern "C" fn handle() { + msg::with_read_on_stack(|msg| { + let available_value = exec::value_available(); + let value = msg::value(); + debug!("inserted: {value}, total: {available_value}"); + + if msg.expect("Failed to load payload bytes") == b"smash" { + debug!("smashing, total: {available_value}"); + msg::reply_bytes(b"send", available_value).unwrap(); + } + }); +} diff --git a/examples/ping/src/lib.rs b/examples/ping/src/lib.rs index 0c48715a6b0..fbc08d47a0b 100644 --- a/examples/ping/src/lib.rs +++ b/examples/ping/src/lib.rs @@ -27,15 +27,4 @@ mod code { pub use code::WASM_BINARY_OPT as WASM_BINARY; #[cfg(not(feature = "std"))] -mod wasm { - use gstd::{msg, prelude::*}; - - #[no_mangle] - extern "C" fn handle() { - let payload = msg::load_bytes().expect("Failed to load payload"); - - if payload == b"PING" { - msg::reply_bytes("PONG", 0).expect("Failed to send reply"); - } - } -} +mod wasm; diff --git a/examples/ping/src/wasm.rs b/examples/ping/src/wasm.rs new file mode 100644 index 00000000000..69b988852d2 --- /dev/null +++ b/examples/ping/src/wasm.rs @@ -0,0 +1,28 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use gstd::{msg, prelude::*}; + +#[no_mangle] +extern "C" fn handle() { + let payload = msg::load_bytes().expect("Failed to load payload"); + + if payload == b"PING" { + msg::reply_bytes("PONG", 0).expect("Failed to send reply"); + } +} diff --git a/examples/program-factory/src/lib.rs b/examples/program-factory/src/lib.rs index 2cb14dfee0e..9a919f1cd11 100644 --- a/examples/program-factory/src/lib.rs +++ b/examples/program-factory/src/lib.rs @@ -48,60 +48,7 @@ const CHILD_CODE_HASH: [u8; 32] = hex_literal::hex!("abf3746e72a6e8740bd9e12b879fbdd59e052cb390f116454e9116c22021ae4a"); #[cfg(not(feature = "std"))] -mod wasm { - use super::{CreateProgram, CHILD_CODE_HASH}; - use gstd::{msg, prog, ActorId}; - - static mut COUNTER: i32 = 0; - static mut ORIGIN: Option = None; - - #[no_mangle] - extern "C" fn init() { - unsafe { ORIGIN = Some(msg::source()) }; - } - - #[no_mangle] - extern "C" fn handle() { - match msg::load().expect("provided invalid payload") { - CreateProgram::Default => { - let submitted_code = CHILD_CODE_HASH.into(); - let (_message_id, new_program_id) = prog::create_program_bytes_with_gas( - submitted_code, - unsafe { COUNTER.to_le_bytes() }, - [], - 10_000_000_000, - 0, - ) - .unwrap(); - msg::send_bytes(new_program_id, [], 0).unwrap(); - - unsafe { COUNTER += 1 }; - } - CreateProgram::Custom(custom_child_data) => { - for (code_hash, salt, gas_limit) in custom_child_data { - let submitted_code = code_hash.into(); - let (_message_id, new_program_id) = prog::create_program_bytes_with_gas( - submitted_code, - &salt, - [], - gas_limit, - 0, - ) - .unwrap(); - msg::send_bytes(new_program_id, [], 0).expect("Failed to send message"); - } - } - }; - } - - #[no_mangle] - extern "C" fn handle_reply() { - if !msg::reply_code().unwrap().is_success() { - let origin = unsafe { ORIGIN.unwrap() }; - msg::send_bytes(origin, [], 0).unwrap(); - } - } -} +mod wasm; #[cfg(test)] mod tests { diff --git a/examples/program-factory/src/wasm.rs b/examples/program-factory/src/wasm.rs new file mode 100644 index 00000000000..f0cd48f1db5 --- /dev/null +++ b/examples/program-factory/src/wasm.rs @@ -0,0 +1,71 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +//! An example of `create_program_with_gas` sys-call. +//! +//! The program is mainly used for testing the sys-call logic in pallet `gear` tests. +//! It works as a program factory: depending on input type it sends program creation +//! request (message). + +use crate::{CreateProgram, CHILD_CODE_HASH}; +use gstd::{msg, prog, ActorId}; + +static mut COUNTER: i32 = 0; +static mut ORIGIN: Option = None; + +#[no_mangle] +extern "C" fn init() { + unsafe { ORIGIN = Some(msg::source()) }; +} + +#[no_mangle] +extern "C" fn handle() { + match msg::load().expect("provided invalid payload") { + CreateProgram::Default => { + let submitted_code = CHILD_CODE_HASH.into(); + let (_message_id, new_program_id) = prog::create_program_bytes_with_gas( + submitted_code, + unsafe { COUNTER.to_le_bytes() }, + [], + 10_000_000_000, + 0, + ) + .unwrap(); + msg::send_bytes(new_program_id, [], 0).unwrap(); + + unsafe { COUNTER += 1 }; + } + CreateProgram::Custom(custom_child_data) => { + for (code_hash, salt, gas_limit) in custom_child_data { + let submitted_code = code_hash.into(); + let (_message_id, new_program_id) = + prog::create_program_bytes_with_gas(submitted_code, &salt, [], gas_limit, 0) + .unwrap(); + msg::send_bytes(new_program_id, [], 0).expect("Failed to send message"); + } + } + }; +} + +#[no_mangle] +extern "C" fn handle_reply() { + if !msg::reply_code().unwrap().is_success() { + let origin = unsafe { ORIGIN.unwrap() }; + msg::send_bytes(origin, [], 0).unwrap(); + } +} diff --git a/examples/program-generator/src/lib.rs b/examples/program-generator/src/lib.rs index b3aa2869011..4333e8bd24e 100644 --- a/examples/program-generator/src/lib.rs +++ b/examples/program-generator/src/lib.rs @@ -38,33 +38,4 @@ pub const CHILD_WAT: &str = r#" "#; #[cfg(not(feature = "std"))] -mod wasm { - use gstd::{prelude::*, prog::ProgramGenerator, CodeId}; - - fn check_salt_uniqueness() { - let salts: Vec<_> = (0..10).map(|_| ProgramGenerator::get_salt()).collect(); - let salts_len = salts.len(); - - // The set's length should be equal to the vector's one - // if there are no repetitive values. - let salts_set: BTreeSet<_> = salts.into_iter().collect(); - assert_eq!(salts_len, salts_set.len()); - } - - #[no_mangle] - extern "C" fn handle() { - let submitted_code: CodeId = - hex_literal::hex!("abf3746e72a6e8740bd9e12b879fbdd59e052cb390f116454e9116c22021ae4a") - .into(); - - ProgramGenerator::create_program_bytes_with_gas( - submitted_code, - b"payload", - 10_000_000_000, - 0, - ) - .unwrap(); - - check_salt_uniqueness(); - } -} +mod wasm; diff --git a/examples/program-generator/src/wasm.rs b/examples/program-generator/src/wasm.rs new file mode 100644 index 00000000000..6847d2ce8c9 --- /dev/null +++ b/examples/program-generator/src/wasm.rs @@ -0,0 +1,41 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use gstd::{prelude::*, prog::ProgramGenerator, CodeId}; + +fn check_salt_uniqueness() { + let salts: Vec<_> = (0..10).map(|_| ProgramGenerator::get_salt()).collect(); + let salts_len = salts.len(); + + // The set's length should be equal to the vector's one + // if there are no repetitive values. + let salts_set: BTreeSet<_> = salts.into_iter().collect(); + assert_eq!(salts_len, salts_set.len()); +} + +#[no_mangle] +extern "C" fn handle() { + let submitted_code: CodeId = + hex_literal::hex!("abf3746e72a6e8740bd9e12b879fbdd59e052cb390f116454e9116c22021ae4a") + .into(); + + ProgramGenerator::create_program_bytes_with_gas(submitted_code, b"payload", 10_000_000_000, 0) + .unwrap(); + + check_salt_uniqueness(); +} diff --git a/examples/proxy-relay/src/lib.rs b/examples/proxy-relay/src/lib.rs index 4852a5435f1..00ff90ce91d 100644 --- a/examples/proxy-relay/src/lib.rs +++ b/examples/proxy-relay/src/lib.rs @@ -49,84 +49,4 @@ pub enum RelayCall { } #[cfg(not(feature = "std"))] -mod wasm { - use super::*; - use gstd::msg::{self, MessageHandle}; - - static mut RELAY_CALL: Option = None; - - fn resend_push(resend_pushes: &[ResendPushData]) { - for data in resend_pushes { - let msg_handle = MessageHandle::init().expect("Failed to obtain new message handle"); - - let ResendPushData { - destination, - start, - end, - } = data; - - let end = end.map(|(e, flag)| (e as usize, flag)); - match start.map(|s| s as usize) { - Some(s) => match end { - None => { - msg_handle.push_input(s..).expect("Push failed"); - } - Some((e, true)) => { - msg_handle.push_input(s..=e).expect("Push failed"); - } - Some((e, _)) => { - msg_handle.push_input(s..e).expect("Push failed"); - } - }, - None => match end { - None => { - msg_handle.push_input(..).expect("Push failed"); - } - Some((e, true)) => { - msg_handle.push_input(..=e).expect("Push failed"); - } - Some((e, _)) => { - msg_handle.push_input(..e).expect("Push failed"); - } - }, - } - - msg_handle - .commit(*destination, msg::value()) - .expect("Commit failed"); - } - } - - #[no_mangle] - extern "C" fn handle() { - use RelayCall::*; - let relay_call = unsafe { RELAY_CALL.as_ref().expect("Relay call is not initialized") }; - - match relay_call { - Resend(d) => { - msg::send_input(*d, msg::value(), ..msg::size()).expect("Resend failed"); - } - ResendWithGas(d, gas) => { - msg::send_input_with_gas(*d, *gas, msg::value(), ..).expect("Resend wgas failed"); - } - ResendPush(data) => { - resend_push(data); - } - Rereply => { - msg::reply_input(msg::value(), 0..msg::size()).expect("Rereply failed"); - } - RereplyPush => { - msg::reply_push_input(0..).expect("Push failed"); - msg::reply_commit(msg::value()).expect("Commit failed"); - } - RereplyWithGas(gas) => { - msg::reply_input_with_gas(*gas, msg::value(), ..).expect("Rereply wgas failed"); - } - } - } - - #[no_mangle] - extern "C" fn init() { - unsafe { RELAY_CALL = Some(msg::load().expect("Failed to decode `RelayCall'")) }; - } -} +mod wasm; diff --git a/examples/proxy-relay/src/wasm.rs b/examples/proxy-relay/src/wasm.rs new file mode 100644 index 00000000000..8e5f1594df4 --- /dev/null +++ b/examples/proxy-relay/src/wasm.rs @@ -0,0 +1,97 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use crate::{RelayCall, ResendPushData}; +use gstd::msg::{self, MessageHandle}; + +static mut RELAY_CALL: Option = None; + +fn resend_push(resend_pushes: &[ResendPushData]) { + for data in resend_pushes { + let msg_handle = MessageHandle::init().expect("Failed to obtain new message handle"); + + let ResendPushData { + destination, + start, + end, + } = data; + + let end = end.map(|(e, flag)| (e as usize, flag)); + match start.map(|s| s as usize) { + Some(s) => match end { + None => { + msg_handle.push_input(s..).expect("Push failed"); + } + Some((e, true)) => { + msg_handle.push_input(s..=e).expect("Push failed"); + } + Some((e, _)) => { + msg_handle.push_input(s..e).expect("Push failed"); + } + }, + None => match end { + None => { + msg_handle.push_input(..).expect("Push failed"); + } + Some((e, true)) => { + msg_handle.push_input(..=e).expect("Push failed"); + } + Some((e, _)) => { + msg_handle.push_input(..e).expect("Push failed"); + } + }, + } + + msg_handle + .commit(*destination, msg::value()) + .expect("Commit failed"); + } +} + +#[no_mangle] +extern "C" fn handle() { + use RelayCall::*; + let relay_call = unsafe { RELAY_CALL.as_ref().expect("Relay call is not initialized") }; + + match relay_call { + Resend(d) => { + msg::send_input(*d, msg::value(), ..msg::size()).expect("Resend failed"); + } + ResendWithGas(d, gas) => { + msg::send_input_with_gas(*d, *gas, msg::value(), ..).expect("Resend wgas failed"); + } + ResendPush(data) => { + resend_push(data); + } + Rereply => { + msg::reply_input(msg::value(), 0..msg::size()).expect("Rereply failed"); + } + RereplyPush => { + msg::reply_push_input(0..).expect("Push failed"); + msg::reply_commit(msg::value()).expect("Commit failed"); + } + RereplyWithGas(gas) => { + msg::reply_input_with_gas(*gas, msg::value(), ..).expect("Rereply wgas failed"); + } + } +} + +#[no_mangle] +extern "C" fn init() { + unsafe { RELAY_CALL = Some(msg::load().expect("Failed to decode `RelayCall'")) }; +} diff --git a/examples/proxy-reservation-with-gas/src/lib.rs b/examples/proxy-reservation-with-gas/src/lib.rs index 00a5c6f8a6a..427db5013d6 100644 --- a/examples/proxy-reservation-with-gas/src/lib.rs +++ b/examples/proxy-reservation-with-gas/src/lib.rs @@ -37,35 +37,4 @@ pub struct InputArgs { } #[cfg(not(feature = "std"))] -mod wasm { - use crate::InputArgs; - use gstd::{msg, ActorId, ReservationId}; - - static mut DESTINATION: ActorId = ActorId::new([0u8; 32]); - static mut DELAY: u32 = 0; - static mut RESERVATION_AMOUNT: u64 = 0; - - #[no_mangle] - extern "C" fn handle() { - let reservation_id = ReservationId::reserve(unsafe { RESERVATION_AMOUNT }, 80) - .expect("Failed to reserve gas"); - msg::send_delayed_from_reservation( - reservation_id, - unsafe { DESTINATION }, - b"proxied message", - msg::value(), - unsafe { DELAY }, - ) - .expect("Failed to proxy message"); - } - - #[no_mangle] - extern "C" fn init() { - let args: InputArgs = msg::load().expect("Failed to decode `InputArgs'"); - unsafe { - DESTINATION = args.destination; - DELAY = args.delay; - RESERVATION_AMOUNT = args.reservation_amount; - } - } -} +mod wasm; diff --git a/examples/proxy-reservation-with-gas/src/wasm.rs b/examples/proxy-reservation-with-gas/src/wasm.rs new file mode 100644 index 00000000000..695e6678d4b --- /dev/null +++ b/examples/proxy-reservation-with-gas/src/wasm.rs @@ -0,0 +1,48 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use crate::InputArgs; +use gstd::{msg, ActorId, ReservationId}; + +static mut DESTINATION: ActorId = ActorId::new([0u8; 32]); +static mut DELAY: u32 = 0; +static mut RESERVATION_AMOUNT: u64 = 0; + +#[no_mangle] +extern "C" fn handle() { + let reservation_id = + ReservationId::reserve(unsafe { RESERVATION_AMOUNT }, 80).expect("Failed to reserve gas"); + msg::send_delayed_from_reservation( + reservation_id, + unsafe { DESTINATION }, + b"proxied message", + msg::value(), + unsafe { DELAY }, + ) + .expect("Failed to proxy message"); +} + +#[no_mangle] +extern "C" fn init() { + let args: InputArgs = msg::load().expect("Failed to decode `InputArgs'"); + unsafe { + DESTINATION = args.destination; + DELAY = args.delay; + RESERVATION_AMOUNT = args.reservation_amount; + } +} diff --git a/examples/proxy/src/lib.rs b/examples/proxy/src/lib.rs index 91cc0648d14..3afdf022b59 100644 --- a/examples/proxy/src/lib.rs +++ b/examples/proxy/src/lib.rs @@ -37,28 +37,4 @@ pub struct InputArgs { pub const HANDLE_REPLY_EXPECT: &str = "I will fail"; #[cfg(not(feature = "wasm-wrapper"))] -mod wasm { - use crate::{InputArgs, HANDLE_REPLY_EXPECT}; - use gstd::{msg, ActorId}; - - static mut DESTINATION: ActorId = ActorId::new([0u8; 32]); - - #[no_mangle] - extern "C" fn init() { - let args: InputArgs = msg::load().expect("Failed to decode `InputArgs'"); - unsafe { DESTINATION = args.destination.into() }; - } - - #[no_mangle] - extern "C" fn handle() { - let payload = msg::load_bytes().expect("failed to load bytes"); - msg::send_bytes(unsafe { DESTINATION }, payload, msg::value()) - .expect("failed to send bytes"); - } - - #[no_mangle] - extern "C" fn handle_reply() { - // Will panic here as replies denied in `handle_reply`. - msg::reply_bytes([], 0).expect(HANDLE_REPLY_EXPECT); - } -} +mod wasm; diff --git a/examples/proxy/src/wasm.rs b/examples/proxy/src/wasm.rs new file mode 100644 index 00000000000..b4c78b974c3 --- /dev/null +++ b/examples/proxy/src/wasm.rs @@ -0,0 +1,40 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use crate::{InputArgs, HANDLE_REPLY_EXPECT}; +use gstd::{msg, ActorId}; + +static mut DESTINATION: ActorId = ActorId::new([0u8; 32]); + +#[no_mangle] +extern "C" fn init() { + let args: InputArgs = msg::load().expect("Failed to decode `InputArgs'"); + unsafe { DESTINATION = args.destination.into() }; +} + +#[no_mangle] +extern "C" fn handle() { + let payload = msg::load_bytes().expect("failed to load bytes"); + msg::send_bytes(unsafe { DESTINATION }, payload, msg::value()).expect("failed to send bytes"); +} + +#[no_mangle] +extern "C" fn handle_reply() { + // Will panic here as replies denied in `handle_reply`. + msg::reply_bytes([], 0).expect(HANDLE_REPLY_EXPECT); +} diff --git a/examples/read-big-state/src/lib.rs b/examples/read-big-state/src/lib.rs index c2c99929b26..9aa874a1eb7 100644 --- a/examples/read-big-state/src/lib.rs +++ b/examples/read-big-state/src/lib.rs @@ -60,24 +60,4 @@ impl State { } #[cfg(not(feature = "std"))] -mod wasm { - use super::*; - use gstd::{msg, prelude::*}; - - static mut STATE: Option = None; - - fn state_mut() -> &'static mut State { - unsafe { STATE.get_or_insert_with(State::new) } - } - - #[no_mangle] - extern "C" fn handle() { - let strings = msg::load().expect("Failed to load state"); - state_mut().insert(strings); - } - - #[no_mangle] - extern "C" fn state() { - msg::reply(state_mut(), 0).expect("Error in reply of state"); - } -} +mod wasm; diff --git a/examples/read-big-state/src/wasm.rs b/examples/read-big-state/src/wasm.rs new file mode 100644 index 00000000000..65f13db548c --- /dev/null +++ b/examples/read-big-state/src/wasm.rs @@ -0,0 +1,37 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use crate::State; +use gstd::{msg, prelude::*}; + +static mut STATE: Option = None; + +fn state_mut() -> &'static mut State { + unsafe { STATE.get_or_insert_with(State::new) } +} + +#[no_mangle] +extern "C" fn handle() { + let strings = msg::load().expect("Failed to load state"); + state_mut().insert(strings); +} + +#[no_mangle] +extern "C" fn state() { + msg::reply(state_mut(), 0).expect("Error in reply of state"); +} diff --git a/examples/reservation-manager/src/lib.rs b/examples/reservation-manager/src/lib.rs index c6a1ddf5522..9e8281a1918 100644 --- a/examples/reservation-manager/src/lib.rs +++ b/examples/reservation-manager/src/lib.rs @@ -35,33 +35,4 @@ pub enum Action { } #[cfg(not(feature = "std"))] -mod wasm { - use super::*; - use gstd::{msg, prelude::*, Reservations}; - - static mut RESERVATIONS: Reservations = Reservations::new(); - - #[no_mangle] - extern "C" fn handle() { - let action: Action = msg::load().expect("Failed to load message"); - - unsafe { - match action { - Action::Reserve { amount, duration } => { - RESERVATIONS - .reserve(amount, duration) - .expect("Failed to reserve gas"); - } - Action::SendMessageFromReservation { gas_amount } => { - let reservation = RESERVATIONS.try_take_reservation(gas_amount); - if let Some(reservation) = reservation { - msg::send_bytes_from_reservation(reservation.id(), msg::source(), [], 0) - .expect("Failed to send message from reservation"); - } else { - panic!("Reservation not found"); - } - } - } - } - } -} +mod wasm; diff --git a/examples/reservation-manager/src/wasm.rs b/examples/reservation-manager/src/wasm.rs new file mode 100644 index 00000000000..a9d81564c0b --- /dev/null +++ b/examples/reservation-manager/src/wasm.rs @@ -0,0 +1,46 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use crate::Action; +use gstd::{msg, prelude::*, Reservations}; + +static mut RESERVATIONS: Reservations = Reservations::new(); + +#[no_mangle] +extern "C" fn handle() { + let action: Action = msg::load().expect("Failed to load message"); + + unsafe { + match action { + Action::Reserve { amount, duration } => { + RESERVATIONS + .reserve(amount, duration) + .expect("Failed to reserve gas"); + } + Action::SendMessageFromReservation { gas_amount } => { + let reservation = RESERVATIONS.try_take_reservation(gas_amount); + if let Some(reservation) = reservation { + msg::send_bytes_from_reservation(reservation.id(), msg::source(), [], 0) + .expect("Failed to send message from reservation"); + } else { + panic!("Reservation not found"); + } + } + } + } +} diff --git a/examples/reserve-gas/src/lib.rs b/examples/reserve-gas/src/lib.rs index da47e95a438..18abd66feee 100644 --- a/examples/reserve-gas/src/lib.rs +++ b/examples/reserve-gas/src/lib.rs @@ -63,195 +63,7 @@ pub type GasAmount = u64; pub type BlockCount = u32; #[cfg(not(feature = "std"))] -mod wasm { - use super::*; - use gstd::{ - errors::{Error, ExecutionError, ExtError, ReservationError}, - exec, msg, - prelude::*, - MessageId, ReservationId, - }; - - static mut RESERVATION_ID: Option = None; - static mut RESERVATIONS: Vec = Vec::new(); - static mut INIT_MSG: MessageId = MessageId::new([0; 32]); - static mut WAKE_STATE: WakeState = WakeState::Initial; - - #[derive(Debug, Eq, PartialEq)] - enum WakeState { - Initial, - Panic, - Exit, - } - - #[no_mangle] - extern "C" fn init() { - unsafe { INIT_MSG = msg::id() }; - - let action: InitAction = msg::load().unwrap(); - - match action { - InitAction::Normal(ref reservations) => { - for (amount, duration) in reservations { - let _ = ReservationId::reserve(*amount, *duration).expect("reservation"); - } - - // no actual reservation and unreservation is occurred - let noop_reservation = - ReservationId::reserve(50_000, 10).expect("noop reservation"); - let unreserved_amount = noop_reservation.unreserve().expect("noop unreservation"); - assert_eq!(unreserved_amount, 50_000); - - unsafe { - RESERVATION_ID = Some( - ReservationId::reserve(RESERVATION_AMOUNT, 15) - .expect("reservation across executions"), - ) - }; - } - InitAction::Wait => match unsafe { &WAKE_STATE } { - WakeState::Initial => { - let _reservation = ReservationId::reserve(50_000, 10); - // to find message to reply to in test - msg::send(msg::source(), (), 0).unwrap(); - exec::wait(); - } - WakeState::Panic => { - panic!() - } - WakeState::Exit => { - exec::exit(msg::source()); - } - }, - InitAction::CheckArgs { mailbox_threshold } => { - assert_eq!( - ReservationId::reserve(0, 10), - Err(Error::Core( - ExtError::Reservation(ReservationError::ReservationBelowMailboxThreshold) - .into() - )) - ); - - assert_eq!( - ReservationId::reserve(50_000, 0), - Err(Error::Core( - ExtError::Reservation(ReservationError::ZeroReservationDuration).into() - )) - ); - - assert_eq!( - ReservationId::reserve(mailbox_threshold - 1, 1), - Err(Error::Core( - ExtError::Reservation(ReservationError::ReservationBelowMailboxThreshold) - .into() - )) - ); - - assert_eq!( - ReservationId::reserve(mailbox_threshold, u32::MAX), - Err(Error::Core( - ExtError::Execution(ExecutionError::NotEnoughGas).into() - )) - ); - - assert_eq!( - ReservationId::reserve(u64::MAX, 1), - Err(Error::Core( - ExtError::Execution(ExecutionError::NotEnoughGas).into() - )) - ); - } - InitAction::FreshReserveUnreserve => { - let id = ReservationId::reserve(10_000, 10).unwrap(); - gstd::msg::send_from_reservation(id, msg::source(), b"fresh_reserve_unreserve", 0) - .unwrap(); - assert_eq!( - id.unreserve(), - Err(Error::Core( - ExtError::Reservation(ReservationError::InvalidReservationId).into() - )) - ); - } - } - } - - #[no_mangle] - extern "C" fn handle() { - let action: HandleAction = msg::load().unwrap(); - match action { - HandleAction::Unreserve => { - let id = unsafe { RESERVATION_ID.take().unwrap() }; - id.unreserve().expect("unreservation across executions"); - } - HandleAction::Exit => { - exec::exit(msg::source()); - } - HandleAction::ReplyFromReservation => { - let id = unsafe { RESERVATION_ID.take().unwrap() }; - msg::reply_from_reservation(id, REPLY_FROM_RESERVATION_PAYLOAD, 0) - .expect("unable to reply from reservation"); - } - HandleAction::AddReservationToList(amount, block_count) => { - let reservation_id = - ReservationId::reserve(amount, block_count).expect("Unable to reserve gas"); - unsafe { - RESERVATIONS.push(reservation_id); - } - } - HandleAction::ConsumeReservationsFromList => { - let reservations = unsafe { mem::take(&mut RESERVATIONS) }; - for reservation_id in reservations { - msg::send_from_reservation( - reservation_id, - exec::program_id(), - HandleAction::RunInifitely, - 0, - ) - .expect("Unable to send using reservation"); - } - } - HandleAction::RunInifitely => { - if msg::source() != exec::program_id() { - panic!( - "Invalid caller, this is a private method reserved for the program itself." - ); - } - loop { - let _msg_source = msg::source(); - } - } - HandleAction::SendFromReservationAndUnreserve => { - let id = unsafe { RESERVATION_ID.take().unwrap() }; - gstd::msg::send_from_reservation( - id, - msg::source(), - b"existing_reserve_unreserve", - 0, - ) - .unwrap(); - assert_eq!( - id.unreserve(), - Err(Error::Core( - ExtError::Reservation(ReservationError::InvalidReservationId).into() - )) - ); - } - } - } - - // must be called after `InitAction::Wait` - #[no_mangle] - extern "C" fn handle_reply() { - let action: ReplyAction = msg::load().unwrap(); - unsafe { - WAKE_STATE = match action { - ReplyAction::Panic => WakeState::Panic, - ReplyAction::Exit => WakeState::Exit, - }; - exec::wake(INIT_MSG).unwrap(); - } - } -} +mod wasm; #[cfg(test)] mod tests { diff --git a/examples/reserve-gas/src/wasm.rs b/examples/reserve-gas/src/wasm.rs new file mode 100644 index 00000000000..09e1d4ab2d9 --- /dev/null +++ b/examples/reserve-gas/src/wasm.rs @@ -0,0 +1,199 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use crate::{ + HandleAction, InitAction, ReplyAction, REPLY_FROM_RESERVATION_PAYLOAD, RESERVATION_AMOUNT, +}; +use gstd::{ + errors::{Error, ExecutionError, ExtError, ReservationError}, + exec, msg, + prelude::*, + MessageId, ReservationId, +}; + +static mut RESERVATION_ID: Option = None; +static mut RESERVATIONS: Vec = Vec::new(); +static mut INIT_MSG: MessageId = MessageId::new([0; 32]); +static mut WAKE_STATE: WakeState = WakeState::Initial; + +#[derive(Debug, Eq, PartialEq)] +enum WakeState { + Initial, + Panic, + Exit, +} + +#[no_mangle] +extern "C" fn init() { + unsafe { INIT_MSG = msg::id() }; + + let action: InitAction = msg::load().unwrap(); + + match action { + InitAction::Normal(ref reservations) => { + for (amount, duration) in reservations { + let _ = ReservationId::reserve(*amount, *duration).expect("reservation"); + } + + // no actual reservation and unreservation is occurred + let noop_reservation = ReservationId::reserve(50_000, 10).expect("noop reservation"); + let unreserved_amount = noop_reservation.unreserve().expect("noop unreservation"); + assert_eq!(unreserved_amount, 50_000); + + unsafe { + RESERVATION_ID = Some( + ReservationId::reserve(RESERVATION_AMOUNT, 15) + .expect("reservation across executions"), + ) + }; + } + InitAction::Wait => match unsafe { &WAKE_STATE } { + WakeState::Initial => { + let _reservation = ReservationId::reserve(50_000, 10); + // to find message to reply to in test + msg::send(msg::source(), (), 0).unwrap(); + exec::wait(); + } + WakeState::Panic => { + panic!() + } + WakeState::Exit => { + exec::exit(msg::source()); + } + }, + InitAction::CheckArgs { mailbox_threshold } => { + assert_eq!( + ReservationId::reserve(0, 10), + Err(Error::Core( + ExtError::Reservation(ReservationError::ReservationBelowMailboxThreshold) + .into() + )) + ); + + assert_eq!( + ReservationId::reserve(50_000, 0), + Err(Error::Core( + ExtError::Reservation(ReservationError::ZeroReservationDuration).into() + )) + ); + + assert_eq!( + ReservationId::reserve(mailbox_threshold - 1, 1), + Err(Error::Core( + ExtError::Reservation(ReservationError::ReservationBelowMailboxThreshold) + .into() + )) + ); + + assert_eq!( + ReservationId::reserve(mailbox_threshold, u32::MAX), + Err(Error::Core( + ExtError::Execution(ExecutionError::NotEnoughGas).into() + )) + ); + + assert_eq!( + ReservationId::reserve(u64::MAX, 1), + Err(Error::Core( + ExtError::Execution(ExecutionError::NotEnoughGas).into() + )) + ); + } + InitAction::FreshReserveUnreserve => { + let id = ReservationId::reserve(10_000, 10).unwrap(); + gstd::msg::send_from_reservation(id, msg::source(), b"fresh_reserve_unreserve", 0) + .unwrap(); + assert_eq!( + id.unreserve(), + Err(Error::Core( + ExtError::Reservation(ReservationError::InvalidReservationId).into() + )) + ); + } + } +} + +#[no_mangle] +extern "C" fn handle() { + let action: HandleAction = msg::load().unwrap(); + match action { + HandleAction::Unreserve => { + let id = unsafe { RESERVATION_ID.take().unwrap() }; + id.unreserve().expect("unreservation across executions"); + } + HandleAction::Exit => { + exec::exit(msg::source()); + } + HandleAction::ReplyFromReservation => { + let id = unsafe { RESERVATION_ID.take().unwrap() }; + msg::reply_from_reservation(id, REPLY_FROM_RESERVATION_PAYLOAD, 0) + .expect("unable to reply from reservation"); + } + HandleAction::AddReservationToList(amount, block_count) => { + let reservation_id = + ReservationId::reserve(amount, block_count).expect("Unable to reserve gas"); + unsafe { + RESERVATIONS.push(reservation_id); + } + } + HandleAction::ConsumeReservationsFromList => { + let reservations = unsafe { mem::take(&mut RESERVATIONS) }; + for reservation_id in reservations { + msg::send_from_reservation( + reservation_id, + exec::program_id(), + HandleAction::RunInifitely, + 0, + ) + .expect("Unable to send using reservation"); + } + } + HandleAction::RunInifitely => { + if msg::source() != exec::program_id() { + panic!("Invalid caller, this is a private method reserved for the program itself."); + } + loop { + let _msg_source = msg::source(); + } + } + HandleAction::SendFromReservationAndUnreserve => { + let id = unsafe { RESERVATION_ID.take().unwrap() }; + gstd::msg::send_from_reservation(id, msg::source(), b"existing_reserve_unreserve", 0) + .unwrap(); + assert_eq!( + id.unreserve(), + Err(Error::Core( + ExtError::Reservation(ReservationError::InvalidReservationId).into() + )) + ); + } + } +} + +// must be called after `InitAction::Wait` +#[no_mangle] +extern "C" fn handle_reply() { + let action: ReplyAction = msg::load().unwrap(); + unsafe { + WAKE_STATE = match action { + ReplyAction::Panic => WakeState::Panic, + ReplyAction::Exit => WakeState::Exit, + }; + exec::wake(INIT_MSG).unwrap(); + } +} diff --git a/examples/rwlock/src/lib.rs b/examples/rwlock/src/lib.rs index 5382886dbf7..8011edf5d94 100644 --- a/examples/rwlock/src/lib.rs +++ b/examples/rwlock/src/lib.rs @@ -39,111 +39,4 @@ pub enum Command { } #[cfg(not(feature = "std"))] -mod wasm { - use crate::Command; - use core::{ - future::Future, - pin::Pin, - ptr, - task::{Context, RawWaker, RawWakerVTable, Waker}, - }; - use gstd::{lock::RwLock, msg, prelude::*, ActorId}; - - static mut DESTINATION: ActorId = ActorId::zero(); - static RW_LOCK: RwLock = RwLock::new(0); - - async fn ping() { - msg::send_bytes_for_reply(unsafe { DESTINATION }, "PING", 0, 0) - .expect("Failed to send message") - .await - .expect("Received error reply"); - } - - #[no_mangle] - extern "C" fn init() { - let destination = msg::load().expect("Failed to load destination"); - unsafe { DESTINATION = destination }; - } - - #[gstd::async_main] - async fn main() { - if let Ok(command) = msg::load() { - match command { - Command::Get => { - let value = RW_LOCK.read().await; - msg::reply(*value, 0).expect("Failed to send reply"); - } - Command::Inc => { - let mut value = RW_LOCK.write().await; - *value += 1; - } - Command::PingGet => { - ping().await; - let value = RW_LOCK.read().await; - msg::reply(*value, 0).expect("Failed to send reply"); - } - Command::IncPing => { - let mut value = RW_LOCK.write().await; - *value += 1; - ping().await; - } - Command::GetPing => { - let value = RW_LOCK.read().await; - ping().await; - msg::reply(*value, 0).expect("Failed to send reply"); - } - Command::CheckReaders => { - let mut storage = Vec::with_capacity(RwLock::::READERS_LIMIT as usize); - - for _ in 0..RwLock::::READERS_LIMIT { - storage.push(RW_LOCK.read().await); - } - - let waker = unsafe { Waker::from_raw(clone_waker(ptr::null())) }; - let mut cx = Context::from_waker(&waker); - - // Read future just for extra testing - let mut wf = RW_LOCK.write(); - - assert!( - !Pin::new(&mut wf).poll(&mut cx).is_ready(), - "Ready, but shouldn't" - ); - - let mut rf = RW_LOCK.read(); - - assert!( - !Pin::new(&mut rf).poll(&mut cx).is_ready(), - "Ready, but shouldn't" - ); - - // Drop of single reader. - storage.pop(); - - // Read future just for extra testing - assert!( - !Pin::new(&mut wf).poll(&mut cx).is_ready(), - "Ready, but shouldn't" - ); - assert!( - Pin::new(&mut rf).poll(&mut cx).is_ready(), - "Not ready, but shouldn't" - ); - - let value = rf.await; - msg::reply(*value, 0).expect("Failed to send reply"); - } - } - } else { - let _write = RW_LOCK.write().await; - RW_LOCK.read().await; - } - } - - unsafe fn clone_waker(ptr: *const ()) -> RawWaker { - RawWaker::new( - ptr, - &RawWakerVTable::new(clone_waker, |_| {}, |_| {}, |_| {}), - ) - } -} +mod wasm; diff --git a/examples/rwlock/src/wasm.rs b/examples/rwlock/src/wasm.rs new file mode 100644 index 00000000000..5680348a781 --- /dev/null +++ b/examples/rwlock/src/wasm.rs @@ -0,0 +1,124 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use crate::Command; +use core::{ + future::Future, + pin::Pin, + ptr, + task::{Context, RawWaker, RawWakerVTable, Waker}, +}; +use gstd::{lock::RwLock, msg, prelude::*, ActorId}; + +static mut DESTINATION: ActorId = ActorId::zero(); +static RW_LOCK: RwLock = RwLock::new(0); + +async fn ping() { + msg::send_bytes_for_reply(unsafe { DESTINATION }, "PING", 0, 0) + .expect("Failed to send message") + .await + .expect("Received error reply"); +} + +#[no_mangle] +extern "C" fn init() { + let destination = msg::load().expect("Failed to load destination"); + unsafe { DESTINATION = destination }; +} + +#[gstd::async_main] +async fn main() { + if let Ok(command) = msg::load() { + match command { + Command::Get => { + let value = RW_LOCK.read().await; + msg::reply(*value, 0).expect("Failed to send reply"); + } + Command::Inc => { + let mut value = RW_LOCK.write().await; + *value += 1; + } + Command::PingGet => { + ping().await; + let value = RW_LOCK.read().await; + msg::reply(*value, 0).expect("Failed to send reply"); + } + Command::IncPing => { + let mut value = RW_LOCK.write().await; + *value += 1; + ping().await; + } + Command::GetPing => { + let value = RW_LOCK.read().await; + ping().await; + msg::reply(*value, 0).expect("Failed to send reply"); + } + Command::CheckReaders => { + let mut storage = Vec::with_capacity(RwLock::::READERS_LIMIT as usize); + + for _ in 0..RwLock::::READERS_LIMIT { + storage.push(RW_LOCK.read().await); + } + + let waker = unsafe { Waker::from_raw(clone_waker(ptr::null())) }; + let mut cx = Context::from_waker(&waker); + + // Read future just for extra testing + let mut wf = RW_LOCK.write(); + + assert!( + !Pin::new(&mut wf).poll(&mut cx).is_ready(), + "Ready, but shouldn't" + ); + + let mut rf = RW_LOCK.read(); + + assert!( + !Pin::new(&mut rf).poll(&mut cx).is_ready(), + "Ready, but shouldn't" + ); + + // Drop of single reader. + storage.pop(); + + // Read future just for extra testing + assert!( + !Pin::new(&mut wf).poll(&mut cx).is_ready(), + "Ready, but shouldn't" + ); + assert!( + Pin::new(&mut rf).poll(&mut cx).is_ready(), + "Not ready, but shouldn't" + ); + + let value = rf.await; + msg::reply(*value, 0).expect("Failed to send reply"); + } + } + } else { + let _write = RW_LOCK.write().await; + RW_LOCK.read().await; + } +} + +unsafe fn clone_waker(ptr: *const ()) -> RawWaker { + RawWaker::new( + ptr, + &RawWakerVTable::new(clone_waker, |_| {}, |_| {}, |_| {}), + ) +} diff --git a/examples/send-from-reservation/src/lib.rs b/examples/send-from-reservation/src/lib.rs index aa927e0333e..7348f9fbb6d 100644 --- a/examples/send-from-reservation/src/lib.rs +++ b/examples/send-from-reservation/src/lib.rs @@ -42,84 +42,4 @@ pub enum HandleAction { } #[cfg(not(feature = "std"))] -mod wasm { - use super::*; - use gstd::{msg, prelude::*, ReservationId}; - - #[derive(Debug, Encode, Decode)] - pub struct Receive([u8; 32]); - - #[no_mangle] - extern "C" fn handle() { - let action: HandleAction = msg::load().expect("Failed to load handle payload"); - match action { - HandleAction::SendToUser => { - let id = ReservationId::reserve(3_000_000_000, 50).expect("Failed to reserve gas"); - msg::send_bytes_from_reservation(id, msg::source(), b"send_to_user", 500) - .expect("Failed to send message"); - } - HandleAction::SendToUserDelayed => { - let id = ReservationId::reserve(4_000_000_000, 60).expect("Failed to reserve gas"); - msg::send_bytes_delayed_from_reservation( - id, - msg::source(), - b"send_to_user_delayed", - 600, - 1, - ) - .expect("Failed to send message"); - } - HandleAction::SendToProgram { pid, user } => { - let id = ReservationId::reserve(5_000_000_000, 70).expect("Failed to reserve gas"); - msg::send_from_reservation( - id, - pid.into(), - HandleAction::ReceiveFromProgram(user), - 700, - ) - .expect("Failed to send message"); - } - HandleAction::SendToProgramDelayed { pid, user } => { - let id = ReservationId::reserve(6_000_000_000, 80).expect("Failed to reserve gas"); - msg::send_delayed_from_reservation( - id, - pid.into(), - HandleAction::ReceiveFromProgramDelayed(user), - 800, - 1, - ) - .expect("Failed to send message"); - } - HandleAction::ReplyToUser => { - let id = ReservationId::reserve(7_000_000_000, 90).expect("Failed to reserve gas"); - msg::reply_bytes_from_reservation(id, b"reply_to_user", 900) - .expect("Failed to send message"); - } - HandleAction::ReplyToProgram { pid, user } => { - msg::send(pid.into(), HandleAction::ReplyToProgramStep2(user), 900) - .expect("Failed to reserve gas"); - } - HandleAction::ReplyToProgramStep2(user) => { - let id = ReservationId::reserve(7_000_000_000, 90).expect("Failed to reserve gas"); - msg::reply_from_reservation(id, Receive(user), 900).expect("Failed to reply"); - } - HandleAction::ReceiveFromProgram(user) => { - assert_eq!(msg::value(), 700); - msg::send_bytes(user.into(), b"receive_from_program", 700) - .expect("Failed to send message"); - } - HandleAction::ReceiveFromProgramDelayed(user) => { - assert_eq!(msg::value(), 800); - msg::send_bytes(user.into(), b"receive_from_program_delayed", 800) - .expect("Failed to send message"); - } - } - } - - #[no_mangle] - extern "C" fn handle_reply() { - let Receive(user) = msg::load().expect("Failed to load handle payload"); - assert_eq!(msg::value(), 900); - msg::send_bytes(user.into(), b"reply", 900).expect("Failed to send message"); - } -} +mod wasm; diff --git a/examples/send-from-reservation/src/wasm.rs b/examples/send-from-reservation/src/wasm.rs new file mode 100644 index 00000000000..a8281f605ec --- /dev/null +++ b/examples/send-from-reservation/src/wasm.rs @@ -0,0 +1,92 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use crate::HandleAction; +use gstd::{msg, prelude::*, ReservationId}; + +#[derive(Debug, Encode, Decode)] +pub struct Receive([u8; 32]); + +#[no_mangle] +extern "C" fn handle() { + let action: HandleAction = msg::load().expect("Failed to load handle payload"); + match action { + HandleAction::SendToUser => { + let id = ReservationId::reserve(3_000_000_000, 50).expect("Failed to reserve gas"); + msg::send_bytes_from_reservation(id, msg::source(), b"send_to_user", 500) + .expect("Failed to send message"); + } + HandleAction::SendToUserDelayed => { + let id = ReservationId::reserve(4_000_000_000, 60).expect("Failed to reserve gas"); + msg::send_bytes_delayed_from_reservation( + id, + msg::source(), + b"send_to_user_delayed", + 600, + 1, + ) + .expect("Failed to send message"); + } + HandleAction::SendToProgram { pid, user } => { + let id = ReservationId::reserve(5_000_000_000, 70).expect("Failed to reserve gas"); + msg::send_from_reservation(id, pid.into(), HandleAction::ReceiveFromProgram(user), 700) + .expect("Failed to send message"); + } + HandleAction::SendToProgramDelayed { pid, user } => { + let id = ReservationId::reserve(6_000_000_000, 80).expect("Failed to reserve gas"); + msg::send_delayed_from_reservation( + id, + pid.into(), + HandleAction::ReceiveFromProgramDelayed(user), + 800, + 1, + ) + .expect("Failed to send message"); + } + HandleAction::ReplyToUser => { + let id = ReservationId::reserve(7_000_000_000, 90).expect("Failed to reserve gas"); + msg::reply_bytes_from_reservation(id, b"reply_to_user", 900) + .expect("Failed to send message"); + } + HandleAction::ReplyToProgram { pid, user } => { + msg::send(pid.into(), HandleAction::ReplyToProgramStep2(user), 900) + .expect("Failed to reserve gas"); + } + HandleAction::ReplyToProgramStep2(user) => { + let id = ReservationId::reserve(7_000_000_000, 90).expect("Failed to reserve gas"); + msg::reply_from_reservation(id, Receive(user), 900).expect("Failed to reply"); + } + HandleAction::ReceiveFromProgram(user) => { + assert_eq!(msg::value(), 700); + msg::send_bytes(user.into(), b"receive_from_program", 700) + .expect("Failed to send message"); + } + HandleAction::ReceiveFromProgramDelayed(user) => { + assert_eq!(msg::value(), 800); + msg::send_bytes(user.into(), b"receive_from_program_delayed", 800) + .expect("Failed to send message"); + } + } +} + +#[no_mangle] +extern "C" fn handle_reply() { + let Receive(user) = msg::load().expect("Failed to load handle payload"); + assert_eq!(msg::value(), 900); + msg::send_bytes(user.into(), b"reply", 900).expect("Failed to send message"); +} diff --git a/examples/signal-entry/src/lib.rs b/examples/signal-entry/src/lib.rs index a3bd551041a..0024fb9da07 100644 --- a/examples/signal-entry/src/lib.rs +++ b/examples/signal-entry/src/lib.rs @@ -49,187 +49,7 @@ pub enum HandleAction { pub const WAIT_AND_RESERVE_WITH_PANIC_GAS: u64 = 10_000_000_000; #[cfg(not(feature = "std"))] -mod wasm { - use super::*; - use gstd::{ - errors::{ExtError, ReservationError, SignalCode, SimpleExecutionError}, - exec, msg, - prelude::*, - ActorId, MessageId, - }; - - static mut INITIATOR: ActorId = ActorId::zero(); - static mut HANDLE_MSG: Option = None; - static mut DO_PANIC: bool = false; - static mut DO_EXIT: bool = false; - static mut HANDLE_SIGNAL_STATE: HandleSignalState = HandleSignalState::Normal; - - enum HandleSignalState { - Normal, - Panic, - ForbiddenCall([u8; 32]), - } - - #[no_mangle] - extern "C" fn init() { - unsafe { INITIATOR = msg::source() }; - } - - #[no_mangle] - extern "C" fn handle() { - unsafe { HANDLE_MSG = Some(msg::id()) }; - let do_panic = unsafe { &mut DO_PANIC }; - - let action: HandleAction = msg::load().unwrap(); - match action { - HandleAction::Simple => { - // must be unreserved as unused - exec::system_reserve_gas(100).unwrap(); - } - HandleAction::Wait => { - exec::system_reserve_gas(1_000_000_000).unwrap(); - // used to found message id in test - msg::send(msg::source(), 0, 0).unwrap(); - exec::wait(); - } - HandleAction::WaitAndPanic => { - if *do_panic { - panic!(); - } - - *do_panic = !*do_panic; - - exec::system_reserve_gas(200).unwrap(); - // used to found message id in test - msg::send(msg::source(), 0, 0).unwrap(); - exec::wait(); - } - HandleAction::WaitAndReserveWithPanic => { - if *do_panic { - exec::system_reserve_gas(1_000_000_000).unwrap(); - panic!(); - } - - *do_panic = !*do_panic; - - exec::system_reserve_gas(WAIT_AND_RESERVE_WITH_PANIC_GAS).unwrap(); - // used to found message id in test - msg::send(msg::source(), 0, 0).unwrap(); - exec::wait(); - } - HandleAction::WaitAndExit => { - if unsafe { DO_EXIT } { - msg::send_bytes(msg::source(), b"wait_and_exit", 0).unwrap(); - exec::exit(msg::source()); - } - - unsafe { DO_EXIT = !DO_EXIT }; - - exec::system_reserve_gas(900).unwrap(); - // used to found message id in test - msg::send(msg::source(), 0, 0).unwrap(); - exec::wait(); - } - HandleAction::Panic => { - exec::system_reserve_gas(5_000_000_000).unwrap(); - panic!(); - } - HandleAction::WaitWithReserveAmountAndPanic(gas_amount) => { - if *do_panic { - panic!(); - } - - *do_panic = !*do_panic; - - exec::system_reserve_gas(gas_amount).unwrap(); - // used to found message id in test - msg::send(msg::source(), 0, 0).unwrap(); - exec::wait(); - } - HandleAction::Exit => { - exec::system_reserve_gas(4_000_000_000).unwrap(); - msg::reply_bytes(b"exit", 0).unwrap(); - exec::exit(msg::source()); - } - HandleAction::Accumulate => { - exec::system_reserve_gas(1000).unwrap(); - exec::system_reserve_gas(234).unwrap(); - exec::wait(); - } - HandleAction::OutOfGas => { - exec::system_reserve_gas(5_000_000_000).unwrap(); - // used to found message id in test - msg::send(msg::source(), 0, 0).unwrap(); - #[allow(clippy::empty_loop)] - loop {} - } - HandleAction::AcrossWaits => { - exec::system_reserve_gas(1_000_000_000).unwrap(); - // used to found message id in test - // we use send instead of reply to avoid duplicated reply error. - msg::send(msg::source(), 0, 0).unwrap(); - exec::wait(); - } - HandleAction::PanicInSignal => { - unsafe { HANDLE_SIGNAL_STATE = HandleSignalState::Panic }; - exec::system_reserve_gas(5_000_000_000).unwrap(); - exec::wait(); - } - HandleAction::ZeroReserve => { - let res = exec::system_reserve_gas(0); - assert_eq!( - res, - Err(ExtError::Reservation(ReservationError::ZeroReservationAmount).into()) - ); - } - HandleAction::ForbiddenCallInSignal(user) => { - unsafe { HANDLE_SIGNAL_STATE = HandleSignalState::ForbiddenCall(user) }; - exec::system_reserve_gas(1_000_000_000).unwrap(); - exec::wait(); - } - } - } - - #[no_mangle] - extern "C" fn handle_signal() { - match unsafe { &HANDLE_SIGNAL_STATE } { - HandleSignalState::Normal => { - msg::send(unsafe { INITIATOR }, b"handle_signal", 0).unwrap(); - let signal_code = msg::signal_code() - .expect("Incorrect call") - .expect("Unsupported code"); - assert!(matches!( - signal_code, - SignalCode::Execution( - SimpleExecutionError::UserspacePanic | SimpleExecutionError::RanOutOfGas - ) - )); - - if let Some(handle_msg) = unsafe { HANDLE_MSG } { - assert_eq!(msg::signal_from(), Ok(handle_msg)); - } - - // TODO: check gas limit (#1796) - // assert_eq!(msg::gas_limit(), 5_000_000_000); - } - HandleSignalState::Panic => { - // to be sure state rolls back so this message won't appear in mailbox in test - msg::send(unsafe { INITIATOR }, b"handle_signal_panic", 0).unwrap(); - panic!(); - } - HandleSignalState::ForbiddenCall(user) => { - msg::send_bytes((*user).into(), b"handle_signal_forbidden_call", 0).unwrap(); - let _ = msg::source(); - } - } - } - - #[no_mangle] - extern "C" fn handle_reply() { - let handle_msg = unsafe { HANDLE_MSG.unwrap() }; - exec::wake(handle_msg).unwrap(); - } -} +mod wasm; #[cfg(test)] mod tests { diff --git a/examples/signal-entry/src/wasm.rs b/examples/signal-entry/src/wasm.rs new file mode 100644 index 00000000000..e7d8c7b7334 --- /dev/null +++ b/examples/signal-entry/src/wasm.rs @@ -0,0 +1,197 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use crate::{HandleAction, WAIT_AND_RESERVE_WITH_PANIC_GAS}; +use gstd::{ + errors::{ExtError, ReservationError, SignalCode, SimpleExecutionError}, + exec, msg, + prelude::*, + ActorId, MessageId, +}; + +static mut INITIATOR: ActorId = ActorId::zero(); +static mut HANDLE_MSG: Option = None; +static mut DO_PANIC: bool = false; +static mut DO_EXIT: bool = false; +static mut HANDLE_SIGNAL_STATE: HandleSignalState = HandleSignalState::Normal; + +enum HandleSignalState { + Normal, + Panic, + ForbiddenCall([u8; 32]), +} + +#[no_mangle] +extern "C" fn init() { + unsafe { INITIATOR = msg::source() }; +} + +#[no_mangle] +extern "C" fn handle() { + unsafe { HANDLE_MSG = Some(msg::id()) }; + let do_panic = unsafe { &mut DO_PANIC }; + + let action: HandleAction = msg::load().unwrap(); + match action { + HandleAction::Simple => { + // must be unreserved as unused + exec::system_reserve_gas(100).unwrap(); + } + HandleAction::Wait => { + exec::system_reserve_gas(1_000_000_000).unwrap(); + // used to found message id in test + msg::send(msg::source(), 0, 0).unwrap(); + exec::wait(); + } + HandleAction::WaitAndPanic => { + if *do_panic { + panic!(); + } + + *do_panic = !*do_panic; + + exec::system_reserve_gas(200).unwrap(); + // used to found message id in test + msg::send(msg::source(), 0, 0).unwrap(); + exec::wait(); + } + HandleAction::WaitAndReserveWithPanic => { + if *do_panic { + exec::system_reserve_gas(1_000_000_000).unwrap(); + panic!(); + } + + *do_panic = !*do_panic; + + exec::system_reserve_gas(WAIT_AND_RESERVE_WITH_PANIC_GAS).unwrap(); + // used to found message id in test + msg::send(msg::source(), 0, 0).unwrap(); + exec::wait(); + } + HandleAction::WaitAndExit => { + if unsafe { DO_EXIT } { + msg::send_bytes(msg::source(), b"wait_and_exit", 0).unwrap(); + exec::exit(msg::source()); + } + + unsafe { DO_EXIT = !DO_EXIT }; + + exec::system_reserve_gas(900).unwrap(); + // used to found message id in test + msg::send(msg::source(), 0, 0).unwrap(); + exec::wait(); + } + HandleAction::Panic => { + exec::system_reserve_gas(5_000_000_000).unwrap(); + panic!(); + } + HandleAction::WaitWithReserveAmountAndPanic(gas_amount) => { + if *do_panic { + panic!(); + } + + *do_panic = !*do_panic; + + exec::system_reserve_gas(gas_amount).unwrap(); + // used to found message id in test + msg::send(msg::source(), 0, 0).unwrap(); + exec::wait(); + } + HandleAction::Exit => { + exec::system_reserve_gas(4_000_000_000).unwrap(); + msg::reply_bytes(b"exit", 0).unwrap(); + exec::exit(msg::source()); + } + HandleAction::Accumulate => { + exec::system_reserve_gas(1000).unwrap(); + exec::system_reserve_gas(234).unwrap(); + exec::wait(); + } + HandleAction::OutOfGas => { + exec::system_reserve_gas(5_000_000_000).unwrap(); + // used to found message id in test + msg::send(msg::source(), 0, 0).unwrap(); + #[allow(clippy::empty_loop)] + loop {} + } + HandleAction::AcrossWaits => { + exec::system_reserve_gas(1_000_000_000).unwrap(); + // used to found message id in test + // we use send instead of reply to avoid duplicated reply error. + msg::send(msg::source(), 0, 0).unwrap(); + exec::wait(); + } + HandleAction::PanicInSignal => { + unsafe { HANDLE_SIGNAL_STATE = HandleSignalState::Panic }; + exec::system_reserve_gas(5_000_000_000).unwrap(); + exec::wait(); + } + HandleAction::ZeroReserve => { + let res = exec::system_reserve_gas(0); + assert_eq!( + res, + Err(ExtError::Reservation(ReservationError::ZeroReservationAmount).into()) + ); + } + HandleAction::ForbiddenCallInSignal(user) => { + unsafe { HANDLE_SIGNAL_STATE = HandleSignalState::ForbiddenCall(user) }; + exec::system_reserve_gas(1_000_000_000).unwrap(); + exec::wait(); + } + } +} + +#[no_mangle] +extern "C" fn handle_signal() { + match unsafe { &HANDLE_SIGNAL_STATE } { + HandleSignalState::Normal => { + msg::send(unsafe { INITIATOR }, b"handle_signal", 0).unwrap(); + let signal_code = msg::signal_code() + .expect("Incorrect call") + .expect("Unsupported code"); + assert!(matches!( + signal_code, + SignalCode::Execution( + SimpleExecutionError::UserspacePanic | SimpleExecutionError::RanOutOfGas + ) + )); + + if let Some(handle_msg) = unsafe { HANDLE_MSG } { + assert_eq!(msg::signal_from(), Ok(handle_msg)); + } + + // TODO: check gas limit (#1796) + // assert_eq!(msg::gas_limit(), 5_000_000_000); + } + HandleSignalState::Panic => { + // to be sure state rolls back so this message won't appear in mailbox in test + msg::send(unsafe { INITIATOR }, b"handle_signal_panic", 0).unwrap(); + panic!(); + } + HandleSignalState::ForbiddenCall(user) => { + msg::send_bytes((*user).into(), b"handle_signal_forbidden_call", 0).unwrap(); + let _ = msg::source(); + } + } +} + +#[no_mangle] +extern "C" fn handle_reply() { + let handle_msg = unsafe { HANDLE_MSG.unwrap() }; + exec::wake(handle_msg).unwrap(); +} diff --git a/examples/stack-allocations/src/lib.rs b/examples/stack-allocations/src/lib.rs index 43440bf2ba4..5aa80e5d0aa 100644 --- a/examples/stack-allocations/src/lib.rs +++ b/examples/stack-allocations/src/lib.rs @@ -59,47 +59,7 @@ pub struct ReplyData { } #[cfg(not(feature = "std"))] -mod wasm { - use crate::{Action, HandleData, ReplyData, Vec}; - use gstd::msg; - - struct State { - actions: Vec, - } - - static mut STATE: State = State { - actions: Vec::new(), - }; - - fn do_actions(mut actions: Vec) -> u32 { - let check_sum = match actions.pop() { - Some(Action::Read) => msg::with_read_on_stack(|payload| { - payload - .map(|payload| payload.iter().fold(0u32, |acc, x| acc + *x as u32)) - .expect("Failed to read payload") - }), - Some(Action::Load) => { - let HandleData { data } = msg::load().expect("Failed to load handle config"); - data.iter().fold(0, |acc, x| acc + *x as u32) - } - None => return 0, - }; - check_sum + do_actions(actions) - } - - #[no_mangle] - extern "C" fn handle() { - let check_sum = do_actions(unsafe { STATE.actions.clone() }); - msg::reply(ReplyData { check_sum }, 0).expect("Failed to reply"); - } - - #[no_mangle] - extern "C" fn init() { - unsafe { - STATE.actions = msg::load().expect("Failed to load init config"); - } - } -} +mod wasm; #[cfg(test)] mod tests { diff --git a/examples/stack-allocations/src/wasm.rs b/examples/stack-allocations/src/wasm.rs new file mode 100644 index 00000000000..2f7876db301 --- /dev/null +++ b/examples/stack-allocations/src/wasm.rs @@ -0,0 +1,62 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +//! This contract recursively calls payload stack allocated read or load, +//! depends on actions vector, which is set in init. +//! For each recursion step we call check_sum, which is sum of all payload bytes. +//! Then reply summary check_sum back to source account. + +use crate::{Action, HandleData, ReplyData, Vec}; +use gstd::msg; + +struct State { + actions: Vec, +} + +static mut STATE: State = State { + actions: Vec::new(), +}; + +fn do_actions(mut actions: Vec) -> u32 { + let check_sum = match actions.pop() { + Some(Action::Read) => msg::with_read_on_stack(|payload| { + payload + .map(|payload| payload.iter().fold(0u32, |acc, x| acc + *x as u32)) + .expect("Failed to read payload") + }), + Some(Action::Load) => { + let HandleData { data } = msg::load().expect("Failed to load handle config"); + data.iter().fold(0, |acc, x| acc + *x as u32) + } + None => return 0, + }; + check_sum + do_actions(actions) +} + +#[no_mangle] +extern "C" fn handle() { + let check_sum = do_actions(unsafe { STATE.actions.clone() }); + msg::reply(ReplyData { check_sum }, 0).expect("Failed to reply"); +} + +#[no_mangle] +extern "C" fn init() { + unsafe { + STATE.actions = msg::load().expect("Failed to load init config"); + } +} diff --git a/examples/state-rollback/src/lib.rs b/examples/state-rollback/src/lib.rs index b430f5f52ca..fbc08d47a0b 100644 --- a/examples/state-rollback/src/lib.rs +++ b/examples/state-rollback/src/lib.rs @@ -27,31 +27,4 @@ mod code { pub use code::WASM_BINARY_OPT as WASM_BINARY; #[cfg(not(feature = "std"))] -mod wasm { - use gstd::{exec, msg, prelude::*}; - - static mut PAYLOAD: Option> = None; - - #[no_mangle] - extern "C" fn handle() { - let payload = msg::load_bytes().expect("Failed to load payload"); - - // Previous value - msg::send(msg::source(), unsafe { &PAYLOAD }, 0).expect("Failed to send message"); - - let is_panic = payload == b"panic"; - let is_leave = payload == b"leave"; - - // New value setting - unsafe { PAYLOAD = Some(payload) }; - - // Newly set value - msg::reply(unsafe { &PAYLOAD }, 0).expect("Failed to send reply"); - - // Stop execution with panic. - is_panic.then(|| panic!()); - - // Stop execution with leave. - is_leave.then(|| exec::leave()); - } -} +mod wasm; diff --git a/examples/state-rollback/src/wasm.rs b/examples/state-rollback/src/wasm.rs new file mode 100644 index 00000000000..6499386ef5e --- /dev/null +++ b/examples/state-rollback/src/wasm.rs @@ -0,0 +1,44 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use gstd::{exec, msg, prelude::*}; + +static mut PAYLOAD: Option> = None; + +#[no_mangle] +extern "C" fn handle() { + let payload = msg::load_bytes().expect("Failed to load payload"); + + // Previous value + msg::send(msg::source(), unsafe { &PAYLOAD }, 0).expect("Failed to send message"); + + let is_panic = payload == b"panic"; + let is_leave = payload == b"leave"; + + // New value setting + unsafe { PAYLOAD = Some(payload) }; + + // Newly set value + msg::reply(unsafe { &PAYLOAD }, 0).expect("Failed to send reply"); + + // Stop execution with panic. + is_panic.then(|| panic!()); + + // Stop execution with leave. + is_leave.then(|| exec::leave()); +} diff --git a/examples/sync-duplicate/src/lib.rs b/examples/sync-duplicate/src/lib.rs index 745af7ac4ce..fbc08d47a0b 100644 --- a/examples/sync-duplicate/src/lib.rs +++ b/examples/sync-duplicate/src/lib.rs @@ -27,33 +27,4 @@ mod code { pub use code::WASM_BINARY_OPT as WASM_BINARY; #[cfg(not(feature = "std"))] -mod wasm { - use gstd::{msg, prelude::*, ActorId}; - - static mut COUNTER: i32 = 0; - static mut DESTINATION: ActorId = ActorId::zero(); - - #[no_mangle] - extern "C" fn init() { - let destination = msg::load().expect("Failed to load destination"); - unsafe { DESTINATION = destination }; - } - - #[gstd::async_main] - async fn main() { - let payload = msg::load_bytes().expect("Failed to load payload"); - - if payload == b"async" { - unsafe { COUNTER += 1 }; - - let _ = msg::send_bytes_for_reply(unsafe { DESTINATION }, "PING", 0, 0) - .expect("Failed to send message") - .await - .expect("Received error reply"); - - msg::reply(unsafe { COUNTER }, 0).expect("Failed to send reply"); - - unsafe { COUNTER = 0 }; - } - } -} +mod wasm; diff --git a/examples/sync-duplicate/src/wasm.rs b/examples/sync-duplicate/src/wasm.rs new file mode 100644 index 00000000000..f949f4afdcd --- /dev/null +++ b/examples/sync-duplicate/src/wasm.rs @@ -0,0 +1,46 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use gstd::{msg, prelude::*, ActorId}; + +static mut COUNTER: i32 = 0; +static mut DESTINATION: ActorId = ActorId::zero(); + +#[no_mangle] +extern "C" fn init() { + let destination = msg::load().expect("Failed to load destination"); + unsafe { DESTINATION = destination }; +} + +#[gstd::async_main] +async fn main() { + let payload = msg::load_bytes().expect("Failed to load payload"); + + if payload == b"async" { + unsafe { COUNTER += 1 }; + + let _ = msg::send_bytes_for_reply(unsafe { DESTINATION }, "PING", 0, 0) + .expect("Failed to send message") + .await + .expect("Received error reply"); + + msg::reply(unsafe { COUNTER }, 0).expect("Failed to send reply"); + + unsafe { COUNTER = 0 }; + } +} diff --git a/examples/sys-calls/src/lib.rs b/examples/sys-calls/src/lib.rs index 84740b82462..dd1eab86fe7 100644 --- a/examples/sys-calls/src/lib.rs +++ b/examples/sys-calls/src/lib.rs @@ -106,429 +106,4 @@ pub enum Kind { pub const PAY_PROGRAM_RENT_EXPECT: &str = "Unable to pay rent"; #[cfg(not(feature = "wasm-wrapper"))] -mod wasm { - use super::Kind; - use gstd::{ - errors::{ReplyCode, SignalCode, SimpleExecutionError}, - exec, format, - msg::{self, MessageHandle}, - prog, ActorId, CodeId, MessageId, ReservationId, Vec, - }; - use parity_scale_codec::Encode; - - static mut CODE_ID: CodeId = CodeId::new([0u8; 32]); - static mut SIGNAL_DETAILS: (MessageId, SignalCode, ActorId) = ( - MessageId::new([0; 32]), - SignalCode::Execution(SimpleExecutionError::Unsupported), - ActorId::zero(), - ); - static mut DO_PANIC: bool = false; - - #[no_mangle] - extern "C" fn init() { - let code_id_bytes: [u8; 32] = msg::load().expect("internal error: invalid payload"); - - unsafe { CODE_ID = code_id_bytes.into() }; - } - - #[no_mangle] - extern "C" fn handle() { - let syscall_kinds: Vec = msg::load().expect("internal error: invalid payload"); - for syscall_kind in syscall_kinds { - process(syscall_kind); - } - - // Report test executed successfully - msg::send_delayed(msg::source(), b"ok", 0, 0).expect("internal error: report send failed"); - } - - fn process(syscall_kind: Kind) { - match syscall_kind { - Kind::CreateProgram(salt, gas_opt, (expected_mid, expected_pid)) => { - let salt = salt.to_le_bytes(); - let res = match gas_opt { - Some(gas) => prog::create_program_bytes_with_gas_delayed( - unsafe { CODE_ID }, - salt, - "payload", - gas, - 0, - 0, - ), - None => prog::create_program_bytes_delayed( - unsafe { CODE_ID }, - salt, - "payload", - 0, - 0, - ), - }; - let (actual_mid, actual_pid) = res.expect("internal error: create program failed"); - let actual_mid: [u8; 32] = actual_mid.into(); - let actual_pid: [u8; 32] = actual_pid.into(); - assert_eq!( - expected_mid, actual_mid, - "Kind::CreateProgram: mid test failed" - ); - assert_eq!( - expected_pid, actual_pid, - "Kind::CreateProgram: pid test failed" - ); - } - Kind::Error(message_value, expected_err) => { - let actual_err = msg::reply(b"", message_value).expect_err("not enough balance"); - assert_eq!( - expected_err, - format!("{actual_err}"), - "Kind::Error: test failed" - ); - } - Kind::Send(gas_opt, expected_mid) => { - let actual_mid_res = match gas_opt { - Some(gas) => msg::send_with_gas_delayed(msg::source(), b"payload", gas, 0, 0), - None => msg::send_delayed(msg::source(), b"payload", 0, 0), - }; - assert_eq!( - Ok(expected_mid.into()), - actual_mid_res, - "Kind::Send: mid test failed" - ); - } - Kind::SendInput(gas_opt, expected_mid) => { - let actual_mid_res = match gas_opt { - Some(gas) => msg::send_input_with_gas_delayed(msg::source(), gas, 0, .., 0), - None => msg::send_input_delayed(msg::source(), 0, .., 0), - }; - assert_eq!( - Ok(expected_mid.into()), - actual_mid_res, - "Kind::SendInput: mid test failed" - ); - } - Kind::SendPushInput(expected_mid) => { - // Sending these 2 to increase internal handler returned by `send_init`. - let _ = msg::send_delayed(msg::source(), b"payload", 0, 0); - let _ = msg::send_delayed(msg::source(), b"payload", 0, 0); - - let handle = MessageHandle::init().expect("internal error: failed send init"); - - // check handle - handle - .push_input(0..) - .expect("internal error: push_input failed"); - - let actual_mid_res = handle.commit_delayed(msg::source(), 0, 0); - assert_eq!( - Ok(expected_mid.into()), - actual_mid_res, - "Kind::SendPushInput: mid test failed" - ); - } - Kind::SendRaw(payload, gas_opt, expected_mid) => { - // Sending these 2 to increase internal handler returned by `send_init`. - let _ = msg::send_delayed(msg::source(), b"payload", 0, 0); - let _ = msg::send_delayed(msg::source(), b"payload", 0, 0); - - let handle = MessageHandle::init().expect("internal error: failed send init"); - // check handle - handle - .push(payload) - .expect("internal error: failed send_push"); - let actual_mid_res = match gas_opt { - Some(gas) => handle.commit_with_gas_delayed(msg::source(), gas, 0, 0), - None => handle.commit_delayed(msg::source(), 0, 0), - }; - assert_eq!( - Ok(expected_mid.into()), - actual_mid_res, - "Kind::SendRaw: mid test failed" - ); - } - Kind::Size(expected_size) => { - let actual_size = msg::size(); - assert_eq!( - expected_size as usize, actual_size, - "Kind::Size: size test failed" - ); - } - Kind::MessageId(expected_mid) => { - let actual_mid: [u8; 32] = msg::id().into(); - assert_eq!(expected_mid, actual_mid, "Kind::MessageId: mid test failed"); - } - Kind::PayProgramRent(program_id, rent, expected) => { - let (unused_value, paid_block_count) = - exec::pay_program_rent(program_id.into(), rent) - .expect(super::PAY_PROGRAM_RENT_EXPECT); - if let Some((expected_unused_value, expected_paid_block_count)) = expected { - assert_eq!(unused_value, expected_unused_value); - assert_eq!(paid_block_count, expected_paid_block_count); - } - } - Kind::ProgramId(expected_pid) => { - let actual_pid: [u8; 32] = exec::program_id().into(); - assert_eq!(expected_pid, actual_pid, "Kind::ProgramId: pid test failed"); - } - Kind::Source(expected_actor) => { - let actual_actor: [u8; 32] = msg::source().into(); - assert_eq!( - expected_actor, actual_actor, - "Kind::Source: actor test failed" - ); - } - Kind::Value(expected_value) => { - let actual_value = msg::value(); - assert_eq!( - expected_value, actual_value, - "Kind::Value: value test failed" - ); - } - Kind::ValueAvailable(expected_value) => { - let _ = msg::send_delayed(msg::source(), b"payload", 2000, 0); - let actual_value = exec::value_available(); - assert_eq!( - expected_value, actual_value, - "Kind::ValueAvailable: value test failed" - ); - } - Kind::Reply(gas_opt, expected_mid) => { - let actual_mid_res = match gas_opt { - Some(gas) => msg::reply_with_gas(b"payload", gas, 0), - None => msg::reply(b"payload", 0), - }; - assert_eq!( - Ok(expected_mid.into()), - actual_mid_res, - "Kind::Reply: mid test failed" - ); - } - Kind::ReplyRaw(payload, gas_opt, expected_mid) => { - msg::reply_push(payload).expect("internal error: failed reply push"); - let actual_mid_res = match gas_opt { - Some(gas) => msg::reply_commit_with_gas(gas, 0), - None => msg::reply_commit(0), - }; - assert_eq!( - Ok(expected_mid.into()), - actual_mid_res, - "Kind::ReplyRaw: mid test failed" - ); - } - Kind::ReplyInput(gas_opt, expected_mid) => { - let actual_mid_res = match gas_opt { - Some(gas) => msg::reply_input_with_gas(gas, 0, ..), - None => msg::reply_input(0, ..), - }; - assert_eq!( - Ok(expected_mid.into()), - actual_mid_res, - "Kind::ReplyInput: mid test failed" - ); - } - Kind::ReplyPushInput(expected_mid) => { - msg::reply_push_input(..).expect("internal error: reply_push_input failed"); - let actual_mid_res = msg::reply_commit(0); - assert_eq!( - Ok(expected_mid.into()), - actual_mid_res, - "Kind::ReplyPushInput: mid test failed" - ); - } - Kind::ReplyDetails(..) => { - // Actual test in handle reply, here just sends a reply - let _ = msg::send_delayed(msg::source(), b"payload", 0, 0); - // To prevent from sending to mailbox "ok" message - exec::leave(); - } - Kind::SignalDetails => { - if unsafe { DO_PANIC } { - // issue a signal - panic!(); - } else { - unsafe { - SIGNAL_DETAILS = ( - msg::id(), - SignalCode::Execution(SimpleExecutionError::UserspacePanic), - msg::source(), - ); - DO_PANIC = true; - } - exec::system_reserve_gas(1_000_000_000).unwrap(); - let _ = msg::send_delayed(msg::source(), b"payload", 0, 0); - exec::wait_for(2); - } - } - Kind::SignalDetailsWake => { - panic!("must be called in handle_reply"); - } - Kind::BlockHeight(expected_height) => { - let actual_height = exec::block_height(); - assert_eq!( - expected_height, actual_height, - "Kind::BlockHeight:: block height test failed" - ); - } - Kind::BlockTimestamp(expected_timestamp) => { - let actual_timestamp = exec::block_timestamp(); - assert_eq!( - expected_timestamp, actual_timestamp, - "Kind::BlockTimestamp:: block timestamp test failed" - ); - } - Kind::Reserve(expected_id) => { - // do 2 reservations to increase internal nonce - let _ = ReservationId::reserve(10_000, 3); - let _ = ReservationId::reserve(20_000, 5); - let actual_id = - ReservationId::reserve(30_000, 7).expect("internal error: reservation failed"); - assert_eq!( - expected_id, - actual_id.encode(), - "Kind::Reserve: reserve gas test failed" - ); - } - Kind::Unreserve(expected_amount) => { - let reservation = ReservationId::reserve(expected_amount, 3) - .expect("internal error: reservation failed"); - let actual_amount = reservation.unreserve(); - assert_eq!( - Ok(expected_amount), - actual_amount, - "Kind::Unreserve: unreserve gas test failed" - ); - } - Kind::Random(salt, (expected_hash, expected_bn)) => { - let (actual_hash, actual_bn) = - exec::random(salt).expect("internal error: random call failed"); - assert_eq!(expected_hash, actual_hash, "Kind::Random: hash test failed"); - assert_eq!(expected_bn, actual_bn, "Kind::Random: bn test failed"); - } - Kind::GasAvailable(lower, upper) => { - let gas_available = exec::gas_available(); - assert!( - gas_available >= lower, - "Kind::GasAvailable: lower bound test failed" - ); - assert!( - gas_available <= upper, - "Kind::GasAvailable: upper bound test failed" - ); - } - Kind::ReservationSend(expected_mid) => { - let reservation_id = - ReservationId::reserve(25_000_000_000, 1).expect("reservation failed"); - let actual_mid = msg::send_bytes_delayed_from_reservation( - reservation_id, - msg::source(), - b"", - 0, - 0, - ); - assert_eq!( - Ok(expected_mid.into()), - actual_mid, - "Kind::ReservationSend: mid test failed" - ); - } - Kind::ReservationSendRaw(payload, expected_mid) => { - let _ = msg::send_delayed(msg::source(), b"payload", 0, 0); - let reservation_id = - ReservationId::reserve(25_000_000_000, 1).expect("reservation failed"); - - let handle = MessageHandle::init().expect("internal error: failed send init"); - // check handle - handle - .push(payload) - .expect("internal error: failed send_push"); - let actual_mid = - handle.commit_delayed_from_reservation(reservation_id, msg::source(), 0, 0); - assert_eq!( - Ok(expected_mid.into()), - actual_mid, - "Kind::ReservationSendRaw: mid test failed" - ); - } - Kind::ReservationReply(expected_mid) => { - let reservation_id = - ReservationId::reserve(25_000_000_000, 1).expect("reservation failed"); - let actual_mid = msg::reply_bytes_from_reservation(reservation_id, b"", 0); - assert_eq!( - Ok(expected_mid.into()), - actual_mid, - "Kind::ReservationReply: mid test failed" - ); - } - Kind::ReservationReplyCommit(payload, expected_mid) => { - let reservation_id = - ReservationId::reserve(25_000_000_000, 1).expect("reservation failed"); - msg::reply_push(payload).expect("internal error: failed reply push"); - let actual_mid = msg::reply_commit_from_reservation(reservation_id, 0); - assert_eq!( - Ok(expected_mid.into()), - actual_mid, - "Kind::ReservationReplyCommit: mid test failed" - ); - } - Kind::SystemReserveGas(amount) => { - exec::system_reserve_gas(amount).expect("Kind::SystemReserveGas: call test failed"); - // The only case with wait, so we send report before ending execution, instead of - // waking the message - msg::send_delayed(msg::source(), b"ok", 0, 0) - .expect("internal error: report send failed"); - exec::wait_for(2); - } - Kind::ReplyDeposit(amount) => { - let mid = msg::send_bytes(ActorId::zero(), [], 0) - .expect("internal error: failed to send message"); - - exec::reply_deposit(mid, amount).expect("Kind::ReplyDeposit: call test failed"); - } - } - } - - #[no_mangle] - extern "C" fn handle_reply() { - match msg::load() { - Ok(Kind::ReplyDetails(expected_reply_to, expected_reply_code_bytes)) => { - let expected_reply_code = ReplyCode::from_bytes(expected_reply_code_bytes); - let actual_reply_to = msg::reply_to(); - assert_eq!( - Ok(expected_reply_to.into()), - actual_reply_to, - "Kind::ReplyDetails: reply_to test failed" - ); - let actual_reply_code = msg::reply_code(); - assert_eq!( - Ok(expected_reply_code), - actual_reply_code, - "Kind::ReplyDetails: reply code test failed" - ); - - // Report test executed successfully - msg::send_delayed(msg::source(), b"ok", 0, 0) - .expect("internal error: report send failed"); - } - Ok(Kind::SignalDetailsWake) => unsafe { - exec::wake(SIGNAL_DETAILS.0).unwrap(); - }, - _ => panic!("internal error: invalid payload for `handle_reply`"), - } - } - - #[no_mangle] - extern "C" fn handle_signal() { - let (signal_from, signal_code, source) = unsafe { SIGNAL_DETAILS }; - - assert_eq!( - msg::signal_code(), - Ok(Some(signal_code)), - "Kind::SignalDetails: status code test failed" - ); - assert_eq!( - msg::signal_from(), - Ok(signal_from), - "Kind::SignalDetails: signal_from test failed" - ); - - msg::send_delayed(source, b"ok", 0, 0).expect("internal error: report send failed"); - } -} +mod wasm; diff --git a/examples/sys-calls/src/wasm.rs b/examples/sys-calls/src/wasm.rs new file mode 100644 index 00000000000..06a194c8fdc --- /dev/null +++ b/examples/sys-calls/src/wasm.rs @@ -0,0 +1,432 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use crate::Kind; +use gstd::{ + errors::{ReplyCode, SignalCode, SimpleExecutionError}, + exec, format, + msg::{self, MessageHandle}, + prog, ActorId, CodeId, MessageId, ReservationId, Vec, +}; +use parity_scale_codec::Encode; + +static mut CODE_ID: CodeId = CodeId::new([0u8; 32]); +static mut SIGNAL_DETAILS: (MessageId, SignalCode, ActorId) = ( + MessageId::new([0; 32]), + SignalCode::Execution(SimpleExecutionError::Unsupported), + ActorId::zero(), +); +static mut DO_PANIC: bool = false; + +#[no_mangle] +extern "C" fn init() { + let code_id_bytes: [u8; 32] = msg::load().expect("internal error: invalid payload"); + + unsafe { CODE_ID = code_id_bytes.into() }; +} + +#[no_mangle] +extern "C" fn handle() { + let syscall_kinds: Vec = msg::load().expect("internal error: invalid payload"); + for syscall_kind in syscall_kinds { + process(syscall_kind); + } + + // Report test executed successfully + msg::send_delayed(msg::source(), b"ok", 0, 0).expect("internal error: report send failed"); +} + +fn process(syscall_kind: Kind) { + match syscall_kind { + Kind::CreateProgram(salt, gas_opt, (expected_mid, expected_pid)) => { + let salt = salt.to_le_bytes(); + let res = match gas_opt { + Some(gas) => prog::create_program_bytes_with_gas_delayed( + unsafe { CODE_ID }, + salt, + "payload", + gas, + 0, + 0, + ), + None => { + prog::create_program_bytes_delayed(unsafe { CODE_ID }, salt, "payload", 0, 0) + } + }; + let (actual_mid, actual_pid) = res.expect("internal error: create program failed"); + let actual_mid: [u8; 32] = actual_mid.into(); + let actual_pid: [u8; 32] = actual_pid.into(); + assert_eq!( + expected_mid, actual_mid, + "Kind::CreateProgram: mid test failed" + ); + assert_eq!( + expected_pid, actual_pid, + "Kind::CreateProgram: pid test failed" + ); + } + Kind::Error(message_value, expected_err) => { + let actual_err = msg::reply(b"", message_value).expect_err("not enough balance"); + assert_eq!( + expected_err, + format!("{actual_err}"), + "Kind::Error: test failed" + ); + } + Kind::Send(gas_opt, expected_mid) => { + let actual_mid_res = match gas_opt { + Some(gas) => msg::send_with_gas_delayed(msg::source(), b"payload", gas, 0, 0), + None => msg::send_delayed(msg::source(), b"payload", 0, 0), + }; + assert_eq!( + Ok(expected_mid.into()), + actual_mid_res, + "Kind::Send: mid test failed" + ); + } + Kind::SendInput(gas_opt, expected_mid) => { + let actual_mid_res = match gas_opt { + Some(gas) => msg::send_input_with_gas_delayed(msg::source(), gas, 0, .., 0), + None => msg::send_input_delayed(msg::source(), 0, .., 0), + }; + assert_eq!( + Ok(expected_mid.into()), + actual_mid_res, + "Kind::SendInput: mid test failed" + ); + } + Kind::SendPushInput(expected_mid) => { + // Sending these 2 to increase internal handler returned by `send_init`. + let _ = msg::send_delayed(msg::source(), b"payload", 0, 0); + let _ = msg::send_delayed(msg::source(), b"payload", 0, 0); + + let handle = MessageHandle::init().expect("internal error: failed send init"); + + // check handle + handle + .push_input(0..) + .expect("internal error: push_input failed"); + + let actual_mid_res = handle.commit_delayed(msg::source(), 0, 0); + assert_eq!( + Ok(expected_mid.into()), + actual_mid_res, + "Kind::SendPushInput: mid test failed" + ); + } + Kind::SendRaw(payload, gas_opt, expected_mid) => { + // Sending these 2 to increase internal handler returned by `send_init`. + let _ = msg::send_delayed(msg::source(), b"payload", 0, 0); + let _ = msg::send_delayed(msg::source(), b"payload", 0, 0); + + let handle = MessageHandle::init().expect("internal error: failed send init"); + // check handle + handle + .push(payload) + .expect("internal error: failed send_push"); + let actual_mid_res = match gas_opt { + Some(gas) => handle.commit_with_gas_delayed(msg::source(), gas, 0, 0), + None => handle.commit_delayed(msg::source(), 0, 0), + }; + assert_eq!( + Ok(expected_mid.into()), + actual_mid_res, + "Kind::SendRaw: mid test failed" + ); + } + Kind::Size(expected_size) => { + let actual_size = msg::size(); + assert_eq!( + expected_size as usize, actual_size, + "Kind::Size: size test failed" + ); + } + Kind::MessageId(expected_mid) => { + let actual_mid: [u8; 32] = msg::id().into(); + assert_eq!(expected_mid, actual_mid, "Kind::MessageId: mid test failed"); + } + Kind::PayProgramRent(program_id, rent, expected) => { + let (unused_value, paid_block_count) = exec::pay_program_rent(program_id.into(), rent) + .expect(super::PAY_PROGRAM_RENT_EXPECT); + if let Some((expected_unused_value, expected_paid_block_count)) = expected { + assert_eq!(unused_value, expected_unused_value); + assert_eq!(paid_block_count, expected_paid_block_count); + } + } + Kind::ProgramId(expected_pid) => { + let actual_pid: [u8; 32] = exec::program_id().into(); + assert_eq!(expected_pid, actual_pid, "Kind::ProgramId: pid test failed"); + } + Kind::Source(expected_actor) => { + let actual_actor: [u8; 32] = msg::source().into(); + assert_eq!( + expected_actor, actual_actor, + "Kind::Source: actor test failed" + ); + } + Kind::Value(expected_value) => { + let actual_value = msg::value(); + assert_eq!( + expected_value, actual_value, + "Kind::Value: value test failed" + ); + } + Kind::ValueAvailable(expected_value) => { + let _ = msg::send_delayed(msg::source(), b"payload", 2000, 0); + let actual_value = exec::value_available(); + assert_eq!( + expected_value, actual_value, + "Kind::ValueAvailable: value test failed" + ); + } + Kind::Reply(gas_opt, expected_mid) => { + let actual_mid_res = match gas_opt { + Some(gas) => msg::reply_with_gas(b"payload", gas, 0), + None => msg::reply(b"payload", 0), + }; + assert_eq!( + Ok(expected_mid.into()), + actual_mid_res, + "Kind::Reply: mid test failed" + ); + } + Kind::ReplyRaw(payload, gas_opt, expected_mid) => { + msg::reply_push(payload).expect("internal error: failed reply push"); + let actual_mid_res = match gas_opt { + Some(gas) => msg::reply_commit_with_gas(gas, 0), + None => msg::reply_commit(0), + }; + assert_eq!( + Ok(expected_mid.into()), + actual_mid_res, + "Kind::ReplyRaw: mid test failed" + ); + } + Kind::ReplyInput(gas_opt, expected_mid) => { + let actual_mid_res = match gas_opt { + Some(gas) => msg::reply_input_with_gas(gas, 0, ..), + None => msg::reply_input(0, ..), + }; + assert_eq!( + Ok(expected_mid.into()), + actual_mid_res, + "Kind::ReplyInput: mid test failed" + ); + } + Kind::ReplyPushInput(expected_mid) => { + msg::reply_push_input(..).expect("internal error: reply_push_input failed"); + let actual_mid_res = msg::reply_commit(0); + assert_eq!( + Ok(expected_mid.into()), + actual_mid_res, + "Kind::ReplyPushInput: mid test failed" + ); + } + Kind::ReplyDetails(..) => { + // Actual test in handle reply, here just sends a reply + let _ = msg::send_delayed(msg::source(), b"payload", 0, 0); + // To prevent from sending to mailbox "ok" message + exec::leave(); + } + Kind::SignalDetails => { + if unsafe { DO_PANIC } { + // issue a signal + panic!(); + } else { + unsafe { + SIGNAL_DETAILS = ( + msg::id(), + SignalCode::Execution(SimpleExecutionError::UserspacePanic), + msg::source(), + ); + DO_PANIC = true; + } + exec::system_reserve_gas(1_000_000_000).unwrap(); + let _ = msg::send_delayed(msg::source(), b"payload", 0, 0); + exec::wait_for(2); + } + } + Kind::SignalDetailsWake => { + panic!("must be called in handle_reply"); + } + Kind::BlockHeight(expected_height) => { + let actual_height = exec::block_height(); + assert_eq!( + expected_height, actual_height, + "Kind::BlockHeight:: block height test failed" + ); + } + Kind::BlockTimestamp(expected_timestamp) => { + let actual_timestamp = exec::block_timestamp(); + assert_eq!( + expected_timestamp, actual_timestamp, + "Kind::BlockTimestamp:: block timestamp test failed" + ); + } + Kind::Reserve(expected_id) => { + // do 2 reservations to increase internal nonce + let _ = ReservationId::reserve(10_000, 3); + let _ = ReservationId::reserve(20_000, 5); + let actual_id = + ReservationId::reserve(30_000, 7).expect("internal error: reservation failed"); + assert_eq!( + expected_id, + actual_id.encode(), + "Kind::Reserve: reserve gas test failed" + ); + } + Kind::Unreserve(expected_amount) => { + let reservation = ReservationId::reserve(expected_amount, 3) + .expect("internal error: reservation failed"); + let actual_amount = reservation.unreserve(); + assert_eq!( + Ok(expected_amount), + actual_amount, + "Kind::Unreserve: unreserve gas test failed" + ); + } + Kind::Random(salt, (expected_hash, expected_bn)) => { + let (actual_hash, actual_bn) = + exec::random(salt).expect("internal error: random call failed"); + assert_eq!(expected_hash, actual_hash, "Kind::Random: hash test failed"); + assert_eq!(expected_bn, actual_bn, "Kind::Random: bn test failed"); + } + Kind::GasAvailable(lower, upper) => { + let gas_available = exec::gas_available(); + assert!( + gas_available >= lower, + "Kind::GasAvailable: lower bound test failed" + ); + assert!( + gas_available <= upper, + "Kind::GasAvailable: upper bound test failed" + ); + } + Kind::ReservationSend(expected_mid) => { + let reservation_id = + ReservationId::reserve(25_000_000_000, 1).expect("reservation failed"); + let actual_mid = + msg::send_bytes_delayed_from_reservation(reservation_id, msg::source(), b"", 0, 0); + assert_eq!( + Ok(expected_mid.into()), + actual_mid, + "Kind::ReservationSend: mid test failed" + ); + } + Kind::ReservationSendRaw(payload, expected_mid) => { + let _ = msg::send_delayed(msg::source(), b"payload", 0, 0); + let reservation_id = + ReservationId::reserve(25_000_000_000, 1).expect("reservation failed"); + + let handle = MessageHandle::init().expect("internal error: failed send init"); + // check handle + handle + .push(payload) + .expect("internal error: failed send_push"); + let actual_mid = + handle.commit_delayed_from_reservation(reservation_id, msg::source(), 0, 0); + assert_eq!( + Ok(expected_mid.into()), + actual_mid, + "Kind::ReservationSendRaw: mid test failed" + ); + } + Kind::ReservationReply(expected_mid) => { + let reservation_id = + ReservationId::reserve(25_000_000_000, 1).expect("reservation failed"); + let actual_mid = msg::reply_bytes_from_reservation(reservation_id, b"", 0); + assert_eq!( + Ok(expected_mid.into()), + actual_mid, + "Kind::ReservationReply: mid test failed" + ); + } + Kind::ReservationReplyCommit(payload, expected_mid) => { + let reservation_id = + ReservationId::reserve(25_000_000_000, 1).expect("reservation failed"); + msg::reply_push(payload).expect("internal error: failed reply push"); + let actual_mid = msg::reply_commit_from_reservation(reservation_id, 0); + assert_eq!( + Ok(expected_mid.into()), + actual_mid, + "Kind::ReservationReplyCommit: mid test failed" + ); + } + Kind::SystemReserveGas(amount) => { + exec::system_reserve_gas(amount).expect("Kind::SystemReserveGas: call test failed"); + // The only case with wait, so we send report before ending execution, instead of + // waking the message + msg::send_delayed(msg::source(), b"ok", 0, 0) + .expect("internal error: report send failed"); + exec::wait_for(2); + } + Kind::ReplyDeposit(amount) => { + let mid = msg::send_bytes(ActorId::zero(), [], 0) + .expect("internal error: failed to send message"); + + exec::reply_deposit(mid, amount).expect("Kind::ReplyDeposit: call test failed"); + } + } +} + +#[no_mangle] +extern "C" fn handle_reply() { + match msg::load() { + Ok(Kind::ReplyDetails(expected_reply_to, expected_reply_code_bytes)) => { + let expected_reply_code = ReplyCode::from_bytes(expected_reply_code_bytes); + let actual_reply_to = msg::reply_to(); + assert_eq!( + Ok(expected_reply_to.into()), + actual_reply_to, + "Kind::ReplyDetails: reply_to test failed" + ); + let actual_reply_code = msg::reply_code(); + assert_eq!( + Ok(expected_reply_code), + actual_reply_code, + "Kind::ReplyDetails: reply code test failed" + ); + + // Report test executed successfully + msg::send_delayed(msg::source(), b"ok", 0, 0) + .expect("internal error: report send failed"); + } + Ok(Kind::SignalDetailsWake) => unsafe { + exec::wake(SIGNAL_DETAILS.0).unwrap(); + }, + _ => panic!("internal error: invalid payload for `handle_reply`"), + } +} + +#[no_mangle] +extern "C" fn handle_signal() { + let (signal_from, signal_code, source) = unsafe { SIGNAL_DETAILS }; + + assert_eq!( + msg::signal_code(), + Ok(Some(signal_code)), + "Kind::SignalDetails: status code test failed" + ); + assert_eq!( + msg::signal_from(), + Ok(signal_from), + "Kind::SignalDetails: signal_from test failed" + ); + + msg::send_delayed(source, b"ok", 0, 0).expect("internal error: report send failed"); +} diff --git a/examples/syscall-error/src/lib.rs b/examples/syscall-error/src/lib.rs index a22dca29e2e..216ee1b7aa1 100644 --- a/examples/syscall-error/src/lib.rs +++ b/examples/syscall-error/src/lib.rs @@ -18,8 +18,6 @@ #![cfg_attr(not(feature = "std"), no_std)] -use gstd::{msg, prelude::*, ActorId}; - #[cfg(feature = "std")] mod code { include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); @@ -27,18 +25,9 @@ mod code { #[cfg(feature = "std")] pub use code::WASM_BINARY_OPT as WASM_BINARY; -use gstd::errors::{Error, ExtError, MessageError}; - -#[no_mangle] -extern "C" fn init() { - let res = msg::send(ActorId::default(), "dummy", 250); - assert_eq!( - res, - Err(Error::Core( - ExtError::Message(MessageError::InsufficientValue).into() - )) - ); -} + +#[cfg(not(feature = "std"))] +mod wasm; #[cfg(test)] mod tests { diff --git a/examples/syscall-error/src/wasm.rs b/examples/syscall-error/src/wasm.rs new file mode 100644 index 00000000000..74a45d9a3aa --- /dev/null +++ b/examples/syscall-error/src/wasm.rs @@ -0,0 +1,35 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use gstd::{ + errors::{Error, ExtError, MessageError}, + msg, + prelude::*, + ActorId, +}; + +#[no_mangle] +extern "C" fn init() { + let res = msg::send(ActorId::default(), "dummy", 250); + assert_eq!( + res, + Err(Error::Core( + ExtError::Message(MessageError::InsufficientValue).into() + )) + ); +} diff --git a/examples/vec/src/lib.rs b/examples/vec/src/lib.rs index 90ea46965f4..fbc08d47a0b 100644 --- a/examples/vec/src/lib.rs +++ b/examples/vec/src/lib.rs @@ -27,39 +27,4 @@ mod code { pub use code::WASM_BINARY_OPT as WASM_BINARY; #[cfg(not(feature = "std"))] -mod wasm { - use gstd::{debug, msg, prelude::*}; - - static mut MESSAGE_LOG: Vec = vec![]; - - #[no_mangle] - extern "C" fn handle() { - let size = msg::load::().expect("Failed to load `i32`") as usize; - - let request = format!("Request: size = {size}"); - - debug!("{request}"); - unsafe { MESSAGE_LOG.push(request) }; - - let vec = vec![42u8; size]; - let last_idx = size - 1; - - debug!("vec.len() = {:?}", vec.len()); - debug!( - "vec[{last_idx}]: {:p} -> {:#04x}", - &vec[last_idx], vec[last_idx] - ); - - msg::reply(size as i32, 0).expect("Failed to send reply"); - - // The test idea is to allocate two wasm pages and check this allocation, - // so we must skip `v` destruction. - core::mem::forget(vec); - - let requests_amount = unsafe { MESSAGE_LOG.len() }; - debug!("Total requests amount: {requests_amount}"); - unsafe { - MESSAGE_LOG.iter().for_each(|log| debug!("{log}")); - } - } -} +mod wasm; diff --git a/examples/vec/src/wasm.rs b/examples/vec/src/wasm.rs new file mode 100644 index 00000000000..fe0eeb50827 --- /dev/null +++ b/examples/vec/src/wasm.rs @@ -0,0 +1,52 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use gstd::{debug, msg, prelude::*}; + +static mut MESSAGE_LOG: Vec = vec![]; + +#[no_mangle] +extern "C" fn handle() { + let size = msg::load::().expect("Failed to load `i32`") as usize; + + let request = format!("Request: size = {size}"); + + debug!("{request}"); + unsafe { MESSAGE_LOG.push(request) }; + + let vec = vec![42u8; size]; + let last_idx = size - 1; + + debug!("vec.len() = {:?}", vec.len()); + debug!( + "vec[{last_idx}]: {:p} -> {:#04x}", + &vec[last_idx], vec[last_idx] + ); + + msg::reply(size as i32, 0).expect("Failed to send reply"); + + // The test idea is to allocate two wasm pages and check this allocation, + // so we must skip `v` destruction. + core::mem::forget(vec); + + let requests_amount = unsafe { MESSAGE_LOG.len() }; + debug!("Total requests amount: {requests_amount}"); + unsafe { + MESSAGE_LOG.iter().for_each(|log| debug!("{log}")); + } +} diff --git a/examples/wait-timeout/src/lib.rs b/examples/wait-timeout/src/lib.rs index 51c746d1082..2d9e85303aa 100644 --- a/examples/wait-timeout/src/lib.rs +++ b/examples/wait-timeout/src/lib.rs @@ -30,9 +30,7 @@ mod code { pub use code::WASM_BINARY_OPT as WASM_BINARY; #[cfg(not(feature = "std"))] -mod wasm { - include! {"./code.rs"} -} +mod wasm; // Re-exports for testing pub fn default_wait_up_to_duration() -> u32 { diff --git a/examples/wait-timeout/src/code.rs b/examples/wait-timeout/src/wasm.rs similarity index 84% rename from examples/wait-timeout/src/code.rs rename to examples/wait-timeout/src/wasm.rs index 7f0ff9e13ba..6bb31bafdbf 100644 --- a/examples/wait-timeout/src/code.rs +++ b/examples/wait-timeout/src/wasm.rs @@ -1,5 +1,22 @@ -use crate::Command; +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use crate::Command; use futures::future; use gstd::{exec, msg, MessageId}; diff --git a/examples/wait/src/lib.rs b/examples/wait/src/lib.rs index 72b8ae64946..fbc08d47a0b 100644 --- a/examples/wait/src/lib.rs +++ b/examples/wait/src/lib.rs @@ -27,40 +27,4 @@ mod code { pub use code::WASM_BINARY_OPT as WASM_BINARY; #[cfg(not(feature = "std"))] -mod wasm { - // for panic/oom handlers - extern crate gstd; - - use gcore::{exec, msg, MessageId}; - - static mut STATE: u32 = 0; - static mut MSG_ID_1: MessageId = MessageId::zero(); - static mut MSG_ID_2: MessageId = MessageId::zero(); - - #[no_mangle] - extern "C" fn handle() { - let state = unsafe { &mut STATE }; - gstd::debug!("{state}"); - - match *state { - 0 => { - *state = 1; - unsafe { MSG_ID_1 = msg::id() }; - exec::wait(); - } - 1 => { - *state = 2; - unsafe { MSG_ID_2 = msg::id() }; - exec::wait(); - } - 2 => { - *state = 3; - exec::wake(unsafe { MSG_ID_1 }).unwrap(); - exec::wake(unsafe { MSG_ID_2 }).unwrap(); - } - _ => { - msg::send(msg::source(), msg::id().as_slice(), 0).unwrap(); - } - } - } -} +mod wasm; diff --git a/examples/wait/src/wasm.rs b/examples/wait/src/wasm.rs new file mode 100644 index 00000000000..b6c0a6afafc --- /dev/null +++ b/examples/wait/src/wasm.rs @@ -0,0 +1,53 @@ +// This file is part of Gear. + +// Copyright (C) 2021-2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// for panic/oom handlers +extern crate gstd; + +use gcore::{exec, msg, MessageId}; + +static mut STATE: u32 = 0; +static mut MSG_ID_1: MessageId = MessageId::zero(); +static mut MSG_ID_2: MessageId = MessageId::zero(); + +#[no_mangle] +extern "C" fn handle() { + let state = unsafe { &mut STATE }; + gstd::debug!("{state}"); + + match *state { + 0 => { + *state = 1; + unsafe { MSG_ID_1 = msg::id() }; + exec::wait(); + } + 1 => { + *state = 2; + unsafe { MSG_ID_2 = msg::id() }; + exec::wait(); + } + 2 => { + *state = 3; + exec::wake(unsafe { MSG_ID_1 }).unwrap(); + exec::wake(unsafe { MSG_ID_2 }).unwrap(); + } + _ => { + msg::send(msg::source(), msg::id().as_slice(), 0).unwrap(); + } + } +} diff --git a/examples/wait_wake/src/lib.rs b/examples/wait_wake/src/lib.rs index 9820a1211ad..cbfe0514f7f 100644 --- a/examples/wait_wake/src/lib.rs +++ b/examples/wait_wake/src/lib.rs @@ -35,41 +35,7 @@ pub enum Request { } #[cfg(not(feature = "std"))] -mod wasm { - use super::*; - use gstd::{exec, msg, prelude::*, MessageId}; - - static mut ECHOES: Option> = None; - - fn process_request(request: Request) { - match request { - Request::EchoWait(n) => { - unsafe { - ECHOES - .get_or_insert_with(BTreeMap::new) - .insert(msg::id(), n) - }; - exec::wait(); - } - Request::Wake(id) => exec::wake(id.into()).unwrap(), - } - } - - #[no_mangle] - extern "C" fn init() { - msg::reply((), 0).unwrap(); - } - - #[no_mangle] - extern "C" fn handle() { - if let Some(reply) = unsafe { ECHOES.get_or_insert_with(BTreeMap::new).remove(&msg::id()) } - { - msg::reply(reply, 0).unwrap(); - } else { - msg::load::().map(process_request).unwrap(); - } - } -} +mod wasm; #[cfg(test)] mod tests { diff --git a/examples/wait_wake/src/wasm.rs b/examples/wait_wake/src/wasm.rs new file mode 100644 index 00000000000..ab98a0ce9f2 --- /dev/null +++ b/examples/wait_wake/src/wasm.rs @@ -0,0 +1,50 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use crate::Request; +use gstd::{exec, msg, prelude::*, MessageId}; + +static mut ECHOES: Option> = None; + +fn process_request(request: Request) { + match request { + Request::EchoWait(n) => { + unsafe { + ECHOES + .get_or_insert_with(BTreeMap::new) + .insert(msg::id(), n) + }; + exec::wait(); + } + Request::Wake(id) => exec::wake(id.into()).unwrap(), + } +} + +#[no_mangle] +extern "C" fn init() { + msg::reply((), 0).unwrap(); +} + +#[no_mangle] +extern "C" fn handle() { + if let Some(reply) = unsafe { ECHOES.get_or_insert_with(BTreeMap::new).remove(&msg::id()) } { + msg::reply(reply, 0).unwrap(); + } else { + msg::load::().map(process_request).unwrap(); + } +} diff --git a/examples/waiter/src/lib.rs b/examples/waiter/src/lib.rs index d02e5988083..0fea13e0e29 100644 --- a/examples/waiter/src/lib.rs +++ b/examples/waiter/src/lib.rs @@ -15,6 +15,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . + #![no_std] use gstd::{ActorId, Vec}; @@ -29,9 +30,7 @@ mod code { pub use code::WASM_BINARY_OPT as WASM_BINARY; #[cfg(not(feature = "std"))] -mod wasm { - include! {"./code.rs"} -} +mod wasm; pub fn system_reserve() -> u64 { gstd::Config::system_reserve() diff --git a/examples/waiter/src/code.rs b/examples/waiter/src/wasm.rs similarity index 90% rename from examples/waiter/src/code.rs rename to examples/waiter/src/wasm.rs index 77753d70c5f..5921d8dc458 100644 --- a/examples/waiter/src/code.rs +++ b/examples/waiter/src/wasm.rs @@ -1,3 +1,21 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + use crate::{ Command, LockContinuation, LockStaticAccessSubcommand, MxLockContinuation, RwLockContinuation, RwLockType, SleepForWaitType, WaitSubcommand, diff --git a/examples/waiting-proxy/src/lib.rs b/examples/waiting-proxy/src/lib.rs index ade290c2ec9..b20b99554f5 100644 --- a/examples/waiting-proxy/src/lib.rs +++ b/examples/waiting-proxy/src/lib.rs @@ -27,31 +27,4 @@ mod code { pub use code::WASM_BINARY_OPT as WASM_BINARY; #[cfg(not(feature = "std"))] -mod wasm { - use gstd::{msg, ActorId}; - - static mut DESTINATION: ActorId = ActorId::new([0u8; 32]); - static mut REPLY_DEPOSIT: u64 = 0; - - #[gstd::async_main] - async fn main() { - let input = msg::load_bytes().expect("Failed to load payload bytes"); - if let Ok(outcome) = - msg::send_bytes_for_reply(unsafe { DESTINATION }, input, 0, unsafe { REPLY_DEPOSIT }) - .expect("Error sending message") - .await - { - msg::reply_bytes(outcome, 0).expect("Failed to send reply"); - } - } - - #[no_mangle] - extern "C" fn init() { - let (destination, reply_deposit) = msg::load().expect("Expecting a contract address"); - unsafe { - DESTINATION = destination; - REPLY_DEPOSIT = reply_deposit; - } - msg::reply((), 0).expect("Failed to send reply"); - } -} +mod wasm; diff --git a/examples/waiting-proxy/src/wasm.rs b/examples/waiting-proxy/src/wasm.rs new file mode 100644 index 00000000000..833c5e2a293 --- /dev/null +++ b/examples/waiting-proxy/src/wasm.rs @@ -0,0 +1,44 @@ +// This file is part of Gear. + +// Copyright (C) 2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use gstd::{msg, ActorId}; + +static mut DESTINATION: ActorId = ActorId::new([0u8; 32]); +static mut REPLY_DEPOSIT: u64 = 0; + +#[gstd::async_main] +async fn main() { + let input = msg::load_bytes().expect("Failed to load payload bytes"); + if let Ok(outcome) = + msg::send_bytes_for_reply(unsafe { DESTINATION }, input, 0, unsafe { REPLY_DEPOSIT }) + .expect("Error sending message") + .await + { + msg::reply_bytes(outcome, 0).expect("Failed to send reply"); + } +} + +#[no_mangle] +extern "C" fn init() { + let (destination, reply_deposit) = msg::load().expect("Expecting a contract address"); + unsafe { + DESTINATION = destination; + REPLY_DEPOSIT = reply_deposit; + } + msg::reply((), 0).expect("Failed to send reply"); +} From a612f0283427a97f887168e0d78a0fd3f5c90bb9 Mon Sep 17 00:00:00 2001 From: Shamil <66209982+shamilsan@users.noreply.github.com> Date: Wed, 23 Aug 2023 13:44:39 +0400 Subject: [PATCH 5/5] chore: fix CI --- examples/async/src/wasm.rs | 2 +- examples/distributor/src/wasm.rs | 3 +- examples/gas-burned/src/wasm.rs | 65 ++++++-------------------- examples/init-wait/src/wasm.rs | 2 +- examples/node/src/wasm.rs | 2 +- examples/program-generator/src/wasm.rs | 2 +- examples/rwlock/src/wasm.rs | 2 +- examples/wait_wake/src/wasm.rs | 2 +- 8 files changed, 21 insertions(+), 59 deletions(-) diff --git a/examples/async/src/wasm.rs b/examples/async/src/wasm.rs index ca9da74e670..1b12121d16f 100644 --- a/examples/async/src/wasm.rs +++ b/examples/async/src/wasm.rs @@ -17,7 +17,7 @@ // along with this program. If not, see . use crate::Command; -use gstd::{lock::Mutex, msg, prelude::*, ActorId}; +use gstd::{msg, prelude::*, sync::Mutex, ActorId}; static mut DESTINATION: ActorId = ActorId::zero(); static MUTEX: Mutex = Mutex::new(0); diff --git a/examples/distributor/src/wasm.rs b/examples/distributor/src/wasm.rs index 1aa264a9921..0fd4ce4b30d 100644 --- a/examples/distributor/src/wasm.rs +++ b/examples/distributor/src/wasm.rs @@ -17,9 +17,8 @@ // along with this program. If not, see . use crate::{Program, Reply, Request}; -use alloc::{collections::BTreeSet, vec::Vec}; use core::future::Future; -use gstd::{debug, lock::Mutex, msg, ActorId}; +use gstd::{collections::BTreeSet, debug, msg, prelude::*, sync::Mutex, ActorId}; use parity_scale_codec::{Decode, Encode}; static mut STATE: Option = None; diff --git a/examples/gas-burned/src/wasm.rs b/examples/gas-burned/src/wasm.rs index 85514ae9dbb..9e4fcf19f35 100644 --- a/examples/gas-burned/src/wasm.rs +++ b/examples/gas-burned/src/wasm.rs @@ -1,58 +1,21 @@ -#![cfg_attr(not(feature = "std"), no_std)] +use gstd::{msg, prelude::*}; -#[cfg(feature = "std")] -mod code { - include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -} - -#[cfg(feature = "std")] -pub use code::WASM_BINARY_OPT as WASM_BINARY; - -#[cfg(not(feature = "std"))] -mod wasm { - use gstd::{msg, prelude::*}; - - const SHORT: usize = 100; - const LONG: usize = 10000; - - #[no_mangle] - extern "C" fn init() { - let mut v = vec![0; SHORT]; - for (i, item) in v.iter_mut().enumerate() { - *item = i * i; - } - msg::reply_bytes(format!("init: {}", v.into_iter().sum::()), 0).unwrap(); - } +const SHORT: usize = 100; +const LONG: usize = 10000; - #[no_mangle] - extern "C" fn handle() { - let mut v = vec![0; LONG]; - for (i, item) in v.iter_mut().enumerate() { - *item = i * i; - } +#[no_mangle] +extern "C" fn init() { + let mut v = vec![0; SHORT]; + for (i, item) in v.iter_mut().enumerate() { + *item = i * i; } + msg::reply_bytes(format!("init: {}", v.into_iter().sum::()), 0).unwrap(); } -#[cfg(test)] -mod tests { - use gtest::{Gas, Program, System}; - - #[test] - fn gas_burned() { - let system = System::new(); - system.init_logger(); - - let from = 42; - - let program = Program::current(&system); - let res = program.send_bytes(from, "init"); - let init_gas_burned = res.main_gas_burned(); - log::debug!("Init gas burned: {init_gas_burned}"); - assert!(init_gas_burned > Gas::zero()); - - let res = program.send_bytes(from, "handle"); - let handle_gas_burned = res.main_gas_burned(); - log::debug!("Handle gas burned: {handle_gas_burned}"); - assert!(handle_gas_burned > init_gas_burned); +#[no_mangle] +extern "C" fn handle() { + let mut v = vec![0; LONG]; + for (i, item) in v.iter_mut().enumerate() { + *item = i * i; } } diff --git a/examples/init-wait/src/wasm.rs b/examples/init-wait/src/wasm.rs index 432a5fe94f1..a7bba2080dc 100644 --- a/examples/init-wait/src/wasm.rs +++ b/examples/init-wait/src/wasm.rs @@ -1,4 +1,4 @@ -use gstd::{exec, msg, collections::BTreeMap, MessageId}; +use gstd::{collections::BTreeMap, exec, msg, MessageId}; #[derive(PartialEq, Debug)] enum State { diff --git a/examples/node/src/wasm.rs b/examples/node/src/wasm.rs index b3eecb340be..83c9acefa07 100644 --- a/examples/node/src/wasm.rs +++ b/examples/node/src/wasm.rs @@ -17,7 +17,7 @@ // along with this program. If not, see . use crate::{Initialization, Operation, Reply, Request}; -use gstd::{debug, exec, msg, prelude::*, ActorId, MessageId}; +use gstd::{collections::BTreeSet, debug, exec, msg, prelude::*, ActorId, MessageId}; static mut STATE: Option = None; diff --git a/examples/program-generator/src/wasm.rs b/examples/program-generator/src/wasm.rs index 6847d2ce8c9..cdf11b1a684 100644 --- a/examples/program-generator/src/wasm.rs +++ b/examples/program-generator/src/wasm.rs @@ -16,7 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use gstd::{prelude::*, prog::ProgramGenerator, CodeId}; +use gstd::{collections::BTreeSet, prelude::*, prog::ProgramGenerator, CodeId}; fn check_salt_uniqueness() { let salts: Vec<_> = (0..10).map(|_| ProgramGenerator::get_salt()).collect(); diff --git a/examples/rwlock/src/wasm.rs b/examples/rwlock/src/wasm.rs index 5680348a781..813f733a4b1 100644 --- a/examples/rwlock/src/wasm.rs +++ b/examples/rwlock/src/wasm.rs @@ -23,7 +23,7 @@ use core::{ ptr, task::{Context, RawWaker, RawWakerVTable, Waker}, }; -use gstd::{lock::RwLock, msg, prelude::*, ActorId}; +use gstd::{msg, prelude::*, sync::RwLock, ActorId}; static mut DESTINATION: ActorId = ActorId::zero(); static RW_LOCK: RwLock = RwLock::new(0); diff --git a/examples/wait_wake/src/wasm.rs b/examples/wait_wake/src/wasm.rs index ab98a0ce9f2..a4cd16f8ed2 100644 --- a/examples/wait_wake/src/wasm.rs +++ b/examples/wait_wake/src/wasm.rs @@ -17,7 +17,7 @@ // along with this program. If not, see . use crate::Request; -use gstd::{exec, msg, prelude::*, MessageId}; +use gstd::{collections::BTreeMap, exec, msg, prelude::*, MessageId}; static mut ECHOES: Option> = None;