From fa4a0676ab15c6cf17aa42b995d88666fda13af3 Mon Sep 17 00:00:00 2001 From: SilentCicero Date: Fri, 16 Aug 2024 20:32:58 +0100 Subject: [PATCH 1/7] readme --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index db12362..745ffc0 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ -# sway-by-example-lib -Library for compiled sway programs +# sway-by-example + +Library of compiled Sway programs to showcase accessible code for the Sway language. + From a860210f24db443824ded3391d8e4f8ec0fcb58a Mon Sep 17 00:00:00 2001 From: SilentCicero Date: Fri, 16 Aug 2024 20:44:30 +0100 Subject: [PATCH 2/7] script example --- docs/src/script.md | 18 ++++++++++++++++++ examples/script/.gitignore | 2 ++ examples/script/Forc.lock | 13 +++++++++++++ examples/script/Forc.toml | 7 +++++++ examples/script/src/main.sw | 15 +++++++++++++++ 5 files changed, 55 insertions(+) create mode 100644 docs/src/script.md create mode 100644 examples/script/.gitignore create mode 100644 examples/script/Forc.lock create mode 100644 examples/script/Forc.toml create mode 100644 examples/script/src/main.sw diff --git a/docs/src/script.md b/docs/src/script.md new file mode 100644 index 0000000..5e55a07 --- /dev/null +++ b/docs/src/script.md @@ -0,0 +1,18 @@ +# Predicate + +Examples of a predicate program type in Sway + +| | Predicates | Contracts | +|--------------------------------|------------|-----------| +| Access data on chain | ❌ | ✅ | +| Read data from smart contracts | ❌ | ✅ | +| Check date or time | ❌ | ✅ | +| Read block hash or number | ❌ | ✅ | +| Read input coins | ✅ | ✅ | +| Read output coins | ✅ | ✅ | +| Read transaction scripts | ✅ | ✅ | +| Read transaction bytecode | ✅ | ✅ | + +```sway +{{#include ../examples/predicate/src/main.sw}} +``` diff --git a/examples/script/.gitignore b/examples/script/.gitignore new file mode 100644 index 0000000..77d3844 --- /dev/null +++ b/examples/script/.gitignore @@ -0,0 +1,2 @@ +out +target diff --git a/examples/script/Forc.lock b/examples/script/Forc.lock new file mode 100644 index 0000000..26cb8e5 --- /dev/null +++ b/examples/script/Forc.lock @@ -0,0 +1,13 @@ +[[package]] +name = "core" +source = "path+from-root-566CA1D5F8BEAFBF" + +[[package]] +name = "script" +source = "member" +dependencies = ["std"] + +[[package]] +name = "std" +source = "git+https://github.com/fuellabs/sway?tag=v0.49.3#0dc6570377ee9c4a6359ade597fa27351e02a728" +dependencies = ["core"] diff --git a/examples/script/Forc.toml b/examples/script/Forc.toml new file mode 100644 index 0000000..3274a6d --- /dev/null +++ b/examples/script/Forc.toml @@ -0,0 +1,7 @@ +[project] +authors = ["Fuel DevRel"] +entry = "main.sw" +license = "Apache-2.0" +name = "script" + +[dependencies] diff --git a/examples/script/src/main.sw b/examples/script/src/main.sw new file mode 100644 index 0000000..46f4769 --- /dev/null +++ b/examples/script/src/main.sw @@ -0,0 +1,15 @@ +script; + +abi ContractA { + fn test_func(x: u64) -> Identity; +} + +const CONTRACTA_ID = 0x79fa8779bed2f36c3581d01c79df8da45eee09fac1fd76a5a656e16326317ef0; + +fn main(a: u64) { + let c = abi(ContractA, CONTRACTA_ID); + + // Call a contract multiple times + log(c.test_func(a)); + log(c.test_func(a + 32)); +} From 56402da89aa0dd12e37b5349150806b3f2867f6b Mon Sep 17 00:00:00 2001 From: SilentCicero Date: Fri, 16 Aug 2024 20:48:21 +0100 Subject: [PATCH 3/7] script example --- docs/src/script.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/src/script.md b/docs/src/script.md index 5e55a07..f56bf2f 100644 --- a/docs/src/script.md +++ b/docs/src/script.md @@ -1,8 +1,8 @@ -# Predicate +# Script -Examples of a predicate program type in Sway +Examples of a script program type in Sway -| | Predicates | Contracts | +| | Predicates | Scripts | |--------------------------------|------------|-----------| | Access data on chain | ❌ | ✅ | | Read data from smart contracts | ❌ | ✅ | @@ -14,5 +14,5 @@ Examples of a predicate program type in Sway | Read transaction bytecode | ✅ | ✅ | ```sway -{{#include ../examples/predicate/src/main.sw}} +{{#include ../examples/script/src/main.sw}} ``` From 545e3415fa557aa19a39f1e150c735b12400f8bf Mon Sep 17 00:00:00 2001 From: SilentCicero Date: Fri, 16 Aug 2024 20:49:04 +0100 Subject: [PATCH 4/7] script example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 745ffc0..6b35e31 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# sway-by-example +# sway-by-example-lib Library of compiled Sway programs to showcase accessible code for the Sway language. From 78f438f1d1005c67e973aabd5343879a08284274 Mon Sep 17 00:00:00 2001 From: Call Delegation <106365423+calldelegation@users.noreply.github.com> Date: Fri, 16 Aug 2024 16:11:19 -0400 Subject: [PATCH 5/7] ci and summary --- .github/workflows/actions.yaml | 1 + docs/src/SUMMARY.md | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/actions.yaml b/.github/workflows/actions.yaml index 4ed1fe3..dbf8da9 100644 --- a/.github/workflows/actions.yaml +++ b/.github/workflows/actions.yaml @@ -73,6 +73,7 @@ jobs: 'math_lib', 'imports', 'predicate', + 'script', ] name: Forc build [ ${{ matrix.dir }} ] diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index bb80aed..4e48cd3 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -25,3 +25,4 @@ - [Vector](./vector.md) - [Base Asset](./base-asset.md) - [Predicate](./predicate.md) +- [Script](./script.md) From 27f223d3408262b3be7fa9510dfb719269ea2634 Mon Sep 17 00:00:00 2001 From: Call Delegation <106365423+calldelegation@users.noreply.github.com> Date: Fri, 16 Aug 2024 16:12:29 -0400 Subject: [PATCH 6/7] index --- docs/src/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/index.md b/docs/src/index.md index bf68c74..6269e8f 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -1,3 +1,3 @@ # Sway By Example -An introduction to Sway with simple examples +Library of compiled Sway programs to showcase accessible code for the Sway language. \ No newline at end of file From a12094a05d0e8cf82f3639edc7d20bcd074bcf8f Mon Sep 17 00:00:00 2001 From: Call Delegation <106365423+calldelegation@users.noreply.github.com> Date: Fri, 16 Aug 2024 16:14:47 -0400 Subject: [PATCH 7/7] ci --- docs/src/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/index.md b/docs/src/index.md index 6269e8f..58dceff 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -1,3 +1,3 @@ # Sway By Example -Library of compiled Sway programs to showcase accessible code for the Sway language. \ No newline at end of file +Library of compiled Sway programs to showcase accessible code for the Sway language.