Skip to content

Commit f74a5ee

Browse files
author
Yasir
authored
Merge pull request #75 from bitfinity-network/fix/estimate-gas-api
fix: estimate-gas-api
2 parents 6f946fe + 8cc3251 commit f74a5ee

4 files changed

Lines changed: 67 additions & 38 deletions

File tree

.github/workflows/build-test.yml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
name: "Build Test"
1+
name: 'Build Test'
22

33
on:
44
pull_request:
55
branches: [main]
66
paths-ignore:
7-
- "**/README.md"
7+
- '**/README.md'
88
push:
99
branches: [main]
1010
tags:
11-
- "v*"
11+
- 'v*'
1212
paths-ignore:
13-
- "**/README.md"
13+
- '**/README.md'
1414

1515
jobs:
1616
build-test:
1717
if: ${{github.ref_type != 'tag'}}
18-
name: "Build and Test"
18+
name: 'Build and Test'
1919
uses: bitfinity-network/ci-wf/.github/workflows/build-n-test.yml@main
2020
with:
2121
runs-on: ubuntu-latest
22-
container-image: ghcr.io/bitfinity-network/ic-dev-base:rust1.72-dfx0.15
23-
git-fetch-depth: "0"
22+
container-image: ghcr.io/bitfinity-network/ic-dev-base:rust1.73-dfx0.15
23+
git-fetch-depth: '0'
2424
skip-test: false
2525
audit-allow-warnings: true
26-
cargo-clippy-extra-args: "-- -D warnings"
26+
cargo-clippy-extra-args: '-- -D warnings'
2727
enable-target-cache: true
2828
test-script: |
2929
export RUST_BACKTRACE="full"
3030
./scripts/test.sh
3131
./scripts/build.sh
3232
./scripts/dfx_test.sh
33-
33+
3434
secrets:
3535
gh_login: ${{ secrets.GH_PKG_LOGIN }}
3636
gh_token: ${{ secrets.GH_PKG_TOKEN }}
@@ -45,7 +45,7 @@ jobs:
4545
os: ubuntu-latest
4646
target: x86_64-unknown-linux-gnu
4747
bin: register-evm-agent
48-
48+
4949
- release_for: Windows-x86_64
5050
os: windows-latest
5151
target: x86_64-pc-windows-msvc
@@ -55,7 +55,7 @@ jobs:
5555
os: macos-latest
5656
target: x86_64-apple-darwin
5757
bin: register-evm-agent
58-
58+
5959
- release_for: MacOS-M1
6060
os: macos-latest
6161
target: aarch64-apple-darwin
@@ -72,14 +72,14 @@ jobs:
7272
target: ${{ matrix.platform.target }}
7373
command: build
7474
strip: true
75-
args: "--release -p register_evm_agent"
75+
args: '--release -p register_evm_agent'
7676

7777
- name: Prepare artifact files
7878
run: |
7979
mkdir -p ./target/artifact
8080
mv target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }} ./target/artifact/${{ matrix.platform.bin }}
81-
82-
- name: "Uploading artifact"
81+
82+
- name: 'Uploading artifact'
8383
uses: actions/upload-artifact@v3
8484
with:
8585
if-no-files-found: error
@@ -92,25 +92,25 @@ jobs:
9292
needs: [release-binaries]
9393
runs-on: ubuntu-latest
9494
steps:
95-
- name: "Artifact Linux"
95+
- name: 'Artifact Linux'
9696
uses: actions/download-artifact@v3
9797
with:
9898
name: Linux-x86_64
9999
path: ./linux
100-
101-
- name: "Artifact MacOs"
100+
101+
- name: 'Artifact MacOs'
102102
uses: actions/download-artifact@v3
103103
with:
104104
name: MacOS-x86_64
105105
path: ./macos
106106

107-
- name: "Artifact MacOs M1"
107+
- name: 'Artifact MacOs M1'
108108
uses: actions/download-artifact@v3
109109
with:
110110
name: MacOS-M1
111111
path: ./macos-m1
112-
113-
- name: "Artifact Windows"
112+
113+
- name: 'Artifact Windows'
114114
uses: actions/download-artifact@v3
115115
with:
116116
name: Windows-x86_64

