Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: script #45

Merged
merged 8 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/actions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ jobs:
'math_lib',
'imports',
'predicate',
'script',
'big_number',
]

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# sway-by-example-lib
Library for compiled sway programs

Library of compiled Sway programs to showcase accessible code for the Sway language.

1 change: 1 addition & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
- [Vector](./vector.md)
- [Base Asset](./base-asset.md)
- [Predicate](./predicate.md)
- [Script](./script.md)
- [Big Numbers](./big-numbers.md)
- [SRC20](./src20.md)
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
@@ -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.
18 changes: 18 additions & 0 deletions docs/src/script.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Script

Examples of a script program type in Sway

| | Predicates | Scripts |
|--------------------------------|------------|-----------|
| 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/script/src/main.sw}}
```
2 changes: 2 additions & 0 deletions examples/script/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
out
target
13 changes: 13 additions & 0 deletions examples/script/Forc.lock
Original file line number Diff line number Diff line change
@@ -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"]
7 changes: 7 additions & 0 deletions examples/script/Forc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[project]
authors = ["Fuel DevRel"]
entry = "main.sw"
license = "Apache-2.0"
name = "script"

[dependencies]
15 changes: 15 additions & 0 deletions examples/script/src/main.sw
Original file line number Diff line number Diff line change
@@ -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));
}
Loading