Skip to content

Commit

Permalink
Merge 1961eb5 into 6862c59
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamincburns committed Jul 13, 2020
2 parents 6862c59 + 1961eb5 commit e4af90b
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 48 deletions.
1 change: 1 addition & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"bitwise": true,
"camelcase": true,
"eqeqeq": true,
"esversion": 8,
"freeze": true,
"funcscope": false,
"maxcomplexity": 15,
Expand Down
10 changes: 5 additions & 5 deletions packages/web3-core-method/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ Method.prototype._confirmTransaction = function (defer, result, payload) {
gas: parsedTx.gasLimit.toHexString(),
gasPrice: parsedTx.gasPrice.toHexString(),
value: parsedTx.value.toHexString()
})
});
}

// Get revert reason string with eth_call
Expand Down Expand Up @@ -549,19 +549,19 @@ Method.prototype._confirmTransaction = function (defer, result, payload) {
var startWatching = function (existingReceipt) {
const startInterval = () => {
intervalId = setInterval(checkConfirmation.bind(null, existingReceipt, true), 1000);
}
};

if (!this.requestManager.provider.on) {
startInterval()
startInterval();
} else {
_ethereumCall.subscribe('newBlockHeaders', function (err, blockHeader, sub) {
if (err || !blockHeader) {
// fall back to polling
startInterval()
startInterval();
} else {
checkConfirmation(existingReceipt, false, err, blockHeader, sub);
}
})
});
}
}.bind(this);

Expand Down
2 changes: 1 addition & 1 deletion packages/web3-core-subscriptions/src/subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ Subscription.prototype.subscribe = function() {
// Re-subscription only: continue fetching from the last block we received.
// a dropped connection may have resulted in gaps in the logs...
if (this.lastBlock && _.isObject(this.options.params)){
payload.params[1] = this.options.params
payload.params[1] = this.options.params;
payload.params[1].fromBlock = formatters.inputBlockNumberFormatter(this.lastBlock + 1);
}

Expand Down
32 changes: 16 additions & 16 deletions packages/web3-eth-abi/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@ ABICoder.prototype.encodeParameter = function (type, param) {
*/
ABICoder.prototype.encodeParameters = function (types, params) {
var self = this;
types = self.mapTypes(types)
types = self.mapTypes(types);

params = params.map(function (param, index) {
let type = types[index]
let type = types[index];
if (typeof type === 'object' && type.type) {
// We may get a named type of shape {name, type}
type = type.type
type = type.type;
}

param = self.formatParam(type, param)
param = self.formatParam(type, param);

// Format params for tuples
if (typeof type === 'string' && type.includes('tuple')) {
Expand All @@ -121,21 +121,21 @@ ABICoder.prototype.encodeParameters = function (types, params) {
ethersAbiCoder._getCoder(ParamType.from(coder.type.replace('[]', ''))),
p
)
)
);
}
coder.coders.forEach((c, i) => {
if (c.name === 'tuple') {
modifyParams(c, param[i])
modifyParams(c, param[i]);
} else {
param[i] = self.formatParam(c.name, param[i])
param[i] = self.formatParam(c.name, param[i]);
}
})
}
modifyParams(coder, param)
});
};
modifyParams(coder, param);
}

return param;
})
});

return ethersAbiCoder.encode(types, params);
};
Expand All @@ -155,7 +155,7 @@ ABICoder.prototype.mapTypes = function (types) {
// recognize former type. Solidity docs say `Function` is a bytes24
// encoding the contract address followed by the function selector hash.
if (typeof type === 'object' && type.type === 'function'){
type.type = "bytes24"
type.type = "bytes24";
}
if (self.isSimplifiedStructFormat(type)) {
var structName = Object.keys(type)[0];
Expand Down Expand Up @@ -259,7 +259,7 @@ ABICoder.prototype.formatParam = function (type, param) {
}

if (type.match(paramTypeBytesArray) || type.match(paramTypeNumberArray)) {
return param.map(p => this.formatParam(type.replace('[]', ''), p))
return param.map(p => this.formatParam(type.replace('[]', ''), p));
}

// Format correct width for u?int[0-9]*
Expand Down Expand Up @@ -288,17 +288,17 @@ ABICoder.prototype.formatParam = function (type, param) {
}
if (param.length < maxSize) {
// pad to correct length
param = utils.rightPad(param, size * 2)
param = utils.rightPad(param, size * 2);
}
}

// format odd-length bytes to even-length
if (param.length % 2 === 1) {
param = '0x0' + param.substring(2)
param = '0x0' + param.substring(2);
}
}

