Skip to content

Commit

Permalink
Run forc-fmt in examples folder
Browse files Browse the repository at this point in the history
  • Loading branch information
cr-fuel committed Oct 21, 2023
1 parent 3f360f0 commit 14c99f2
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 24 deletions.
4 changes: 1 addition & 3 deletions examples/enums/src/enum_of_structs.sw
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ enum MyEnum {

fn main() {
let my_enum = MyEnum::Item(Item {
price: 5,
amount: 2,
id: 42,
price: 5, amount: 2, id: 42,
});
}
6 changes: 4 additions & 2 deletions examples/identity/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ impl IdentityExample for Contract {
fn access_control_with_identity() {
// ANCHOR: access_control_with_identity
let sender = msg_sender().unwrap();
require(sender == storage.owner.read(), MyError::UnauthorizedUser(sender));
// ANCHOR_END: access_control_with_identity
require(sender == storage
.owner
.read(), MyError::UnauthorizedUser(sender));
// ANCHOR_END: access_control_with_identity
}
}
14 changes: 12 additions & 2 deletions examples/storage_map/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,19 @@ impl StorageMapExample for Contract {
storage.nested_map.get(2).insert(3, 24);

assert(storage.nested_map.get(0).get(1).read() == 42);
assert(storage.nested_map.get(0).get(0).try_read().is_none()); // Nothing inserted here
assert(storage
.nested_map
.get(0)
.get(0)
.try_read()
.is_none()); // Nothing inserted here
assert(storage.nested_map.get(2).get(3).read() == 24);
assert(storage.nested_map.get(2).get(2).try_read().is_none()); // Nothing inserted here
assert(storage
.nested_map
.get(2)
.get(2)
.try_read()
.is_none()); // Nothing inserted here
}
// ANCHOR_END: storage_map_nested_access
}
11 changes: 9 additions & 2 deletions examples/storage_variables/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ impl StorageExample for Contract {
fn store_something() {
storage.var1.x.write(42);
storage.var1.y.write(77);
storage.var2.w.write(0x1111111111111111111111111111111111111111111111111111111111111111);
storage
.var2
.w
.write(
0x1111111111111111111111111111111111111111111111111111111111111111,
);
storage.var2.z.write(true);
}
// ANCHOR_END: storage_write
Expand All @@ -44,7 +49,9 @@ impl StorageExample for Contract {
(
storage.var1.x.try_read().unwrap_or(0),
storage.var1.y.try_read().unwrap_or(0),
storage.var2.w.try_read().unwrap_or(0x0000000000000000000000000000000000000000000000000000000000000000),
storage.var2.w.try_read().unwrap_or(
0x0000000000000000000000000000000000000000000000000000000000000000,
),
storage.var2.z.try_read().unwrap_or(false),
)
}
Expand Down
6 changes: 5 additions & 1 deletion examples/storage_vec/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ impl StorageVecContract for Contract {
#[storage(read, write)]
fn push_to_multiple_types_storage_vec() {
storage.row.push(TableCell::Int(3));
storage.row.push(TableCell::B256(0x0101010101010101010101010101010101010101010101010101010101010101));
storage
.row
.push(
TableCell::B256(0x0101010101010101010101010101010101010101010101010101010101010101),
);
storage.row.push(TableCell::Boolean(true));
}
// ANCHOR_END: storage_vec_multiple_types_fn
Expand Down
6 changes: 2 additions & 4 deletions examples/structs/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use data_structures::{Foo, Line, Point, TupleInStruct};
fn hardcoded_instantiation() -> Foo {
// Instantiate `foo` as `Foo`
let mut foo = Foo {
bar: 42,
baz: false,
bar: 42, baz: false,
};

// Access and write to "baz"
Expand Down Expand Up @@ -60,8 +59,7 @@ fn struct_destructuring() {
let Point { x, .. } = point2;

let line = Line {
p1: point1,
p2: point2,
p1: point1, p2: point2,
};
// Destructure the values from the nested structs into variables
let Line {
Expand Down
22 changes: 20 additions & 2 deletions examples/subcurrency/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,16 @@ impl Token for Contract {
};

// Increase the balance of receiver
storage.balances.insert(receiver, storage.balances.get(receiver).try_read().unwrap_or(0) + amount);
storage
.balances
.insert(
receiver,
storage
.balances
.get(receiver)
.try_read()
.unwrap_or(0) + amount,
);
}

#[storage(read, write)]
Expand All @@ -81,7 +90,16 @@ impl Token for Contract {
storage.balances.insert(sender, sender_amount - amount);

// Increase the balance of receiver
storage.balances.insert(receiver, storage.balances.get(receiver).try_read().unwrap_or(0) + amount);
storage
.balances
.insert(
receiver,
storage
.balances
.get(receiver)
.try_read()
.unwrap_or(0) + amount,
);

log(Sent {
from: sender,
Expand Down
12 changes: 9 additions & 3 deletions examples/vec/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ fn main() {
// ANCHOR_END: vec_get_oob
// ANCHOR: vec_iterate
let mut i = 0;
while i < v.len() {
log(v.get(i).unwrap());
while i < v
.len() {
log(v
.get(i)
.unwrap());
i += 1;
}
// ANCHOR_END: vec_iterate
Expand All @@ -39,7 +42,10 @@ fn main() {

let mut row = Vec::new();
row.push(TableCell::Int(3));
row.push(TableCell::B256(0x0101010101010101010101010101010101010101010101010101010101010101));
row
.push(
TableCell::B256(0x0101010101010101010101010101010101010101010101010101010101010101),
);
row.push(TableCell::Boolean(true));
// ANCHOR_END: vec_multiple_data_types
}
11 changes: 6 additions & 5 deletions examples/wallet_contract_caller_script/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ fn main() {
let caller = abi(Wallet, contract_address);
let amount_to_send = 200;
let recipient_address = Address::from(0x9299da6c73e6dc03eeabcce242bb347de3f5f56cd1c70926d76526d7ed199b8b);
caller.send_funds {
gas: 10000,
coins: 0,
asset_id: ZERO_B256,
}(amount_to_send, recipient_address);
caller
.send_funds {
gas: 10000,
coins: 0,
asset_id: ZERO_B256,
}(amount_to_send, recipient_address);
}

0 comments on commit 14c99f2

Please sign in to comment.