Skip to content

Commit

Permalink
Debug - new code refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
spacesailor24 committed Aug 5, 2021
1 parent fbfbbca commit 3ef9420
Showing 1 changed file with 60 additions and 100 deletions.
160 changes: 60 additions & 100 deletions packages/web3-core-method/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -770,70 +770,31 @@ Method.prototype.buildCall = function () {
return method.requestManager.send(payload, sendTxCallback);
};

// Send the actual transaction
// if (isSendTx
// && !!payload.params[0]
// && typeof payload.params[0] === 'object'
// && typeof payload.params[0].gasPrice === 'undefined'
// ) {

// var getGasPrice = (new Method({
// name: 'getGasPrice',
// call: 'eth_gasPrice',
// params: 0
// })).createFunction(method.requestManager);

// getGasPrice(function (err, gasPrice) {
// console.log('debug1', gasPrice, payload)

// if (gasPrice) {
// payload.params[0].gasPrice = gasPrice;
// }

// console.log('debug2', gasPrice, payload)

// if (isSendTx) {
// setTimeout(() => {
// defer.eventEmitter.emit('sending', payload);
// }, 0);
// }

// sendRequest(payload, method);
// });

// } else {
// if (isSendTx) {
// setTimeout(() => {
// defer.eventEmitter.emit('sending', payload);
// }, 0);
// }

// sendRequest(payload, method);
// }

// Send the actual transaction
if (isSendTx
&& !!payload.params[0]
&& typeof payload.params[0] === 'object'
&& typeof payload.params[0].gasPrice === 'undefined'
// && (
// typeof payload.params[0].gasPrice === 'undefined'
// && (
// typeof payload.params[0].maxPriorityFeePerGas === 'undefined'
// || typeof payload.params[0].maxFeePerGas === 'undefined'
// )
// )
&& (
typeof payload.params[0].gasPrice === 'undefined'
&& (
typeof payload.params[0].maxPriorityFeePerGas === 'undefined'
|| typeof payload.params[0].maxFeePerGas === 'undefined'
)
)
) {
// if (typeof payload.params[0].type === 'undefined')
// payload.params[0].type = _handleTxType(payload.params[0]);
if (typeof payload.params[0].type === 'undefined')
payload.params[0].type = _handleTxType(payload.params[0]);

_handleTxPricing(method, payload.params[0]).then(txPricing => {
console.log('debug1', payload)
console.log('debug3', txPricing)
if (txPricing.gasPrice)
if (txPricing.gasPrice !== undefined) {
payload.params[0].gasPrice = txPricing.gasPrice;
// payload.params[0] = {...payload.params[0], ...txPricing};
console.log('debug2', payload)
} else if (
txPricing.maxPriorityFeePerGas !== undefined
&& txPricing.maxFeePerGas !== undefined
) {
payload.params[0].maxPriorityFeePerGas = txPricing.maxPriorityFeePerGas;
payload.params[0].maxFeePerGas = txPricing.maxFeePerGas;
}

if (isSendTx) {
setTimeout(() => {
Expand Down Expand Up @@ -912,62 +873,61 @@ function _handleTxType(tx) {
function _handleTxPricing(method, tx) {
return new Promise((resolve, reject) => {
try {
// var getBlockByNumber = (new Method({
// name: 'getBlockByNumber',
// call: 'eth_getBlockByNumber',
// params: 2,
// inputFormatter: [function(blockNumber) {
// return blockNumber ? utils.toHex(blockNumber) : 'latest'
// }, function() {
// return false
// }]
// })).createFunction(method.requestManager);
var getBlockByNumber = (new Method({
name: 'getBlockByNumber',
call: 'eth_getBlockByNumber',
params: 2,
inputFormatter: [function(blockNumber) {
return blockNumber ? utils.toHex(blockNumber) : 'latest'
}, function() {
return false
}]
})).createFunction(method.requestManager);
var getGasPrice = (new Method({
name: 'getGasPrice',
call: 'eth_gasPrice',
params: 0
})).createFunction(method.requestManager);

// if (tx.type < '0x2' && tx.gasPrice !== undefined) {
// // Legacy transaction, return provided gasPrice
// resolve({ gasPrice: tx.gasPrice })
// } else {
if (tx.type < '0x2' && tx.gasPrice !== undefined) {
// Legacy transaction, return provided gasPrice
resolve({ gasPrice: tx.gasPrice })
} else {
Promise.all([
// getBlockByNumber(),
getBlockByNumber(),
getGasPrice()
]).then(responses => {
const [gasPrice] = responses;
// const [block, gasPrice] = responses;
// if (
// (tx.type === '0x2') &&
// block && block.baseFeePerGas
// ) {
// // The network supports EIP-1559
const [block, gasPrice] = responses;
if (
(tx.type === '0x2') &&
block && block.baseFeePerGas
) {
// The network supports EIP-1559

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

// if (tx.gasPrice) {
// // Using legacy gasPrice property on an eip-1559 network,
// // so use gasPrice as both fee properties
// maxPriorityFeePerGas = tx.gasPrice;
// maxFeePerGas = tx.gasPrice;
// delete tx.gasPrice;
// } else {
// maxPriorityFeePerGas = tx.maxPriorityFeePerGas || '0x3B9ACA00'; // 1 Gwei
// maxFeePerGas = tx.maxFeePerGas ||
// utils.toHex(
// utils.toBN(block.baseFeePerGas)
// .mul(utils.toBN(2))
// .add(utils.toBN(maxPriorityFeePerGas))
// );
// }
// resolve({ maxFeePerGas, maxPriorityFeePerGas });
// } else {
// if (tx.maxPriorityFeePerGas || tx.maxFeePerGas)
// throw Error("Network doesn't support eip-1559")
if (tx.gasPrice) {
// Using legacy gasPrice property on an eip-1559 network,
// so use gasPrice as both fee properties
maxPriorityFeePerGas = tx.gasPrice;
maxFeePerGas = tx.gasPrice;
delete tx.gasPrice;
} else {
maxPriorityFeePerGas = tx.maxPriorityFeePerGas || '0x3B9ACA00'; // 1 Gwei
maxFeePerGas = tx.maxFeePerGas ||
utils.toHex(
utils.toBN(block.baseFeePerGas)
.mul(utils.toBN(2))
.add(utils.toBN(maxPriorityFeePerGas))
);
}
resolve({ maxFeePerGas, maxPriorityFeePerGas });
} else {
if (tx.maxPriorityFeePerGas || tx.maxFeePerGas)
throw Error("Network doesn't support eip-1559")
resolve({ gasPrice });
// }
}
})
// }
} catch (error) {
Expand Down

0 comments on commit 3ef9420

Please sign in to comment.