Skip to content

Commit

Permalink
update increment contract to new-style storage (FuelLabs#2336)
Browse files Browse the repository at this point in the history
* update increment contract to new-style storage

* update oracles for test
  • Loading branch information
sezna authored Jul 16, 2022
1 parent 01651cb commit 9f4d9f8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use increment_abi::Incrementor;
use std::assert::assert;

fn main() -> bool {
let the_abi = abi(Incrementor, 0x1ab62c759c218a0890ef97ad8da655740b92426df26a2aae569685659a28a889);
the_abi.initialize(0); // comment this line out to just increment without initializing
let the_abi = abi(Incrementor, 0x0bb4d41501aed8a57965e65946157c401a1acfe30df3326a660d7b3288457ddd);
the_abi.increment(5);
the_abi.increment(5);
let result = the_abi.get();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
library increment_abi;

abi Incrementor {
#[storage(write)]
fn initialize(initial_value: u64) -> u64;
#[storage(read, write)]
fn increment(initial_value: u64) -> u64;
#[storage(read)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,4 @@
[
{
"inputs": [
{
"components": null,
"name": "initial_value",
"type": "u64",
"typeArguments": null
}
],
"name": "initialize",
"outputs": [
{
"components": null,
"name": "",
"type": "u64",
"typeArguments": null
}
],
"type": "function"
},
{
"inputs": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
[]
[
{
"key": "f383b0ce51358be57daa3b725fe44acdb2d880604e367199080b4379c41bb6ed",
"value": "0000000000000000000000000000000000000000000000000000000000000000"
}
]
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
contract;

use increment_abi::Incrementor;
use std::storage::{get, store};

const KEY = 0x0000000000000000000000000000000000000000000000000000000000000000;
storage {
value: u64 = 0,
}

impl Incrementor for Contract {
#[storage(write)]
fn initialize(initial_value: u64) -> u64 {
store(KEY, initial_value);
initial_value
}
#[storage(read, write)]
fn increment(increment_by: u64) -> u64 {
let new_val = get::<u64>(KEY) + increment_by;
// check that monomorphization doesn't overwrite the type of the above
let dummy = get::<u32>(KEY) + increment_by;
store(KEY, new_val);
let new_val = storage.value + increment_by;
storage.value = new_val;
new_val
}

#[storage(read)]
fn get() -> u64 {
get::<u64>(KEY)
storage.value
}
}

0 comments on commit 9f4d9f8

Please sign in to comment.