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

Bump Sway-Libs to Forc v0.47.0 and Sway-Standards v0.2.0 #202

Merged
merged 11 commits into from
Nov 13, 2023
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ env:
CARGO_TERM_COLOR: always
REGISTRY: ghcr.io
RUST_VERSION: 1.71.1
FORC_VERSION: 0.46.0
CORE_VERSION: 0.20.3
FORC_VERSION: 0.47.0
CORE_VERSION: 0.20.8
PATH_TO_SCRIPTS: .github/scripts

jobs:
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-libs/actions/workflows/ci.yml" alt="CI">
<img src="https://github.com/FuelLabs/sway-libs/actions/workflows/ci.yml/badge.svg" />
</a>
<a href="https://crates.io/crates/forc/0.46.0" alt="forc">
<img src="https://img.shields.io/badge/forc-v0.46.0-orange" />
<a href="https://crates.io/crates/forc/0.47.0" alt="forc">
<img src="https://img.shields.io/badge/forc-v0.47.0-orange" />
</a>
<a href="./LICENSE" alt="forc">
<img src="https://img.shields.io/github/license/FuelLabs/sway-libs" />
Expand Down Expand Up @@ -82,7 +82,7 @@ cargo test
Any instructions related to using a specific library should be found within the README.md of that library.

> **Note**
> All projects currently use `forc v0.46.0`, `fuels-rs v0.46.0` and `fuel-core 0.20.3`.
> All projects currently use `forc v0.47.0`, `fuels-rs v0.46.0` and `fuel-core 0.20.8`.

## Contributing

