Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shunjizhan committed Dec 4, 2023
1 parent 4ccf7ba commit b6b6d2a
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions packages/eth-providers/src/base-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,11 @@ export abstract class BaseProvider extends AbstractProvider {
transaction: Deferrable<TransactionRequest>,
blockTag?: BlockTag | Promise<BlockTag>
): Promise<BigNumber> => {
const { usedGas, gasLimit, usedStorage } = await this.estimateResources(transaction, blockTag);
const blockHash = blockTag && blockTag !== 'latest'
? await this._getBlockHash(blockTag)
: undefined; // if blockTag is latest, avoid explicit blockhash for better performance

const { usedGas, gasLimit, usedStorage } = await this.estimateResources(transaction, blockHash);

const tx = await resolveProperties(transaction);
const data = tx.data?.toString() ?? '0x';
Expand Down Expand Up @@ -968,9 +972,13 @@ export abstract class BaseProvider extends AbstractProvider {
return encodeGasLimit(txFee, gasPrice, gasLimit, usedStorage, isTokenTransfer);
};

_estimateGasCost = async (extrinsic: SubmittableExtrinsic<'promise', ISubmittableResult>) => {
_estimateGasCost = async (
extrinsic: SubmittableExtrinsic<'promise', ISubmittableResult>,
at?: string,
) => {
const apiAt = await this.api.at(at ?? await this.bestBlockHash);

const u8a = extrinsic.toU8a();
const apiAt = await this.api.at(await this.bestBlockHash);
const lenIncreaseAfterSignature = 100; // approximate length increase after signature
const feeDetails = await apiAt.call.transactionPaymentApi.queryFeeDetails(
u8a,
Expand Down Expand Up @@ -1102,7 +1110,7 @@ export abstract class BaseProvider extends AbstractProvider {
*/
estimateResources = async (
transaction: Deferrable<TransactionRequest>,
blockTag?: BlockTag | Promise<BlockTag>,
blockHash?: string,
): Promise<{
usedGas: BigNumber;
gasLimit: BigNumber;
Expand All @@ -1120,10 +1128,6 @@ export abstract class BaseProvider extends AbstractProvider {
storageLimit: STORAGE_LIMIT,
};

const blockHash = blockTag && blockTag !== 'latest'
? await this._getBlockHash(blockTag)
: undefined; // if blockTag is latest, avoid explicit blockhash for better performance

const gasInfo = await this._ethCall(txRequest, blockHash);
const usedGas = BigNumber.from(gasInfo.used_gas).toNumber();
const usedStorage = gasInfo.used_storage;
Expand Down

0 comments on commit b6b6d2a

Please sign in to comment.