Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
sdankel committed Mar 23, 2024
1 parent 5358cb7 commit 5ec6af3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 32 deletions.
2 changes: 1 addition & 1 deletion app/src/features/editor/examples/examples.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ describe(`test examples`, () => {
expect(bytecode).toBeDefined();
expect(storageSlots).toBeDefined();
expect(forcVersion).toBeDefined();
}, 10000);
}, 40000);
});
});
35 changes: 19 additions & 16 deletions app/src/features/editor/examples/sway/src20.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
export const EXAMPLE_SWAY_CONTRACT_SRC20 = `contract;
use ownership;
use src3::SRC3;
use src5::SRC5;
use src5::{SRC5, State, AccessError};
use src20::SRC20;
use std::{
asset::{
burn,
mint_to,
},
call_frames::{
contract_id,
msg_asset_id,
},
constants::DEFAULT_SUB_ID,
context::msg_amount,
string::String,
};
abi NativeAsset {
abi Constructor {
#[storage(read, write)]
fn constructor(owner_: Identity);
#[storage(read, write)]
fn transferOwnership(owner_: Identity);
}
configurable {
Expand All @@ -37,6 +34,9 @@ configurable {
storage {
/// The total supply of the asset minted by this contract.
total_supply: u64 = 0,
/// Owner.
owner: State = State::Uninitialized,
}
impl SRC20 for Contract {
Expand Down Expand Up @@ -82,31 +82,34 @@ impl SRC20 for Contract {
}
}
impl NativeAsset for Contract {
#[storage(read)]
fn is_owner() {
require(
storage.owner.read() == State::Initialized(msg_sender().unwrap()),
AccessError::NotOwner,
);
}
impl Constructor for Contract {
#[storage(read, write)]
fn constructor(owner_: Identity) {
require(storage.owner.read() == State::Uninitialized, "owner-initialized");
ownership::initialize_ownership(owner_);
}
#[storage(read, write)]
fn transferOwner(owner_: Identity) {
ownership::transfer_ownership(owner_);
storage.owner.write(State::Initialized(owner_));
}
}
impl SRC5 for Contract {
#[storage(read)]
fn owner() -> State {
_owner()
storage.owner.read()
}
}
impl SRC3 for Contract {
#[storage(read, write)]
fn mint(recipient: Identity, sub_id: SubId, amount: u64) {
require(sub_id == DEFAULT_SUB_ID, "Incorrect Sub Id");
ownership::only_owner();
is_owner();
// Increment total supply of the asset and mint to the recipient.
storage
Expand All @@ -123,7 +126,7 @@ impl SRC3 for Contract {
msg_asset_id() == AssetId::default(),
"Incorrect asset provided",
);
ownership::only_owner();
is_owner();
// Decrement total supply of the asset and burn.
storage
Expand Down
14 changes: 0 additions & 14 deletions projects/swaypad/Forc.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
name = "core"
source = "path+from-root-B672DC9E3D340CD2"

[[package]]
name = "ownership"
source = "git+https://github.com/FuelLabs/sway-libs?tag=v0.18.0#8d196e9379463d4596ac582a20a84ed52ff58c69"
dependencies = [
"src_5",
"std",
]

[[package]]
name = "src20"
source = "git+https://github.com/FuelLabs/sway-standards?tag=v0.3.3#4198b4b07449ad16104cc8a0501f3013670fdcfd"
Expand All @@ -25,11 +17,6 @@ name = "src5"
source = "git+https://github.com/FuelLabs/sway-standards?tag=v0.3.3#4198b4b07449ad16104cc8a0501f3013670fdcfd"
dependencies = ["std"]

[[package]]
name = "src_5"
source = "git+https://github.com/FuelLabs/sway-standards?tag=v0.2.2#6989cf8224b0d8aabea62f3d3c648fc754948705"
dependencies = ["std"]

[[package]]
name = "std"
source = "git+https://github.com/fuellabs/sway?tag=v0.49.2#a70c746d27b3300beef896ccd1dcce1299836192"
Expand All @@ -39,7 +26,6 @@ dependencies = ["core"]
name = "swaypad"
source = "member"
dependencies = [
"ownership",
"src20",
"src3",
"src5",
Expand Down
1 change: 0 additions & 1 deletion projects/swaypad/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ license = "Apache-2.0"
name = "swaypad"

[dependencies]
ownership = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.18.0" }
src3 = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.3.3" }
src5 = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.3.3" }
src20 = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.3.3" }

0 comments on commit 5ec6af3

Please sign in to comment.