web3-core-method
Advanced tools
Comparing version 1.5.1 to 1.5.2-rc.0
@@ -29,3 +29,2 @@ /* | ||
var Subscriptions = require('web3-core-subscriptions').subscriptions; | ||
var HardForks = require('@ethereumjs/common').Hardfork; | ||
var EthersTransactionUtils = require('@ethersproject/transactions'); | ||
@@ -626,4 +625,2 @@ var Method = function Method(options) { | ||
|| typeof payload.params[0].maxFeePerGas === 'undefined'))) { | ||
if (typeof payload.params[0].type === 'undefined') | ||
payload.params[0].type = _handleTxType(payload.params[0]); | ||
_handleTxPricing(method, payload.params[0]).then(txPricing => { | ||
@@ -667,31 +664,2 @@ if (txPricing.gasPrice !== undefined) { | ||
}; | ||
function _handleTxType(tx) { | ||
// Taken from https://github.com/ethers-io/ethers.js/blob/2a7ce0e72a1e0c9469e10392b0329e75e341cf18/packages/abstract-signer/src.ts/index.ts#L215 | ||
const hasEip1559 = (tx.maxFeePerGas !== undefined || tx.maxPriorityFeePerGas !== undefined); | ||
let txType; | ||
if (tx.type !== undefined) { | ||
txType = utils.toHex(tx.type); | ||
} | ||
else if (tx.type === undefined && hasEip1559) { | ||
txType = '0x2'; | ||
} | ||
else { | ||
txType = '0x0'; | ||
} | ||
if (tx.gasPrice !== undefined && (txType === '0x2' || hasEip1559)) | ||
throw Error("eip-1559 transactions don't support gasPrice"); | ||
if ((txType === '0x1' || txType === '0x0') && hasEip1559) | ||
throw Error("pre-eip-1559 transaction don't support maxFeePerGas/maxPriorityFeePerGas"); | ||
if (hasEip1559 || | ||
((tx.common && tx.common.hardfork && tx.common.hardfork.toLowerCase() === HardForks.London) || | ||
(tx.hardfork && tx.hardfork.toLowerCase() === HardForks.London))) { | ||
txType = '0x2'; | ||
} | ||
else if (tx.accessList || | ||
((tx.common && tx.common.hardfork && tx.common.hardfork.toLowerCase() === HardForks.Berlin) || | ||
(tx.hardfork && tx.hardfork.toLowerCase() === HardForks.Berlin))) { | ||
txType = '0x1'; | ||
} | ||
return txType; | ||
} | ||
function _handleTxPricing(method, tx) { | ||
@@ -715,40 +683,33 @@ return new Promise((resolve, reject) => { | ||
})).createFunction(method.requestManager); | ||
if (tx.type < '0x2' && tx.gasPrice !== undefined) { | ||
// Legacy transaction, return provided gasPrice | ||
resolve({ gasPrice: tx.gasPrice }); | ||
} | ||
else { | ||
Promise.all([ | ||
getBlockByNumber(), | ||
getGasPrice() | ||
]).then(responses => { | ||
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; | ||
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 }); | ||
Promise.all([ | ||
getBlockByNumber(), | ||
getGasPrice() | ||
]).then(responses => { | ||
const [block, gasPrice] = responses; | ||
if (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; | ||
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 { | ||
if (tx.maxPriorityFeePerGas || tx.maxFeePerGas) | ||
throw Error("Network doesn't support eip-1559"); | ||
resolve({ gasPrice }); | ||
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 }); | ||
} | ||
}); | ||
} | ||
@@ -755,0 +716,0 @@ catch (error) { |
{ | ||
"name": "web3-core-method", | ||
"version": "1.5.1", | ||
"version": "1.5.2-rc.0", | ||
"description": "Creates the methods on the web3 modules. This is an internal package.", | ||
@@ -19,6 +19,6 @@ "repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-core-method", | ||
"@ethersproject/transactions": "^5.0.0-beta.135", | ||
"web3-core-helpers": "1.5.1", | ||
"web3-core-promievent": "1.5.1", | ||
"web3-core-subscriptions": "1.5.1", | ||
"web3-utils": "1.5.1" | ||
"web3-core-helpers": "1.5.2-rc.0", | ||
"web3-core-promievent": "1.5.2-rc.0", | ||
"web3-core-subscriptions": "1.5.2-rc.0", | ||
"web3-utils": "1.5.2-rc.0" | ||
}, | ||
@@ -29,3 +29,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "37a046d53ba193e89f3c53921c8b0ddc6a2e86fe" | ||
"gitHead": "6a92e72388767e94e838a9c1d6c4c486d6b5176e" | ||
} |
114
src/index.js
@@ -31,3 +31,2 @@ /* | ||
var Subscriptions = require('web3-core-subscriptions').subscriptions; | ||
var HardForks = require('@ethereumjs/common').Hardfork; | ||
@@ -786,5 +785,2 @@ var EthersTransactionUtils = require('@ethersproject/transactions'); | ||
) { | ||
if (typeof payload.params[0].type === 'undefined') | ||
payload.params[0].type = _handleTxType(payload.params[0]); | ||
_handleTxPricing(method, payload.params[0]).then(txPricing => { | ||
@@ -835,42 +831,2 @@ if (txPricing.gasPrice !== undefined) { | ||
function _handleTxType(tx) { | ||
// Taken from https://github.com/ethers-io/ethers.js/blob/2a7ce0e72a1e0c9469e10392b0329e75e341cf18/packages/abstract-signer/src.ts/index.ts#L215 | ||
const hasEip1559 = (tx.maxFeePerGas !== undefined || tx.maxPriorityFeePerGas !== undefined); | ||
let txType; | ||
if (tx.type !== undefined) { | ||
txType = utils.toHex(tx.type) | ||
} else if (tx.type === undefined && hasEip1559) { | ||
txType = '0x2' | ||
} else { | ||
txType = '0x0' | ||
} | ||
if (tx.gasPrice !== undefined && (txType === '0x2' || hasEip1559)) | ||
throw Error("eip-1559 transactions don't support gasPrice"); | ||
if ((txType === '0x1' || txType === '0x0') && hasEip1559) | ||
throw Error("pre-eip-1559 transaction don't support maxFeePerGas/maxPriorityFeePerGas"); | ||
if ( | ||
hasEip1559 || | ||
( | ||
(tx.common && tx.common.hardfork && tx.common.hardfork.toLowerCase() === HardForks.London) || | ||
(tx.hardfork && tx.hardfork.toLowerCase() === HardForks.London) | ||
) | ||
) { | ||
txType = '0x2'; | ||
} else if ( | ||
tx.accessList || | ||
( | ||
(tx.common && tx.common.hardfork && tx.common.hardfork.toLowerCase() === HardForks.Berlin) || | ||
(tx.hardfork && tx.hardfork.toLowerCase() === HardForks.Berlin) | ||
) | ||
) { | ||
txType = '0x1'; | ||
} | ||
return txType | ||
} | ||
function _handleTxPricing(method, tx) { | ||
@@ -895,43 +851,35 @@ return new Promise((resolve, reject) => { | ||
if (tx.type < '0x2' && tx.gasPrice !== undefined) { | ||
// Legacy transaction, return provided gasPrice | ||
resolve({ gasPrice: tx.gasPrice }) | ||
} else { | ||
Promise.all([ | ||
getBlockByNumber(), | ||
getGasPrice() | ||
]).then(responses => { | ||
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; | ||
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 }); | ||
Promise.all([ | ||
getBlockByNumber(), | ||
getGasPrice() | ||
]).then(responses => { | ||
const [block, gasPrice] = responses; | ||
if (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; | ||
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 { | ||
if (tx.maxPriorityFeePerGas || tx.maxFeePerGas) | ||
throw Error("Network doesn't support eip-1559") | ||
resolve({ gasPrice }); | ||
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) { | ||
@@ -938,0 +886,0 @@ reject(error) |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
75644
1658
1
+ Addedweb3-core-helpers@1.5.2-rc.0(transitive)
+ Addedweb3-core-promievent@1.5.2-rc.0(transitive)
+ Addedweb3-core-subscriptions@1.5.2-rc.0(transitive)
+ Addedweb3-eth-iban@1.5.2-rc.0(transitive)
+ Addedweb3-utils@1.5.2-rc.0(transitive)
- Removedweb3-core-helpers@1.5.1(transitive)
- Removedweb3-core-promievent@1.5.1(transitive)
- Removedweb3-core-subscriptions@1.5.1(transitive)
- Removedweb3-eth-iban@1.5.1(transitive)
- Removedweb3-utils@1.5.1(transitive)
Updatedweb3-core-helpers@1.5.2-rc.0
Updatedweb3-utils@1.5.2-rc.0