return param
return param;
};

/**
Expand Down
56 changes: 31 additions & 25 deletions packages/web3-eth-accounts/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,29 +149,7 @@ Accounts.prototype.signTransaction = function signTransaction(tx, privateKey, ca
}

function signed(tx) {
if (tx.common && (tx.chain && tx.hardfork)) {
error = new Error(
'Please provide the ethereumjs-common object or the chain and hardfork property but not all together.'
);
}

if ((tx.chain && !tx.hardfork) || (tx.hardfork && !tx.chain)) {
error = new Error(
'When specifying chain and hardfork, both values must be defined. ' +
'Received "chain": ' + tx.chain + ', "hardfork": ' + tx.hardfork
);
}

if (!tx.gas && !tx.gasLimit) {
error = new Error('"gas" is missing');
}

if (tx.nonce < 0 ||
tx.gas < 0 ||
tx.gasPrice < 0 ||
tx.chainId < 0) {
error = new Error('Gas, gasPrice, nonce or chainId is lower than 0');
}
const error = _validateTransactionForSigning(tx);

if (error) {
callback(error);
Expand Down Expand Up @@ -280,6 +258,35 @@ Accounts.prototype.signTransaction = function signTransaction(tx, privateKey, ca
});
};

function _validateTransactionForSigning(tx) {
if (tx.common && (tx.chain && tx.hardfork)) {
return new Error(
'Please provide the ethereumjs-common object or the chain and hardfork property but not all together.'
);
}

if ((tx.chain && !tx.hardfork) || (tx.hardfork && !tx.chain)) {
return new Error(
'When specifying chain and hardfork, both values must be defined. ' +
'Received "chain": ' + tx.chain + ', "hardfork": ' + tx.hardfork
);
}

if (!tx.gas && !tx.gasLimit) {
return new Error('"gas" is missing');
}

if (tx.nonce < 0 ||
tx.gas < 0 ||
tx.gasPrice < 0 ||
tx.chainId < 0) {
return new Error('Gas, gasPrice, nonce or chainId is lower than 0');
}

return;
}


/* jshint ignore:start */
Accounts.prototype.recoverTransaction = function recoverTransaction(rawTx) {
var values = RLP.decode(rawTx);
Expand All @@ -294,7 +301,7 @@ Accounts.prototype.recoverTransaction = function recoverTransaction(rawTx) {

Accounts.prototype.hashMessage = function hashMessage(data) {
var messageHex = utils.isHexStrict(data) ? data : utils.utf8ToHex(data);
var messageBytes = utils.hexToBytes(messageHex)
var messageBytes = utils.hexToBytes(messageHex);
var messageBuffer = Buffer.from(messageBytes);
var preamble = '\x19Ethereum Signed Message:\n' + messageBytes.length;
var preambleBuffer = Buffer.from(preamble);
Expand Down Expand Up @@ -630,5 +637,4 @@ function storageAvailable(type) {
}
}


module.exports = Accounts;
2 changes: 1 addition & 1 deletion packages/web3/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var Web3 = function Web3() {

// overwrite package setProvider
var setProvider = this.setProvider;
this.setProvider = function (provider, net) {
this.setProvider = function (provider) {
setProvider.apply(_this, arguments);

_this.eth.setRequestManager(_this._requestManager);
Expand Down

0 comments on commit e4af90b

Please sign in to comment.