-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from FuelLabs/add/predicates
feat: Predicate
- Loading branch information
Showing
10 changed files
with
100 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,5 @@ msg | |
cheatsheet | ||
enums | ||
Forc | ||
toml | ||
toml | ||
bytecode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
out | ||
target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[[package]] | ||
name = "core" | ||
source = "path+from-root-2AB5BCE55EAAEFF4" | ||
|
||
[[package]] | ||
name = "predicate" | ||
source = "member" | ||
dependencies = ["std"] | ||
|
||
[[package]] | ||
name = "std" | ||
source = "git+https://github.com/fuellabs/sway?tag=v0.62.0#efda0397c7bee77de73bd726ec0b732d57614973" | ||
dependencies = ["core"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[project] | ||
authors = ["Kin Chan"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "predicate" | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
predicate; | ||
|
||
use std::{ | ||
auth::predicate_address, | ||
inputs::{ | ||
input_amount, | ||
}, | ||
outputs::{ | ||
output_amount, | ||
}, | ||
tx::{ | ||
tx_id, | ||
tx_witnesses_count | ||
}, | ||
constants::ZERO_B256, | ||
}; | ||
|
||
// Configurables | ||
configurable { | ||
FLOOR: u64 = 1, | ||
} | ||
|
||
fn input_output_checks() -> bool { | ||
if (100 >= input_amount(0).unwrap() && 100 >= output_amount(0)) { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
// Primitive Arguments | ||
fn main(a: u64, b: str, c: bool, d: b256) -> bool { | ||
// This predicate's own address | ||
let this_predicate_root = predicate_address(); | ||
|
||
if (a == 0 || b == "a" || c == false || d == ZERO_B256) { | ||
return false | ||
} | ||
|
||
if tx_witnesses_count() < 1 { | ||
return false | ||
} | ||
|
||
// While loop | ||
let mut x = 10; | ||
while x != FLOOR { | ||
x -= 1; | ||
} | ||
|
||
return input_output_checks() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters