From 162b0a04400f36d7327c29660b31a5f4a9c82197 Mon Sep 17 00:00:00 2001 From: nivida Date: Fri, 22 Nov 2019 10:11:16 +0100 Subject: [PATCH 01/14] hexToNumber call replaced with hexToNumberString if required --- packages/web3-core-helpers/src/formatters.js | 38 ++++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/web3-core-helpers/src/formatters.js b/packages/web3-core-helpers/src/formatters.js index d96a17330fb..e24807f42a5 100644 --- a/packages/web3-core-helpers/src/formatters.js +++ b/packages/web3-core-helpers/src/formatters.js @@ -225,13 +225,13 @@ var inputSignFormatter = function (data) { */ var outputTransactionFormatter = function (tx) { if (tx.blockNumber !== null) - tx.blockNumber = utils.hexToNumber(tx.blockNumber); + tx.blockNumber = utils.hexToNumberString(tx.blockNumber); if (tx.transactionIndex !== null) tx.transactionIndex = utils.hexToNumber(tx.transactionIndex); - tx.nonce = utils.hexToNumber(tx.nonce); - tx.gas = utils.hexToNumber(tx.gas); - tx.gasPrice = outputBigNumberFormatter(tx.gasPrice); - tx.value = outputBigNumberFormatter(tx.value); + tx.nonce = utils.hexToNumberString(tx.nonce); + tx.gas = utils.hexToNumberString(tx.gas); + tx.gasPrice = utils.hexToNumberString(tx.gasPrice); + tx.value = utils.hexToNumberString(tx.value); if (tx.to && utils.isAddress(tx.to)) { // tx.to could be `0x0` or `null` while contract creation tx.to = utils.toChecksumAddress(tx.to); @@ -259,11 +259,11 @@ var outputTransactionReceiptFormatter = function (receipt) { } if (receipt.blockNumber !== null) - receipt.blockNumber = utils.hexToNumber(receipt.blockNumber); + receipt.blockNumber = utils.hexToNumberString(receipt.blockNumber); if (receipt.transactionIndex !== null) receipt.transactionIndex = utils.hexToNumber(receipt.transactionIndex); - receipt.cumulativeGasUsed = utils.hexToNumber(receipt.cumulativeGasUsed); - receipt.gasUsed = utils.hexToNumber(receipt.gasUsed); + receipt.cumulativeGasUsed = utils.hexToNumberString(receipt.cumulativeGasUsed); + receipt.gasUsed = utils.hexToNumberString(receipt.gasUsed); if (_.isArray(receipt.logs)) { receipt.logs = receipt.logs.map(outputLogFormatter); @@ -290,17 +290,17 @@ var outputTransactionReceiptFormatter = function (receipt) { var outputBlockFormatter = function (block) { // transform to number - block.gasLimit = utils.hexToNumber(block.gasLimit); - block.gasUsed = utils.hexToNumber(block.gasUsed); - block.size = utils.hexToNumber(block.size); - block.timestamp = utils.hexToNumber(block.timestamp); + block.gasLimit = utils.hexToNumberString(block.gasLimit); + block.gasUsed = utils.hexToNumberString(block.gasUsed); + block.size = utils.hexToNumberString(block.size); + block.timestamp = utils.hexToNumberString(block.timestamp); if (block.number !== null) - block.number = utils.hexToNumber(block.number); + block.number = utils.hexToNumberString(block.number); if (block.difficulty) - block.difficulty = outputBigNumberFormatter(block.difficulty); + block.difficulty = utils.hexToNumber(block.difficulty); if (block.totalDifficulty) - block.totalDifficulty = outputBigNumberFormatter(block.totalDifficulty); + block.totalDifficulty = utils.hexToNumber(block.totalDifficulty); if (_.isArray(block.transactions)) { block.transactions.forEach(function (item) { @@ -380,7 +380,7 @@ var outputLogFormatter = function (log) { } if (log.blockNumber !== null) - log.blockNumber = utils.hexToNumber(log.blockNumber); + log.blockNumber = utils.hexToNumberString(log.blockNumber); if (log.transactionIndex !== null) log.transactionIndex = utils.hexToNumber(log.transactionIndex); if (log.logIndex !== null) @@ -469,9 +469,9 @@ var inputAddressFormatter = function (address) { var outputSyncingFormatter = function (result) { - result.startingBlock = utils.hexToNumber(result.startingBlock); - result.currentBlock = utils.hexToNumber(result.currentBlock); - result.highestBlock = utils.hexToNumber(result.highestBlock); + result.startingBlock = utils.hexToNumberString(result.startingBlock); + result.currentBlock = utils.hexToNumberString(result.currentBlock); + result.highestBlock = utils.hexToNumberString(result.highestBlock); if (result.knownStates) { result.knownStates = utils.hexToNumber(result.knownStates); result.pulledStates = utils.hexToNumber(result.pulledStates); From ecb0fa4a931524c2ad93ca3f051dcf4899b9c628 Mon Sep 17 00:00:00 2001 From: nivida Date: Fri, 22 Nov 2019 10:14:43 +0100 Subject: [PATCH 02/14] hexToNumber replaced with hexToNumberString in formatters.outputBlockFormatter --- packages/web3-core-helpers/src/formatters.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/web3-core-helpers/src/formatters.js b/packages/web3-core-helpers/src/formatters.js index e24807f42a5..4ec0b71067f 100644 --- a/packages/web3-core-helpers/src/formatters.js +++ b/packages/web3-core-helpers/src/formatters.js @@ -298,9 +298,9 @@ var outputBlockFormatter = function (block) { block.number = utils.hexToNumberString(block.number); if (block.difficulty) - block.difficulty = utils.hexToNumber(block.difficulty); + block.difficulty = utils.hexToNumberString(block.difficulty); if (block.totalDifficulty) - block.totalDifficulty = utils.hexToNumber(block.totalDifficulty); + block.totalDifficulty = utils.hexToNumberString(block.totalDifficulty); if (_.isArray(block.transactions)) { block.transactions.forEach(function (item) { From 283ce79bb61dd594d4fec4505992caefdfd8fa69 Mon Sep 17 00:00:00 2001 From: nivida Date: Fri, 22 Nov 2019 10:27:51 +0100 Subject: [PATCH 03/14] hexToNumberString replaced with formatters.outputBigNumberFormatter --- packages/web3-core-helpers/src/formatters.js | 42 ++++++++++---------- packages/web3-eth/src/index.js | 2 +- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/packages/web3-core-helpers/src/formatters.js b/packages/web3-core-helpers/src/formatters.js index 4ec0b71067f..4715905d19e 100644 --- a/packages/web3-core-helpers/src/formatters.js +++ b/packages/web3-core-helpers/src/formatters.js @@ -52,8 +52,8 @@ var inputStorageKeysFormatter = function (keys) { */ var outputProofFormatter = function (proof) { proof.address = utils.toChecksumAddress(proof.address); - proof.nonce = utils.hexToNumberString(proof.nonce); - proof.balance = utils.hexToNumberString(proof.balance); + proof.nonce = outputBigNumberFormatter(proof.nonce); + proof.balance = outputBigNumberFormatter(proof.balance); return proof; }; @@ -225,13 +225,13 @@ var inputSignFormatter = function (data) { */ var outputTransactionFormatter = function (tx) { if (tx.blockNumber !== null) - tx.blockNumber = utils.hexToNumberString(tx.blockNumber); + tx.blockNumber = outputBigNumberFormatter(tx.blockNumber); if (tx.transactionIndex !== null) tx.transactionIndex = utils.hexToNumber(tx.transactionIndex); - tx.nonce = utils.hexToNumberString(tx.nonce); - tx.gas = utils.hexToNumberString(tx.gas); - tx.gasPrice = utils.hexToNumberString(tx.gasPrice); - tx.value = utils.hexToNumberString(tx.value); + tx.nonce = outputBigNumberFormatter(tx.nonce); + tx.value = outputBigNumberFormatter(tx.value); + tx.gas = utils.hexToNumber(tx.gas); + tx.gasPrice = utils.hexToNumber(tx.gasPrice); if (tx.to && utils.isAddress(tx.to)) { // tx.to could be `0x0` or `null` while contract creation tx.to = utils.toChecksumAddress(tx.to); @@ -259,11 +259,11 @@ var outputTransactionReceiptFormatter = function (receipt) { } if (receipt.blockNumber !== null) - receipt.blockNumber = utils.hexToNumberString(receipt.blockNumber); + receipt.blockNumber = outputBigNumberFormatter(receipt.blockNumber); if (receipt.transactionIndex !== null) receipt.transactionIndex = utils.hexToNumber(receipt.transactionIndex); - receipt.cumulativeGasUsed = utils.hexToNumberString(receipt.cumulativeGasUsed); - receipt.gasUsed = utils.hexToNumberString(receipt.gasUsed); + receipt.cumulativeGasUsed = utils.hexToNumber(receipt.cumulativeGasUsed); + receipt.gasUsed = utils.hexToNumber(receipt.gasUsed); if (_.isArray(receipt.logs)) { receipt.logs = receipt.logs.map(outputLogFormatter); @@ -290,17 +290,17 @@ var outputTransactionReceiptFormatter = function (receipt) { var outputBlockFormatter = function (block) { // transform to number - block.gasLimit = utils.hexToNumberString(block.gasLimit); - block.gasUsed = utils.hexToNumberString(block.gasUsed); - block.size = utils.hexToNumberString(block.size); - block.timestamp = utils.hexToNumberString(block.timestamp); + block.gasLimit = utils.hexToNumber(block.gasLimit); + block.gasUsed = utils.hexToNumber(block.gasUsed); + block.size = outputBigNumberFormatter(block.size); + block.timestamp = outputBigNumberFormatter(block.timestamp); if (block.number !== null) - block.number = utils.hexToNumberString(block.number); + block.number = outputBigNumberFormatter(block.number); if (block.difficulty) - block.difficulty = utils.hexToNumberString(block.difficulty); + block.difficulty = outputBigNumberFormatter(block.difficulty); if (block.totalDifficulty) - block.totalDifficulty = utils.hexToNumberString(block.totalDifficulty); + block.totalDifficulty = outputBigNumberFormatter(block.totalDifficulty); if (_.isArray(block.transactions)) { block.transactions.forEach(function (item) { @@ -380,7 +380,7 @@ var outputLogFormatter = function (log) { } if (log.blockNumber !== null) - log.blockNumber = utils.hexToNumberString(log.blockNumber); + log.blockNumber = outputBigNumberFormatter(log.blockNumber); if (log.transactionIndex !== null) log.transactionIndex = utils.hexToNumber(log.transactionIndex); if (log.logIndex !== null) @@ -469,9 +469,9 @@ var inputAddressFormatter = function (address) { var outputSyncingFormatter = function (result) { - result.startingBlock = utils.hexToNumberString(result.startingBlock); - result.currentBlock = utils.hexToNumberString(result.currentBlock); - result.highestBlock = utils.hexToNumberString(result.highestBlock); + result.startingBlock = outputBigNumberFormatter(result.startingBlock); + result.currentBlock = outputBigNumberFormatter(result.currentBlock); + result.highestBlock = outputBigNumberFormatter(result.highestBlock); if (result.knownStates) { result.knownStates = utils.hexToNumber(result.knownStates); result.pulledStates = utils.hexToNumber(result.pulledStates); diff --git a/packages/web3-eth/src/index.js b/packages/web3-eth/src/index.js index ced9b9e7d15..8893f98c9db 100644 --- a/packages/web3-eth/src/index.js +++ b/packages/web3-eth/src/index.js @@ -341,7 +341,7 @@ var Eth = function Eth() { name: 'getBlockNumber', call: 'eth_blockNumber', params: 0, - outputFormatter: utils.hexToNumber + outputFormatter: formatter.outputBigNumberFormatter }), new Method({ name: 'getBalance', From bb49434b4d5b48f555bb9ca9e35e5c366ea80676 Mon Sep 17 00:00:00 2001 From: nivida Date: Fri, 22 Nov 2019 10:55:46 +0100 Subject: [PATCH 04/14] numbers checked and eth.* tests updated --- packages/web3-core-helpers/src/formatters.js | 4 +-- test/eth.getBlock.js | 12 +++---- test/eth.getBlockNumber.js | 2 +- test/eth.getTransaction.js | 6 ++-- test/eth.getTransactionFromBlock.js | 6 ++-- test/eth.getTransactionReceipt.js | 8 ++--- test/eth.getUncle.js | 12 +++---- test/eth.subscribe.js | 34 ++++++++++---------- 8 files changed, 42 insertions(+), 42 deletions(-) diff --git a/packages/web3-core-helpers/src/formatters.js b/packages/web3-core-helpers/src/formatters.js index 4715905d19e..783aaffee4d 100644 --- a/packages/web3-core-helpers/src/formatters.js +++ b/packages/web3-core-helpers/src/formatters.js @@ -230,8 +230,8 @@ var outputTransactionFormatter = function (tx) { tx.transactionIndex = utils.hexToNumber(tx.transactionIndex); tx.nonce = outputBigNumberFormatter(tx.nonce); tx.value = outputBigNumberFormatter(tx.value); + tx.gasPrice = outputBigNumberFormatter(tx.gasPrice); tx.gas = utils.hexToNumber(tx.gas); - tx.gasPrice = utils.hexToNumber(tx.gasPrice); if (tx.to && utils.isAddress(tx.to)) { // tx.to could be `0x0` or `null` while contract creation tx.to = utils.toChecksumAddress(tx.to); @@ -292,7 +292,7 @@ var outputBlockFormatter = function (block) { // transform to number block.gasLimit = utils.hexToNumber(block.gasLimit); block.gasUsed = utils.hexToNumber(block.gasUsed); - block.size = outputBigNumberFormatter(block.size); + block.size = utils.hexToNumber(block.size); block.timestamp = outputBigNumberFormatter(block.timestamp); if (block.number !== null) block.number = outputBigNumberFormatter(block.number); diff --git a/test/eth.getBlock.js b/test/eth.getBlock.js index 1fe66a346da..0d1656852cd 100644 --- a/test/eth.getBlock.js +++ b/test/eth.getBlock.js @@ -23,7 +23,7 @@ var blockResult = { "uncles": ["0x460cfb8472af2c5fd05b5a2", "0xd5460cfb8472af2c5fd05b5a2"] }; var formattedBlockResult = { - "number": 436, + "number": '436', "hash": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331", "parentHash": "0x9646252be9520f6e71339a8df9c55e4d7619deeb018d2a3f2d21fc165dde5eb5", "nonce": "0xe04d296d2460cfb8472af2c5fd05b5a214109c25688d3704aed5484f9a7792f2", @@ -38,7 +38,7 @@ var formattedBlockResult = { "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", "gasLimit": 653145, "gasUsed": 653145, - "timestamp": 1424182926, + "timestamp": '1424182926', "transactions": ['0x460cfb8472af2c5fd05b5a2','0x460cfb8472af2c5fd05b5a2'], "uncles": ["0x460cfb8472af2c5fd05b5a2", "0xd5460cfb8472af2c5fd05b5a2"] }; @@ -76,7 +76,7 @@ var blockResultWithTx = { "uncles": ["0x460cfb8472af2c5fd05b5a2", "0xd5460cfb8472af2c5fd05b5a2"] }; var formattedBlockResultWithTx = { - "number": 436, + "number": '436', "hash": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331", "parentHash": "0x9646252be9520f6e71339a8df9c55e4d7619deeb018d2a3f2d21fc165dde5eb5", "nonce": "0xe04d296d2460cfb8472af2c5fd05b5a214109c25688d3704aed5484f9a7792f2", @@ -91,13 +91,13 @@ var formattedBlockResultWithTx = { "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", "gasLimit": 653145, "gasUsed": 653145, - "timestamp": 1424182926, + "timestamp": '1424182926', "transactions": [{ "status": "mined", "hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", - "nonce": 2, + "nonce": '2', "blockHash": "0x6fd9e2a26ab", - "blockNumber": 5599, + "blockNumber": '5599', "transactionIndex": 1, "from":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", "to":"0x85F43D8a49eeB85d32Cf465507DD71d507100C1d", diff --git a/test/eth.getBlockNumber.js b/test/eth.getBlockNumber.js index d5357dd09bd..30aa62ab1fe 100644 --- a/test/eth.getBlockNumber.js +++ b/test/eth.getBlockNumber.js @@ -4,7 +4,7 @@ var method = 'getBlockNumber'; var tests = [{ result: '0xb', - formattedResult: 11, + formattedResult: '11', call: 'eth_blockNumber' }]; diff --git a/test/eth.getTransaction.js b/test/eth.getTransaction.js index d0fae0de54f..2a7f52c2b99 100644 --- a/test/eth.getTransaction.js +++ b/test/eth.getTransaction.js @@ -16,10 +16,10 @@ var txResult = { "input":"0x603880600c6000396000f30060" }; var formattedTxResult = { - "hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", - "nonce":5, + "hash": "0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", + "nonce": '5', "blockHash": "0x6fd9e2a26ab", - "blockNumber": 5599, + "blockNumber": '5599', "transactionIndex": 1, "from":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address "to":"0x85F43D8a49eeB85d32Cf465507DD71d507100C1d", // checksum address diff --git a/test/eth.getTransactionFromBlock.js b/test/eth.getTransactionFromBlock.js index 32260659ac2..880d762bcb2 100644 --- a/test/eth.getTransactionFromBlock.js +++ b/test/eth.getTransactionFromBlock.js @@ -18,10 +18,10 @@ var txResult = { }; var formattedTxResult = { "status": "mined", - "hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", - "nonce":11, + "hash": "0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", + "nonce": '11', "blockHash": "0x6fd9e2a26ab", - "blockNumber": 5599, + "blockNumber": '5599', "transactionIndex": 1, "from":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address "to":"0x85F43D8a49eeB85d32Cf465507DD71d507100C1d", // checksum address diff --git a/test/eth.getTransactionReceipt.js b/test/eth.getTransactionReceipt.js index dabb7f6bb64..f8d8e6dad72 100644 --- a/test/eth.getTransactionReceipt.js +++ b/test/eth.getTransactionReceipt.js @@ -30,7 +30,7 @@ var txResult = { }; var formattedTxResult = { "blockHash": "0x6fd9e2a26ab", - "blockNumber": 5599, + "blockNumber": '5599', "transactionHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "transactionIndex": 1, "contractAddress":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address @@ -40,7 +40,7 @@ var formattedTxResult = { id: "log_2b801386", transactionIndex: 1000, logIndex: 1000, - blockNumber: 1000, + blockNumber: '1000', transactionHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265', blockHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265', data: '0x7b2274657374223a2274657374227', @@ -79,7 +79,7 @@ var tests = [{ formattedResult: { "status": true, "blockHash": "0x6fd9e2a26ab", - "blockNumber": 5599, + "blockNumber": '5599', "transactionHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "transactionIndex": 1, "contractAddress":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address @@ -103,7 +103,7 @@ var tests = [{ formattedResult: { "status": false, "blockHash": "0x6fd9e2a26ab", - "blockNumber": 5599, + "blockNumber": '5599', "transactionHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "transactionIndex": 16, "contractAddress":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address diff --git a/test/eth.getUncle.js b/test/eth.getUncle.js index 31c3a91a948..73a2c947ff6 100644 --- a/test/eth.getUncle.js +++ b/test/eth.getUncle.js @@ -23,7 +23,7 @@ var blockResult = { "uncles": ["0x460cfb8472af2c5fd05b5a2", "0xd5460cfb8472af2c5fd05b5a2"] }; var formattedBlockResult = { - "number": 436, + "number": '436', "hash": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331", "parentHash": "0x9646252be9520f6e71339a8df9c55e4d7619deeb018d2a3f2d21fc165dde5eb5", "nonce": "0xe04d296d2460cfb8472af2c5fd05b5a214109c25688d3704aed5484f9a7792f2", @@ -38,7 +38,7 @@ var formattedBlockResult = { "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", "gasLimit": 653145, "gasUsed": 653145, - "timestamp": 1424182926, + "timestamp": '1424182926', "transactions": ['0x460cfb8472af2c5fd05b5a2','0x460cfb8472af2c5fd05b5a2'], "uncles": ["0x460cfb8472af2c5fd05b5a2", "0xd5460cfb8472af2c5fd05b5a2"] }; @@ -76,7 +76,7 @@ var blockResultWithTx = { "uncles": ["0x460cfb8472af2c5fd05b5a2", "0xd5460cfb8472af2c5fd05b5a2"] }; var formattedBlockResultWithTx = { - "number": 436, + "number": '436', "hash": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331", "parentHash": "0x9646252be9520f6e71339a8df9c55e4d7619deeb018d2a3f2d21fc165dde5eb5", "nonce": "0xe04d296d2460cfb8472af2c5fd05b5a214109c25688d3704aed5484f9a7792f2", @@ -91,13 +91,13 @@ var formattedBlockResultWithTx = { "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", "gasLimit": 653145, "gasUsed": 653145, - "timestamp": 1424182926, + "timestamp": '1424182926', "transactions": [{ // "status": "mined", "hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", - "nonce": 2, + "nonce": '2', "blockHash": "0x6fd9e2a26ab", - "blockNumber": 5599, + "blockNumber": '5599', "transactionIndex": 1, "from":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address "to":"0x85F43D8a49eeB85d32Cf465507DD71d507100C1d", // checksum address diff --git a/test/eth.subscribe.js b/test/eth.subscribe.js index 4f2db3b1308..f89b322238e 100644 --- a/test/eth.subscribe.js +++ b/test/eth.subscribe.js @@ -46,12 +46,12 @@ var tests = [{ logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", miner: "0xf8b483DbA2c3B7176a3Da549ad41A48BB3121069", // checksum address nonce: "0x084149998194cc5f", - number: 1263817, + number: '1263817', parentHash: "0x7736fab79e05dc611604d22470dadad26f56fe494421b5b333de816ce1f25701", receiptRoot: "0x2fab35823ad00c7bb388595cb46652fe7886e00660a01e867824d3dceb1c8d36", sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", stateRoot: "0xb3346685172db67de536d8765c43c31009d0eb3bd9c501c9be3229203f15f378", - timestamp: 1459613688, + timestamp: '1459613688', transactionsRoot: "0x0167ffa60e3ebc0b080cdb95f7c0087dd6c0e61413140e39d94d3468d7c9689f", size: 0 }] @@ -108,7 +108,7 @@ var tests = [{ subscriptionResults: [{ id: "log_d43624aa", blockHash: "0x43534ffddd", - blockNumber: 12834, + blockNumber: '12834', logIndex: 35, transactionHash: '0x2345fdfdf', transactionIndex: 1, @@ -151,7 +151,7 @@ var tests = [{ subscriptionResults: [{ id: "log_d43624aa", blockHash: "0x43534ffddd", - blockNumber: 12834, + blockNumber: '12834', logIndex: 35, transactionHash: '0x2345fdfdf', transactionIndex: 1, @@ -206,7 +206,7 @@ var tests = [{ subscriptionResults: [{ id: "log_d43624aa", blockHash: "0x43534ffddd", - blockNumber: 12834, + blockNumber: '12834', logIndex: 35, transactionHash: '0x2345fdfdf', transactionIndex: 1, @@ -219,7 +219,7 @@ var tests = [{ },{ id: "log_b20551f9", blockHash: "0x43534ffddd", - blockNumber: 12834, + blockNumber: '12834', logIndex: 35, transactionHash: '0x2345fdfdd', transactionIndex: 1, @@ -274,7 +274,7 @@ var tests = [{ subscriptionResults: [{ id: "log_d43624aa", blockHash: "0x43534ffddd", - blockNumber: 12834, + blockNumber: '12834', logIndex: 35, transactionHash: '0x2345fdfdf', transactionIndex: 1, @@ -287,7 +287,7 @@ var tests = [{ },{ id: "log_b20551f9", blockHash: "0x43534ffddd", - blockNumber: 12834, + blockNumber: '12834', logIndex: 35, transactionHash: '0x2345fdfdd', transactionIndex: 1, @@ -331,7 +331,7 @@ var tests = [{ subscriptionResults: [{ id: "log_d43624aa", blockHash: "0x43534ffddd", - blockNumber: 12834, + blockNumber: '12834', logIndex: 35, transactionHash: '0x2345fdfdf', transactionIndex: 1, @@ -392,7 +392,7 @@ var tests = [{ subscriptionResults: [{ id: "log_d43624aa", blockHash: "0x43534ffddd", - blockNumber: 12834, + blockNumber: '12834', logIndex: 35, transactionHash: '0x2345fdfdf', transactionIndex: 1, @@ -405,7 +405,7 @@ var tests = [{ },{ id: "log_d43624aa", blockHash: "0x43534ffddd", - blockNumber: 12834, + blockNumber: '12834', removed: true, logIndex: 35, transactionHash: '0x2345fdfdf', @@ -456,16 +456,16 @@ var tests = [{ subscriptionResults: [ true, { - startingBlock: 786211, - currentBlock: 786193, - highestBlock: 712483, + startingBlock: '786211', + currentBlock: '786193', + highestBlock: '712483', knownStates: 698915, pulledStates: 35 }, { - startingBlock: 786211, - currentBlock: 786193, - highestBlock: 786193, + startingBlock: '786211', + currentBlock: '786193', + highestBlock: '786193', knownStates: 698915, pulledStates: 35 }, From ab098979ccd972a71bf0d9810bbdf7fe6714e9eb Mon Sep 17 00:00:00 2001 From: nivida Date: Fri, 22 Nov 2019 11:50:18 +0100 Subject: [PATCH 05/14] usage of those properties checked and code/tests updated if required --- packages/web3-core-helpers/src/formatters.js | 4 +++ packages/web3-core-method/src/index.js | 2 +- packages/web3-eth-accounts/src/index.js | 2 +- packages/web3-eth-ens/src/ENS.js | 6 ++-- packages/web3-eth/src/index.js | 2 +- test/contract.js | 34 +++++++++---------- test/e2e.contract.deploy.js | 2 +- test/e2e.method.send.js | 2 +- test/eth.sendTransaction.js | 2 +- test/event.decode.js | 8 ++--- test/formatters.outputBlockFormatter.js | 6 ++-- test/formatters.outputLogFormatter.js | 2 +- test/formatters.outputTransactionFormatter.js | 8 ++--- ...tters.outputTransactionReceiptFormatter.js | 4 +-- test/helpers/test.method.js | 2 +- test/method.buildCall.js | 12 +++---- 16 files changed, 52 insertions(+), 46 deletions(-) diff --git a/packages/web3-core-helpers/src/formatters.js b/packages/web3-core-helpers/src/formatters.js index 783aaffee4d..b2366a48f31 100644 --- a/packages/web3-core-helpers/src/formatters.js +++ b/packages/web3-core-helpers/src/formatters.js @@ -68,6 +68,10 @@ var outputProofFormatter = function (proof) { * @returns {BN} object */ var outputBigNumberFormatter = function (number) { + if (!number) { + return number; + } + return utils.toBN(number).toString(10); }; diff --git a/packages/web3-core-method/src/index.js b/packages/web3-core-method/src/index.js index 98cea3d63c5..18fc17affd9 100644 --- a/packages/web3-core-method/src/index.js +++ b/packages/web3-core-method/src/index.js @@ -299,7 +299,7 @@ Method.prototype._confirmTransaction = function(defer, result, payload) { if (existingReceipt === undefined || confirmationCount !== 0) { if (isPolling) { // Check if actually a new block is existing on polling if (lastBlock) { - block = await _ethereumCall.getBlockByNumber(lastBlock.number + 1); + block = await _ethereumCall.getBlockByNumber(parseInt(lastBlock.number) + 1); if (block) { lastBlock = block; defer.eventEmitter.emit('confirmation', confirmationCount, receipt); diff --git a/packages/web3-eth-accounts/src/index.js b/packages/web3-eth-accounts/src/index.js index ca73e7bffab..2ad6ca62f36 100644 --- a/packages/web3-eth-accounts/src/index.js +++ b/packages/web3-eth-accounts/src/index.js @@ -159,7 +159,7 @@ Accounts.prototype.signTransaction = function signTransaction(tx, privateKey, ca error = new Error('"gas" is missing'); } - if (tx.nonce < 0 || + if (utils.toBN(tx.nonce).ltn(0) || tx.gas < 0 || tx.gasPrice < 0 || tx.chainId < 0) { diff --git a/packages/web3-eth-ens/src/ENS.js b/packages/web3-eth-ens/src/ENS.js index 741eb5b2b4e..e06970de0b5 100644 --- a/packages/web3-eth-ens/src/ENS.js +++ b/packages/web3-eth-ens/src/ENS.js @@ -23,6 +23,7 @@ var config = require('./config'); var Registry = require('./contracts/Registry'); var ResolverMethodHandler = require('./lib/ResolverMethodHandler'); +var utils = require('web3-utils'); /** * Constructs a new instance of ENS @@ -171,8 +172,9 @@ ENS.prototype.setMultihash = function (name, hash, sendOptions, callback) { ENS.prototype.checkNetwork = function () { var self = this; return self.eth.getBlock('latest').then(function (block) { - var headAge = new Date() / 1000 - block.timestamp; - if (headAge > 3600) { + // TODO: Check with Quorum timestamp + var headAge = utils.toBN((Math.floor(new Date() / 1000))).sub(utils.toBN(block.timestamp)); + if (headAge.gtn(3600)) { throw new Error("Network not synced; last block was " + headAge + " seconds ago"); } return self.eth.net.getNetworkType(); diff --git a/packages/web3-eth/src/index.js b/packages/web3-eth/src/index.js index 8893f98c9db..11a3eea0188 100644 --- a/packages/web3-eth/src/index.js +++ b/packages/web3-eth/src/index.js @@ -417,7 +417,7 @@ var Eth = function Eth() { call: 'eth_getTransactionCount', params: 2, inputFormatter: [formatter.inputAddressFormatter, formatter.inputDefaultBlockNumberFormatter], - outputFormatter: utils.hexToNumber + outputFormatter: formatter.outputBigNumberFormatter }), new Method({ name: 'sendSignedTransaction', diff --git a/test/contract.js b/test/contract.js index 18d0a9c6c77..59ea6d5b6c7 100644 --- a/test/contract.js +++ b/test/contract.js @@ -461,7 +461,7 @@ var runTests = function(contractFactory) { '0000000000000000000000000000000000000000000000000000000000000008' }); - assert.equal(result.blockNumber, 3); + assert.equal(result.blockNumber, '3'); assert.equal(result.blockHash, '0x1345'); assert.equal(result.logIndex, 4); assert.equal(result.id, 'log_9ff24cb4'); @@ -567,7 +567,7 @@ var runTests = function(contractFactory) { contractAddress: address, cumulativeGasUsed: 10, transactionIndex: 3, - blockNumber: 10, + blockNumber: '10', blockHash: '0xbf1234', gasUsed: 0 }); @@ -661,7 +661,7 @@ var runTests = function(contractFactory) { contractAddress: address, cumulativeGasUsed: 10, transactionIndex: 3, - blockNumber: 10, + blockNumber: '10', blockHash: '0xbf1234', gasUsed: 0 }); @@ -1799,13 +1799,13 @@ var runTests = function(contractFactory) { cumulativeGasUsed: 10, transactionIndex: 3, transactionHash: '0x1234', - blockNumber: 10, + blockNumber: '10', blockHash: '0x1234', gasUsed: 0, events: { Unchanged: { address: address, - blockNumber: 10, + blockNumber: '10', transactionHash: '0x1234', blockHash: '0x1345', logIndex: 4, @@ -1830,7 +1830,7 @@ var runTests = function(contractFactory) { }, Changed: { address: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', - blockNumber: 10, + blockNumber: '10', transactionHash: '0x1234', blockHash: '0x1345', logIndex: 4, @@ -1962,14 +1962,14 @@ var runTests = function(contractFactory) { cumulativeGasUsed: 10, transactionIndex: 3, transactionHash: '0x1234', - blockNumber: 10, + blockNumber: '10', blockHash: '0x1234', gasUsed: 0, events: { Changed: [ { address: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', - blockNumber: 10, + blockNumber: '10', transactionHash: '0x1234', blockHash: '0x1345', logIndex: 4, @@ -1995,7 +1995,7 @@ var runTests = function(contractFactory) { } }, { address: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', - blockNumber: 10, + blockNumber: '10', transactionHash: '0x1234', blockHash: '0x1345', logIndex: 5, @@ -2114,13 +2114,13 @@ var runTests = function(contractFactory) { cumulativeGasUsed: 10, transactionIndex: 3, transactionHash: '0x1234', - blockNumber: 10, + blockNumber: '10', blockHash: '0x43ffdd', gasUsed: 0, events: { Unchanged: { address: address, - blockNumber: 10, + blockNumber: '10', transactionHash: '0x1234', blockHash: '0x1345', logIndex: 4, @@ -2145,7 +2145,7 @@ var runTests = function(contractFactory) { }, Changed: { address: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', - blockNumber: 10, + blockNumber: '10', transactionHash: '0x1234', blockHash: '0x1345', logIndex: 4, @@ -2229,7 +2229,7 @@ var runTests = function(contractFactory) { cumulativeGasUsed: 10, transactionIndex: 3, transactionHash: '0x1234', - blockNumber: 10, + blockNumber: '10', blockHash: '0x1234', gasUsed: 0, events: {} @@ -2243,7 +2243,7 @@ var runTests = function(contractFactory) { cumulativeGasUsed: 10, transactionIndex: 3, transactionHash: '0x1234', - blockNumber: 10, + blockNumber: '10', blockHash: '0x1234', gasUsed: 0, events: {} @@ -2693,7 +2693,7 @@ var runTests = function(contractFactory) { signature: "0xc00c1c37cc8b83163fb4fddc06c74d1d5c00d74648e7cb28c0ebada3e32fd62c", id: "log_9ff24cb4", address: address, - blockNumber: 3, + blockNumber: '3', transactionHash: '0x1234', blockHash: '0x1345', logIndex: 4, @@ -2719,7 +2719,7 @@ var runTests = function(contractFactory) { signature: "0xc00c1c37cc8b83163fb4fddc06c74d1d5c00d74648e7cb28c0ebada3e32fd62c", id: "log_29c93e15", address: address, - blockNumber: 4, + blockNumber: '4', transactionHash: '0x1235', blockHash: '0x1346', logIndex: 1, @@ -3091,7 +3091,7 @@ describe('typical usage', function() { gas: 54872, gasPrice: 3000, chainId: 1, - nonce: 1, + nonce: '1', chain: 'mainnet', hardfork: 'petersburg' }) diff --git a/test/e2e.contract.deploy.js b/test/e2e.contract.deploy.js index 380881c9bc0..92df70d7d92 100644 --- a/test/e2e.contract.deploy.js +++ b/test/e2e.contract.deploy.js @@ -151,7 +151,7 @@ describe('contract.deploy [ @E2E ]', function() { .on('confirmation', async (number, receipt) => { if (number === 1) { // Confirmation numbers are zero indexed var endBlock = await web3.eth.getBlockNumber(); - assert(endBlock >= (startBlock + 2)); + assert(parseInt(endBlock) >= (parseInt(startBlock) + 2)); resolve(); } }) diff --git a/test/e2e.method.send.js b/test/e2e.method.send.js index d9bfa9f1713..f100f66a09c 100644 --- a/test/e2e.method.send.js +++ b/test/e2e.method.send.js @@ -156,7 +156,7 @@ describe('method.send [ @E2E ]', function() { .on('confirmation', async (number, receipt) => { if (number === 1) { // Confirmation numbers are zero indexed var endBlock = await web3.eth.getBlockNumber(); - assert(endBlock >= (startBlock + 2)); + assert(parseInt(endBlock) >= (parseInt(startBlock) + 2)); resolve(); } }) diff --git a/test/eth.sendTransaction.js b/test/eth.sendTransaction.js index 4a77bd8e791..74c9919b34c 100644 --- a/test/eth.sendTransaction.js +++ b/test/eth.sendTransaction.js @@ -287,7 +287,7 @@ describe(method, function () { // test receipt assert.deepEqual(result, { "blockHash": "0x6fd9e2a26ab", - "blockNumber": 5599, + "blockNumber": "5599", "transactionHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "transactionIndex": 1, "contractAddress":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address diff --git a/test/event.decode.js b/test/event.decode.js index 619b4ed6d64..09e33f3149c 100644 --- a/test/event.decode.js +++ b/test/event.decode.js @@ -30,7 +30,7 @@ var tests = [{ transactionHash: '0x1234567890', address: resultAddress, blockHash: '0x1234567890', - blockNumber: 1, + blockNumber: '1', id: "log_c71f2e84", raw: { topics: [], @@ -67,7 +67,7 @@ var tests = [{ transactionHash: '0x1234567890', address: resultAddress, blockHash: '0x1234567890', - blockNumber: 1, + blockNumber: '1', id: "log_c71f2e84", raw: { data: "0x0000000000000000000000000000000000000000000000000000000000000001", @@ -129,7 +129,7 @@ var tests = [{ transactionHash: '0x1234567890', address: resultAddress, blockHash: '0x1234567890', - blockNumber: 1, + blockNumber: '1', id: "log_c71f2e84", raw: { data: '0x' + @@ -197,7 +197,7 @@ var tests = [{ transactionHash: '0x1234567890', address: resultAddress, blockHash: '0x1234567890', - blockNumber: 1, + blockNumber: '1', id: "log_c71f2e84", raw: { data: '0x' + diff --git a/test/formatters.outputBlockFormatter.js b/test/formatters.outputBlockFormatter.js index d6bf27563de..502369e8e0f 100644 --- a/test/formatters.outputBlockFormatter.js +++ b/test/formatters.outputBlockFormatter.js @@ -32,10 +32,10 @@ describe('formatters', function () { bloom: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265', difficulty: '1000', totalDifficulty: '1000', - number: 1000, + number: '1000', gasLimit: 1000, gasUsed: 1000, - timestamp: 1000, + timestamp: '1000', extraData: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265', nonce: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265', size: 1000 @@ -71,7 +71,7 @@ describe('formatters', function () { number: null, gasLimit: 1000, gasUsed: 1000, - timestamp: 1000, + timestamp: '1000', extraData: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265', nonce: null, size: 1000 diff --git a/test/formatters.outputLogFormatter.js b/test/formatters.outputLogFormatter.js index da692001512..41303bf9e23 100644 --- a/test/formatters.outputLogFormatter.js +++ b/test/formatters.outputLogFormatter.js @@ -17,7 +17,7 @@ describe('formatters', function () { }), { transactionIndex: 1000, logIndex: 1000, - blockNumber: 1000, + blockNumber: '1000', transactionHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265', blockHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265', data: '0x7b2274657374223a2274657374227', diff --git a/test/formatters.outputTransactionFormatter.js b/test/formatters.outputTransactionFormatter.js index 38dede445de..d3b00b179a8 100644 --- a/test/formatters.outputTransactionFormatter.js +++ b/test/formatters.outputTransactionFormatter.js @@ -23,8 +23,8 @@ describe('formatters', function () { value: '1000', gas: 1000, gasPrice: '1000', - nonce: 11, - blockNumber: 1000, + nonce: '11', + blockNumber: '1000', blockHash: '0xc9b9cdc2092a9d6589d96662b1fd6949611163fb3910cf8a173cd060f17702f9', transactionIndex: 1 }); @@ -47,10 +47,10 @@ describe('formatters', function () { input: '0x3454645634534', from: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', to: null, - value: 1000, + value: '1000', gas: 1000, gasPrice: '1000', - nonce: 11, + nonce: '11', blockNumber: null, blockHash: null, transactionIndex: null diff --git a/test/formatters.outputTransactionReceiptFormatter.js b/test/formatters.outputTransactionReceiptFormatter.js index 7647d725d36..c7e117522f5 100644 --- a/test/formatters.outputTransactionReceiptFormatter.js +++ b/test/formatters.outputTransactionReceiptFormatter.js @@ -19,7 +19,7 @@ describe('outputTransactionReceiptFormatter', function() { status: false, cumulativeGasUsed: 256, gasUsed: 256, - blockNumber: 256, + blockNumber: '256', transactionIndex: 10, to: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078', from: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078', @@ -44,7 +44,7 @@ describe('outputTransactionReceiptFormatter', function() { status: false, cumulativeGasUsed: 256, gasUsed: 256, - blockNumber: 256, + blockNumber: '256', transactionIndex: 10, to: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078', from: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078', diff --git a/test/helpers/test.method.js b/test/helpers/test.method.js index 0d0e4300c49..451a58f8888 100644 --- a/test/helpers/test.method.js +++ b/test/helpers/test.method.js @@ -130,7 +130,7 @@ var runTests = function (obj, method, tests) { // test receipt assert.deepEqual(result, { "blockHash": "0x6fd9e2a26ab", - "blockNumber": 5599, + "blockNumber": '5599', "transactionHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "transactionIndex": 1, "contractAddress":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address diff --git a/test/method.buildCall.js b/test/method.buildCall.js index 49f4e1f0b49..443ca967e58 100644 --- a/test/method.buildCall.js +++ b/test/method.buildCall.js @@ -306,7 +306,7 @@ describe('lib/web3/method', function () { contractAddress: address, cumulativeGasUsed: 10, transactionIndex: 3, - blockNumber: 10, + blockNumber: '10', blockHash: '0xafff', gasUsed: 0 }); @@ -331,7 +331,7 @@ describe('lib/web3/method', function () { contractAddress: address, cumulativeGasUsed: 10, transactionIndex: 3, - blockNumber: 10, + blockNumber: '10', blockHash: '0xafff', gasUsed: 0 }); @@ -426,7 +426,7 @@ describe('lib/web3/method', function () { contractAddress: address, cumulativeGasUsed: 10, transactionIndex: 3, - blockNumber: 10, + blockNumber: '10', blockHash: '0xafff', gasUsed: 0 }); @@ -450,7 +450,7 @@ describe('lib/web3/method', function () { contractAddress: address, cumulativeGasUsed: 10, transactionIndex: 3, - blockNumber: 10, + blockNumber: '10', blockHash: '0xafff', gasUsed: 0 }); @@ -833,7 +833,7 @@ describe('lib/web3/method', function () { contractAddress: null, cumulativeGasUsed: 10, transactionIndex: 3, - blockNumber: 10, + blockNumber: '10', blockHash: '0xafff', gasUsed: 0 }); @@ -845,7 +845,7 @@ describe('lib/web3/method', function () { contractAddress: null, cumulativeGasUsed: 10, transactionIndex: 3, - blockNumber: 10, + blockNumber: '10', blockHash: '0xafff', gasUsed: 0 }); From 150c1bcb41fd9e2d4615104d0d01041d4d60b247 Mon Sep 17 00:00:00 2001 From: nivida Date: Fri, 22 Nov 2019 12:34:28 +0100 Subject: [PATCH 06/14] gas related block or transaction object properties are now handled as BigNumber --- packages/web3-core-helpers/src/formatters.js | 49 ++++++++----------- test/contract.js | 32 ++++++------ test/eth.getBlock.js | 14 +++--- test/eth.getTransaction.js | 2 +- test/eth.getTransactionFromBlock.js | 2 +- test/eth.getTransactionReceipt.js | 12 ++--- test/eth.getUncle.js | 14 +++--- test/eth.sendTransaction.js | 4 +- test/eth.subscribe.js | 14 +++--- test/formatters.outputBlockFormatter.js | 12 ++--- test/formatters.outputTransactionFormatter.js | 4 +- ...tters.outputTransactionReceiptFormatter.js | 8 +-- test/helpers/test.method.js | 4 +- test/helpers/test.subscription.js | 2 +- test/method.buildCall.js | 24 ++++----- 15 files changed, 95 insertions(+), 102 deletions(-) diff --git a/packages/web3-core-helpers/src/formatters.js b/packages/web3-core-helpers/src/formatters.js index b2366a48f31..7c7d8c6f887 100644 --- a/packages/web3-core-helpers/src/formatters.js +++ b/packages/web3-core-helpers/src/formatters.js @@ -228,14 +228,12 @@ var inputSignFormatter = function (data) { * @returns {Object} */ var outputTransactionFormatter = function (tx) { - if (tx.blockNumber !== null) - tx.blockNumber = outputBigNumberFormatter(tx.blockNumber); - if (tx.transactionIndex !== null) - tx.transactionIndex = utils.hexToNumber(tx.transactionIndex); + tx.transactionIndex = utils.hexToNumber(tx.transactionIndex); + tx.blockNumber = outputBigNumberFormatter(tx.blockNumber); tx.nonce = outputBigNumberFormatter(tx.nonce); tx.value = outputBigNumberFormatter(tx.value); tx.gasPrice = outputBigNumberFormatter(tx.gasPrice); - tx.gas = utils.hexToNumber(tx.gas); + tx.gas = outputBigNumberFormatter(tx.gas); if (tx.to && utils.isAddress(tx.to)) { // tx.to could be `0x0` or `null` while contract creation tx.to = utils.toChecksumAddress(tx.to); @@ -262,12 +260,10 @@ var outputTransactionReceiptFormatter = function (receipt) { throw new Error('Received receipt is invalid: ' + receipt); } - if (receipt.blockNumber !== null) - receipt.blockNumber = outputBigNumberFormatter(receipt.blockNumber); - if (receipt.transactionIndex !== null) - receipt.transactionIndex = utils.hexToNumber(receipt.transactionIndex); - receipt.cumulativeGasUsed = utils.hexToNumber(receipt.cumulativeGasUsed); - receipt.gasUsed = utils.hexToNumber(receipt.gasUsed); + receipt.blockNumber = outputBigNumberFormatter(receipt.blockNumber); + receipt.cumulativeGasUsed = outputBigNumberFormatter(receipt.cumulativeGasUsed); + receipt.gasUsed = outputBigNumberFormatter(receipt.gasUsed); + receipt.transactionIndex = utils.hexToNumber(receipt.transactionIndex); if (_.isArray(receipt.logs)) { receipt.logs = receipt.logs.map(outputLogFormatter); @@ -292,19 +288,20 @@ var outputTransactionReceiptFormatter = function (receipt) { * @returns {Object} */ var outputBlockFormatter = function (block) { - // transform to number - block.gasLimit = utils.hexToNumber(block.gasLimit); - block.gasUsed = utils.hexToNumber(block.gasUsed); - block.size = utils.hexToNumber(block.size); + block.gasLimit = outputBigNumberFormatter(block.gasLimit); + block.gasUsed = outputBigNumberFormatter(block.gasUsed); + block.size = outputBigNumberFormatter(block.size); block.timestamp = outputBigNumberFormatter(block.timestamp); - if (block.number !== null) - block.number = outputBigNumberFormatter(block.number); + block.number = outputBigNumberFormatter(block.number); - if (block.difficulty) + if (block.difficulty) { block.difficulty = outputBigNumberFormatter(block.difficulty); - if (block.totalDifficulty) + } + + if (block.totalDifficulty) { block.totalDifficulty = outputBigNumberFormatter(block.totalDifficulty); + } if (_.isArray(block.transactions)) { block.transactions.forEach(function (item) { @@ -372,7 +369,6 @@ var inputLogFormatter = function (options) { * @returns {Object} log */ var outputLogFormatter = function (log) { - // generate a custom log id if (typeof log.blockHash === 'string' && typeof log.transactionHash === 'string' && @@ -383,12 +379,9 @@ var outputLogFormatter = function (log) { log.id = null; } - if (log.blockNumber !== null) - log.blockNumber = outputBigNumberFormatter(log.blockNumber); - if (log.transactionIndex !== null) - log.transactionIndex = utils.hexToNumber(log.transactionIndex); - if (log.logIndex !== null) - log.logIndex = utils.hexToNumber(log.logIndex); + log.blockNumber = outputBigNumberFormatter(log.blockNumber); + log.transactionIndex = utils.hexToNumber(log.transactionIndex); + log.logIndex = utils.hexToNumber(log.logIndex); if (log.address) { log.address = utils.toChecksumAddress(log.address); @@ -477,8 +470,8 @@ var outputSyncingFormatter = function (result) { result.currentBlock = outputBigNumberFormatter(result.currentBlock); result.highestBlock = outputBigNumberFormatter(result.highestBlock); if (result.knownStates) { - result.knownStates = utils.hexToNumber(result.knownStates); - result.pulledStates = utils.hexToNumber(result.pulledStates); + result.knownStates = outputBigNumberFormatter(result.knownStates); + result.pulledStates = outputBigNumberFormatter(result.pulledStates); } return result; diff --git a/test/contract.js b/test/contract.js index 59ea6d5b6c7..17fa09d5840 100644 --- a/test/contract.js +++ b/test/contract.js @@ -565,11 +565,11 @@ var runTests = function(contractFactory) { assert.deepEqual(result, { contractAddress: address, - cumulativeGasUsed: 10, + cumulativeGasUsed: '10', transactionIndex: 3, blockNumber: '10', blockHash: '0xbf1234', - gasUsed: 0 + gasUsed: '0' }); done(); }); @@ -659,11 +659,11 @@ var runTests = function(contractFactory) { .on('receipt', function(result){ assert.deepEqual(result, { contractAddress: address, - cumulativeGasUsed: 10, + cumulativeGasUsed: '10', transactionIndex: 3, blockNumber: '10', blockHash: '0xbf1234', - gasUsed: 0 + gasUsed: '0' }); done(); }).catch(console.log); @@ -1796,12 +1796,12 @@ var runTests = function(contractFactory) { // wont throw if it errors ?! assert.deepEqual(receipt, { contractAddress: null, - cumulativeGasUsed: 10, + cumulativeGasUsed: '10', transactionIndex: 3, transactionHash: '0x1234', blockNumber: '10', blockHash: '0x1234', - gasUsed: 0, + gasUsed: '0', events: { Unchanged: { address: address, @@ -1959,12 +1959,12 @@ var runTests = function(contractFactory) { // wont throw if it errors ?! nope: causes a timeout assert.deepEqual(receipt, { contractAddress: null, - cumulativeGasUsed: 10, + cumulativeGasUsed: '10', transactionIndex: 3, transactionHash: '0x1234', blockNumber: '10', blockHash: '0x1234', - gasUsed: 0, + gasUsed: '0', events: { Changed: [ { @@ -2111,12 +2111,12 @@ var runTests = function(contractFactory) { // wont throw if it errors ?! assert.deepEqual(receipt, { contractAddress: null, - cumulativeGasUsed: 10, + cumulativeGasUsed: '10', transactionIndex: 3, transactionHash: '0x1234', blockNumber: '10', blockHash: '0x43ffdd', - gasUsed: 0, + gasUsed: '0', events: { Unchanged: { address: address, @@ -2226,12 +2226,12 @@ var runTests = function(contractFactory) { if(count === 1) { assert.deepEqual(receipt, { contractAddress: null, - cumulativeGasUsed: 10, + cumulativeGasUsed: '10', transactionIndex: 3, transactionHash: '0x1234', blockNumber: '10', blockHash: '0x1234', - gasUsed: 0, + gasUsed: '0', events: {} }); @@ -2240,12 +2240,12 @@ var runTests = function(contractFactory) { if(count === 2) { assert.deepEqual(receipt, { contractAddress: null, - cumulativeGasUsed: 10, + cumulativeGasUsed: '10', transactionIndex: 3, transactionHash: '0x1234', blockNumber: '10', blockHash: '0x1234', - gasUsed: 0, + gasUsed: '0', events: {} }); @@ -3088,8 +3088,8 @@ describe('typical usage', function() { arguments: [account.address, 200] }).send({ from: account.address, - gas: 54872, - gasPrice: 3000, + gas: '54872', + gasPrice: '3000', chainId: 1, nonce: '1', chain: 'mainnet', diff --git a/test/eth.getBlock.js b/test/eth.getBlock.js index 0d1656852cd..13fc9fb3243 100644 --- a/test/eth.getBlock.js +++ b/test/eth.getBlock.js @@ -34,10 +34,10 @@ var formattedBlockResult = { "miner": "0x4E65FDa2159562a496F9f3522f89122A3088497a", "difficulty": '163591', "totalDifficulty": '163591', - "size": 163591, + "size": '163591', "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", - "gasLimit": 653145, - "gasUsed": 653145, + "gasLimit": '653145', + "gasUsed": '653145', "timestamp": '1424182926', "transactions": ['0x460cfb8472af2c5fd05b5a2','0x460cfb8472af2c5fd05b5a2'], "uncles": ["0x460cfb8472af2c5fd05b5a2", "0xd5460cfb8472af2c5fd05b5a2"] @@ -87,10 +87,10 @@ var formattedBlockResultWithTx = { "miner": "0x4E65FDa2159562a496F9f3522f89122A3088497a", "difficulty": '163591', "totalDifficulty": '163591', - "size": 163591, + "size": '163591', "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", - "gasLimit": 653145, - "gasUsed": 653145, + "gasLimit": '653145', + "gasUsed": '653145', "timestamp": '1424182926', "transactions": [{ "status": "mined", @@ -102,7 +102,7 @@ var formattedBlockResultWithTx = { "from":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", "to":"0x85F43D8a49eeB85d32Cf465507DD71d507100C1d", "value": '520464', - "gas": 520464, + "gas": '520464', "gasPrice": '10000000000000', "input":"0x603880600c6000396000f30060", }], diff --git a/test/eth.getTransaction.js b/test/eth.getTransaction.js index 2a7f52c2b99..7bcb45ff2cb 100644 --- a/test/eth.getTransaction.js +++ b/test/eth.getTransaction.js @@ -24,7 +24,7 @@ var formattedTxResult = { "from":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address "to":"0x85F43D8a49eeB85d32Cf465507DD71d507100C1d", // checksum address "value": '520464', - "gas": 520464, + "gas": '520464', "gasPrice": '10000000000000', "input":"0x603880600c6000396000f30060" }; diff --git a/test/eth.getTransactionFromBlock.js b/test/eth.getTransactionFromBlock.js index 880d762bcb2..a892b167283 100644 --- a/test/eth.getTransactionFromBlock.js +++ b/test/eth.getTransactionFromBlock.js @@ -26,7 +26,7 @@ var formattedTxResult = { "from":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address "to":"0x85F43D8a49eeB85d32Cf465507DD71d507100C1d", // checksum address "value": '520464', - "gas": 520464, + "gas": '520464', "gasPrice": '10000000000000', "input":"0x603880600c6000396000f30060" }; diff --git a/test/eth.getTransactionReceipt.js b/test/eth.getTransactionReceipt.js index f8d8e6dad72..d5206ba28ec 100644 --- a/test/eth.getTransactionReceipt.js +++ b/test/eth.getTransactionReceipt.js @@ -34,8 +34,8 @@ var formattedTxResult = { "transactionHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "transactionIndex": 1, "contractAddress":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address - "cumulativeGasUsed": 520464, - "gasUsed": 520464, + "cumulativeGasUsed": '520464', + "gasUsed": '520464', "logs": [{ id: "log_2b801386", transactionIndex: 1000, @@ -83,8 +83,8 @@ var tests = [{ "transactionHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "transactionIndex": 1, "contractAddress":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address - "cumulativeGasUsed": 520464, - "gasUsed": 520464, + "cumulativeGasUsed": '520464', + "gasUsed": '520464', }, call: 'eth_'+ method },{ @@ -107,8 +107,8 @@ var tests = [{ "transactionHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "transactionIndex": 16, "contractAddress":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address - "cumulativeGasUsed": 520464, - "gasUsed": 520464, + "cumulativeGasUsed": '520464', + "gasUsed": '520464', }, call: 'eth_'+ method }]; diff --git a/test/eth.getUncle.js b/test/eth.getUncle.js index 73a2c947ff6..079c1500554 100644 --- a/test/eth.getUncle.js +++ b/test/eth.getUncle.js @@ -34,10 +34,10 @@ var formattedBlockResult = { "miner": "0x4E65FDa2159562a496F9f3522f89122A3088497a", // checksum address "difficulty": '163591', "totalDifficulty": '163591', - "size": 163591, + "size": '163591', "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", - "gasLimit": 653145, - "gasUsed": 653145, + "gasLimit": '653145', + "gasUsed": '653145', "timestamp": '1424182926', "transactions": ['0x460cfb8472af2c5fd05b5a2','0x460cfb8472af2c5fd05b5a2'], "uncles": ["0x460cfb8472af2c5fd05b5a2", "0xd5460cfb8472af2c5fd05b5a2"] @@ -87,10 +87,10 @@ var formattedBlockResultWithTx = { "miner": "0x4E65FDa2159562a496F9f3522f89122A3088497a", // checksum address "difficulty": '163591', "totalDifficulty": '163591', - "size": 163591, + "size": '163591', "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", - "gasLimit": 653145, - "gasUsed": 653145, + "gasLimit": '653145', + "gasUsed": '653145', "timestamp": '1424182926', "transactions": [{ // "status": "mined", @@ -102,7 +102,7 @@ var formattedBlockResultWithTx = { "from":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address "to":"0x85F43D8a49eeB85d32Cf465507DD71d507100C1d", // checksum address "value": '520464', - "gas": 520464, + "gas": '520464', "gasPrice": '10000000000000', "input":"0x603880600c6000396000f30060", }], diff --git a/test/eth.sendTransaction.js b/test/eth.sendTransaction.js index 74c9919b34c..dcd6269f041 100644 --- a/test/eth.sendTransaction.js +++ b/test/eth.sendTransaction.js @@ -291,8 +291,8 @@ describe(method, function () { "transactionHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "transactionIndex": 1, "contractAddress":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address - "cumulativeGasUsed": 520464, - "gasUsed": 520464 + "cumulativeGasUsed": '520464', + "gasUsed": '520464' }); } else { assert.deepEqual(result, test.formattedResult); diff --git a/test/eth.subscribe.js b/test/eth.subscribe.js index f89b322238e..2c0452667a5 100644 --- a/test/eth.subscribe.js +++ b/test/eth.subscribe.js @@ -40,8 +40,8 @@ var tests = [{ difficulty: "24022326322090", totalDifficulty: "24022326322090", extraData: "0xd983010305844765746887676f312e342e328777696e646f7773", - gasLimit: 4712388, - gasUsed: 231000, + gasLimit: '4712388', + gasUsed: '231000', hash: "0x950427f707bf395fda0092d4f5dcbcf32d632106fb08e397124d0726082693e6", logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", miner: "0xf8b483DbA2c3B7176a3Da549ad41A48BB3121069", // checksum address @@ -53,7 +53,7 @@ var tests = [{ stateRoot: "0xb3346685172db67de536d8765c43c31009d0eb3bd9c501c9be3229203f15f378", timestamp: '1459613688', transactionsRoot: "0x0167ffa60e3ebc0b080cdb95f7c0087dd6c0e61413140e39d94d3468d7c9689f", - size: 0 + size: '0' }] }, // PENDING TRANSACTIONS @@ -459,15 +459,15 @@ var tests = [{ startingBlock: '786211', currentBlock: '786193', highestBlock: '712483', - knownStates: 698915, - pulledStates: 35 + knownStates: '698915', + pulledStates: '35' }, { startingBlock: '786211', currentBlock: '786193', highestBlock: '786193', - knownStates: 698915, - pulledStates: 35 + knownStates: '698915', + pulledStates: '35' }, false ] diff --git a/test/formatters.outputBlockFormatter.js b/test/formatters.outputBlockFormatter.js index 502369e8e0f..bec780c01b5 100644 --- a/test/formatters.outputBlockFormatter.js +++ b/test/formatters.outputBlockFormatter.js @@ -33,12 +33,12 @@ describe('formatters', function () { difficulty: '1000', totalDifficulty: '1000', number: '1000', - gasLimit: 1000, - gasUsed: 1000, + gasLimit: '1000', + gasUsed: '1000', timestamp: '1000', extraData: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265', nonce: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265', - size: 1000 + size: '1000' }); }); it('should return the correct value, when null values are present', function () { @@ -69,12 +69,12 @@ describe('formatters', function () { difficulty: '1000', totalDifficulty: '1000', number: null, - gasLimit: 1000, - gasUsed: 1000, + gasLimit: '1000', + gasUsed: '1000', timestamp: '1000', extraData: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265', nonce: null, - size: 1000 + size: '1000' }); }); }); diff --git a/test/formatters.outputTransactionFormatter.js b/test/formatters.outputTransactionFormatter.js index d3b00b179a8..b4d17af8843 100644 --- a/test/formatters.outputTransactionFormatter.js +++ b/test/formatters.outputTransactionFormatter.js @@ -21,7 +21,7 @@ describe('formatters', function () { from: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', to: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', value: '1000', - gas: 1000, + gas: '1000', gasPrice: '1000', nonce: '11', blockNumber: '1000', @@ -48,7 +48,7 @@ describe('formatters', function () { from: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', to: null, value: '1000', - gas: 1000, + gas: '1000', gasPrice: '1000', nonce: '11', blockNumber: null, diff --git a/test/formatters.outputTransactionReceiptFormatter.js b/test/formatters.outputTransactionReceiptFormatter.js index c7e117522f5..eb4991f05af 100644 --- a/test/formatters.outputTransactionReceiptFormatter.js +++ b/test/formatters.outputTransactionReceiptFormatter.js @@ -17,8 +17,8 @@ describe('outputTransactionReceiptFormatter', function() { assert.deepEqual(formatters.outputTransactionReceiptFormatter(receipt), { status: false, - cumulativeGasUsed: 256, - gasUsed: 256, + cumulativeGasUsed: '256', + gasUsed: '256', blockNumber: '256', transactionIndex: 10, to: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078', @@ -42,8 +42,8 @@ describe('outputTransactionReceiptFormatter', function() { assert.deepEqual(formatters.outputTransactionReceiptFormatter(receipt), { status: false, - cumulativeGasUsed: 256, - gasUsed: 256, + cumulativeGasUsed: '256', + gasUsed: '256', blockNumber: '256', transactionIndex: 10, to: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078', diff --git a/test/helpers/test.method.js b/test/helpers/test.method.js index 451a58f8888..49c1337bfa5 100644 --- a/test/helpers/test.method.js +++ b/test/helpers/test.method.js @@ -134,8 +134,8 @@ var runTests = function (obj, method, tests) { "transactionHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "transactionIndex": 1, "contractAddress":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address - "cumulativeGasUsed": 520464, - "gasUsed": 520464 + "cumulativeGasUsed": '520464', + "gasUsed": '520464' }); } else { assert.deepEqual(result, test.formattedResult); diff --git a/test/helpers/test.subscription.js b/test/helpers/test.subscription.js index 651a92586dc..d70fad6b8e9 100644 --- a/test/helpers/test.subscription.js +++ b/test/helpers/test.subscription.js @@ -6,7 +6,7 @@ var Web3 = require('../../packages/web3'); var runTests = function (protocol, tests) { - describe('web3.shh.subscribe', function () { + describe('web3.' + protocol + '.subscribe', function () { tests.forEach(function (test, index) { it('should create a subscription for "'+ test.args[0] +'"', function (done) { diff --git a/test/method.buildCall.js b/test/method.buildCall.js index 443ca967e58..5cdb2d6a120 100644 --- a/test/method.buildCall.js +++ b/test/method.buildCall.js @@ -304,11 +304,11 @@ describe('lib/web3/method', function () { assert.deepEqual(result, { contractAddress: address, - cumulativeGasUsed: 10, + cumulativeGasUsed: '10', transactionIndex: 3, blockNumber: '10', blockHash: '0xafff', - gasUsed: 0 + gasUsed: '0' }); done(); @@ -329,11 +329,11 @@ describe('lib/web3/method', function () { assert.deepEqual(result, { contractAddress: address, - cumulativeGasUsed: 10, + cumulativeGasUsed: '10', transactionIndex: 3, blockNumber: '10', blockHash: '0xafff', - gasUsed: 0 + gasUsed: '0' }); done(); @@ -424,11 +424,11 @@ describe('lib/web3/method', function () { assert.deepEqual(result, { contractAddress: address, - cumulativeGasUsed: 10, + cumulativeGasUsed: '10', transactionIndex: 3, blockNumber: '10', blockHash: '0xafff', - gasUsed: 0 + gasUsed: '0' }); done(); @@ -448,11 +448,11 @@ describe('lib/web3/method', function () { assert.deepEqual(result, { contractAddress: address, - cumulativeGasUsed: 10, + cumulativeGasUsed: '10', transactionIndex: 3, blockNumber: '10', blockHash: '0xafff', - gasUsed: 0 + gasUsed: '0' }); done(); @@ -831,11 +831,11 @@ describe('lib/web3/method', function () { assert.deepEqual(result, { contractAddress: null, - cumulativeGasUsed: 10, + cumulativeGasUsed: '10', transactionIndex: 3, blockNumber: '10', blockHash: '0xafff', - gasUsed: 0 + gasUsed: '0' }); }) @@ -843,11 +843,11 @@ describe('lib/web3/method', function () { assert.deepEqual(receipt, { contractAddress: null, - cumulativeGasUsed: 10, + cumulativeGasUsed: '10', transactionIndex: 3, blockNumber: '10', blockHash: '0xafff', - gasUsed: 0 + gasUsed: '0' }); assert.deepEqual(conf, countConf); From af5f3db6f7df5bf317a9320bb033fda8bc917046 Mon Sep 17 00:00:00 2001 From: nivida Date: Fri, 22 Nov 2019 13:27:36 +0100 Subject: [PATCH 07/14] documentation updated for web3-eth-ens, web3-eth, and web3-eth-contract. The eth.estimateGas return value is now handled as BigInt and I've updated related tests --- docs/web3-eth-contract.rst | 42 ++++++------ docs/web3-eth-ens.rst | 20 +++--- docs/web3-eth.rst | 74 ++++++++++----------- packages/web3-core/types/index.d.ts | 16 ++--- packages/web3-eth-contract/src/index.js | 2 +- packages/web3-eth-contract/types/index.d.ts | 12 ++-- packages/web3-eth/src/index.js | 2 +- packages/web3-eth/types/index.d.ts | 36 +++++----- test/contract.js | 4 +- test/eth.estimateGas.js | 2 +- 10 files changed, 105 insertions(+), 105 deletions(-) diff --git a/docs/web3-eth-contract.rst b/docs/web3-eth-contract.rst index 5e22ce4aa8e..6335702085f 100644 --- a/docs/web3-eth-contract.rst +++ b/docs/web3-eth-contract.rst @@ -48,8 +48,8 @@ Parameters 2. ``address`` - ``String`` (optional): The address of the smart contract to call. 3. ``options`` - ``Object`` (optional): The options of the contract. Some are used as fallbacks for calls and transactions: * ``from`` - ``String``: The address transactions should be made from. - * ``gasPrice`` - ``String``: The gas price in wei to use for transactions. - * ``gas`` - ``Number``: The maximum gas provided for a transaction (gas limit). + * ``gasPrice`` - ``Number|String|BN|BigNumber``: The gas price in wei to use for transactions. + * ``gas`` - ``Number|String|BN|BigNumber``: The maximum gas provided for a transaction (gas limit). * ``data`` - ``String``: The byte code of the contract. Used when the contract gets :ref:`deployed `. ------- @@ -140,7 +140,7 @@ Property The default block parameters can be one of the following: -- ``Number``: A block number +- ``Number|String|BN|BigNumber``: A block number - ``"genesis"`` - ``String``: The genesis block - ``"latest"`` - ``String``: The latest block (current head of the blockchain) - ``"pending"`` - ``String``: The currently mined block (including pending transactions) @@ -380,8 +380,8 @@ Properties - ``jsonInterface`` - ``Array``: The json interface of the contract. See :ref:`options.jsonInterface `. - ``data`` - ``String``: The byte code of the contract. Used when the contract gets :ref:`deployed `. - ``from`` - ``String``: The address transactions should be made from. -- ``gasPrice`` - ``String``: The gas price in wei to use for transactions. -- ``gas`` - ``Number``: The maximum gas provided for a transaction (gas limit). +- ``gasPrice`` - ``Number|String|BN|BigNumber``: The gas price in wei to use for transactions. +- ``gas`` - ``Number|String|BN|BigNumber``: The maximum gas provided for a transaction (gas limit). ------- @@ -723,8 +723,8 @@ Parameters 1. ``options`` - ``Object`` (optional): The options used for calling. * ``from`` - ``String`` (optional): The address the call "transaction" should be made from. - * ``gasPrice`` - ``String`` (optional): The gas price in wei to use for this call "transaction". - * ``gas`` - ``Number`` (optional): The maximum gas provided for this call "transaction" (gas limit). + * ``gasPrice`` - ``Number|String|BN|BigNumber`` (optional): The gas price in wei to use for this call "transaction". + * ``gas`` - ``Number|String|BN|BigNumber`` (optional): The maximum gas provided for this call "transaction" (gas limit). 2. ``callback`` - ``Function`` (optional): This callback will be fired with the result of the smart contract method execution as the second argument, or with an error object as the first argument. ------- @@ -810,8 +810,8 @@ Parameters 1. ``options`` - ``Object``: The options used for sending. * ``from`` - ``String``: The address the transaction should be sent from. - * ``gasPrice`` - ``String`` (optional): The gas price in wei to use for this transaction. - * ``gas`` - ``Number`` (optional): The maximum gas provided for this transaction (gas limit). + * ``gasPrice`` - ``Number|String|BN|BigNumber`` (optional): The gas price in wei to use for this transaction. + * ``gas`` - ``Number|String|BN|BigNumber`` (optional): The maximum gas provided for this transaction (gas limit). * ``value`` - ``Number|String|BN|BigNumber``(optional): The value transferred for the transaction in wei. 2. ``callback`` - ``Function`` (optional): This callback will be fired first with the "transactionHash", or with an error object as the first argument. @@ -862,10 +862,10 @@ Example "transactionHash": "0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b", "transactionIndex": 0, "blockHash": "0xef95f2f1ed3ca60b048b4bf67cde2195961e0bba6f70bcbea9a2c4e133e34b46", - "blockNumber": 3, + "blockNumber": '3', "contractAddress": "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe", - "cumulativeGasUsed": 314159, - "gasUsed": 30234, + "cumulativeGasUsed": '314159', + "gasUsed": '30234', "events": { "MyEvent": { returnValues: { @@ -883,7 +883,7 @@ Example transactionIndex: 0, transactionHash: '0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385', blockHash: '0xfd43ade1c09fade1c0d57a7af66ab4ead7c2c2eb7b11a91ffdd57a7af66ab4ead7', - blockNumber: 1234, + blockNumber: '1234', address: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe' }, "MyOtherEvent": { @@ -918,7 +918,7 @@ Parameters 1. ``options`` - ``Object`` (optional): The options used for calling. * ``from`` - ``String`` (optional): The address the call "transaction" should be made from. - * ``gas`` - ``Number`` (optional): The maximum gas provided for this call "transaction" (gas limit). Setting a specific value helps to detect out of gas errors. If all gas is used it will return the same number. + * ``gas`` - ``Number|String|BN|BigNumber`` (optional): The maximum gas provided for this call "transaction" (gas limit). Setting a specific value helps to detect out of gas errors. If all gas is used it will return the same number. * ``value`` - ``Number|String|BN|BigNumber``(optional): The value transferred for the call "transaction" in wei. 2. ``callback`` - ``Function`` (optional): This callback will be fired with the result of the gas estimation as the second argument, or with an error object as the first argument. @@ -926,7 +926,7 @@ Parameters Returns ------- -``Promise`` returns ``Number``: The gas amount estimated. +``Promise`` returns ``String``: The gas amount estimated. ------- Example @@ -1050,7 +1050,7 @@ Example transactionIndex: 0, transactionHash: '0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385', blockHash: '0xfd43ade1c09fade1c0d57a7af66ab4ead7c2c2eb7b11a91ffdd57a7af66ab4ead7', - blockNumber: 1234, + blockNumber: '1234', address: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe' } @@ -1074,7 +1074,7 @@ Parameters 1. ``options`` - ``Object`` (optional): The options used for deployment. * ``filter`` - ``Object`` (optional): Let you filter events by indexed parameters, e.g. ``{filter: {myNumber: [12,13]}}`` means all events where "myNumber" is 12 or 13. - * ``fromBlock`` - ``Number|String|BN|BigNumber`` (optional): The block number (greater than or equal to) from which to get events on. Pre-defined block numbers as ``"latest"``, ``"earlist"``, ``"pending"``, and ``"genesis"`` can also be used. + * ``fromBlock`` - ``Number|String|BN|BigNumber`` (optional): The block number (greater than or equal to) from which to get events on. Pre-defined block numbers as ``"latest"``, ``"earliest"``, ``"pending"``, and ``"genesis"`` can also be used. * ``topics`` - ``Array`` (optional): This allows to manually set the topics for the event filter. If given the filter property and event signature, (topic[0]) will not be set automatically. 2. ``callback`` - ``Function`` (optional): This callback will be fired for each *event* as the second argument, or an error as the first argument. @@ -1102,7 +1102,7 @@ The structure of the returned event ``Object`` looks as follows: - ``transactionIndex`` - ``Number``: Integer of the transaction's index position the event was created in. - ``transactionHash`` 32 Bytes - ``String``: Hash of the transaction this event was created in. - ``blockHash`` 32 Bytes - ``String``: Hash of the block this event was created in. ``null`` when it's still pending. -- ``blockNumber`` - ``Number``: The block number this log was created in. ``null`` when still pending. +- ``blockNumber`` - ``String``: The block number this log was created in. ``null`` when still pending. - ``raw.data`` - ``String``: The data containing non-indexed log parameter. - ``raw.topics`` - ``Array``: An array with max 4 32 Byte topics, topic 1-3 contains indexed parameters of the event. @@ -1146,7 +1146,7 @@ Example transactionIndex: 0, transactionHash: '0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385', blockHash: '0xfd43ade1c09fade1c0d57a7af66ab4ead7c2c2eb7b11a91ffdd57a7af66ab4ead7', - blockNumber: 1234, + blockNumber: '1234', address: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe' } @@ -1183,7 +1183,7 @@ Parameters 1. ``event`` - ``String``: The name of the event in the contract, or ``"allEvents"`` to get all events. 2. ``options`` - ``Object`` (optional): The options used for deployment. * ``filter`` - ``Object`` (optional): Lets you filter events by indexed parameters, e.g. ``{filter: {myNumber: [12,13]}}`` means all events where "myNumber" is 12 or 13. - * ``fromBlock`` - ``Number|String|BN|BigNumber`` (optional): The block number (greater than or equal to) from which to get events on. Pre-defined block numbers as ``"latest"``, ``"earlist"``, ``"pending"``, and ``"genesis"`` can also be used. + * ``fromBlock`` - ``Number|String|BN|BigNumber`` (optional): The block number (greater than or equal to) from which to get events on. Pre-defined block numbers as ``"latest"``, ``"earliest"``, ``"pending"``, and ``"genesis"`` can also be used. * ``toBlock`` - ``Number|String|BN|BigNumber`` (optional): The block number (less than or equal to) to get events up to (Defaults to ``"latest"``). Pre-defined block numbers as ``"latest"``, ``"earlist"``, ``"pending"``, and ``"genesis"`` can also be used. * ``topics`` - ``Array`` (optional): This allows manually setting the topics for the event filter. If given the filter property and event signature, (topic[0]) will not be set automatically. 3. ``callback`` - ``Function`` (optional): This callback will be fired with an array of event logs as the second argument, or an error as the first argument. @@ -1228,7 +1228,7 @@ Example transactionIndex: 0, transactionHash: '0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385', blockHash: '0xfd43ade1c09fade1c0d57a7af66ab4ead7c2c2eb7b11a91ffdd57a7af66ab4ead7', - blockNumber: 1234, + blockNumber: '1234', address: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe' },{ ... diff --git a/docs/web3-eth-ens.rst b/docs/web3-eth-ens.rst index cb1f5565703..4aacdc764aa 100644 --- a/docs/web3-eth-ens.rst +++ b/docs/web3-eth-ens.rst @@ -118,8 +118,8 @@ Parameters 2. ``address`` - ``String``: The address to set. 3. ``options`` - ``Object``: The options used for sending. * ``from`` - ``String``: The address the transaction should be sent from. - * ``gasPrice`` - ``String`` (optional): The gas price in wei to use for this transaction. - * ``gas`` - ``Number`` (optional): The maximum gas provided for this transaction (gas limit). + * ``gasPrice`` - ``Number|String|BN|BigNumber`` (optional): The gas price in wei to use for this transaction. + * ``gas`` - ``Number|String|BN|BigNumber`` (optional): The maximum gas provided for this transaction (gas limit). Emits an ``AddrChanged`` event. @@ -237,8 +237,8 @@ Parameters 3. ``y`` - ``String``: The Y coordinate of the public key. 4. ``options`` - ``Object``: The options used for sending. * ``from`` - ``String``: The address the transaction should be sent from. - * ``gasPrice`` - ``String`` (optional): The gas price in wei to use for this transaction. - * ``gas`` - ``Number`` (optional): The maximum gas provided for this transaction (gas limit). + * ``gasPrice`` - ``Number|String|BN|BigNumber`` (optional): The gas price in wei to use for this transaction. + * ``gas`` - ``Number|String|BN|BigNumber`` (optional): The maximum gas provided for this transaction (gas limit). Emits an ``PubkeyChanged`` event. @@ -353,8 +353,8 @@ Parameters 2. ``hash`` - ``String``: The content hash to set. 3. ``options`` - ``Object``: The options used for sending. * ``from`` - ``String``: The address the transaction should be sent from. - * ``gasPrice`` - ``String`` (optional): The gas price in wei to use for this transaction. - * ``gas`` - ``Number`` (optional): The maximum gas provided for this transaction (gas limit). + * ``gasPrice`` - ``Number|String|BN|BigNumber`` (optional): The gas price in wei to use for this transaction. + * ``gas`` - ``Number|String|BN|BigNumber`` (optional): The maximum gas provided for this transaction (gas limit). Emits an ``ContentChanged`` event. @@ -467,8 +467,8 @@ Parameters 2. ``hash`` - ``String``: The multihash to set. 3. ``options`` - ``Object``: The options used for sending. * ``from`` - ``String``: The address the transaction should be sent from. - * ``gasPrice`` - ``String`` (optional): The gas price in wei to use for this transaction. - * ``gas`` - ``Number`` (optional): The maximum gas provided for this transaction (gas limit). + * ``gasPrice`` - ``Number|String|BN|BigNumber`` (optional): The gas price in wei to use for this transaction. + * ``gas`` - ``Number|String|BN|BigNumber`` (optional): The maximum gas provided for this transaction (gas limit). Emits an ``MultihashChanged``event. @@ -566,7 +566,7 @@ Example transactionIndex: 0, transactionHash: '0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385', blockHash: '0xfd43ade1c09fade1c0d57a7af66ab4ead7c2c2eb7b11a91ffdd57a7af66ab4ead7', - blockNumber: 1234, + blockNumber: '1234', address: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe' } @@ -615,7 +615,7 @@ Example transactionIndex: 0, transactionHash: '0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385', blockHash: '0xfd43ade1c09fade1c0d57a7af66ab4ead7c2c2eb7b11a91ffdd57a7af66ab4ead7', - blockNumber: 1234, + blockNumber: '1234', address: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe' } diff --git a/docs/web3-eth.rst b/docs/web3-eth.rst index eeff7f48585..753bc16f6cf 100644 --- a/docs/web3-eth.rst +++ b/docs/web3-eth.rst @@ -448,11 +448,11 @@ Returns ``Promise`` returns ``Object|Boolean`` - A sync object when the node is currently syncing or ``false``: - - ``startingBlock`` - ``Number``: The block number where the sync started. - - ``currentBlock`` - ``Number``: The block number where at which block the node currently synced to already. - - ``highestBlock`` - ``Number``: The estimated block number to sync to. - - ``knownStates`` - ``Number``: The estimated states to download - - ``pulledStates`` - ``Number``: The already downloaded states + - ``startingBlock`` - ``String``: The block number where the sync started. + - ``currentBlock`` - ``String``: The block number where at which block the node currently synced to already. + - ``highestBlock`` - ``String``: The estimated block number to sync to. + - ``knownStates`` - ``String``: The estimated states to download + - ``pulledStates`` - ``String``: The already downloaded states ------- @@ -806,7 +806,7 @@ Returns ``Promise`` returns ``Object`` - The block object: - - ``number`` - ``Number``: The block number. ``null`` when its pending block. + - ``number`` - ``String``: The block number. ``null`` when its pending block. - ``hash`` 32 Bytes - ``String``: Hash of the block. ``null`` when its pending block. - ``parentHash`` 32 Bytes - ``String``: Hash of the parent block. - ``nonce`` 8 Bytes - ``String``: Hash of the generated proof-of-work. ``null`` when its pending block. @@ -818,10 +818,10 @@ Returns - ``difficulty`` - ``String``: Integer of the difficulty for this block. - ``totalDifficulty`` - ``String``: Integer of the total difficulty of the chain until this block. - ``extraData`` - ``String``: The "extra data" field of this block. - - ``size`` - ``Number``: Integer the size of this block in bytes. - - ``gasLimit`` - ``Number``: The maximum gas allowed in this block. - - ``gasUsed`` - ``Number``: The total used gas by all transactions in this block. - - ``timestamp`` - ``Number``: The unix timestamp for when the block was collated. + - ``size`` - ``String``: Integer the size of this block in bytes. + - ``gasLimit`` - ``String``: The maximum gas allowed in this block. + - ``gasUsed`` - ``String``: The total used gas by all transactions in this block. + - ``timestamp`` - ``String``: The unix timestamp for when the block was collated. - ``transactions`` - ``Array``: Array of transaction objects, or 32 Bytes transaction hashes depending on the ``returnTransactionObjects`` parameter. - ``uncles`` - ``Array``: Array of uncle hashes. @@ -836,7 +836,7 @@ Example .then(console.log); > { - "number": 3, + "number": "3", "hash": "0xef95f2f1ed3ca60b048b4bf67cde2195961e0bba6f70bcbea9a2c4e133e34b46", "parentHash": "0x2302e1c0b972d00932deb5dab9eb2982f570597d9d42504c05d9c2147eaf9c88", "nonce": "0xfb6e1a62d119228b", @@ -845,13 +845,13 @@ Example "transactionsRoot": "0x3a1b03875115b79539e5bd33fb00d8f7b7cd61929d5a3c574f507b8acf415bee", "stateRoot": "0xf1133199d44695dfa8fd1bcfe424d82854b5cebef75bddd7e40ea94cda515bcb", "miner": "0x8888f1f195afa192cfee860698584c030f4c9db1", - "difficulty": '21345678965432', - "totalDifficulty": '324567845321', - "size": 616, + "difficulty": "21345678965432", + "totalDifficulty": "324567845321", + "size": "616", "extraData": "0x", - "gasLimit": 3141592, - "gasUsed": 21662, - "timestamp": 1429287689, + "gasLimit": "3141592", + "gasUsed": "21662", + "timestamp": "1429287689", "transactions": [ "0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b" ], @@ -1011,15 +1011,15 @@ Returns ``Promise`` returns ``Object`` - A transaction object its hash ``transactionHash``: - ``hash`` 32 Bytes - ``String``: Hash of the transaction. - - ``nonce`` - ``Number``: The number of transactions made by the sender prior to this one. + - ``nonce`` - ``String``: The number of transactions made by the sender prior to this one. - ``blockHash`` 32 Bytes - ``String``: Hash of the block where this transaction was in. ``null`` when its pending. - - ``blockNumber`` - ``Number``: Block number where this transaction was in. ``null`` when its pending. + - ``blockNumber`` - ``String``: Block number where this transaction was in. ``null`` when its pending. - ``transactionIndex`` - ``Number``: Integer of the transactions index position in the block. ``null`` when its pending. - ``from`` - ``String``: Address of the sender. - ``to`` - ``String``: Address of the receiver. ``null`` when its a contract creation transaction. - ``value`` - ``String``: Value transferred in :ref:`wei `. - ``gasPrice`` - ``String``: Gas price provided by the sender in :ref:`wei `. - - ``gas`` - ``Number``: Gas provided by the sender. + - ``gas`` - ``String``: Gas provided by the sender. - ``input`` - ``String``: The data sent along with the transaction. @@ -1035,15 +1035,15 @@ Example > { "hash": "0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b", - "nonce": 2, + "nonce": "2", "blockHash": "0xef95f2f1ed3ca60b048b4bf67cde2195961e0bba6f70bcbea9a2c4e133e34b46", - "blockNumber": 3, + "blockNumber": "3", "transactionIndex": 0, "from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", "to": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f", - "value": '123450000000000000', - "gas": 314159, - "gasPrice": '2000000000000', + "value": "123450000000000000", + "gas": "314159", + "gasPrice": "2000000000000", "input": "0x57cb2fc4" } @@ -1124,14 +1124,14 @@ Returns - ``status`` - ``Boolean``: ``TRUE`` if the transaction was successful, ``FALSE``, if the EVM reverted the transaction. - ``blockHash`` 32 Bytes - ``String``: Hash of the block where this transaction was in. - - ``blockNumber`` - ``Number``: Block number where this transaction was in. + - ``blockNumber`` - ``String``: Block number where this transaction was in. - ``transactionHash`` 32 Bytes - ``String``: Hash of the transaction. - ``transactionIndex``- ``Number``: Integer of the transactions index position in the block. - ``from`` - ``String``: Address of the sender. - ``to`` - ``String``: Address of the receiver. ``null`` when its a contract creation transaction. - ``contractAddress`` - ``String``: The contract address created, if the transaction was a contract creation, otherwise ``null``. - - ``cumulativeGasUsed`` - ``Number``: The total amount of gas used when this transaction was executed in the block. - - ``gasUsed``- ``Number``: The amount of gas used by this specific transaction alone. + - ``cumulativeGasUsed`` - ``String``: The total amount of gas used when this transaction was executed in the block. + - ``gasUsed``- ``String``: The amount of gas used by this specific transaction alone. - ``logs`` - ``Array``: Array of log objects, which this transaction generated. ------- @@ -1148,10 +1148,10 @@ Example "transactionHash": "0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b", "transactionIndex": 0, "blockHash": "0xef95f2f1ed3ca60b048b4bf67cde2195961e0bba6f70bcbea9a2c4e133e34b46", - "blockNumber": 3, + "blockNumber": "3", "contractAddress": "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe", - "cumulativeGasUsed": 314159, - "gasUsed": 30234, + "cumulativeGasUsed": "314159", + "gasUsed": "30234", "logs": [{ // logs as returned by getPastLogs, etc. }, ...] @@ -1185,7 +1185,7 @@ Returns ------- -``Promise`` returns ``Number`` - The number of transactions sent from the given address. +``Promise`` returns ``String`` - The number of transactions sent from the given address. ------- Example @@ -1196,7 +1196,7 @@ Example web3.eth.getTransactionCount("0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe") .then(console.log); - > 1 + > "1" ------------------------------------------------------------------------------ @@ -1221,10 +1221,10 @@ Parameters - ``from`` - ``String|Number``: The address for the sending account. Uses the :ref:`web3.eth.defaultAccount ` property, if not specified. Or an address or index of a local wallet in :ref:`web3.eth.accounts.wallet `. - ``to`` - ``String``: (optional) The destination address of the message, left undefined for a contract-creation transaction. - ``value`` - ``Number|String|BN|BigNumber``: (optional) The value transferred for the transaction in :ref:`wei `, also the endowment if it's a contract-creation transaction. - - ``gas`` - ``Number``: (optional, default: To-Be-Determined) The amount of gas to use for the transaction (unused gas is refunded). + - ``gas`` - ``Number|String|BN|BigNumber``: (optional, default: To-Be-Determined) The amount of gas to use for the transaction (unused gas is refunded). - ``gasPrice`` - ``Number|String|BN|BigNumber``: (optional) The price of gas for this transaction in :ref:`wei `, defaults to :ref:`web3.eth.gasPrice `. - ``data`` - ``String``: (optional) Either a `ABI byte string `_ containing the data of the function call on a contract, or in the case of a contract-creation transaction the initialisation code. - - ``nonce`` - ``Number``: (optional) Integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce. + - ``nonce`` - ``Number|String|BN|BigNumber``: (optional) Integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce. - ``chain`` - ``String``: (optional) Defaults to ``mainnet``. - ``hardfork`` - ``String``: (optional) Defaults to ``petersburg``. - ``common`` - ``Object``: (optional) The common object @@ -1541,7 +1541,7 @@ Parameters Returns ------- -``Promise`` returns ``Number`` - the used gas for the simulated call/transaction. +``Promise`` returns ``String`` - the used gas for the simulated call/transaction. ------- Example @@ -1598,7 +1598,7 @@ The structure of the returned event ``Object`` in the ``Array`` looks as follows - ``transactionIndex`` - ``Number``: Integer of the transaction's index position, the event was created in. - ``transactionHash`` 32 Bytes - ``String``: Hash of the transaction this event was created in. - ``blockHash`` 32 Bytes - ``String``: Hash of the block where this event was created in. ``null`` when its still pending. -- ``blockNumber`` - ``Number``: The block number where this log was created in. ``null`` when still pending. +- ``blockNumber`` - ``String``: The block number where this log was created in. ``null`` when still pending. ------- Example diff --git a/packages/web3-core/types/index.d.ts b/packages/web3-core/types/index.d.ts index e4c561b19c0..d3773fdc079 100644 --- a/packages/web3-core/types/index.d.ts +++ b/packages/web3-core/types/index.d.ts @@ -104,15 +104,15 @@ export interface PromiEvent extends Promise { export interface Transaction { hash: string; - nonce: number; + nonce: string; blockHash: string | null; - blockNumber: number | null; + blockNumber: string | null; transactionIndex: number | null; from: string; to: string | null; value: string; gasPrice: string; - gas: number; + gas: string; input: string; } @@ -181,12 +181,12 @@ export interface TransactionReceipt { transactionHash: string; transactionIndex: number; blockHash: string; - blockNumber: number; + blockNumber: string; from: string; to: string; contractAddress?: string; - cumulativeGasUsed: number; - gasUsed: number; + cumulativeGasUsed: string; + gasUsed: string; logs: Log[]; logsBloom: string; events?: { @@ -202,7 +202,7 @@ export interface EventLog { transactionIndex: number; transactionHash: string; blockHash: string; - blockNumber: number; + blockNumber: string; raw?: {data: string; topics: any[]}; } @@ -214,7 +214,7 @@ export interface Log { transactionIndex: number; transactionHash: string; blockHash: string; - blockNumber: number; + blockNumber: string; } // had to move `web3-net` due to other modules in `1.x` not referencing diff --git a/packages/web3-eth-contract/src/index.js b/packages/web3-eth-contract/src/index.js index 0920b10b8b6..23ac40aaf9a 100644 --- a/packages/web3-eth-contract/src/index.js +++ b/packages/web3-eth-contract/src/index.js @@ -801,7 +801,7 @@ Contract.prototype._executeMethod = function _executeMethod(){ call: 'eth_estimateGas', params: 1, inputFormatter: [formatters.inputCallFormatter], - outputFormatter: utils.hexToNumber, + outputFormatter: formatters.outputBigNumberFormatter, requestManager: _this._parent._requestManager, accounts: ethAccounts, // is eth.accounts (necessary for wallet signing) defaultAccount: _this._parent.defaultAccount, diff --git a/packages/web3-eth-contract/types/index.d.ts b/packages/web3-eth-contract/types/index.d.ts index a9e2dabf478..54ba6f2874f 100644 --- a/packages/web3-eth-contract/types/index.d.ts +++ b/packages/web3-eth-contract/types/index.d.ts @@ -91,18 +91,18 @@ export interface ContractSendMethod { estimateGas( options: EstimateGasOptions, callback?: (err: Error, gas: number) => void - ): Promise; + ): Promise; - estimateGas(callback: (err: Error, gas: number) => void): Promise; + estimateGas(callback: (err: Error, gas: number) => void): Promise; estimateGas( options: EstimateGasOptions, callback: (err: Error, gas: number) => void - ): Promise; + ): Promise; - estimateGas(options: EstimateGasOptions): Promise; + estimateGas(options: EstimateGasOptions): Promise; - estimateGas(): Promise; + estimateGas(): Promise; encodeABI(): string; } @@ -157,6 +157,6 @@ export interface EventData { transactionIndex: number; transactionHash: string; blockHash: string; - blockNumber: number; + blockNumber: string; address: string; } diff --git a/packages/web3-eth/src/index.js b/packages/web3-eth/src/index.js index 11a3eea0188..563f818a66c 100644 --- a/packages/web3-eth/src/index.js +++ b/packages/web3-eth/src/index.js @@ -458,7 +458,7 @@ var Eth = function Eth() { call: 'eth_estimateGas', params: 1, inputFormatter: [formatter.inputCallFormatter], - outputFormatter: utils.hexToNumber + outputFormatter: formatter.outputBigNumberFormatter }), new Method({ name: 'submitWork', diff --git a/packages/web3-eth/types/index.d.ts b/packages/web3-eth/types/index.d.ts index 83d67ffd0ce..671af771188 100644 --- a/packages/web3-eth/types/index.d.ts +++ b/packages/web3-eth/types/index.d.ts @@ -154,7 +154,7 @@ export class Eth { getBlockNumber( callback?: (error: Error, blockNumber: number) => void - ): Promise; + ): Promise; getBalance( address: string @@ -276,20 +276,20 @@ export class Eth { ) => void ): Promise; - getTransactionCount(address: string): Promise; + getTransactionCount(address: string): Promise; getTransactionCount( address: string, defaultBlock: BlockNumber - ): Promise; + ): Promise; getTransactionCount( address: string, callback?: (error: Error, count: number) => void - ): Promise; + ): Promise; getTransactionCount( address: string, defaultBlock: BlockNumber, callback?: (error: Error, count: number) => void - ): Promise; + ): Promise; sendTransaction( transactionConfig: TransactionConfig, @@ -345,7 +345,7 @@ export class Eth { estimateGas( transactionConfig: TransactionConfig, callback?: (error: Error, gas: number) => void - ): Promise; + ): Promise; getPastLogs( options: PastLogsOptions, @@ -379,15 +379,15 @@ export class Eth { } export interface Syncing { - StartingBlock: number; - CurrentBlock: number; - HighestBlock: number; - KnownStates: number; - PulledStates: number; + startingBlock: string; + currentBlock: string; + highestBlock: string; + knownStates: string; + pulledStates: string; } export interface BlockHeader { - number: number; + number: string; hash: string; parentHash: string; nonce: string; @@ -398,9 +398,9 @@ export interface BlockHeader { receiptRoot: string; miner: string; extraData: string; - gasLimit: number; - gasUsed: number; - timestamp: number | string; + gasLimit: string; + gasUsed: string; + timestamp: string; } // TODO: This interface does exist to provide backwards-compatibility and can get removed on a minor release @@ -409,9 +409,9 @@ export interface Block extends BlockTransactionBase { } export interface BlockTransactionBase extends BlockHeader { - size: number; - difficulty: number; - totalDifficulty: number; + size: string; + difficulty: string; + totalDifficulty: string; uncles: string[]; } diff --git a/test/contract.js b/test/contract.js index 17fa09d5840..4173ccf7d2d 100644 --- a/test/contract.js +++ b/test/contract.js @@ -1477,7 +1477,7 @@ var runTests = function(contractFactory) { var contract = contractFactory(abi, address, provider); contract.methods.balance(address).estimateGas(function (err, res) { - assert.deepEqual(res, 50); + assert.deepEqual(res, '50'); done(); }); }); @@ -1499,7 +1499,7 @@ var runTests = function(contractFactory) { contract.deploy({ arguments: [address, 50] }).estimateGas(function (err, res) { - assert.deepEqual(res, 10); + assert.deepEqual(res, '10'); done(); }); }); diff --git a/test/eth.estimateGas.js b/test/eth.estimateGas.js index 808f6828456..45ea0d839c9 100644 --- a/test/eth.estimateGas.js +++ b/test/eth.estimateGas.js @@ -16,7 +16,7 @@ var tests = [{ gasPrice: '0xb' }], result: '0x31981', - formattedResult: 203137, + formattedResult: '203137', call: 'eth_'+ method }]; From 3306074cb8d99abadab6fbdb7b3f4d0ef03e942b Mon Sep 17 00:00:00 2001 From: nivida Date: Fri, 22 Nov 2019 14:05:12 +0100 Subject: [PATCH 08/14] documentation updated in web3-eth.rst and inputDefaultBlockFormatter updated to accept the same types as anywhere else for the block parameter --- docs/web3-eth.rst | 2 +- packages/web3-core-helpers/src/formatters.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/web3-eth.rst b/docs/web3-eth.rst index 753bc16f6cf..32acf65b6f7 100644 --- a/docs/web3-eth.rst +++ b/docs/web3-eth.rst @@ -187,7 +187,7 @@ Property Default block parameters can be one of the following: -- ``Number``: A block number +- ``Number|String|BN|BigNumber``: A block number - ``"genesis"`` - ``String``: The genesis block - ``"latest"`` - ``String``: The latest block (current head of the blockchain) - ``"pending"`` - ``String``: The currently mined block (including pending transactions) diff --git a/packages/web3-core-helpers/src/formatters.js b/packages/web3-core-helpers/src/formatters.js index 7c7d8c6f887..4681f254afd 100644 --- a/packages/web3-core-helpers/src/formatters.js +++ b/packages/web3-core-helpers/src/formatters.js @@ -99,7 +99,7 @@ var isPredefinedBlockNumber = function (blockNumber) { */ var inputDefaultBlockNumberFormatter = function (blockNumber) { if (this && (blockNumber === undefined || blockNumber === null)) { - return this.defaultBlock; + return utils.numberToHex(this.defaultBlock); } if (blockNumber === 'genesis' || blockNumber === 'earliest') { return '0x0'; From 8e83edece2f75230f88ffdc05e925f555a65246e Mon Sep 17 00:00:00 2001 From: nivida Date: Fri, 22 Nov 2019 14:09:12 +0100 Subject: [PATCH 09/14] increason of blockNumber in Method object for the HTTP confirmation workflow updated --- packages/web3-core-method/src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web3-core-method/src/index.js b/packages/web3-core-method/src/index.js index 18fc17affd9..e5fa5443292 100644 --- a/packages/web3-core-method/src/index.js +++ b/packages/web3-core-method/src/index.js @@ -299,7 +299,7 @@ Method.prototype._confirmTransaction = function(defer, result, payload) { if (existingReceipt === undefined || confirmationCount !== 0) { if (isPolling) { // Check if actually a new block is existing on polling if (lastBlock) { - block = await _ethereumCall.getBlockByNumber(parseInt(lastBlock.number) + 1); + block = await _ethereumCall.getBlockByNumber(utils.toBN(lastBlock.number).add(1)); if (block) { lastBlock = block; defer.eventEmitter.emit('confirmation', confirmationCount, receipt); From 9aa020ce9f3260893a8f684838ad92dd4935cfb1 Mon Sep 17 00:00:00 2001 From: nivida Date: Fri, 22 Nov 2019 14:16:44 +0100 Subject: [PATCH 10/14] type definition for the defaultBlock property and type tests updated --- packages/web3-eth-contract/types/index.d.ts | 2 +- .../types/tests/contract-test.ts | 8 +++--- packages/web3-eth/types/index.d.ts | 2 +- packages/web3-eth/types/tests/eth.tests.ts | 26 +++++++++---------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/web3-eth-contract/types/index.d.ts b/packages/web3-eth-contract/types/index.d.ts index 54ba6f2874f..c1a1031d45b 100644 --- a/packages/web3-eth-contract/types/index.d.ts +++ b/packages/web3-eth-contract/types/index.d.ts @@ -31,7 +31,7 @@ export class Contract { private _address: string; private _jsonInterface: AbiItem[]; defaultAccount: string | null; - defaultBlock: string | number; + defaultBlock: BlockNumber; defaultCommon: Common; defaultHardfork: hardfork; defaultChain: chain; diff --git a/packages/web3-eth-contract/types/tests/contract-test.ts b/packages/web3-eth-contract/types/tests/contract-test.ts index 631e08e88ad..8dce8d5a16c 100644 --- a/packages/web3-eth-contract/types/tests/contract-test.ts +++ b/packages/web3-eth-contract/types/tests/contract-test.ts @@ -25,7 +25,7 @@ const contract = new Contract([]); // $ExpectType string | null contract.defaultAccount; -// $ExpectType string | number +// $ExpectType BlockNumber contract.defaultBlock; // $ExpectType Common @@ -119,7 +119,7 @@ contract.getPastEvents( // $ExpectType Promise contract.getPastEvents('MyEvent', (error, events) => {}); -// $ExpectType Promise +// $ExpectType Promise contract .deploy({ data: '0x12345...', @@ -127,7 +127,7 @@ contract }) .estimateGas(); -// $ExpectType Promise +// $ExpectType Promise contract .deploy({ data: '0x12345...', @@ -135,7 +135,7 @@ contract }) .estimateGas({ from: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe' }); -// $ExpectType Promise +// $ExpectType Promise contract .deploy({ data: '0x12345...', diff --git a/packages/web3-eth/types/index.d.ts b/packages/web3-eth/types/index.d.ts index 671af771188..3f7510076c5 100644 --- a/packages/web3-eth/types/index.d.ts +++ b/packages/web3-eth/types/index.d.ts @@ -80,7 +80,7 @@ export class Eth { readonly givenProvider: any; static readonly givenProvider: any; defaultAccount: string | null; - defaultBlock: string | number; + defaultBlock: BlockNumber; defaultCommon: Common; defaultHardfork: hardfork; defaultChain: chain; diff --git a/packages/web3-eth/types/tests/eth.tests.ts b/packages/web3-eth/types/tests/eth.tests.ts index c62a89c8365..7fddf8d7101 100644 --- a/packages/web3-eth/types/tests/eth.tests.ts +++ b/packages/web3-eth/types/tests/eth.tests.ts @@ -46,7 +46,7 @@ const eth = new Eth('http://localhost:8545'); // $ExpectType string | null eth.defaultAccount; -// $ExpectType string | number +// $ExpectType BlockNumber eth.defaultBlock; // $ExpectType Common @@ -132,7 +132,7 @@ eth.givenProvider; // $ExpectType string | null eth.defaultAccount; -// $ExpectType string | number +// $ExpectType BlockNumber eth.defaultBlock; // $ExpectType boolean @@ -186,9 +186,9 @@ eth.getAccounts(); // $ExpectType Promise eth.getAccounts((error: Error, accounts: string[]) => {}); -// $ExpectType Promise +// $ExpectType Promise eth.getBlockNumber(); -// $ExpectType Promise +// $ExpectType Promise eth.getBlockNumber((error: Error, blockNumber: number) => {}); // $ExpectType Promise @@ -354,29 +354,29 @@ eth.getTransactionReceipt( (error: Error, transactionReceipt: TransactionReceipt) => {} ); -// $ExpectType Promise +// $ExpectType Promise eth.getTransactionCount('0x407d73d8a49eeb85d32cf465507dd71d507100c1'); -// $ExpectType Promise +// $ExpectType Promise eth.getTransactionCount('0x407d73d8a49eeb85d32cf465507dd71d507100c1', 1000); -// $ExpectType Promise +// $ExpectType Promise eth.getTransactionCount('0x407d73d8a49eeb85d32cf465507dd71d507100c1', '1000'); -// $ExpectType Promise +// $ExpectType Promise eth.getTransactionCount( '0x407d73d8a49eeb85d32cf465507dd71d507100c1', (error: Error, count: number) => {} ); -// $ExpectType Promise +// $ExpectType Promise eth.getTransactionCount( '0x407d73d8a49eeb85d32cf465507dd71d507100c1', (error: Error, count: number) => {} ); -// $ExpectType Promise +// $ExpectType Promise eth.getTransactionCount( '0x407d73d8a49eeb85d32cf465507dd71d507100c1', 1000, (error: Error, count: number) => {} ); -// $ExpectType Promise +// $ExpectType Promise eth.getTransactionCount( '0x407d73d8a49eeb85d32cf465507dd71d507100c1', '1000', @@ -532,13 +532,13 @@ eth.call( (error: Error, data: string) => {} ); -// $ExpectType Promise +// $ExpectType Promise eth.estimateGas({ to: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', data: '0xc6888fa10000000000000000000000000000000000000000000000000000000000000003' }); -// $ExpectType Promise +// $ExpectType Promise eth.estimateGas( { to: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', From 67fb2d2574ee0f25d820c7fa0bc5f028dd2520b4 Mon Sep 17 00:00:00 2001 From: nivida Date: Fri, 22 Nov 2019 14:33:00 +0100 Subject: [PATCH 11/14] timestamp handling in ens.checkNetwork updated to support nanosecond timestamps as well --- packages/web3-eth-ens/src/ENS.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/web3-eth-ens/src/ENS.js b/packages/web3-eth-ens/src/ENS.js index e06970de0b5..559d86bb207 100644 --- a/packages/web3-eth-ens/src/ENS.js +++ b/packages/web3-eth-ens/src/ENS.js @@ -172,11 +172,20 @@ ENS.prototype.setMultihash = function (name, hash, sendOptions, callback) { ENS.prototype.checkNetwork = function () { var self = this; return self.eth.getBlock('latest').then(function (block) { - // TODO: Check with Quorum timestamp - var headAge = utils.toBN((Math.floor(new Date() / 1000))).sub(utils.toBN(block.timestamp)); + var headAge; + var now = utils.toBN((Math.floor(new Date() / 1000))); + var timestamp = utils.toBN(block.timestamp); + + if (timestamp.bitLength() <= 53) { + headAge = now.sub(timestamp); + } else { + headAge = now.sub(timestamp.divn(1000000)); + } + if (headAge.gtn(3600)) { throw new Error("Network not synced; last block was " + headAge + " seconds ago"); } + return self.eth.net.getNetworkType(); }).then(function (networkType) { var addr = config.addresses[networkType]; From 48e951db2ec1ee82eb3238cf595abaf4cf594eab Mon Sep 17 00:00:00 2001 From: nivida Date: Fri, 22 Nov 2019 14:52:42 +0100 Subject: [PATCH 12/14] ens.checkNetwork updated because it was using the seconds and not miliseconds as I thought --- packages/web3-eth-ens/src/ENS.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/web3-eth-ens/src/ENS.js b/packages/web3-eth-ens/src/ENS.js index 559d86bb207..c92c952f961 100644 --- a/packages/web3-eth-ens/src/ENS.js +++ b/packages/web3-eth-ens/src/ENS.js @@ -173,13 +173,13 @@ ENS.prototype.checkNetwork = function () { var self = this; return self.eth.getBlock('latest').then(function (block) { var headAge; - var now = utils.toBN((Math.floor(new Date() / 1000))); + var now = utils.toBN((Math.floor(new Date().getTime() / 1000))); var timestamp = utils.toBN(block.timestamp); if (timestamp.bitLength() <= 53) { headAge = now.sub(timestamp); } else { - headAge = now.sub(timestamp.divn(1000000)); + headAge = now.sub(timestamp.divn(1000000000)); } if (headAge.gtn(3600)) { From f58a0dfc734e7b5ad297f74452f89c5da1b99b2b Mon Sep 17 00:00:00 2001 From: nivida Date: Fri, 22 Nov 2019 15:02:50 +0100 Subject: [PATCH 13/14] inputDefaultBlockNumberFormatter fixed for predefined block numbers --- packages/web3-core-helpers/src/formatters.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/web3-core-helpers/src/formatters.js b/packages/web3-core-helpers/src/formatters.js index 4681f254afd..395ba80511b 100644 --- a/packages/web3-core-helpers/src/formatters.js +++ b/packages/web3-core-helpers/src/formatters.js @@ -98,6 +98,10 @@ var isPredefinedBlockNumber = function (blockNumber) { * @returns {String} */ var inputDefaultBlockNumberFormatter = function (blockNumber) { + if (isPredefinedBlockNumber(blockNumber)) { + return blockNumber; + } + if (this && (blockNumber === undefined || blockNumber === null)) { return utils.numberToHex(this.defaultBlock); } From a4aed067ab1d20a37e131421b63c73b0bf43a4a5 Mon Sep 17 00:00:00 2001 From: nivida Date: Fri, 22 Nov 2019 15:05:04 +0100 Subject: [PATCH 14/14] block number handling updated for the web3.js predefined block number --- packages/web3-core-helpers/src/formatters.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/web3-core-helpers/src/formatters.js b/packages/web3-core-helpers/src/formatters.js index 395ba80511b..c7357f96710 100644 --- a/packages/web3-core-helpers/src/formatters.js +++ b/packages/web3-core-helpers/src/formatters.js @@ -98,6 +98,10 @@ var isPredefinedBlockNumber = function (blockNumber) { * @returns {String} */ var inputDefaultBlockNumberFormatter = function (blockNumber) { + if (blockNumber === 'genesis') { + return 'earliest'; + } + if (isPredefinedBlockNumber(blockNumber)) { return blockNumber; } @@ -105,9 +109,7 @@ var inputDefaultBlockNumberFormatter = function (blockNumber) { if (this && (blockNumber === undefined || blockNumber === null)) { return utils.numberToHex(this.defaultBlock); } - if (blockNumber === 'genesis' || blockNumber === 'earliest') { - return '0x0'; - } + return inputBlockNumberFormatter(blockNumber); };