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

counter-script docs #721

Merged
merged 3 commits into from
Aug 14, 2023
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 counter-script/project/contracts/counter/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ contract;
use libraries::Counter;

storage {
/// Internal counter updated via calls from a script.
count: u64 = 0,
}

Expand Down
24 changes: 24 additions & 0 deletions counter-script/project/libraries/src/interface.sw
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
library;

abi Counter {
/// Increments the counter by one.
///
/// # Returns
///
/// * [u64] - The new value of the counter.
///
/// # Number of Storage Accesses
///
/// * Reads: `1`
/// * Write: `1`
#[storage(read, write)]
fn increment() -> u64;
/// Returns the current value of the counter.
///
/// # Returns
///
/// * [u64] - The current value of the counter.
///
/// # Number of Storage Accesses
///
/// * Reads: `1`
#[storage(read)]
fn count() -> u64;
/// Clears the counter.
///
/// # Number of Storage Accesses
///
/// * Clears: `1`
#[storage(write)]
fn clear();
}
10 changes: 10 additions & 0 deletions counter-script/project/scripts/interaction_script/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ script;

use libraries::Counter;

/// Calls the methods of the counter contract at the given contract_id.
SwayStar123 marked this conversation as resolved.
Show resolved Hide resolved
///
/// # Arguments
///
/// * `contract_id`: [ContractId] - The ContractId at which the counter contract is deployed.
/// * `clear`: [bool] - If true, the counter will be cleared at the end of the script.
///
/// # Returns
///
/// * [u64] - The count at the end of the script.
fn main(contract_id: ContractId, clear: bool) -> u64 {
// An abi cast is a way to call a contract at a given contract_id with the given abi
let counter = abi(Counter, contract_id.value);
Expand Down
Loading