Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 3ef9420

Browse files
committed
Debug - new code refactored
1 parent fbfbbca commit 3ef9420

File tree

1 file changed

+60
-100
lines changed

1 file changed

+60
-100
lines changed

packages/web3-core-method/src/index.js

+60-100
Original file line numberDiff line numberDiff line change
@@ -770,70 +770,31 @@ Method.prototype.buildCall = function () {
770770
return method.requestManager.send(payload, sendTxCallback);
771771
};
772772

773-
// Send the actual transaction
774-
// if (isSendTx
775-
// && !!payload.params[0]
776-
// && typeof payload.params[0] === 'object'
777-
// && typeof payload.params[0].gasPrice === 'undefined'
778-
// ) {
779-
780-
// var getGasPrice = (new Method({
781-
// name: 'getGasPrice',
782-
// call: 'eth_gasPrice',
783-
// params: 0
784-
// })).createFunction(method.requestManager);
785-
786-
// getGasPrice(function (err, gasPrice) {
787-
// console.log('debug1', gasPrice, payload)
788-
789-
// if (gasPrice) {
790-
// payload.params[0].gasPrice = gasPrice;
791-
// }
792-
793-
// console.log('debug2', gasPrice, payload)
794-
795-
// if (isSendTx) {
796-
// setTimeout(() => {
797-
// defer.eventEmitter.emit('sending', payload);
798-
// }, 0);
799-
// }
800-
801-
// sendRequest(payload, method);
802-
// });
803-
804-
// } else {
805-
// if (isSendTx) {
806-
// setTimeout(() => {
807-
// defer.eventEmitter.emit('sending', payload);
808-
// }, 0);
809-
// }
810-
811-
// sendRequest(payload, method);
812-
// }
813-
814773
// Send the actual transaction
815774
if (isSendTx
816775
&& !!payload.params[0]
817776
&& typeof payload.params[0] === 'object'
818-
&& typeof payload.params[0].gasPrice === 'undefined'
819-
// && (
820-
// typeof payload.params[0].gasPrice === 'undefined'
821-
// && (
822-
// typeof payload.params[0].maxPriorityFeePerGas === 'undefined'
823-
// || typeof payload.params[0].maxFeePerGas === 'undefined'
824-
// )
825-
// )
777+
&& (
778+
typeof payload.params[0].gasPrice === 'undefined'
779+
&& (
780+
typeof payload.params[0].maxPriorityFeePerGas === 'undefined'
781+
|| typeof payload.params[0].maxFeePerGas === 'undefined'
782+
)
783+
)
826784
) {
827-
// if (typeof payload.params[0].type === 'undefined')
828-
// payload.params[0].type = _handleTxType(payload.params[0]);
785+
if (typeof payload.params[0].type === 'undefined')
786+
payload.params[0].type = _handleTxType(payload.params[0]);
829787

830788
_handleTxPricing(method, payload.params[0]).then(txPricing => {
831-
console.log('debug1', payload)
832-
console.log('debug3', txPricing)
833-
if (txPricing.gasPrice)
789+
if (txPricing.gasPrice !== undefined) {
834790
payload.params[0].gasPrice = txPricing.gasPrice;
835-
// payload.params[0] = {...payload.params[0], ...txPricing};
836-
console.log('debug2', payload)
791+
} else if (
792+
txPricing.maxPriorityFeePerGas !== undefined
793+
&& txPricing.maxFeePerGas !== undefined
794+
) {
795+
payload.params[0].maxPriorityFeePerGas = txPricing.maxPriorityFeePerGas;
796+
payload.params[0].maxFeePerGas = txPricing.maxFeePerGas;
797+
}
837798

838799
if (isSendTx) {
839800
setTimeout(() => {
@@ -912,62 +873,61 @@ function _handleTxType(tx) {
912873
function _handleTxPricing(method, tx) {
913874
return new Promise((resolve, reject) => {
914875
try {
915-
// var getBlockByNumber = (new Method({
916-
// name: 'getBlockByNumber',
917-
// call: 'eth_getBlockByNumber',
918-
// params: 2,
919-
// inputFormatter: [function(blockNumber) {
920-
// return blockNumber ? utils.toHex(blockNumber) : 'latest'
921-
// }, function() {
922-
// return false
923-
// }]
924-
// })).createFunction(method.requestManager);
876+
var getBlockByNumber = (new Method({
877+
name: 'getBlockByNumber',
878+
call: 'eth_getBlockByNumber',
879+
params: 2,
880+
inputFormatter: [function(blockNumber) {
881+
return blockNumber ? utils.toHex(blockNumber) : 'latest'
882+
}, function() {
883+
return false
884+
}]
885+
})).createFunction(method.requestManager);
925886
var getGasPrice = (new Method({
926887
name: 'getGasPrice',
927888
call: 'eth_gasPrice',
928889
params: 0
929890
})).createFunction(method.requestManager);
930891

931-
// if (tx.type < '0x2' && tx.gasPrice !== undefined) {
932-
// // Legacy transaction, return provided gasPrice
933-
// resolve({ gasPrice: tx.gasPrice })
934-
// } else {
892+
if (tx.type < '0x2' && tx.gasPrice !== undefined) {
893+
// Legacy transaction, return provided gasPrice
894+
resolve({ gasPrice: tx.gasPrice })
895+
} else {
935896
Promise.all([
936-
// getBlockByNumber(),
897+
getBlockByNumber(),
937898
getGasPrice()
938899
]).then(responses => {
939-
const [gasPrice] = responses;
940-
// const [block, gasPrice] = responses;
941-
// if (
942-
// (tx.type === '0x2') &&
943-
// block && block.baseFeePerGas
944-
// ) {
945-
// // The network supports EIP-1559
900+
const [block, gasPrice] = responses;
901+
if (
902+
(tx.type === '0x2') &&
903+
block && block.baseFeePerGas
904+
) {
905+
// The network supports EIP-1559
946906

947-
// // Taken from https://github.com/ethers-io/ethers.js/blob/ba6854bdd5a912fe873d5da494cb5c62c190adde/packages/abstract-provider/src.ts/index.ts#L230
948-
// let maxPriorityFeePerGas, maxFeePerGas;
907+
// Taken from https://github.com/ethers-io/ethers.js/blob/ba6854bdd5a912fe873d5da494cb5c62c190adde/packages/abstract-provider/src.ts/index.ts#L230
908+
let maxPriorityFeePerGas, maxFeePerGas;
949909

950-
// if (tx.gasPrice) {
951-
// // Using legacy gasPrice property on an eip-1559 network,
952-
// // so use gasPrice as both fee properties
953-
// maxPriorityFeePerGas = tx.gasPrice;
954-
// maxFeePerGas = tx.gasPrice;
955-
// delete tx.gasPrice;
956-
// } else {
957-
// maxPriorityFeePerGas = tx.maxPriorityFeePerGas || '0x3B9ACA00'; // 1 Gwei
958-
// maxFeePerGas = tx.maxFeePerGas ||
959-
// utils.toHex(
960-
// utils.toBN(block.baseFeePerGas)
961-
// .mul(utils.toBN(2))
962-
// .add(utils.toBN(maxPriorityFeePerGas))
963-
// );
964-
// }
965-
// resolve({ maxFeePerGas, maxPriorityFeePerGas });
966-
// } else {
967-
// if (tx.maxPriorityFeePerGas || tx.maxFeePerGas)
968-
// throw Error("Network doesn't support eip-1559")
910+
if (tx.gasPrice) {
911+
// Using legacy gasPrice property on an eip-1559 network,
912+
// so use gasPrice as both fee properties
913+
maxPriorityFeePerGas = tx.gasPrice;
914+
maxFeePerGas = tx.gasPrice;
915+
delete tx.gasPrice;
916+
} else {
917+
maxPriorityFeePerGas = tx.maxPriorityFeePerGas || '0x3B9ACA00'; // 1 Gwei
918+
maxFeePerGas = tx.maxFeePerGas ||
919+
utils.toHex(
920+
utils.toBN(block.baseFeePerGas)
921+
.mul(utils.toBN(2))
922+
.add(utils.toBN(maxPriorityFeePerGas))
923+
);
924+
}
925+
resolve({ maxFeePerGas, maxPriorityFeePerGas });
926+
} else {
927+
if (tx.maxPriorityFeePerGas || tx.maxFeePerGas)
928+
throw Error("Network doesn't support eip-1559")
969929
resolve({ gasPrice });
970-
// }
930+
}
971931
})
972932
// }
973933
} catch (error) {

0 commit comments

Comments
 (0)