-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
64 changed files
with
1,279 additions
and
445 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
2 changes: 2 additions & 0 deletions
2
docs/reference/src/code/operations/storage/storage_in_keyword/.gitignore
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 |
14 changes: 14 additions & 0 deletions
14
docs/reference/src/code/operations/storage/storage_in_keyword/Forc.lock
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,14 @@ | ||
[[package]] | ||
name = 'core' | ||
source = 'path+from-root-815C32BB386C1563' | ||
dependencies = [] | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'git+https://github.com/fuellabs/sway?tag=v0.25.2#dfa6224932a97c514b707dcfc300715b2a0895dc' | ||
dependencies = ['core'] | ||
|
||
[[package]] | ||
name = 'storage_init' | ||
source = 'root' | ||
dependencies = ['std'] |
8 changes: 8 additions & 0 deletions
8
docs/reference/src/code/operations/storage/storage_in_keyword/Forc.toml
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,8 @@ | ||
[project] | ||
authors = ["Fuel Labs <contact@fuel.sh>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "storage_in_keyword" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../../sway-lib-std" } |
39 changes: 39 additions & 0 deletions
39
docs/reference/src/code/operations/storage/storage_in_keyword/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,39 @@ | ||
contract; | ||
|
||
// ANCHOR: data_structures | ||
struct Owner { | ||
maximum_owners: u64, | ||
role: Role, | ||
} | ||
|
||
impl Owner { | ||
// a constructor that can be evaluated to a constant `Owner` during compilation | ||
fn default() -> Self { | ||
Self { | ||
maximum_owners: 10, | ||
role: Role::FullAccess, | ||
} | ||
} | ||
} | ||
|
||
enum Role { | ||
FullAccess: (), | ||
PartialAccess: (), | ||
NoAccess: (), | ||
} | ||
|
||
const HASH_KEY: b256 = 0x7616e5793ef977b22465f0c843bcad56155c4369245f347bcc8a61edb08b7645; | ||
|
||
// ANCHOR_END: data_structures | ||
// ANCHOR: initialization | ||
storage { | ||
// ANCHOR: in_keyword | ||
current_owners in HASH_KEY: u64 = 0, | ||
// ANCHOR_END: in_keyword | ||
explicit_declaration: Owner = Owner { | ||
maximum_owners: 10, | ||
role: Role::FullAccess, | ||
}, | ||
encapsulated_declaration: Owner = Owner::default(), | ||
} | ||
// ANCHOR_END: initialization |
12 changes: 0 additions & 12 deletions
12
docs/reference/src/documentation/language/annotations/attributes/namespace.md
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
docs/reference/src/documentation/operations/storage/in-keyword.md
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,14 @@ | ||
|
||
# Storage `in` keyword | ||
|
||
The `in` keyword can be used within a storage variable to override the position where the value is stored. | ||
|
||
## Example | ||
|
||
The `in` keyword and position value are used as follows: | ||
|
||
```sway | ||
{{#include ../../../../code/operations/storage/storage_in_keyword/src/main.sw:in_keyword}} | ||
``` | ||
|
||
The code above will force the storage of the variable into the position `HASH_KEY` which is set to `0x7616e5793ef977b22465f0c843bcad56155c4369245f347bcc8a61edb08b7645` instead of the position that would be calculated from the variable name `sha256("storage.current_owners")` which would be `0x84f905e3f560d70fbfab9ffcd92198998ce6f936e3d45f8fcb16b00f6a6a8d7e` |
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
20 changes: 20 additions & 0 deletions
20
docs/reference/src/documentation/operations/storage/namespace.md
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,20 @@ | ||
|
||
# Namespace | ||
|
||
Namespaces can be used on a `storage` block and variables placed inside the namespaces. A single `storage` block may contain multiple namespaces placed sequentially and or nested. | ||
|
||
The hash calculations determining the position of variables in a block with namespace `my_namespace` that contains the variable `foobar` are calculated from `sha256("storage::my_namespace.foobar")`. | ||
|
||
## Example | ||
|
||
A namespace can be declared as follows: | ||
|
||
```sway | ||
{{#include ../../../../code/language/annotations/src/main.sw:storage_namespace}} | ||
``` | ||
|
||
A variable inside a namespace can be accessed as follows: | ||
|
||
```sway | ||
{{#include ../../../../code/language/annotations/src/main.sw:storage_namespace_access}} | ||
``` |
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
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
Oops, something went wrong.