Skip to content

Commit

Permalink
Run formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
bitzoic committed Jan 24, 2025
1 parent 2def8e8 commit 10d90f9
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 193 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ contract;

use standards::src11::{SecurityInformation, SRC11};

use std::{string::String, vec::Vec,};
use std::{string::String, vec::Vec};

/// The name of the project
const NAME: str[7] = __to_str_array("Example");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ contract;

use standards::src11::{SecurityInformation, SRC11};

use std::{storage::{storage_string::*, storage_vec::*,}, string::String, vec::Vec,};
use std::{storage::{storage_string::*, storage_vec::*}, string::String, vec::Vec};

/// The name of the project
const NAME: str[7] = __to_str_array("Example");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
library;

use std::{alloc::{alloc, alloc_bytes, realloc_bytes}, bytes::Bytes,};
use std::{alloc::{alloc, alloc_bytes, realloc_bytes}, bytes::Bytes};

/// Pre-defined number of bytes of a leaf in a bytecode merkle tree.
const LEAF_SIZE = 16 * 1024;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod utils;

use utils::{_compute_bytecode_root, _swap_configurables};
use standards::src12::*;
use std::{external::bytecode_root, hash::{Hash, sha256,}, storage::storage_vec::*,};
use std::{external::bytecode_root, hash::{Hash, sha256}, storage::storage_vec::*};

