Skip to content

Commit

Permalink
fix: error
Browse files Browse the repository at this point in the history
  • Loading branch information
damartripamungkas committed Nov 14, 2023
1 parent 34f897f commit 04c7ea6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/provider/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,23 @@ export default class {
this.#sendBatch = sendBatch;
}

getGasPriceLevel = async () => {
const { transactions } = await this.#ethSend.eth_getBlockByNumber("latest", false);
const arrGasPrice = transactions.map((it: any) => BigInt(it.gasPrice));
const totalValGasPrice = arrGasPrice.reduce((total: any, nilai: any) => total + nilai);
getGasPriceLevel = async (blockNumber: string) => {
const { transactions } = await this.#ethSend.eth_getBlockByNumber(blockNumber, true);
const arrGasPrice = transactions.map((it: any) => it.gasPrice);
const lengthArrGasPrice = arrGasPrice.length;
return {
veryHigh: arrGasPrice[0], // BigInt
average: totalValGasPrice / lengthArrGasPrice, // BigInt
veryLow: arrGasPrice[lengthArrGasPrice - 1], // BigInt
get all() {
return arrGasPrice.reduce((acc: any, cur: any) => BigInt(acc) + BigInt(cur), 0);
},
get top() {
return BigInt(arrGasPrice[0]);
},
get mid() {
return BigInt(arrGasPrice[lengthArrGasPrice / 2]);
},
get bottom() {
return BigInt(arrGasPrice[lengthArrGasPrice - 1]);
},
};
};

Expand Down
8 changes: 8 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,12 @@ const provider = new Provider("https://bscrpc.com", null, null, [
provider.ethBuild.eth_blockNumber()
);
console.log(`INFO: result eth_chainId, eth_blockNumber:`, getBlockNumberAndChainId);

/**
* @test custom send eth
* @info get gasPriceLevel in spesific block
* @returns Object{ all, top, mid, bottom }
*/
const getGasPriceLevel = await provider.customSend.getGasPriceLevel();
console.log(`INFO: result gasprice level top: ${getGasPriceLevel.top}`);
})();

0 comments on commit 04c7ea6

Please sign in to comment.