web3-core-helpers
Advanced tools
Comparing version 1.2.4 to 1.2.5-rc.0
{ | ||
"name": "web3-core-helpers", | ||
"version": "1.2.4", | ||
"version": "1.2.5-rc.0", | ||
"description": "Web3 core tools helper for sub packages. This is an internal package.", | ||
@@ -17,4 +17,4 @@ "repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-core-helpers", | ||
"underscore": "1.9.1", | ||
"web3-eth-iban": "1.2.4", | ||
"web3-utils": "1.2.4" | ||
"web3-eth-iban": "1.2.5-rc.0", | ||
"web3-utils": "1.2.5-rc.0" | ||
}, | ||
@@ -26,3 +26,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "341015ab24efc3ea1e5d8afd07e8c92a7c738536" | ||
"gitHead": "e919f81ccf7fee23a2d9075fa141bec0ff4a087a" | ||
} |
@@ -46,3 +46,36 @@ /* | ||
return new Error('CONNECTION TIMEOUT: timeout of ' + ms + ' ms achived'); | ||
}, | ||
RevertInstructionError: function(reason, signature) { | ||
var error = new Error('Your request got reverted with the following reason string: ' + reason); | ||
error.reason = reason; | ||
error.signature = signature; | ||
return error; | ||
}, | ||
TransactionRevertInstructionError: function(reason, signature, receipt) { | ||
var error = new Error('Transaction has been reverted by the EVM:\n' + JSON.stringify(receipt, null, 2)); | ||
error.reason = reason; | ||
error.signature = signature; | ||
error.receipt = receipt; | ||
return error; | ||
}, | ||
TransactionError: function(message, receipt) { | ||
var error = new Error(message); | ||
error.receipt = receipt; | ||
return error; | ||
}, | ||
NoContractAddressFoundError: function(receipt) { | ||
return this.TransactionError('The transaction receipt didn\'t contain a contract address.', receipt); | ||
}, | ||
ContractCodeNotStoredError: function(receipt) { | ||
return this.TransactionError('The contract code couldn\'t be stored, please check your gas limit.', receipt); | ||
}, | ||
TransactionRevertedWithoutReasonError: function(receipt) { | ||
return this.TransactionError('Transaction has been reverted by the EVM:\n' + JSON.stringify(receipt, null, 2), receipt); | ||
}, | ||
TransactionOutOfGasError: function(receipt) { | ||
return this.TransactionError('Transaction ran out of gas. Please provide more gas:\n' + JSON.stringify(receipt, null, 2), receipt); | ||
} | ||
}; |
@@ -26,3 +26,2 @@ /* | ||
var _ = require('underscore'); | ||
@@ -32,3 +31,34 @@ var utils = require('web3-utils'); | ||
/** | ||
* Will format the given storage key array values to hex strings. | ||
* | ||
* @method inputStorageKeysFormatter | ||
* | ||
* @param {Array<Number|String|BN|BigNumber>} keys | ||
* | ||
* @returns {Array<String>} | ||
*/ | ||
var inputStorageKeysFormatter = function (keys) { | ||
return keys.map(utils.numberToHex); | ||
}; | ||
/** | ||
* Will format the given proof response from the node. | ||
* | ||
* @method outputProofFormatter | ||
* | ||
* @param {object} proof | ||
* | ||
* @returns {object} | ||
*/ | ||
var outputProofFormatter = function (proof) { | ||
proof.address = utils.toChecksumAddress(proof.address); | ||
proof.nonce = utils.hexToNumberString(proof.nonce); | ||
proof.balance = utils.hexToNumberString(proof.balance); | ||
return proof; | ||
}; | ||
/** | ||
* Should the format output to a big number | ||
@@ -70,7 +100,5 @@ * | ||
if (this && (blockNumber === undefined || blockNumber === null)) { | ||
return this.defaultBlock; | ||
return inputBlockNumberFormatter(this.defaultBlock); | ||
} | ||
if (blockNumber === 'genesis' || blockNumber === 'earliest') { | ||
return '0x0'; | ||
} | ||
return inputBlockNumberFormatter(blockNumber); | ||
@@ -82,5 +110,5 @@ }; | ||
* | ||
* @param {String|Number|undefined} blockNumber | ||
* @param {String|Number|BN|BigNumber} blockNumber | ||
* | ||
* @returns {String|Number|BN|BigNumber} | ||
* @returns {String} | ||
*/ | ||
@@ -90,5 +118,12 @@ var inputBlockNumberFormatter = function (blockNumber) { | ||
return undefined; | ||
} else if (isPredefinedBlockNumber(blockNumber)) { | ||
} | ||
if (isPredefinedBlockNumber(blockNumber)) { | ||
return blockNumber; | ||
} | ||
if (blockNumber === 'genesis') { | ||
return '0x0'; | ||
} | ||
return (utils.isHexStrict(blockNumber)) ? ((_.isString(blockNumber)) ? blockNumber.toLowerCase() : blockNumber) : utils.numberToHex(blockNumber); | ||
@@ -104,3 +139,3 @@ }; | ||
*/ | ||
var _txInputFormatter = function (options){ | ||
var _txInputFormatter = function (options) { | ||
@@ -120,3 +155,3 @@ if (options.to) { // it might be contract creation | ||
if(options.data && !utils.isHex(options.data)) { | ||
if (options.data && !utils.isHex(options.data)) { | ||
throw new Error('The data field must be HEX encoded data.'); | ||
@@ -132,3 +167,3 @@ } | ||
return options[key] !== undefined; | ||
}).forEach(function(key){ | ||
}).forEach(function (key) { | ||
options[key] = utils.numberToHex(options[key]); | ||
@@ -146,4 +181,4 @@ }); | ||
* @returns object | ||
*/ | ||
var inputCallFormatter = function (options){ | ||
*/ | ||
var inputCallFormatter = function (options) { | ||
@@ -168,3 +203,3 @@ options = _txInputFormatter(options); | ||
* @returns object | ||
*/ | ||
*/ | ||
var inputTransactionFormatter = function (options) { | ||
@@ -205,7 +240,7 @@ | ||
* @returns {Object} | ||
*/ | ||
var outputTransactionFormatter = function (tx){ | ||
if(tx.blockNumber !== null) | ||
*/ | ||
var outputTransactionFormatter = function (tx) { | ||
if (tx.blockNumber !== null) | ||
tx.blockNumber = utils.hexToNumber(tx.blockNumber); | ||
if(tx.transactionIndex !== null) | ||
if (tx.transactionIndex !== null) | ||
tx.transactionIndex = utils.hexToNumber(tx.transactionIndex); | ||
@@ -217,3 +252,3 @@ tx.nonce = utils.hexToNumber(tx.nonce); | ||
if(tx.to && utils.isAddress(tx.to)) { // tx.to could be `0x0` or `null` while contract creation | ||
if (tx.to && utils.isAddress(tx.to)) { // tx.to could be `0x0` or `null` while contract creation | ||
tx.to = utils.toChecksumAddress(tx.to); | ||
@@ -224,3 +259,3 @@ } else { | ||
if(tx.from) { | ||
if (tx.from) { | ||
tx.from = utils.toChecksumAddress(tx.from); | ||
@@ -238,11 +273,11 @@ } | ||
* @returns {Object} | ||
*/ | ||
var outputTransactionReceiptFormatter = function (receipt){ | ||
if(typeof receipt !== 'object') { | ||
throw new Error('Received receipt is invalid: '+ receipt); | ||
*/ | ||
var outputTransactionReceiptFormatter = function (receipt) { | ||
if (typeof receipt !== 'object') { | ||
throw new Error('Received receipt is invalid: ' + receipt); | ||
} | ||
if(receipt.blockNumber !== null) | ||
if (receipt.blockNumber !== null) | ||
receipt.blockNumber = utils.hexToNumber(receipt.blockNumber); | ||
if(receipt.transactionIndex !== null) | ||
if (receipt.transactionIndex !== null) | ||
receipt.transactionIndex = utils.hexToNumber(receipt.transactionIndex); | ||
@@ -252,11 +287,11 @@ receipt.cumulativeGasUsed = utils.hexToNumber(receipt.cumulativeGasUsed); | ||
if(_.isArray(receipt.logs)) { | ||
if (_.isArray(receipt.logs)) { | ||
receipt.logs = receipt.logs.map(outputLogFormatter); | ||
} | ||
if(receipt.contractAddress) { | ||
if (receipt.contractAddress) { | ||
receipt.contractAddress = utils.toChecksumAddress(receipt.contractAddress); | ||
} | ||
if(typeof receipt.status !== 'undefined' && receipt.status !== null) { | ||
if (typeof receipt.status !== 'undefined' && receipt.status !== null) { | ||
receipt.status = Boolean(parseInt(receipt.status)); | ||
@@ -274,4 +309,4 @@ } | ||
* @returns {Object} | ||
*/ | ||
var outputBlockFormatter = function(block) { | ||
*/ | ||
var outputBlockFormatter = function (block) { | ||
@@ -286,10 +321,10 @@ // transform to 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){ | ||
if(!_.isString(item)) | ||
block.transactions.forEach(function (item) { | ||
if (!_.isString(item)) | ||
return outputTransactionFormatter(item); | ||
@@ -311,7 +346,7 @@ }); | ||
* @returns {Object} log | ||
*/ | ||
var inputLogFormatter = function(options) { | ||
var toTopic = function(value){ | ||
*/ | ||
var inputLogFormatter = function (options) { | ||
var toTopic = function (value) { | ||
if(value === null || typeof value === 'undefined') | ||
if (value === null || typeof value === 'undefined') | ||
return null; | ||
@@ -321,3 +356,3 @@ | ||
if(value.indexOf('0x') === 0) | ||
if (value.indexOf('0x') === 0) | ||
return value; | ||
@@ -337,3 +372,3 @@ else | ||
options.topics = options.topics || []; | ||
options.topics = options.topics.map(function(topic){ | ||
options.topics = options.topics.map(function (topic) { | ||
return (_.isArray(topic)) ? topic.map(toTopic) : toTopic(topic); | ||
@@ -359,12 +394,12 @@ }); | ||
* @returns {Object} log | ||
*/ | ||
var outputLogFormatter = function(log) { | ||
*/ | ||
var outputLogFormatter = function (log) { | ||
// generate a custom log id | ||
if(typeof log.blockHash === 'string' && | ||
typeof log.transactionHash === 'string' && | ||
typeof log.logIndex === 'string') { | ||
var shaId = utils.sha3(log.blockHash.replace('0x','') + log.transactionHash.replace('0x','') + log.logIndex.replace('0x','')); | ||
log.id = 'log_'+ shaId.replace('0x','').substr(0,8); | ||
} else if(!log.id) { | ||
if (typeof log.blockHash === 'string' && | ||
typeof log.transactionHash === 'string' && | ||
typeof log.logIndex === 'string') { | ||
var shaId = utils.sha3(log.blockHash.replace('0x', '') + log.transactionHash.replace('0x', '') + log.logIndex.replace('0x', '')); | ||
log.id = 'log_' + shaId.replace('0x', '').substr(0, 8); | ||
} else if (!log.id) { | ||
log.id = null; | ||
@@ -393,4 +428,4 @@ } | ||
* @returns {Object} | ||
*/ | ||
var inputPostFormatter = function(post) { | ||
*/ | ||
var inputPostFormatter = function (post) { | ||
@@ -412,3 +447,3 @@ // post.payload = utils.toHex(post.payload); | ||
// format the following options | ||
post.topics = post.topics.map(function(topic){ | ||
post.topics = post.topics.map(function (topic) { | ||
// convert only if not hex | ||
@@ -428,3 +463,3 @@ return (topic.indexOf('0x') === 0) ? topic : utils.fromUtf8(topic); | ||
*/ | ||
var outputPostFormatter = function(post){ | ||
var outputPostFormatter = function (post) { | ||
@@ -446,3 +481,3 @@ post.expiry = utils.hexToNumber(post.expiry); | ||
} | ||
post.topics = post.topics.map(function(topic){ | ||
post.topics = post.topics.map(function (topic) { | ||
return utils.toUtf8(topic); | ||
@@ -459,9 +494,9 @@ }); | ||
} else if (utils.isAddress(address)) { | ||
return '0x' + address.toLowerCase().replace('0x',''); | ||
return '0x' + address.toLowerCase().replace('0x', ''); | ||
} | ||
throw new Error('Provided address "'+ address +'" is invalid, the capitalization checksum test failed, or its an indrect IBAN address which can\'t be converted.'); | ||
throw new Error('Provided address "' + address + '" is invalid, the capitalization checksum test failed, or its an indrect IBAN address which can\'t be converted.'); | ||
}; | ||
var outputSyncingFormatter = function(result) { | ||
var outputSyncingFormatter = function (result) { | ||
@@ -488,2 +523,4 @@ result.startingBlock = utils.hexToNumber(result.startingBlock); | ||
inputSignFormatter: inputSignFormatter, | ||
inputStorageKeysFormatter: inputStorageKeysFormatter, | ||
outputProofFormatter: outputProofFormatter, | ||
outputBigNumberFormatter: outputBigNumberFormatter, | ||
@@ -490,0 +527,0 @@ outputTransactionFormatter: outputTransactionFormatter, |
@@ -21,2 +21,4 @@ /* | ||
import * as net from 'net'; | ||
import * as http from 'http'; | ||
import * as https from 'https'; | ||
@@ -70,2 +72,9 @@ export class formatters { | ||
static ConnectionTimeout(ms: string): Error; | ||
static RevertInstructionError(reason: string, signature: string): RevertInstructionError | ||
static TransactionRevertInstructionError(reason: string, signature: string, receipt: object): TransactionRevertInstructionError | ||
static TransactionError(message: string, receipt: object): TransactionError | ||
static NoContractAddressFoundError(receipt: object): TransactionError | ||
static ContractCodeNotStoredError(receipt: object): TransactionError | ||
static TransactionRevertedWithoutReasonError(receipt: object): TransactionError | ||
static TransactionOutOfGasError(receipt: object): TransactionError | ||
} | ||
@@ -156,4 +165,11 @@ | ||
withCredentials?: boolean; | ||
agent?: HttpAgent | ||
} | ||
export interface HttpAgent { | ||
http?: http.Agent; | ||
https?: https.Agent; | ||
baseUrl?: string; | ||
} | ||
export interface HttpHeader { | ||
@@ -188,1 +204,15 @@ name: string; | ||
} | ||
export interface RevertInstructionError extends Error { | ||
reason: string; | ||
signature: string; | ||
} | ||
export interface TransactionRevertInstructionError extends Error { | ||
reason: string; | ||
signature: string; | ||
} | ||
export interface TransactionError extends Error { | ||
receipt: object; | ||
} |
@@ -39,1 +39,7 @@ /* | ||
errors.ConnectionTimeout('timeout'); | ||
// $ExpectType RevertInstructionError | ||
errors.RevertInstructionError('reason', 'signature'); | ||
// $ExpectType TransactionRevertInstructionError | ||
errors.TransactionRevertInstructionError('reason', 'signature', {}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30683
787
2
+ Addedweb3-eth-iban@1.2.5-rc.0(transitive)
+ Addedweb3-utils@1.2.5-rc.0(transitive)
- Removedweb3-eth-iban@1.2.4(transitive)
- Removedweb3-utils@1.2.4(transitive)
Updatedweb3-eth-iban@1.2.5-rc.0
Updatedweb3-utils@1.2.5-rc.0