-
Notifications
You must be signed in to change notification settings - Fork 50
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 #33 from FuelLabs/bitzoic-src5-example
Add SRC-5 Basic examples
- Loading branch information
Showing
5 changed files
with
110 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
[workspace] | ||
members = ["src_20/single_asset", "src_20/multi_asset"] | ||
members = [ | ||
"src_5/initialized_example", | ||
"src_5/uninitialized_example", | ||
"src_20/single_asset", | ||
"src_20/multi_asset", | ||
] |
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 <[email protected]>"] | ||
entry = "initialized_example.sw" | ||
license = "Apache-2.0" | ||
name = "initialized_src5_example" | ||
|
||
[dependencies] | ||
src_5 = { path = "../../../standards/src_5" } |
47 changes: 47 additions & 0 deletions
47
examples/src_5/initialized_example/src/initialized_example.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,47 @@ | ||
contract; | ||
|
||
use src_5::{Ownership, SRC_5, State}; | ||
use std::constants::ZERO_B256; | ||
|
||
configurable { | ||
/// The owner of this contract at deployment. | ||
INITIAL_OWNER: Identity = Identity::Address(Address::from(ZERO_B256)), | ||
} | ||
|
||
storage { | ||
/// The owner in storage. | ||
owner: Ownership = Ownership { | ||
state: State::Initialized(INITIAL_OWNER), | ||
}, | ||
} | ||
|
||
impl SRC_5 for Contract { | ||
/// Returns the owner. | ||
/// | ||
/// # Return Values | ||
/// | ||
/// * [State] - Represents the state of ownership for this contract. | ||
/// | ||
/// # Number of Storage Accesses | ||
/// | ||
/// * Reads: `1` | ||
/// | ||
/// # Examples | ||
/// | ||
/// ```sway | ||
/// use src_5::SRC_5; | ||
/// | ||
/// fn foo(contract_id: ContractId) { | ||
/// let ownership_abi = abi(contract_id, SRC_5); | ||
/// | ||
/// match ownership_abi.owner() { | ||
/// State::Initialized(owner) => log("The ownership is initalized"), | ||
/// _ => log("This example will never reach this statement"), | ||
/// } | ||
/// } | ||
/// ``` | ||
#[storage(read)] | ||
fn owner() -> State { | ||
storage.owner.read().state | ||
} | ||
} |
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 <[email protected]>"] | ||
entry = "uninitialized_example.sw" | ||
license = "Apache-2.0" | ||
name = "uninitialized_src5_example" | ||
|
||
[dependencies] | ||
src_5 = { path = "../../../standards/src_5" } |
41 changes: 41 additions & 0 deletions
41
examples/src_5/uninitialized_example/src/uninitialized_example.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,41 @@ | ||
contract; | ||
|
||
use src_5::{Ownership, SRC_5, State}; | ||
|
||
storage { | ||
/// The owner in storage. | ||
owner: Ownership = Ownership { | ||
state: State::Uninitialized, | ||
}, | ||
} | ||
|
||
impl SRC_5 for Contract { | ||
/// Returns the owner. | ||
/// | ||
/// # Return Values | ||
/// | ||
/// * [State] - Represents the state of ownership for this contract. | ||
/// | ||
/// # Number of Storage Accesses | ||
/// | ||
/// * Reads: `1` | ||
/// | ||
/// # Examples | ||
/// | ||
/// ```sway | ||
/// use src_5::SRC_5; | ||
/// | ||
/// fn foo(contract_id: ContractId) { | ||
/// let ownership_abi = abi(contract_id, SRC_5); | ||
/// | ||
/// match ownership_abi.owner() { | ||
/// State::Uninitalized => log("The ownership is uninitalized"), | ||
/// _ => log("This example will never reach this statement"), | ||
/// } | ||
/// } | ||
/// ``` | ||
#[storage(read)] | ||
fn owner() -> State { | ||
storage.owner.read().state | ||
} | ||
} |