Skip to content

Commit

Permalink
apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
kpob committed Dec 12, 2023
1 parent 871700f commit c5ba790
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
6 changes: 2 additions & 4 deletions core/src/variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@ impl<T: FromBytes> Variable<T> {

pub fn get_or_revert_with<E: Into<OdraError>>(&self, error: E) -> T {
let env = self.env();
env.get_value(&env.current_key())
.unwrap_or_revert_with(&env, error)
self.get().unwrap_or_revert_with(&env, error)
}
}

impl<T: FromBytes + Default> Variable<T> {
pub fn get_or_default(&self) -> T {
let env = self.env();
env.get_value(&env.current_key()).unwrap_or_default()
self.get().unwrap_or_default()
}
}

Expand Down
24 changes: 11 additions & 13 deletions examples2/src/counter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use odra::prelude::*;
use odra::{runtime_args, Address, FromBytes, OdraType, RuntimeArgs};
use odra::{CallDef, ContractEnv, HostEnv, Mapping, Variable};
use odra::{Address, CallDef, ContractEnv, HostEnv, Mapping, Module, OdraType, Variable};

#[derive(OdraType)]
struct MyCounter {
Expand All @@ -17,7 +16,6 @@ enum MyEnum {

#[odra::module]
pub struct Counter {
env: Rc<ContractEnv>,
count0: Variable<MyCounter>,
count1: Variable<MyCounter>,
count2: Variable<MyCounter>,
Expand Down Expand Up @@ -50,16 +48,16 @@ impl Counter {

pub fn increment(&mut self, index: u8) {
match index {
0 => increment(&self.env, &mut self.count0),
1 => increment(&self.env, &mut self.count1),
2 => increment(&self.env, &mut self.count2),
3 => increment(&self.env, &mut self.count3),
4 => increment(&self.env, &mut self.count4),
5 => increment(&self.env, &mut self.count5),
6 => increment(&self.env, &mut self.count6),
7 => increment(&self.env, &mut self.count7),
8 => increment(&self.env, &mut self.count8),
9 => increment(&self.env, &mut self.count9),
0 => increment(&self.env(), &mut self.count0),
1 => increment(&self.env(), &mut self.count1),
2 => increment(&self.env(), &mut self.count2),
3 => increment(&self.env(), &mut self.count3),
4 => increment(&self.env(), &mut self.count4),
5 => increment(&self.env(), &mut self.count5),
6 => increment(&self.env(), &mut self.count6),
7 => increment(&self.env(), &mut self.count7),
8 => increment(&self.env(), &mut self.count8),
9 => increment(&self.env(), &mut self.count9),
_ => unreachable!()
};
}
Expand Down
2 changes: 1 addition & 1 deletion examples2/src/erc20.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use casper_event_standard::Event;
use odra::{casper_event_standard, Bytes, Module, OdraError, PublicKey};
use odra::{prelude::*, CallDef, ModuleWrapper};
use odra::{Address, ContractEnv, Mapping, Variable, U256, U512};
use odra::{Address, Mapping, Variable, U256, U512};

#[derive(Event, Eq, PartialEq, Debug)]
pub struct OnTransfer {
Expand Down
7 changes: 3 additions & 4 deletions examples2/src/reentrancy_guard.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use odra::{prelude::*, ContractEnv, Variable};
use odra::{prelude::*, Module, Variable};

#[odra::module]
pub struct ReentrancyMock {
env: Rc<ContractEnv>,
counter: Variable<u32>
}

Expand All @@ -21,8 +20,8 @@ impl ReentrancyMock {
if n > 0 {
self.count();
let other_erc20 = ReentrancyMockContractRef {
address: self.env.self_address(),
env: self.env.clone()
address: self.env().self_address(),
env: self.env().clone()
}
.count_ref_recursive(n - 1);
}
Expand Down

0 comments on commit c5ba790

Please sign in to comment.