src/did/src/gas.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use candid::CandidType;
2+
use serde::{Deserialize, Serialize};
3+
4+
use crate::transaction::AccessList;
5+
use crate::{Bytes, H160, U256};
6+
7+
#[derive(Debug, Clone, Default, Eq, PartialEq, Serialize, CandidType, Deserialize)]
8+
/// The `estimate_gas` method parameters
9+
pub struct EstimateGasRequest {
10+
pub from: Option<H160>,
11+
pub to: Option<H160>,
12+
#[serde(rename = "gasPrice", default, skip_serializing_if = "Option::is_none")]
13+
pub gas_price: Option<U256>,
14+
/// EIP-1559 Max base fee the caller is willing to pay
15+
#[serde(
16+
rename = "maxFeePerGas",
17+
default,
18+
skip_serializing_if = "Option::is_none"
19+
)]
20+
pub max_fee_per_gas: Option<U256>,
21+
/// EIP-1559 Priority fee the caller is paying to the block author
22+
#[serde(
23+
rename = "maxPriorityFeePerGas",
24+
default,
25+
skip_serializing_if = "Option::is_none"
26+
)]
27+
pub max_priority_fee_per_gas: Option<U256>,
28+
pub gas: Option<U256>,
29+
pub value: Option<U256>,
30+
pub data: Option<Bytes>,
31+
pub nonce: Option<U256>,
32+
#[serde(rename = "chainId", default, skip_serializing_if = "Option::is_none")]
33+
pub chain_id: Option<U256>,
34+
#[serde(
35+
rename = "accessList",
36+
default,
37+
skip_serializing_if = "Option::is_none"
38+
)]
39+
pub access_list: Option<AccessList>,
40+
}

src/did/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub mod bytes;
88
pub mod codec;
99
pub mod constant;
1010
pub mod error;
11+
pub mod gas;
1112
pub mod hash;
1213
pub mod ic;
1314
pub mod integer;
@@ -24,6 +25,7 @@ pub use block::Block;
2425
use candid::{CandidType, Deserialize};
2526
pub use error::{ExitFatal, HaltError};
2627
pub use fees::FeeHistory;
28+
pub use gas::*;
2729
pub use hash::{H160, H256, H64};
2830
pub use integer::{U256, U64};
2931
pub use mint_order_exemption::MintOrderExemptionUserData;

src/evm-canister-client/src/client.rs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use candid::Principal;
22
use did::block::{BlockResult, ExeResult};
33
use did::error::Result;
44
use did::{
5-
BasicAccount, Block, BlockNumber, Bytes, Transaction, TransactionReceipt, H160, H256, U256,
5+
BasicAccount, Block, BlockNumber, Bytes, EstimateGasRequest, Transaction, TransactionReceipt,
6+
H160, H256, U256,
67
};
78
use ic_canister_client::{CanisterClient, CanisterClientResult};
89

@@ -329,29 +330,15 @@ impl<C: CanisterClient> EvmCanisterClient<C> {
329330
///
330331
/// # Arguments
331332
///
332-
/// * `from` - The address of the caller
333-
/// * `to` - The address of the contract to call
334-
/// * `gas_limit` - The gas limit for the call
335-
/// * `value` - The value to send to the contract
336-
/// * `input` - The data to send to the contract
337-
///
333+
/// * `request` - The request to estimate the gas for the call
338334
/// # Returns
339335
///
340336
/// The estimated gas for the call
341337
pub async fn eth_estimate_gas(
342338
&self,
343-
from: H160,
344-
to: Option<H160>,
345-
gas_limit: u64,
346-
value: U256,
347-
input: Bytes,
339+
request: EstimateGasRequest,
348340
) -> CanisterClientResult<EvmResult<U256>> {
349-
self.client
350-
.query(
351-
"eth_estimate_gas",
352-
(from, to, gas_limit, value, gas_limit, input),
353-
)
354-
.await
341+
self.client.query("eth_estimate_gas", (request,)).await
355342
}
356343

357344
/// Get the transaction count at a given block hash

0 commit comments

Comments
 (0)