Skip to content

Commit 0bb6b45

Browse files
committedMar 11, 2021
fix: Don't use env::signer_account_id
Instead use env::predecessor_account_id. Using signer_account_id has the same problems of using tx.origin in Ethereum. See link below for more details: ethereum/solidity#683
1 parent ac1c156 commit 0bb6b45

File tree

4 files changed

+30
-34
lines changed

4 files changed

+30
-34
lines changed
 

‎contracts/near/admin-controlled/src/lib.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1+
pub mod macros;
2+
pub use macros::*;
3+
14
use near_sdk::env;
25

36
pub type Mask = u128;
47

58
pub trait AdminControlled {
69
fn is_owner(&self) -> bool {
7-
env::current_account_id() == env::signer_account_id()
8-
}
9-
10-
fn assert_owner(&self) {
11-
assert!(self.is_owner());
10+
env::current_account_id() == env::predecessor_account_id()
1211
}
1312

1413
/// Return the current mask representing all paused events.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#[macro_export]
2+
macro_rules! impl_admin_controlled {
3+
($contract: ident, $paused: ident) => {
4+
use admin_controlled::{AdminControlled as AdminControlledInner, Mask as MaskInner};
5+
use near_sdk as near_sdk_inner;
6+
7+
#[near_bindgen]
8+
impl AdminControlledInner for $contract {
9+
#[result_serializer(borsh)]
10+
fn get_paused(&self) -> MaskInner {
11+
self.$paused
12+
}
13+
14+
#[result_serializer(borsh)]
15+
fn set_paused(&mut self, #[serializer(borsh)] paused: MaskInner) {
16+
near_sdk_inner::assert_self();
17+
self.$paused = paused;
18+
}
19+
}
20+
};
21+
}

‎contracts/near/eth-client/src/lib.rs

+3-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use admin_controlled::{AdminControlled, Mask};
1+
use admin_controlled::Mask;
22
use borsh::{BorshDeserialize, BorshSerialize};
33
use eth_types::*;
44
use near_sdk::collections::UnorderedMap;
@@ -111,20 +111,6 @@ impl Default for EthClient {
111111
}
112112
}
113113

114-
#[near_bindgen]
115-
impl AdminControlled for EthClient {
116-
#[result_serializer(borsh)]
117-
fn get_paused(&self) -> Mask {
118-
self.paused
119-
}
120-
121-
#[result_serializer(borsh)]
122-
fn set_paused(&mut self, #[serializer(borsh)] paused: Mask) {
123-
self.assert_owner();
124-
self.paused = paused;
125-
}
126-
}
127-
128114
#[near_bindgen]
129115
impl EthClient {
130116
#[init]
@@ -441,3 +427,5 @@ impl EthClient {
441427
(H256(pair.0), H256(pair.1))
442428
}
443429
}
430+
431+
admin_controlled::impl_admin_controlled!(EthClient, paused);

‎contracts/near/eth-prover/src/lib.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use admin_controlled::{AdminControlled, Mask};
1+
use admin_controlled::Mask;
22
use borsh::{BorshDeserialize, BorshSerialize};
33
use eth_types::*;
44
use near_sdk::{env, ext_contract, near_bindgen, PromiseOrValue};
@@ -320,16 +320,4 @@ impl EthProver {
320320
}
321321
}
322322

323-
#[near_bindgen]
324-
impl AdminControlled for EthProver {
325-
#[result_serializer(borsh)]
326-
fn get_paused(&self) -> Mask {
327-
self.paused
328-
}
329-
330-
#[result_serializer(borsh)]
331-
fn set_paused(&mut self, #[serializer(borsh)] paused: Mask) {
332-
self.assert_owner();
333-
self.paused = paused;
334-
}
335-
}
323+
admin_controlled::impl_admin_controlled!(EthProver, paused);

0 commit comments

Comments
 (0)