configurable {
TEMPLATE_BYTECODE_ROOT: b256 = b256::zero(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
contract;

use standards::src12::*;
use std::{external::bytecode_root, hash::Hash,};
use std::{external::bytecode_root, hash::Hash};

configurable {
TEMPLATE_BYTECODE_ROOT: b256 = b256::zero(),
Expand Down
5 changes: 1 addition & 4 deletions examples/src16-typed-data/Forc.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
[workspace]
members = [
"fuel_example",
"ethereum_example",
]
members = ["fuel_example", "ethereum_example"]
2 changes: 1 addition & 1 deletion examples/src16-typed-data/ethereum_example/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ license = "Apache-2.0"
name = "src16_ethereum_typed_data"

[dependencies]
standards = { path = "../../../standards" }
standards = { path = "../../../standards" }
66 changes: 16 additions & 50 deletions examples/src16-typed-data/ethereum_example/src/main.sw
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
contract;

use standards::src16::{
SRC16Base,
DataEncoder,
DomainHash,
EIP712,
EIP712Domain,
DomainHash,
TypedDataHash,
DataEncoder,
SRC16Payload,
SRC16Base,
SRC16Encode,
SRC16Payload,
TypedDataHash,
};
use std::{
bytes::Bytes,
string::String,
hash::*,
contract_id::*,
};

use std::{bytes::Bytes, contract_id::*, hash::*, string::String};

configurable {
/// The name of the signing domain.
Expand All @@ -27,7 +21,6 @@ configurable {
CHAIN_ID: u64 = 9889u64,
}


/// A demo struct representing a mail message
pub struct Mail {
/// The sender's address
Expand All @@ -47,7 +40,6 @@ pub struct Mail {
const MAIL_TYPE_HASH: b256 = 0xcfc972d321844e0304c5a752957425d5df13c3b09c563624a806b517155d7056;

impl TypedDataHash for Mail {

fn type_hash() -> b256 {
MAIL_TYPE_HASH
}
Expand All @@ -56,19 +48,11 @@ impl TypedDataHash for Mail {
let mut encoded = Bytes::new();

// Add the Mail type hash.
encoded.append(
MAIL_TYPE_HASH.to_be_bytes()
);
encoded.append(MAIL_TYPE_HASH.to_be_bytes());
// Use the DataEncoder to encode each field for known types
encoded.append(
DataEncoder::encode_b256(self.from).to_be_bytes()
);
encoded.append(
DataEncoder::encode_b256(self.to).to_be_bytes()
);
encoded.append(
DataEncoder::encode_string(self.contents).to_be_bytes()
);
encoded.append(DataEncoder::encode_b256(self.from).to_be_bytes());
encoded.append(DataEncoder::encode_b256(self.to).to_be_bytes());
encoded.append(DataEncoder::encode_string(self.contents).to_be_bytes());

keccak256(encoded)
}
Expand All @@ -86,9 +70,7 @@ impl TypedDataHash for Mail {
/// SRC16Payload::encode_hash()
///
impl SRC16Encode<Mail> for Mail {

fn encode(s: Mail) -> b256 {

// encodeData hash
let data_hash = s.struct_hash();
// setup payload
Expand All @@ -105,9 +87,7 @@ impl SRC16Encode<Mail> for Mail {
}
}


impl SRC16Base for Contract {

fn domain_separator_hash() -> b256 {
_get_domain_separator().domain_hash()
}
Expand All @@ -118,24 +98,16 @@ impl SRC16Base for Contract {
}

impl EIP712 for Contract {

fn domain_separator() -> EIP712Domain {
_get_domain_separator()
}

}


abi MailMe {
fn send_mail_get_hash(
from_addr: b256,
to_addr: b256,
contents: String,
) -> b256;
fn send_mail_get_hash(from_addr: b256, to_addr: b256, contents: String) -> b256;
}

impl MailMe for Contract {

/// Sends a some mail and returns its encoded hash
///
/// # Arguments
Expand All @@ -148,11 +120,7 @@ impl MailMe for Contract {
///
/// * [b256] - The encoded hash of the mail data
///
fn send_mail_get_hash(
from_addr: b256,
to_addr: b256,
contents: String,
) -> b256 {
fn send_mail_get_hash(from_addr: b256, to_addr: b256, contents: String) -> b256 {
// Create the mail struct from data passed in call
let some_mail = Mail {
from: from_addr,
Expand All @@ -162,7 +130,6 @@ impl MailMe for Contract {

Mail::encode(some_mail)
}

}

/// A program specific implementation to get the Ethereum EIP712Domain
Expand All @@ -177,10 +144,9 @@ fn _get_domain_separator() -> EIP712Domain {
EIP712Domain::new(
String::from_ascii_str(from_str_array(DOMAIN)),
String::from_ascii_str(from_str_array(VERSION)),
(asm(r1: (0, 0, 0, CHAIN_ID)) { r1: u256 }),
ContractId::this()
(asm(r1: (0, 0, 0, CHAIN_ID)) {
r1: u256
}),
ContractId::this(),
)
}



2 changes: 1 addition & 1 deletion examples/src16-typed-data/fuel_example/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ license = "Apache-2.0"
name = "src16_fuel_typed_data"

[dependencies]
standards = { path = "../../../standards" }
standards = { path = "../../../standards" }
61 changes: 13 additions & 48 deletions examples/src16-typed-data/fuel_example/src/main.sw
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
contract;

use standards::src16::{
SRC16Base,
DataEncoder,
DomainHash,
SRC16,
SRC16Base,
SRC16Domain,
DomainHash,
TypedDataHash,
DataEncoder,
SRC16Payload,
SRC16Encode,
SRC16Payload,
TypedDataHash,
};
use std::{
bytes::Bytes,
string::String,
hash::*,
contract_id::*,
};

use std::{bytes::Bytes, contract_id::*, hash::*, string::String};

configurable {
/// The name of the signing domain.
Expand All @@ -27,7 +21,6 @@ configurable {
CHAIN_ID: u64 = 9889u64,
}


/// A demo struct representing a mail message
pub struct Mail {
/// The sender's address
Expand All @@ -47,27 +40,18 @@ pub struct Mail {
const MAIL_TYPE_HASH: b256 = 0x536e54c54e6699204b424f41f6dea846ee38ac369afec3e7c141d2c92c65e67f;

impl TypedDataHash for Mail {

fn type_hash() -> b256 {
MAIL_TYPE_HASH
}

fn struct_hash(self) -> b256 {
let mut encoded = Bytes::new();
// Add the Mail type hash.
encoded.append(
MAIL_TYPE_HASH.to_be_bytes()
);
encoded.append(MAIL_TYPE_HASH.to_be_bytes());
// Use the DataEncoder to encode each field for known types
encoded.append(
DataEncoder::encode_address(self.from).to_be_bytes()
);
encoded.append(
DataEncoder::encode_address(self.to).to_be_bytes()
);
encoded.append(
DataEncoder::encode_string(self.contents).to_be_bytes()
);
encoded.append(DataEncoder::encode_address(self.from).to_be_bytes());
encoded.append(DataEncoder::encode_address(self.to).to_be_bytes());
encoded.append(DataEncoder::encode_string(self.contents).to_be_bytes());

keccak256(encoded)
}
Expand All @@ -85,9 +69,7 @@ impl TypedDataHash for Mail {
/// SRC16Payload::encode_hash()
///
impl SRC16Encode<Mail> for Mail {

fn encode(s: Mail) -> b256 {

// encodeData hash
let data_hash = s.struct_hash();
// setup payload
Expand All @@ -104,9 +86,7 @@ impl SRC16Encode<Mail> for Mail {
}
}


impl SRC16Base for Contract {

fn domain_separator_hash() -> b256 {
_get_domain_separator().domain_hash()
}
Expand All @@ -117,24 +97,16 @@ impl SRC16Base for Contract {
}

impl SRC16 for Contract {

fn domain_separator() -> SRC16Domain {
_get_domain_separator()
}

}


abi MailMe {
fn send_mail_get_hash(
from_addr: Address,
to_addr: Address,
contents: String,
) -> b256;
fn send_mail_get_hash(from_addr: Address, to_addr: Address, contents: String) -> b256;
}

impl MailMe for Contract {

/// Sends a some mail and returns its encoded hash
///
/// # Arguments
Expand All @@ -147,11 +119,7 @@ impl MailMe for Contract {
///
/// * [b256] - The encoded hash of the mail data
///
fn send_mail_get_hash(
from_addr: Address,
to_addr: Address,
contents: String,
) -> b256 {
fn send_mail_get_hash(from_addr: Address, to_addr: Address, contents: String) -> b256 {
// Create the mail struct from data passed in call
let some_mail = Mail {
from: from_addr,
Expand All @@ -161,7 +129,6 @@ impl MailMe for Contract {

Mail::encode(some_mail)
}

}

/// A program specific implementation to get the Fuel SRC16Domain
Expand All @@ -177,8 +144,6 @@ fn _get_domain_separator() -> SRC16Domain {
String::from_ascii_str(from_str_array(DOMAIN)),
String::from_ascii_str(from_str_array(VERSION)),
CHAIN_ID,
ContractId::this()
ContractId::this(),
)
}


2 changes: 1 addition & 1 deletion examples/src20-native-asset/multi_asset/src/multi_asset.sw
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
contract;

use standards::src20::{SetDecimalsEvent, SetNameEvent, SetSymbolEvent, SRC20, TotalSupplyEvent,};
use standards::src20::{SetDecimalsEvent, SetNameEvent, SetSymbolEvent, SRC20, TotalSupplyEvent};
use std::{hash::Hash, storage::storage_string::*, string::String};

storage {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
contract;

use standards::src20::{SetDecimalsEvent, SetNameEvent, SetSymbolEvent, SRC20, TotalSupplyEvent,};
use standards::src20::{SetDecimalsEvent, SetNameEvent, SetSymbolEvent, SRC20, TotalSupplyEvent};
use std::{auth::msg_sender, string::String};

configurable {
Expand Down
Loading

0 comments on commit 10d90f9

Please sign in to comment.