Expand Down
5 changes: 4 additions & 1 deletion libs/merkle_proof/src/binary_merkle_proof.sw
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ pub fn process_proof(
proof: Vec<b256>,
) -> b256 {
let proof_length = proof.len();
require((num_leaves > 1 && proof_length == path_length_from_key(key, num_leaves)) || (num_leaves <= 1 && proof_length == 0), ProofError::InvalidProofLength);
require(
(num_leaves > 1 && proof_length == path_length_from_key(key, num_leaves)) || (num_leaves <= 1 && proof_length == 0),
ProofError::InvalidProofLength,
);
require(key < num_leaves, ProofError::InvalidKey);

let mut digest = merkle_leaf;
Expand Down
2 changes: 1 addition & 1 deletion libs/ownership/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ license = "Apache-2.0"
name = "ownership"

[dependencies]
src_5 = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.1.0" }
src_5 = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.2.0" }
18 changes: 15 additions & 3 deletions libs/ownership/src/ownable.sw
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ pub mod events;
use errors::AccessError;
use events::{OwnershipRenounced, OwnershipSet, OwnershipTransferred};
use std::{auth::msg_sender, hash::sha256, storage::storage_api::{read, write}};
use src_5::{Ownership, State};
use src_5::State;

pub struct Ownership {
state: State,
}

impl Ownership {
/// Returns the `Ownership` struct in the `Uninitalized` state.
Expand Down Expand Up @@ -143,7 +147,11 @@ impl StorageKey<Ownership> {
/// ```
#[storage(read)]
pub fn only_owner(self) {
require(self.owner() == State::Initialized(msg_sender().unwrap()), AccessError::NotOwner);
require(
self
.owner() == State::Initialized(msg_sender().unwrap()),
AccessError::NotOwner,
);
}
}

Expand Down Expand Up @@ -217,7 +225,11 @@ impl StorageKey<Ownership> {
/// ```
#[storage(read, write)]
pub fn set_ownership(self, new_owner: Identity) {
require(self.owner() == State::Uninitialized, AccessError::CannotReinitialized);
require(
self
.owner() == State::Uninitialized,
AccessError::CannotReinitialized,
);

self.write(Ownership::initialized(new_owner));

Expand Down
36 changes: 28 additions & 8 deletions libs/signed_integers/src/i128.sw
Original file line number Diff line number Diff line change
Expand Up @@ -250,20 +250,32 @@ impl core::ops::Divide for I128 {
|| self.underlying == Self::indent())
&& divisor.underlying > Self::indent()
{
res = Self::from_uint((self.underlying - Self::indent()) / (divisor.underlying - Self::indent()) + Self::indent());
res = Self::from_uint(
(self.underlying - Self::indent()) / (divisor
.underlying - Self::indent()) + Self::indent(),
);
} else if self.underlying < Self::indent()
&& divisor.underlying < Self::indent()
{
res = Self::from_uint((Self::indent() - self.underlying) / (Self::indent() - divisor.underlying) + Self::indent());
res = Self::from_uint(
(Self::indent() - self.underlying) / (Self::indent() - divisor
.underlying) + Self::indent(),
);
} else if (self.underlying > Self::indent()
|| self.underlying == Self::indent())
&& divisor.underlying < Self::indent()
{
res = Self::from_uint(Self::indent() - (self.underlying - Self::indent()) / (Self::indent() - divisor.underlying));
res = Self::from_uint(
Self::indent() - (self.underlying - Self::indent()) / (Self::indent() - divisor
.underlying),
);
} else if self.underlying < Self::indent()
&& divisor.underlying > Self::indent()
{
res = Self::from_uint(Self::indent() - (Self::indent() - self.underlying) / (divisor.underlying - Self::indent()));
res = Self::from_uint(
Self::indent() - (Self::indent() - self.underlying) / (divisor
.underlying - Self::indent()),
);
}
res
}
Expand All @@ -278,21 +290,29 @@ impl core::ops::Multiply for I128 {
&& (other.underlying > Self::indent()
|| other.underlying == Self::indent())
{
res = Self::from_uint((self.underlying - Self::indent()) * (other.underlying - Self::indent()) + Self::indent());
res = Self::from_uint(
(self.underlying - Self::indent()) * (other.underlying - Self::indent()) + Self::indent(),
);
} else if self.underlying < Self::indent()
&& other.underlying < Self::indent()
{
res = Self::from_uint((Self::indent() - self.underlying) * (Self::indent() - other.underlying) + Self::indent());
res = Self::from_uint(
(Self::indent() - self.underlying) * (Self::indent() - other.underlying) + Self::indent(),
);
} else if (self.underlying > Self::indent()
|| self.underlying == Self::indent())
&& other.underlying < Self::indent()
{
res = Self::from_uint(Self::indent() - (self.underlying - Self::indent()) * (Self::indent() - other.underlying));
res = Self::from_uint(
Self::indent() - (self.underlying - Self::indent()) * (Self::indent() - other.underlying),
);
} else if self.underlying < Self::indent()
&& (other.underlying > Self::indent()
|| other.underlying == Self::indent())
{
res = Self::from_uint(Self::indent() - (other.underlying - Self::indent()) * (Self::indent() - self.underlying));
res = Self::from_uint(
Self::indent() - (other.underlying - Self::indent()) * (Self::indent() - self.underlying),
);
}
res
}
Expand Down
36 changes: 28 additions & 8 deletions libs/signed_integers/src/i16.sw
Original file line number Diff line number Diff line change
Expand Up @@ -237,19 +237,31 @@ impl core::ops::Divide for I16 {
if self.underlying >= Self::indent()
&& divisor.underlying > Self::indent()
{
res = Self::from_uint((self.underlying - Self::indent()) / (divisor.underlying - Self::indent()) + Self::indent());
res = Self::from_uint(
(self.underlying - Self::indent()) / (divisor
.underlying - Self::indent()) + Self::indent(),
);
} else if self.underlying < Self::indent()
&& divisor.underlying < Self::indent()
{
res = Self::from_uint((Self::indent() - self.underlying) / (Self::indent() - divisor.underlying) + Self::indent());
res = Self::from_uint(
(Self::indent() - self.underlying) / (Self::indent() - divisor
.underlying) + Self::indent(),
);
} else if self.underlying >= Self::indent()
&& divisor.underlying < Self::indent()
{
res = Self::from_uint(Self::indent() - (self.underlying - Self::indent()) / (Self::indent() - divisor.underlying));
res = Self::from_uint(
Self::indent() - (self.underlying - Self::indent()) / (Self::indent() - divisor
.underlying),
);
} else if self.underlying < Self::indent()
&& divisor.underlying > Self::indent()
{
res = Self::from_uint(Self::indent() - (Self::indent() - self.underlying) / (divisor.underlying - Self::indent()));
res = Self::from_uint(
Self::indent() - (Self::indent() - self.underlying) / (divisor
.underlying - Self::indent()),
);
}
res
}
Expand All @@ -262,19 +274,27 @@ impl core::ops::Multiply for I16 {
if self.underlying >= Self::indent()
&& other.underlying >= Self::indent()
{
res = Self::from_uint((self.underlying - Self::indent()) * (other.underlying - Self::indent()) + Self::indent());
res = Self::from_uint(
(self.underlying - Self::indent()) * (other.underlying - Self::indent()) + Self::indent(),
);
} else if self.underlying < Self::indent()
&& other.underlying < Self::indent()
{
res = Self::from_uint((Self::indent() - self.underlying) * (Self::indent() - other.underlying) + Self::indent());
res = Self::from_uint(
(Self::indent() - self.underlying) * (Self::indent() - other.underlying) + Self::indent(),
);
} else if self.underlying >= Self::indent()
&& other.underlying < Self::indent()
{
res = Self::from_uint(Self::indent() - (self.underlying - Self::indent()) * (Self::indent() - other.underlying));
res = Self::from_uint(
Self::indent() - (self.underlying - Self::indent()) * (Self::indent() - other.underlying),
);
} else if self.underlying < Self::indent()
&& other.underlying >= Self::indent()
{
res = Self::from_uint(Self::indent() - (other.underlying - Self::indent()) * (Self::indent() - self.underlying));
res = Self::from_uint(
Self::indent() - (other.underlying - Self::indent()) * (Self::indent() - self.underlying),
);
}
res
}
Expand Down
36 changes: 28 additions & 8 deletions libs/signed_integers/src/i256.sw
Original file line number Diff line number Diff line change
Expand Up @@ -249,20 +249,32 @@ impl core::ops::Divide for I256 {
let self_ge_indent = self.underlying > Self::indent() || self.underlying == Self::indent();
let divisor_gt_indent = divisor.underlying > Self::indent();
if self_ge_indent && divisor_gt_indent {
res = Self::from_uint((self.underlying - Self::indent()) / (divisor.underlying - Self::indent()) + Self::indent());
res = Self::from_uint(
(self.underlying - Self::indent()) / (divisor
.underlying - Self::indent()) + Self::indent(),
);
} else if self.underlying < Self::indent()
&& divisor.underlying < Self::indent()
{
res = Self::from_uint((Self::indent() - self.underlying) / (Self::indent() - divisor.underlying) + Self::indent());
res = Self::from_uint(
(Self::indent() - self.underlying) / (Self::indent() - divisor
.underlying) + Self::indent(),
);
} else if (self.underlying > Self::indent()
|| self.underlying == Self::indent())
&& divisor.underlying < Self::indent()
{
res = Self::from_uint(Self::indent() - (self.underlying - Self::indent()) / (Self::indent() - divisor.underlying));
res = Self::from_uint(
Self::indent() - (self.underlying - Self::indent()) / (Self::indent() - divisor
.underlying),
);
} else if self.underlying < Self::indent()
&& divisor.underlying > Self::indent()
{
res = Self::from_uint(Self::indent() - (Self::indent() - self.underlying) / (divisor.underlying - Self::indent()));
res = Self::from_uint(
Self::indent() - (Self::indent() - self.underlying) / (divisor
.underlying - Self::indent()),
);
}
res
}
Expand All @@ -277,21 +289,29 @@ impl core::ops::Multiply for I256 {
&& (other.underlying > Self::indent()
|| other.underlying == Self::indent())
{
res = Self::from_uint((self.underlying - Self::indent()) * (other.underlying - Self::indent()) + Self::indent());
res = Self::from_uint(
(self.underlying - Self::indent()) * (other.underlying - Self::indent()) + Self::indent(),
);
} else if self.underlying < Self::indent()
&& other.underlying < Self::indent()
{
res = Self::from_uint((Self::indent() - self.underlying) * (Self::indent() - other.underlying) + Self::indent());
res = Self::from_uint(
(Self::indent() - self.underlying) * (Self::indent() - other.underlying) + Self::indent(),
);
} else if (self.underlying > Self::indent()
|| self.underlying == Self::indent())
&& other.underlying < Self::indent()
{
res = Self::from_uint(Self::indent() - (self.underlying - Self::indent()) * (Self::indent() - other.underlying));
res = Self::from_uint(
Self::indent() - (self.underlying - Self::indent()) * (Self::indent() - other.underlying),
);
} else if self.underlying < Self::indent()
&& (other.underlying > Self::indent()
|| other.underlying == Self::indent())
{
res = Self::from_uint(Self::indent() - (other.underlying - Self::indent()) * (Self::indent() - self.underlying));
res = Self::from_uint(
Self::indent() - (other.underlying - Self::indent()) * (Self::indent() - self.underlying),
);
}
res
}
Expand Down
36 changes: 28 additions & 8 deletions libs/signed_integers/src/i32.sw
Original file line number Diff line number Diff line change
Expand Up @@ -268,19 +268,27 @@ impl core::ops::Multiply for I32 {
if self.underlying >= Self::indent()
&& other.underlying >= Self::indent()
{
res = Self::from_uint((self.underlying - Self::indent()) * (other.underlying - Self::indent()) + Self::indent());
res = Self::from_uint(
(self.underlying - Self::indent()) * (other.underlying - Self::indent()) + Self::indent(),
);
} else if self.underlying < Self::indent()
&& other.underlying < Self::indent()
{
res = Self::from_uint((Self::indent() - self.underlying) * (Self::indent() - other.underlying) + Self::indent());
res = Self::from_uint(
(Self::indent() - self.underlying) * (Self::indent() - other.underlying) + Self::indent(),
);
} else if self.underlying >= Self::indent()
&& other.underlying < Self::indent()
{
res = Self::from_uint(Self::indent() - (self.underlying - Self::indent()) * (Self::indent() - other.underlying));
res = Self::from_uint(
Self::indent() - (self.underlying - Self::indent()) * (Self::indent() - other.underlying),
);
} else if self.underlying < Self::indent()
&& other.underlying >= Self::indent()
{
res = Self::from_uint(Self::indent() - (other.underlying - Self::indent()) * (Self::indent() - self.underlying));
res = Self::from_uint(
Self::indent() - (other.underlying - Self::indent()) * (Self::indent() - self.underlying),
);
}
res
}
Expand All @@ -294,19 +302,31 @@ impl core::ops::Divide for I32 {
if self.underlying >= Self::indent()
&& divisor.underlying > Self::indent()
{
res = Self::from_uint((self.underlying - Self::indent()) / (divisor.underlying - Self::indent()) + Self::indent());
res = Self::from_uint(
(self.underlying - Self::indent()) / (divisor
.underlying - Self::indent()) + Self::indent(),
);
} else if self.underlying < Self::indent()
&& divisor.underlying < Self::indent()
{
res = Self::from_uint((Self::indent() - self.underlying) / (Self::indent() - divisor.underlying) + Self::indent());
res = Self::from_uint(
(Self::indent() - self.underlying) / (Self::indent() - divisor
.underlying) + Self::indent(),
);
} else if self.underlying >= Self::indent()
&& divisor.underlying < Self::indent()
{
res = Self::from_uint(Self::indent() - (self.underlying - Self::indent()) / (Self::indent() - divisor.underlying));
res = Self::from_uint(
Self::indent() - (self.underlying - Self::indent()) / (Self::indent() - divisor
.underlying),
);
} else if self.underlying < Self::indent()
&& divisor.underlying > Self::indent()
{
res = Self::from_uint(Self::indent() - (Self::indent() - self.underlying) / (divisor.underlying - Self::indent()));
res = Self::from_uint(
Self::indent() - (Self::indent() - self.underlying) / (divisor
.underlying - Self::indent()),
);
}
res
}
Expand Down