-
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.
Introduce index() and index_assign() to StorageMap and showcase nested
storage vecs using both `get/push` and the `[]` operator.
- Loading branch information
1 parent
c7a2e45
commit 9dab5f8
Showing
63 changed files
with
2,471 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
test/src/sdk-harness/test_artifacts/experimental_storage_vec/svec_array/.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 |
13 changes: 13 additions & 0 deletions
13
test/src/sdk-harness/test_artifacts/experimental_storage_vec/svec_array/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,13 @@ | ||
[[package]] | ||
name = 'core' | ||
source = 'path+from-root-F1A9B05C249770CB' | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'path+from-root-F1A9B05C249770CB' | ||
dependencies = ['core'] | ||
|
||
[[package]] | ||
name = 'svec_array' | ||
source = 'member' | ||
dependencies = ['std'] |
8 changes: 8 additions & 0 deletions
8
test/src/sdk-harness/test_artifacts/experimental_storage_vec/svec_array/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 = "svec_array" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../sway-lib-std" } |
92 changes: 92 additions & 0 deletions
92
test/src/sdk-harness/test_artifacts/experimental_storage_vec/svec_array/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,92 @@ | ||
contract; | ||
|
||
use core::experimental::storage::*; | ||
use std::experimental::storage::*; | ||
|
||
abi MyContract { | ||
#[storage(read, write)] | ||
fn push(value: [u8; 3]); | ||
|
||
#[storage(read, write)] | ||
fn pop() -> [u8; 3]; | ||
|
||
#[storage(read)] | ||
fn get(index: u64) -> [u8; 3]; | ||
|
||
#[storage(read, write)] | ||
fn remove(index: u64) -> [u8; 3]; | ||
|
||
#[storage(read, write)] | ||
fn swap_remove(index: u64) -> [u8; 3]; | ||
|
||
#[storage(read, write)] | ||
fn set(index: u64, value: [u8; 3]); | ||
|
||
#[storage(read, write)] | ||
fn insert(index: u64, value: [u8; 3]); | ||
|
||
#[storage(read)] | ||
fn len() -> u64; | ||
|
||
#[storage(read)] | ||
fn is_empty() -> bool; | ||
|
||
#[storage(write)] | ||
fn clear(); | ||
} | ||
|
||
storage { | ||
my_vec: StorageVec<[u8; 3]> = StorageVec {}, | ||
} | ||
|
||
impl MyContract for Contract { | ||
#[storage(read, write)] | ||
fn push(value: [u8; 3]) { | ||
storage.my_vec.push(value); | ||
} | ||
|
||
#[storage(read, write)] | ||
fn pop() -> [u8; 3] { | ||
storage.my_vec.pop().unwrap() | ||
} | ||
|
||
#[storage(read)] | ||
fn get(index: u64) -> [u8; 3] { | ||
storage.my_vec.get(index).unwrap().read() | ||
} | ||
|
||
#[storage(read, write)] | ||
fn remove(index: u64) -> [u8; 3] { | ||
storage.my_vec.remove(index) | ||
} | ||
|
||
#[storage(read, write)] | ||
fn swap_remove(index: u64) -> [u8; 3] { | ||
storage.my_vec.swap_remove(index) | ||
} | ||
|
||
#[storage(read, write)] | ||
fn set(index: u64, value: [u8; 3]) { | ||
storage.my_vec.set(index, value); | ||
} | ||
|
||
#[storage(read, write)] | ||
fn insert(index: u64, value: [u8; 3]) { | ||
storage.my_vec.insert(index, value); | ||
} | ||
|
||
#[storage(read)] | ||
fn len() -> u64 { | ||
storage.my_vec.len() | ||
} | ||
|
||
#[storage(read)] | ||
fn is_empty() -> bool { | ||
storage.my_vec.is_empty() | ||
} | ||
|
||
#[storage(write)] | ||
fn clear() { | ||
storage.my_vec.clear(); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
test/src/sdk-harness/test_artifacts/experimental_storage_vec/svec_b256/.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 |
13 changes: 13 additions & 0 deletions
13
test/src/sdk-harness/test_artifacts/experimental_storage_vec/svec_b256/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,13 @@ | ||
[[package]] | ||
name = 'core' | ||
source = 'path+from-root-BAD4826C86E6CE3D' | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'path+from-root-BAD4826C86E6CE3D' | ||
dependencies = ['core'] | ||
|
||
[[package]] | ||
name = 'svec_b256' | ||
source = 'member' | ||
dependencies = ['std'] |
8 changes: 8 additions & 0 deletions
8
test/src/sdk-harness/test_artifacts/experimental_storage_vec/svec_b256/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 = "svec_b256" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../sway-lib-std" } |
92 changes: 92 additions & 0 deletions
92
test/src/sdk-harness/test_artifacts/experimental_storage_vec/svec_b256/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,92 @@ | ||
contract; | ||
|
||
use core::experimental::storage::*; | ||
use std::experimental::storage::*; | ||
|
||
abi MyContract { | ||
#[storage(read, write)] | ||
fn push(value: b256); | ||
|
||
#[storage(read, write)] | ||
fn pop() -> b256; | ||
|
||
#[storage(read)] | ||
fn get(index: u64) -> b256; | ||
|
||
#[storage(read, write)] | ||
fn remove(index: u64) -> b256; | ||
|
||
#[storage(read, write)] | ||
fn swap_remove(index: u64) -> b256; | ||
|
||
#[storage(read, write)] | ||
fn set(index: u64, value: b256); | ||
|
||
#[storage(read, write)] | ||
fn insert(index: u64, value: b256); | ||
|
||
#[storage(read)] | ||
fn len() -> u64; | ||
|
||
#[storage(read)] | ||
fn is_empty() -> bool; | ||
|
||
#[storage(write)] | ||
fn clear(); | ||
} | ||
|
||
storage { | ||
my_vec: StorageVec<b256> = StorageVec {}, | ||
} | ||
|
||
impl MyContract for Contract { | ||
#[storage(read, write)] | ||
fn push(value: b256) { | ||
storage.my_vec.push(value); | ||
} | ||
|
||
#[storage(read, write)] | ||
fn pop() -> b256 { | ||
storage.my_vec.pop().unwrap() | ||
} | ||
|
||
#[storage(read)] | ||
fn get(index: u64) -> b256 { | ||
storage.my_vec.get(index).unwrap().read() | ||
} | ||
|
||
#[storage(read, write)] | ||
fn remove(index: u64) -> b256 { | ||
storage.my_vec.remove(index) | ||
} | ||
|
||
#[storage(read, write)] | ||
fn swap_remove(index: u64) -> b256 { | ||
storage.my_vec.swap_remove(index) | ||
} | ||
|
||
#[storage(read, write)] | ||
fn set(index: u64, value: b256) { | ||
storage.my_vec.set(index, value); | ||
} | ||
|
||
#[storage(read, write)] | ||
fn insert(index: u64, value: b256) { | ||
storage.my_vec.insert(index, value); | ||
} | ||
|
||
#[storage(read)] | ||
fn len() -> u64 { | ||
storage.my_vec.len() | ||
} | ||
|
||
#[storage(read)] | ||
fn is_empty() -> bool { | ||
storage.my_vec.is_empty() | ||
} | ||
|
||
#[storage(write)] | ||
fn clear() { | ||
storage.my_vec.clear(); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
test/src/sdk-harness/test_artifacts/experimental_storage_vec/svec_bool/.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 |
13 changes: 13 additions & 0 deletions
13
test/src/sdk-harness/test_artifacts/experimental_storage_vec/svec_bool/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,13 @@ | ||
[[package]] | ||
name = 'core' | ||
source = 'path+from-root-112F6FFCFCECE066' | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'path+from-root-112F6FFCFCECE066' | ||
dependencies = ['core'] | ||
|
||
[[package]] | ||
name = 'svec_bool' | ||
source = 'member' | ||
dependencies = ['std'] |
8 changes: 8 additions & 0 deletions
8
test/src/sdk-harness/test_artifacts/experimental_storage_vec/svec_bool/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 = "svec_bool" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../sway-lib-std" } |
92 changes: 92 additions & 0 deletions
92
test/src/sdk-harness/test_artifacts/experimental_storage_vec/svec_bool/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,92 @@ | ||
contract; | ||
|
||
use core::experimental::storage::*; | ||
use std::experimental::storage::*; | ||
|
||
abi MyContract { | ||
#[storage(read, write)] | ||
fn push(value: bool); | ||
|
||
#[storage(read, write)] | ||
fn pop() -> bool; | ||
|
||
#[storage(read)] | ||
fn get(index: u64) -> bool; | ||
|
||
#[storage(read, write)] | ||
fn remove(index: u64) -> bool; | ||
|
||
#[storage(read, write)] | ||
fn swap_remove(index: u64) -> bool; | ||
|
||
#[storage(read, write)] | ||
fn set(index: u64, value: bool); | ||
|
||
#[storage(read, write)] | ||
fn insert(index: u64, value: bool); | ||
|
||
#[storage(read)] | ||
fn len() -> u64; | ||
|
||
#[storage(read)] | ||
fn is_empty() -> bool; | ||
|
||
#[storage(write)] | ||
fn clear(); | ||
} | ||
|
||
storage { | ||
my_vec: StorageVec<bool> = StorageVec {}, | ||
} | ||
|
||
impl MyContract for Contract { | ||
#[storage(read, write)] | ||
fn push(value: bool) { | ||
storage.my_vec.push(value); | ||
} | ||
|
||
#[storage(read, write)] | ||
fn pop() -> bool { | ||
storage.my_vec.pop().unwrap() | ||
} | ||
|
||
#[storage(read)] | ||
fn get(index: u64) -> bool { | ||
storage.my_vec.get(index).unwrap().read() | ||
} | ||
|
||
#[storage(read, write)] | ||
fn remove(index: u64) -> bool { | ||
storage.my_vec.remove(index) | ||
} | ||
|
||
#[storage(read, write)] | ||
fn swap_remove(index: u64) -> bool { | ||
storage.my_vec.swap_remove(index) | ||
} | ||
|
||
#[storage(read, write)] | ||
fn set(index: u64, value: bool) { | ||
storage.my_vec.set(index, value); | ||
} | ||
|
||
#[storage(read, write)] | ||
fn insert(index: u64, value: bool) { | ||
storage.my_vec.insert(index, value); | ||
} | ||
|
||
#[storage(read)] | ||
fn len() -> u64 { | ||
storage.my_vec.len() | ||
} | ||
|
||
#[storage(read)] | ||
fn is_empty() -> bool { | ||
storage.my_vec.is_empty() | ||
} | ||
|
||
#[storage(write)] | ||
fn clear() { | ||
storage.my_vec.clear(); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
test/src/sdk-harness/test_artifacts/experimental_storage_vec/svec_enum/.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 |
13 changes: 13 additions & 0 deletions
13
test/src/sdk-harness/test_artifacts/experimental_storage_vec/svec_enum/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,13 @@ | ||
[[package]] | ||
name = 'core' | ||
source = 'path+from-root-BA7DA646BFFC59D3' | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'path+from-root-BA7DA646BFFC59D3' | ||
dependencies = ['core'] | ||
|
||
[[package]] | ||
name = 'svec_enum' | ||
source = 'member' | ||
dependencies = ['std'] |
8 changes: 8 additions & 0 deletions
8
test/src/sdk-harness/test_artifacts/experimental_storage_vec/svec_enum/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 = "svec_enum" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../sway-lib-std" } |
Oops, something went wrong.