Skip to content

Commit

Permalink
chore: misc. implementation review follow-ups (#141)
Browse files Browse the repository at this point in the history
* Progress

* Update readme

* Fix 'get_authorized()' condition

* Misc

* Replace 'rvanasa/wasm-bindgen' with 'dfinity/wasm-bindgen'

* Update Cargo.lock

* Specify features for 'getrandom'

* Update tests

* Automatically revoke 'RegisterProvider' permission after registering a provider

* Change trap message for consistency

* Update tests

* Change return type of 'getAuthorized()' to 'vec Principal'

* Misc

* Fix Candid interface

* Fix
  • Loading branch information
rvanasa authored Jan 23, 2024
1 parent 71f957c commit 632ad9c
Show file tree
Hide file tree
Showing 14 changed files with 248 additions and 1,186 deletions.
1,050 changes: 202 additions & 848 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ inherits = "release"

[dependencies]
candid = { workspace = true }
getrandom = { workspace = true }
ic-canister-log = { workspace = true }
ic-canisters-http-types = { workspace = true }
ic-nervous-system-common = { workspace = true }
Expand All @@ -26,7 +27,6 @@ ic-stable-structures = { workspace = true }
ic-certified-map = { workspace = true }
ic-cdk = { workspace = true }
ic-cdk-macros = { workspace = true }
ic-eth = { workspace = true }
cketh-common = { git = "https://github.com/rvanasa/ic", rev = "e9bf2ad9decb97f9fefb8190719c69c0281aef37", package = "ic-cketh-minter" }
maplit = "1.0"
num = "0.4"
Expand All @@ -48,6 +48,7 @@ assert_matches = "1.5"

[workspace.dependencies]
candid = { version = "0.9" }
getrandom = { version = "0.2", features = ["custom"] }
ic-canister-log = { git = "https://github.com/dfinity/ic", rev = "release-2023-09-27_23-01" }
ic-canisters-http-types = { git = "https://github.com/dfinity/ic", rev = "release-2023-09-27_23-01" }
ic-nervous-system-common = { git = "https://github.com/dfinity/ic", rev = "release-2023-09-27_23-01" }
Expand All @@ -57,10 +58,9 @@ ic-certified-map = "0.4"
ic-cdk = "0.10"
ic-cdk-macros = "0.7"
ic-cdk-bindgen = "0.1"
ic-eth = { path = "lib/rust" }

[patch.crates-io]
wasm-bindgen = { git = "https://github.com/rvanasa/wasm-bindgen", rev = "62965b0749ca68237e2ab3da487c141a5b3dbd2d" }
wasm-bindgen = { git = "https://github.com/dfinity/wasm-bindgen", rev = "77722c689ed4f2392685efd348c91c7d72e5d07f" }

[workspace]
members = ["lib/rust", "e2e/rust"]
members = ["e2e/rust"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Run the following commands to run the canister in your local environment:
dfx start --background

# Deploy the `evm_rpc` canister
dfx deploy evm_rpc
dfx deploy evm_rpc --argument '(record { nodesInSubnet = 13 })'

# Call the `eth_gasPrice` JSON-RPC method
dfx canister call evm_rpc request '(variant {Url="https://cloudflare-eth.com/v1/mainnet"}, "{\"jsonrpc\":\"2.0\",\"method\":\"eth_gasPrice\",\"params\":[],\"id\":1}", 1000)' --wallet $(dfx identity get-wallet) --with-cycles 600000000
Expand Down
2 changes: 1 addition & 1 deletion candid/evm_rpc.did
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ service : (InitArgs) -> {
eth_getTransactionReceipt : (RpcSource, text) -> (MultiGetTransactionReceiptResult);
eth_sendRawTransaction : (RpcSource, text) -> (MultiSendRawTransactionResult);
getAccumulatedCycleCount : (nat64) -> (nat) query;
getAuthorized : (Auth) -> (vec text) query;
getAuthorized : (Auth) -> (vec principal) query;
getMetrics : () -> (Metrics) query;
getOpenRpcAccess : () -> (bool) query;
getProviders : () -> (vec ProviderView) query;
Expand Down
1 change: 0 additions & 1 deletion e2e/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ candid = { workspace = true }
ic-certified-map = { workspace = true }
ic-cdk = { workspace = true }
ic-cdk-macros = { workspace = true }
ic-eth = { workspace = true }
serde = "1"
serde_bytes = "0.11"

Expand Down
28 changes: 0 additions & 28 deletions lib/rust/Cargo.toml

This file was deleted.

9 changes: 0 additions & 9 deletions lib/rust/src/abi.rs

This file was deleted.

18 changes: 0 additions & 18 deletions lib/rust/src/lib.rs

This file was deleted.

234 changes: 0 additions & 234 deletions lib/rust/src/rpc.rs

This file was deleted.

10 changes: 0 additions & 10 deletions lib/rust/src/utils.rs

This file was deleted.

8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ fn register_provider(provider: RegisterProviderArgs) -> u64 {
do_register_provider(ic_cdk::caller(), provider)
}

#[update(name = "unregisterProvider", guard = "require_register_provider")]
#[update(name = "unregisterProvider")]
#[candid_method(rename = "unregisterProvider")]
fn unregister_provider(provider_id: u64) -> bool {
do_unregister_provider(ic_cdk::caller(), provider_id)
Expand Down Expand Up @@ -307,12 +307,12 @@ fn authorize(principal: Principal, auth: Auth) {

#[query(name = "getAuthorized", guard = "require_admin_or_controller")]
#[candid_method(query, rename = "getAuthorized")]
fn get_authorized(auth: Auth) -> Vec<String> {
fn get_authorized(auth: Auth) -> Vec<Principal> {
AUTH.with(|a| {
let mut result = Vec::new();
for (k, v) in a.borrow().iter() {
if !v.is_authorized(auth) {
result.push(k.0.to_string());
if v.is_authorized(auth) {
result.push(k.0);
}
}
result
Expand Down
Loading

0 comments on commit 632ad9c

Please sign in to comment.