Skip to content

Commit

Permalink
Use new namespace syntax for storage (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
IGI-111 authored Jul 22, 2024
1 parent 3acac2b commit ade6077
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ env:
CARGO_TERM_COLOR: always
REGISTRY: ghcr.io
RUST_VERSION: 1.77.0
FORC_VERSION: 0.60.0
FORC_VERSION: 0.61.0
CORE_VERSION: 0.26.0
PATH_TO_SCRIPTS: .github/scripts

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Description of the upcoming release here.

- [#103](https://github.com/FuelLabs/sway-standards/pull/103) Removes standards in the `./SRC` folder in favor of `./docs`.
- [#106](https://github.com/FuelLabs/sway-standards/pull/106) Updates links from the Sway Book to Docs Hub.
- [#120](https://github.com/FuelLabs/sway-standards/pull/120) Updates repository to forc v0.61.0 and uses new namespace in SRC-14 example.

### Fixed v0.5.1

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<a href="https://github.com/FuelLabs/sway-standards/actions/workflows/ci.yml" alt="CI">
<img src="https://github.com/FuelLabs/sway-standards/actions/workflows/ci.yml/badge.svg" />
</a>
<a href="https://crates.io/crates/forc/0.60.0" alt="forc">
<img src="https://img.shields.io/badge/forc-v0.60.0-orange" />
<a href="https://crates.io/crates/forc/0.61.0" alt="forc">
<img src="https://img.shields.io/badge/forc-v0.61.0-orange" />
</a>
<a href="./LICENSE" alt="forc">
<img src="https://img.shields.io/github/license/FuelLabs/sway-standards" />
Expand Down Expand Up @@ -162,7 +162,7 @@ Example of a minimal SRC-14 implementation with no access control.
Example of a SRC-14 implementation that also implements [SRC-5](https://docs.fuel.network/docs/sway-standards/src-5-ownership/).

> **Note**
> All standards currently use `forc v0.60.0`.
> All standards currently use `forc v0.61.0`.
<!-- TODO:
## Contributing
Expand Down
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Standards in this repository may be in various stages of development. Use of dra
If you don't find what you're looking for, feel free to create an issue and propose a new standard!

> **Note**
> All standards currently use `forc v0.60.0`.
> All standards currently use `forc v0.61.0`.
## Using a standard

Expand Down
4 changes: 1 addition & 3 deletions examples/src14-simple-proxy/minimal/src/minimal.sw
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
contract;

use std::execution::run_external;
use standards::src14::SRC14;
use standards::src14::{SRC14, SRC14_TARGET_STORAGE};

// use sha256("storage_SRC14") as base to avoid collisions
#[namespace(SRC14)]
storage {
// target is at sha256("storage_SRC14_0")
target: ContractId = ContractId::zero(),
Expand Down
14 changes: 7 additions & 7 deletions examples/src14-simple-proxy/owned/src/owned.sw
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ contract;

use std::execution::run_external;
use standards::src5::{AccessError, State};
use standards::src14::{SRC14, SRC14Extension};
use standards::src14::{SRC14, SRC14_TARGET_STORAGE, SRC14Extension};

/// The owner of this contract at deployment.
const INITIAL_OWNER: Identity = Identity::Address(Address::zero());

// use sha256("storage_SRC14") as base to avoid collisions
#[namespace(SRC14)]
storage {
// target is at sha256("storage_SRC14_0")
proxy {
// target is at sha256("storage_SRC14_0")
owner: State = State::Initialized(INITIAL_OWNER),
},
target: ContractId = ContractId::zero(),
owner: State = State::Initialized(INITIAL_OWNER),
}

impl SRC14 for Contract {
Expand All @@ -31,7 +31,7 @@ impl SRC14 for Contract {
impl SRC14Extension for Contract {
#[storage(read)]
fn proxy_owner() -> State {
storage.owner.read()
storage::proxy.owner.read()
}
}

Expand All @@ -45,7 +45,7 @@ fn fallback() {
#[storage(read)]
fn only_owner() {
require(
storage
storage::proxy
.owner
.read() == State::Initialized(msg_sender().unwrap()),
AccessError::NotOwner,
Expand Down

0 comments on commit ade6077

Please sign in to comment.