forked from tornado-packages/ethers.js
Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bcba17a9e7 | ||
|
|
918b66bc2e | ||
|
|
152d672278 | ||
|
|
51fb472809 | ||
|
|
66440b8542 | ||
|
|
fefdd51084 | ||
|
|
6ca1d77298 | ||
|
|
4f6748ec4c | ||
|
|
f56fc572f1 | ||
|
|
16fdf6b621 | ||
|
|
a863037ca3 | ||
|
|
2d854bd94c | ||
|
|
9565c28a91 | ||
|
|
bc457bb3bd | ||
|
|
db383a3121 | ||
|
|
3f76f603d9 | ||
|
|
68304848ae | ||
|
|
bb6bc4cac3 | ||
|
|
ef8b9c36ef | ||
|
|
e6c943d01f | ||
|
|
31d3ee899f | ||
|
|
98143a845b | ||
|
|
bffc557be1 | ||
|
|
09208fa8fe | ||
|
|
048c571d3d | ||
|
|
24757f1064 | ||
|
|
88f2f51266 | ||
|
|
93152ef863 | ||
|
|
09b698b0a9 | ||
|
|
478aaf9619 | ||
|
|
fad902b438 | ||
|
|
7bfaf292db | ||
|
|
be0488a1a0 |
2
_version.d.ts
vendored
2
_version.d.ts
vendored
@@ -1 +1 @@
|
||||
export declare const version = "4.0.7";
|
||||
export declare const version = "4.0.18";
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.version = "4.0.7";
|
||||
exports.version = "4.0.18";
|
||||
|
||||
13
contract.js
13
contract.js
@@ -106,7 +106,6 @@ function resolveAddresses(provider, value, paramType) {
|
||||
function runMethod(contract, functionName, estimateOnly) {
|
||||
var method = contract.interface.functions[functionName];
|
||||
return function () {
|
||||
var _this = this;
|
||||
var params = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
params[_i] = arguments[_i];
|
||||
@@ -118,8 +117,8 @@ function runMethod(contract, functionName, estimateOnly) {
|
||||
tx = properties_1.shallowCopy(params.pop());
|
||||
if (tx.blockTag != null) {
|
||||
blockTag = tx.blockTag;
|
||||
delete tx.blockTag;
|
||||
}
|
||||
delete tx.blockTag;
|
||||
// Check for unexpected keys (e.g. using "gas" instead of "gasLimit")
|
||||
for (var key in tx) {
|
||||
if (!allowedTransactionKeys[key]) {
|
||||
@@ -218,19 +217,19 @@ function runMethod(contract, functionName, estimateOnly) {
|
||||
return wait(confirmations).then(function (receipt) {
|
||||
receipt.events = receipt.logs.map(function (log) {
|
||||
var event = properties_1.deepCopy(log);
|
||||
var parsed = _this.interface.parseLog(log);
|
||||
var parsed = contract.interface.parseLog(log);
|
||||
if (parsed) {
|
||||
event.args = parsed.values;
|
||||
event.decode = parsed.decode;
|
||||
event.event = parsed.name;
|
||||
event.eventSignature = parsed.signature;
|
||||
}
|
||||
event.removeListener = function () { return _this.provider; };
|
||||
event.removeListener = function () { return contract.provider; };
|
||||
event.getBlock = function () {
|
||||
return _this.provider.getBlock(receipt.blockHash);
|
||||
return contract.provider.getBlock(receipt.blockHash);
|
||||
};
|
||||
event.getTransaction = function () {
|
||||
return _this.provider.getTransaction(receipt.transactionHash);
|
||||
return contract.provider.getTransaction(receipt.transactionHash);
|
||||
};
|
||||
event.getTransactionReceipt = function () {
|
||||
return Promise.resolve(receipt);
|
||||
@@ -655,7 +654,7 @@ var ContractFactory = /** @class */ (function () {
|
||||
errors.throwError('cannot override ' + key, errors.UNSUPPORTED_OPERATION, { operation: key });
|
||||
});
|
||||
// Make sure the call matches the constructor signature
|
||||
errors.checkArgumentCount(args.length, this.interface.deployFunction.inputs.length, 'in Contract constructor');
|
||||
errors.checkArgumentCount(args.length, this.interface.deployFunction.inputs.length, ' in Contract constructor');
|
||||
// Set the data to the bytecode + the encoded constructor arguments
|
||||
tx.data = this.interface.deployFunction.encode(this.bytecode, args);
|
||||
return tx;
|
||||
|
||||
375
dist/ethers.js
vendored
375
dist/ethers.js
vendored
@@ -1,7 +1,7 @@
|
||||
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ethers = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.version = "4.0.7";
|
||||
exports.version = "4.0.18";
|
||||
|
||||
},{}],2:[function(require,module,exports){
|
||||
"use strict";
|
||||
@@ -154,7 +154,6 @@ function resolveAddresses(provider, value, paramType) {
|
||||
function runMethod(contract, functionName, estimateOnly) {
|
||||
var method = contract.interface.functions[functionName];
|
||||
return function () {
|
||||
var _this = this;
|
||||
var params = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
params[_i] = arguments[_i];
|
||||
@@ -166,8 +165,8 @@ function runMethod(contract, functionName, estimateOnly) {
|
||||
tx = properties_1.shallowCopy(params.pop());
|
||||
if (tx.blockTag != null) {
|
||||
blockTag = tx.blockTag;
|
||||
delete tx.blockTag;
|
||||
}
|
||||
delete tx.blockTag;
|
||||
// Check for unexpected keys (e.g. using "gas" instead of "gasLimit")
|
||||
for (var key in tx) {
|
||||
if (!allowedTransactionKeys[key]) {
|
||||
@@ -266,19 +265,19 @@ function runMethod(contract, functionName, estimateOnly) {
|
||||
return wait(confirmations).then(function (receipt) {
|
||||
receipt.events = receipt.logs.map(function (log) {
|
||||
var event = properties_1.deepCopy(log);
|
||||
var parsed = _this.interface.parseLog(log);
|
||||
var parsed = contract.interface.parseLog(log);
|
||||
if (parsed) {
|
||||
event.args = parsed.values;
|
||||
event.decode = parsed.decode;
|
||||
event.event = parsed.name;
|
||||
event.eventSignature = parsed.signature;
|
||||
}
|
||||
event.removeListener = function () { return _this.provider; };
|
||||
event.removeListener = function () { return contract.provider; };
|
||||
event.getBlock = function () {
|
||||
return _this.provider.getBlock(receipt.blockHash);
|
||||
return contract.provider.getBlock(receipt.blockHash);
|
||||
};
|
||||
event.getTransaction = function () {
|
||||
return _this.provider.getTransaction(receipt.transactionHash);
|
||||
return contract.provider.getTransaction(receipt.transactionHash);
|
||||
};
|
||||
event.getTransactionReceipt = function () {
|
||||
return Promise.resolve(receipt);
|
||||
@@ -703,7 +702,7 @@ var ContractFactory = /** @class */ (function () {
|
||||
errors.throwError('cannot override ' + key, errors.UNSUPPORTED_OPERATION, { operation: key });
|
||||
});
|
||||
// Make sure the call matches the constructor signature
|
||||
errors.checkArgumentCount(args.length, this.interface.deployFunction.inputs.length, 'in Contract constructor');
|
||||
errors.checkArgumentCount(args.length, this.interface.deployFunction.inputs.length, ' in Contract constructor');
|
||||
// Set the data to the bytecode + the encoded constructor arguments
|
||||
tx.data = this.interface.deployFunction.encode(this.bytecode, args);
|
||||
return tx;
|
||||
@@ -861,6 +860,26 @@ function setCensorship(censorship, permanent) {
|
||||
_permanentCensorErrors = !!permanent;
|
||||
}
|
||||
exports.setCensorship = setCensorship;
|
||||
function checkNormalize() {
|
||||
try {
|
||||
// Make sure all forms of normalization are supported
|
||||
["NFD", "NFC", "NFKD", "NFKC"].forEach(function (form) {
|
||||
try {
|
||||
"test".normalize(form);
|
||||
}
|
||||
catch (error) {
|
||||
throw new Error('missing ' + form);
|
||||
}
|
||||
});
|
||||
if (String.fromCharCode(0xe9).normalize('NFD') !== String.fromCharCode(0x65, 0x0301)) {
|
||||
throw new Error('broken implementation');
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
throwError('platform missing String.prototype.normalize', exports.UNSUPPORTED_OPERATION, { operation: 'String.prototype.normalize', form: error.message });
|
||||
}
|
||||
}
|
||||
exports.checkNormalize = checkNormalize;
|
||||
|
||||
},{"./_version":1}],6:[function(require,module,exports){
|
||||
'use strict';
|
||||
@@ -901,10 +920,17 @@ exports.version = _version_1.version;
|
||||
////////////////////////
|
||||
// Helper Functions
|
||||
function getDefaultProvider(network) {
|
||||
return new providers.FallbackProvider([
|
||||
new providers.InfuraProvider(network),
|
||||
new providers.EtherscanProvider(network),
|
||||
]);
|
||||
if (network == null) {
|
||||
network = 'homestead';
|
||||
}
|
||||
var n = utils.getNetwork(network);
|
||||
if (!n || !n._defaultProvider) {
|
||||
errors.throwError('unsupported getDefaultProvider network', errors.UNSUPPORTED_OPERATION, {
|
||||
operation: 'getDefaultProvider',
|
||||
network: network
|
||||
});
|
||||
}
|
||||
return n._defaultProvider(providers);
|
||||
}
|
||||
exports.getDefaultProvider = getDefaultProvider;
|
||||
|
||||
@@ -9922,9 +9948,15 @@ function arrayOf(check) {
|
||||
return result;
|
||||
});
|
||||
}
|
||||
function checkHash(hash) {
|
||||
if (typeof (hash) === 'string' && bytes_1.hexDataLength(hash) === 32) {
|
||||
return hash.toLowerCase();
|
||||
function checkHash(hash, requirePrefix) {
|
||||
if (typeof (hash) === 'string') {
|
||||
// geth-etc does add a "0x" prefix on receipt.root
|
||||
if (!requirePrefix && hash.substring(0, 2) !== '0x') {
|
||||
hash = '0x' + hash;
|
||||
}
|
||||
if (bytes_1.hexDataLength(hash) === 32) {
|
||||
return hash.toLowerCase();
|
||||
}
|
||||
}
|
||||
errors.throwError('invalid hash', errors.INVALID_ARGUMENT, { arg: 'hash', value: hash });
|
||||
return null;
|
||||
@@ -10045,6 +10077,10 @@ function checkTransactionResponse(transaction) {
|
||||
}
|
||||
var result = check(formatTransaction, transaction);
|
||||
var networkId = transaction.networkId;
|
||||
// geth-etc returns chainId
|
||||
if (transaction.chainId != null && networkId == null && result.v == null) {
|
||||
networkId = transaction.chainId;
|
||||
}
|
||||
if (bytes_1.isHexString(networkId)) {
|
||||
networkId = bignumber_1.bigNumberify(networkId).toNumber();
|
||||
}
|
||||
@@ -10218,12 +10254,12 @@ function getEventTag(eventName) {
|
||||
return 'address:' + address_1.getAddress(eventName);
|
||||
}
|
||||
eventName = eventName.toLowerCase();
|
||||
if (eventName === 'block' || eventName === 'pending' || eventName === 'error') {
|
||||
return eventName;
|
||||
}
|
||||
else if (bytes_1.hexDataLength(eventName) === 32) {
|
||||
if (bytes_1.hexDataLength(eventName) === 32) {
|
||||
return 'tx:' + eventName;
|
||||
}
|
||||
if (eventName.indexOf(':') === -1) {
|
||||
return eventName;
|
||||
}
|
||||
}
|
||||
else if (Array.isArray(eventName)) {
|
||||
return 'filter::' + serializeTopics(eventName);
|
||||
@@ -10248,6 +10284,8 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
properties_1.defineReadOnly(_this, '_network', network);
|
||||
return network;
|
||||
}));
|
||||
// Squash any "unhandled promise" errors; the don't need to be handled
|
||||
_this.ready.catch(function (error) { });
|
||||
}
|
||||
else {
|
||||
var knownNetwork = networks_1.getNetwork((network == null) ? 'homestead' : network);
|
||||
@@ -10265,11 +10303,7 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
// Events being listened to
|
||||
_this._events = [];
|
||||
_this._pollingInterval = 4000;
|
||||
// We use this to track recent emitted events; for example, if we emit a "block" of 100
|
||||
// and we get a `getBlock(100)` request which would result in null, we should retry
|
||||
// until we get a response. This provides devs with a consistent view. Similarly for
|
||||
// transaction hashes.
|
||||
_this._emitted = { block: _this._lastBlockNumber };
|
||||
_this._emitted = { block: -2 };
|
||||
_this._fastQueryDate = 0;
|
||||
return _this;
|
||||
}
|
||||
@@ -10281,25 +10315,40 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
if (blockNumber === _this._lastBlockNumber) {
|
||||
return;
|
||||
}
|
||||
if (_this._lastBlockNumber === -2) {
|
||||
_this._lastBlockNumber = blockNumber - 1;
|
||||
// First polling cycle, trigger a "block" events
|
||||
if (_this._emitted.block === -2) {
|
||||
_this._emitted.block = blockNumber - 1;
|
||||
}
|
||||
// Notify all listener for each block that has passed
|
||||
for (var i = _this._lastBlockNumber + 1; i <= blockNumber; i++) {
|
||||
if (_this._emitted.block < i) {
|
||||
_this._emitted.block = i;
|
||||
for (var i = _this._emitted.block + 1; i <= blockNumber; i++) {
|
||||
_this.emit('block', i);
|
||||
}
|
||||
// The emitted block was updated, check for obsolete events
|
||||
if (_this._emitted.block !== blockNumber) {
|
||||
_this._emitted.block = blockNumber;
|
||||
Object.keys(_this._emitted).forEach(function (key) {
|
||||
// The block event does not expire
|
||||
if (key === 'block') {
|
||||
return;
|
||||
}
|
||||
// The block we were at when we emitted this event
|
||||
var eventBlockNumber = _this._emitted[key];
|
||||
// We cannot garbage collect pending transactions or blocks here
|
||||
// They should be garbage collected by the Provider when setting
|
||||
// "pending" events
|
||||
if (eventBlockNumber === 'pending') {
|
||||
return;
|
||||
}
|
||||
// Evict any transaction hashes or block hashes over 12 blocks
|
||||
// old, since they should not return null anyways
|
||||
Object.keys(_this._emitted).forEach(function (key) {
|
||||
if (key === 'block') {
|
||||
return;
|
||||
}
|
||||
if (_this._emitted[key] > i + 12) {
|
||||
delete _this._emitted[key];
|
||||
}
|
||||
});
|
||||
}
|
||||
_this.emit('block', i);
|
||||
if (blockNumber - eventBlockNumber > 12) {
|
||||
delete _this._emitted[key];
|
||||
}
|
||||
});
|
||||
}
|
||||
// First polling cycle
|
||||
if (_this._lastBlockNumber === -2) {
|
||||
_this._lastBlockNumber = blockNumber - 1;
|
||||
}
|
||||
// Sweep balances and remove addresses we no longer have events for
|
||||
var newBalances = {};
|
||||
@@ -10325,25 +10374,27 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
newBalances[address_2] = _this._balances[address_2];
|
||||
}
|
||||
_this.getBalance(address_2, 'latest').then(function (balance) {
|
||||
var lastBalance = this._balances[address_2];
|
||||
var lastBalance = _this._balances[address_2];
|
||||
if (lastBalance && balance.eq(lastBalance)) {
|
||||
return;
|
||||
}
|
||||
this._balances[address_2] = balance;
|
||||
this.emit(address_2, balance);
|
||||
_this._balances[address_2] = balance;
|
||||
_this.emit(address_2, balance);
|
||||
return null;
|
||||
}).catch(function (error) { _this.emit('error', error); });
|
||||
break;
|
||||
}
|
||||
case 'filter': {
|
||||
var address = comps[1];
|
||||
var topics = deserializeTopics(comps[2]);
|
||||
var filter_1 = {
|
||||
address: address,
|
||||
address: comps[1],
|
||||
fromBlock: _this._lastBlockNumber + 1,
|
||||
toBlock: blockNumber,
|
||||
topics: topics
|
||||
};
|
||||
if (!filter_1.address) {
|
||||
delete filter_1.address;
|
||||
}
|
||||
_this.getLogs(filter_1).then(function (logs) {
|
||||
if (logs.length === 0) {
|
||||
return;
|
||||
@@ -10366,8 +10417,10 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
this.doPoll();
|
||||
};
|
||||
BaseProvider.prototype.resetEventsBlock = function (blockNumber) {
|
||||
this._lastBlockNumber = blockNumber;
|
||||
this._doPoll();
|
||||
this._lastBlockNumber = blockNumber - 1;
|
||||
if (this.polling) {
|
||||
this._doPoll();
|
||||
}
|
||||
};
|
||||
Object.defineProperty(BaseProvider.prototype, "network", {
|
||||
get: function () {
|
||||
@@ -10381,10 +10434,7 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
};
|
||||
Object.defineProperty(BaseProvider.prototype, "blockNumber", {
|
||||
get: function () {
|
||||
if (this._lastBlockNumber < 0) {
|
||||
return null;
|
||||
}
|
||||
return this._lastBlockNumber;
|
||||
return this._fastBlockNumber;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
@@ -10458,11 +10508,14 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
// this will be used once we move to the WebSocket or other alternatives to polling
|
||||
BaseProvider.prototype.waitForTransaction = function (transactionHash, confirmations) {
|
||||
var _this = this;
|
||||
if (!confirmations) {
|
||||
if (confirmations == null) {
|
||||
confirmations = 1;
|
||||
}
|
||||
return web_1.poll(function () {
|
||||
return _this.getTransactionReceipt(transactionHash).then(function (receipt) {
|
||||
if (confirmations === 0) {
|
||||
return receipt;
|
||||
}
|
||||
if (receipt == null || receipt.confirmations < confirmations) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -10580,10 +10633,20 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
if (hash != null && tx.hash !== hash) {
|
||||
errors.throwError('Transaction hash mismatch from Provider.sendTransaction.', errors.UNKNOWN_ERROR, { expectedHash: tx.hash, returnedHash: hash });
|
||||
}
|
||||
this._emitted['t:' + tx.hash] = 'pending';
|
||||
// @TODO: (confirmations? number, timeout? number)
|
||||
result.wait = function (confirmations) {
|
||||
// We know this transaction *must* exist (whether it gets mined is
|
||||
// another story), so setting an emitted value forces us to
|
||||
// wait even if the node returns null for the receipt
|
||||
if (confirmations !== 0) {
|
||||
_this._emitted['t:' + tx.hash] = 'pending';
|
||||
}
|
||||
return _this.waitForTransaction(tx.hash, confirmations).then(function (receipt) {
|
||||
if (receipt == null && confirmations === 0) {
|
||||
return null;
|
||||
}
|
||||
// No longer pending, allow the polling loop to garbage collect this
|
||||
_this._emitted['t:' + tx.hash] = receipt.blockNumber;
|
||||
if (receipt.status === 0) {
|
||||
errors.throwError('transaction failed', errors.CALL_EXCEPTION, {
|
||||
transactionHash: tx.hash,
|
||||
@@ -10636,12 +10699,12 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
return properties_1.resolveProperties({ blockHashOrBlockTag: blockHashOrBlockTag }).then(function (_a) {
|
||||
var blockHashOrBlockTag = _a.blockHashOrBlockTag;
|
||||
try {
|
||||
var blockHash = bytes_1.hexlify(blockHashOrBlockTag);
|
||||
if (bytes_1.hexDataLength(blockHash) === 32) {
|
||||
var blockHash_1 = bytes_1.hexlify(blockHashOrBlockTag);
|
||||
if (bytes_1.hexDataLength(blockHash_1) === 32) {
|
||||
return web_1.poll(function () {
|
||||
return _this.perform('getBlock', { blockHash: blockHash, includeTransactions: !!includeTransactions }).then(function (block) {
|
||||
return _this.perform('getBlock', { blockHash: blockHash_1, includeTransactions: !!includeTransactions }).then(function (block) {
|
||||
if (block == null) {
|
||||
if (_this._emitted['b:' + blockHash] == null) {
|
||||
if (_this._emitted['b:' + blockHash_1] == null) {
|
||||
return null;
|
||||
}
|
||||
return undefined;
|
||||
@@ -10661,7 +10724,7 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
return web_1.poll(function () {
|
||||
return _this.perform('getBlock', { blockTag: blockTag_1, includeTransactions: !!includeTransactions }).then(function (block) {
|
||||
if (block == null) {
|
||||
if (blockNumber_1 > _this._emitted.block) {
|
||||
if (blockNumber_1 <= _this._emitted.block) {
|
||||
return undefined;
|
||||
}
|
||||
return null;
|
||||
@@ -10680,7 +10743,7 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
return this.ready.then(function () {
|
||||
return properties_1.resolveProperties({ transactionHash: transactionHash }).then(function (_a) {
|
||||
var transactionHash = _a.transactionHash;
|
||||
var params = { transactionHash: checkHash(transactionHash) };
|
||||
var params = { transactionHash: checkHash(transactionHash, true) };
|
||||
return web_1.poll(function () {
|
||||
return _this.perform('getTransaction', params).then(function (result) {
|
||||
if (result == null) {
|
||||
@@ -10715,7 +10778,7 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
return this.ready.then(function () {
|
||||
return properties_1.resolveProperties({ transactionHash: transactionHash }).then(function (_a) {
|
||||
var transactionHash = _a.transactionHash;
|
||||
var params = { transactionHash: checkHash(transactionHash) };
|
||||
var params = { transactionHash: checkHash(transactionHash, true) };
|
||||
return web_1.poll(function () {
|
||||
return _this.perform('getTransactionReceipt', params).then(function (result) {
|
||||
if (result == null) {
|
||||
@@ -11114,40 +11177,52 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
return _this;
|
||||
}
|
||||
EtherscanProvider.prototype.perform = function (method, params) {
|
||||
var _this = this;
|
||||
var url = this.baseUrl;
|
||||
var apiKey = '';
|
||||
if (this.apiKey) {
|
||||
apiKey += '&apikey=' + this.apiKey;
|
||||
}
|
||||
var get = function (url, procFunc) {
|
||||
return web_1.fetchJson(url, null, procFunc || getJsonResult).then(function (result) {
|
||||
_this.emit('debug', {
|
||||
action: 'perform',
|
||||
request: url,
|
||||
response: result,
|
||||
provider: _this
|
||||
});
|
||||
return result;
|
||||
});
|
||||
};
|
||||
switch (method) {
|
||||
case 'getBlockNumber':
|
||||
url += '/api?module=proxy&action=eth_blockNumber' + apiKey;
|
||||
return web_1.fetchJson(url, null, getJsonResult);
|
||||
return get(url);
|
||||
case 'getGasPrice':
|
||||
url += '/api?module=proxy&action=eth_gasPrice' + apiKey;
|
||||
return web_1.fetchJson(url, null, getJsonResult);
|
||||
return get(url);
|
||||
case 'getBalance':
|
||||
// Returns base-10 result
|
||||
url += '/api?module=account&action=balance&address=' + params.address;
|
||||
url += '&tag=' + params.blockTag + apiKey;
|
||||
return web_1.fetchJson(url, null, getResult);
|
||||
return get(url, getResult);
|
||||
case 'getTransactionCount':
|
||||
url += '/api?module=proxy&action=eth_getTransactionCount&address=' + params.address;
|
||||
url += '&tag=' + params.blockTag + apiKey;
|
||||
return web_1.fetchJson(url, null, getJsonResult);
|
||||
return get(url);
|
||||
case 'getCode':
|
||||
url += '/api?module=proxy&action=eth_getCode&address=' + params.address;
|
||||
url += '&tag=' + params.blockTag + apiKey;
|
||||
return web_1.fetchJson(url, null, getJsonResult);
|
||||
return get(url, getJsonResult);
|
||||
case 'getStorageAt':
|
||||
url += '/api?module=proxy&action=eth_getStorageAt&address=' + params.address;
|
||||
url += '&position=' + params.position;
|
||||
url += '&tag=' + params.blockTag + apiKey;
|
||||
return web_1.fetchJson(url, null, getJsonResult);
|
||||
return get(url, getJsonResult);
|
||||
case 'sendTransaction':
|
||||
url += '/api?module=proxy&action=eth_sendRawTransaction&hex=' + params.signedTransaction;
|
||||
url += apiKey;
|
||||
return web_1.fetchJson(url, null, getJsonResult).catch(function (error) {
|
||||
return get(url).catch(function (error) {
|
||||
if (error.responseText) {
|
||||
// "Insufficient funds. The account you tried to send transaction from does not have enough funds. Required 21464000000000 and got: 0"
|
||||
if (error.responseText.toLowerCase().indexOf('insufficient funds') >= 0) {
|
||||
@@ -11174,17 +11249,17 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
url += '&boolean=false';
|
||||
}
|
||||
url += apiKey;
|
||||
return web_1.fetchJson(url, null, getJsonResult);
|
||||
return get(url);
|
||||
}
|
||||
throw new Error('getBlock by blockHash not implmeneted');
|
||||
case 'getTransaction':
|
||||
url += '/api?module=proxy&action=eth_getTransactionByHash&txhash=' + params.transactionHash;
|
||||
url += apiKey;
|
||||
return web_1.fetchJson(url, null, getJsonResult);
|
||||
return get(url);
|
||||
case 'getTransactionReceipt':
|
||||
url += '/api?module=proxy&action=eth_getTransactionReceipt&txhash=' + params.transactionHash;
|
||||
url += apiKey;
|
||||
return web_1.fetchJson(url, null, getJsonResult);
|
||||
return get(url);
|
||||
case 'call': {
|
||||
var transaction = getTransactionString(params.transaction);
|
||||
if (transaction) {
|
||||
@@ -11196,7 +11271,7 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
throw new Error('EtherscanProvider does not support blockTag for call');
|
||||
}
|
||||
url += apiKey;
|
||||
return web_1.fetchJson(url, null, getJsonResult);
|
||||
return get(url);
|
||||
}
|
||||
case 'estimateGas': {
|
||||
var transaction = getTransactionString(params.transaction);
|
||||
@@ -11205,7 +11280,7 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
}
|
||||
url += '/api?module=proxy&action=eth_estimateGas&' + transaction;
|
||||
url += apiKey;
|
||||
return web_1.fetchJson(url, null, getJsonResult);
|
||||
return get(url);
|
||||
}
|
||||
case 'getLogs':
|
||||
url += '/api?module=logs&action=getLogs';
|
||||
@@ -11236,7 +11311,7 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
}
|
||||
url += apiKey;
|
||||
var self = this;
|
||||
return web_1.fetchJson(url, null, getResult).then(function (logs) {
|
||||
return get(url, getResult).then(function (logs) {
|
||||
var txs = {};
|
||||
var seq = Promise.resolve();
|
||||
logs.forEach(function (log) {
|
||||
@@ -11265,7 +11340,7 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
}
|
||||
url += '/api?module=stats&action=ethprice';
|
||||
url += apiKey;
|
||||
return web_1.fetchJson(url, null, getResult).then(function (result) {
|
||||
return get(url, getResult).then(function (result) {
|
||||
return parseFloat(result.ethusd);
|
||||
});
|
||||
default:
|
||||
@@ -11275,6 +11350,7 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
};
|
||||
// @TODO: Allow startBlock and endBlock to be Promises
|
||||
EtherscanProvider.prototype.getHistory = function (addressOrName, startBlock, endBlock) {
|
||||
var _this = this;
|
||||
var url = this.baseUrl;
|
||||
var apiKey = '';
|
||||
if (this.apiKey) {
|
||||
@@ -11292,6 +11368,12 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
url += '&endblock=' + endBlock;
|
||||
url += '&sort=asc' + apiKey;
|
||||
return web_1.fetchJson(url, null, getResult).then(function (result) {
|
||||
_this.emit('debug', {
|
||||
action: 'getHistory',
|
||||
request: url,
|
||||
response: result,
|
||||
provider: _this
|
||||
});
|
||||
var output = [];
|
||||
result.forEach(function (tx) {
|
||||
['contractAddress', 'to'].forEach(function (key) {
|
||||
@@ -11359,7 +11441,8 @@ function checkNetworks(networks) {
|
||||
// Matches!
|
||||
if (check.name === network.name &&
|
||||
check.chainId === network.chainId &&
|
||||
check.ensAddress === network.ensAddress) {
|
||||
((check.ensAddress === network.ensAddress) ||
|
||||
(check.ensAddress == null && network.ensAddress == null))) {
|
||||
return;
|
||||
}
|
||||
errors.throwError('provider mismatch', errors.INVALID_ARGUMENT, { arg: 'networks', value: networks });
|
||||
@@ -11546,7 +11629,6 @@ var address_1 = require("../utils/address");
|
||||
var bytes_1 = require("../utils/bytes");
|
||||
var networks_1 = require("../utils/networks");
|
||||
var properties_1 = require("../utils/properties");
|
||||
var transaction_1 = require("../utils/transaction");
|
||||
var utf8_1 = require("../utils/utf8");
|
||||
var web_1 = require("../utils/web");
|
||||
function timer(timeout) {
|
||||
@@ -11620,17 +11702,28 @@ var JsonRpcSigner = /** @class */ (function (_super) {
|
||||
};
|
||||
JsonRpcSigner.prototype.sendTransaction = function (transaction) {
|
||||
var _this = this;
|
||||
// Once populateTransaction resolves, the from address will be populated from getAddress
|
||||
var from = null;
|
||||
var getAddress = this.getAddress().then(function (address) {
|
||||
transaction = properties_1.shallowCopy(transaction);
|
||||
var fromAddress = this.getAddress().then(function (address) {
|
||||
if (address) {
|
||||
from = address.toLowerCase();
|
||||
address = address.toLowerCase();
|
||||
}
|
||||
return from;
|
||||
return address;
|
||||
});
|
||||
return transaction_1.populateTransaction(transaction, this.provider, getAddress).then(function (tx) {
|
||||
// The JSON-RPC for eth_sendTransaction uses 90000 gas; if the user
|
||||
// wishes to use this, it is easy to specify explicitly, otherwise
|
||||
// we look it up for them.
|
||||
if (transaction.gasLimit == null) {
|
||||
var estimate = properties_1.shallowCopy(transaction);
|
||||
estimate.from = fromAddress;
|
||||
transaction.gasLimit = this.provider.estimateGas(estimate);
|
||||
}
|
||||
return Promise.all([
|
||||
properties_1.resolveProperties(transaction),
|
||||
fromAddress
|
||||
]).then(function (results) {
|
||||
var tx = results[0];
|
||||
var hexTx = JsonRpcProvider.hexlifyTransaction(tx);
|
||||
hexTx.from = from;
|
||||
hexTx.from = results[1];
|
||||
return _this.provider.send('eth_sendTransaction', [hexTx]).then(function (hash) {
|
||||
return web_1.poll(function () {
|
||||
return _this.provider.getTransaction(hash).then(function (tx) {
|
||||
@@ -11738,13 +11831,22 @@ var JsonRpcProvider = /** @class */ (function (_super) {
|
||||
});
|
||||
};
|
||||
JsonRpcProvider.prototype.send = function (method, params) {
|
||||
var _this = this;
|
||||
var request = {
|
||||
method: method,
|
||||
params: params,
|
||||
id: 42,
|
||||
jsonrpc: "2.0"
|
||||
};
|
||||
return web_1.fetchJson(this.connection, JSON.stringify(request), getResult);
|
||||
return web_1.fetchJson(this.connection, JSON.stringify(request), getResult).then(function (result) {
|
||||
_this.emit('debug', {
|
||||
action: 'send',
|
||||
request: request,
|
||||
response: result,
|
||||
provider: _this
|
||||
});
|
||||
return result;
|
||||
});
|
||||
};
|
||||
JsonRpcProvider.prototype.perform = function (method, params) {
|
||||
switch (method) {
|
||||
@@ -11820,6 +11922,7 @@ var JsonRpcProvider = /** @class */ (function (_super) {
|
||||
}
|
||||
var seq = Promise.resolve();
|
||||
hashes.forEach(function (hash) {
|
||||
// @TODO: This should be garbage collected at some point... How? When?
|
||||
self._emitted['t:' + hash.toLowerCase()] = 'pending';
|
||||
seq = seq.then(function () {
|
||||
return self.getTransaction(hash).then(function (tx) {
|
||||
@@ -11888,7 +11991,7 @@ var JsonRpcProvider = /** @class */ (function (_super) {
|
||||
}(base_provider_1.BaseProvider));
|
||||
exports.JsonRpcProvider = JsonRpcProvider;
|
||||
|
||||
},{"../abstract-signer":2,"../errors":5,"../utils/address":59,"../utils/bytes":62,"../utils/networks":70,"../utils/properties":72,"../utils/transaction":81,"../utils/utf8":83,"../utils/web":84,"./base-provider":50}],57:[function(require,module,exports){
|
||||
},{"../abstract-signer":2,"../errors":5,"../utils/address":59,"../utils/bytes":62,"../utils/networks":70,"../utils/properties":72,"../utils/utf8":83,"../utils/web":84,"./base-provider":50}],57:[function(require,module,exports){
|
||||
'use strict';
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = Object.setPrototypeOf ||
|
||||
@@ -12029,9 +12132,11 @@ function verifyType(type) {
|
||||
return type;
|
||||
}
|
||||
function parseParam(param, allowIndexed) {
|
||||
var originalParam = param;
|
||||
function throwError(i) {
|
||||
throw new Error('unexpected character "' + param[i] + '" at position ' + i + ' in "' + param + '"');
|
||||
throw new Error('unexpected character "' + originalParam[i] + '" at position ' + i + ' in "' + originalParam + '"');
|
||||
}
|
||||
param = param.replace(/\s/g, ' ');
|
||||
var parent = { type: '', name: '', state: { allowType: true } };
|
||||
var node = parent;
|
||||
for (var i = 0; i < param.length; i++) {
|
||||
@@ -12276,6 +12381,7 @@ exports.formatSignature = formatSignature;
|
||||
function parseSignature(fragment) {
|
||||
if (typeof (fragment) === 'string') {
|
||||
// Make sure the "returns" is surrounded by a space and all whitespace is exactly one space
|
||||
fragment = fragment.replace(/\s/g, ' ');
|
||||
fragment = fragment.replace(/\(/g, ' (').replace(/\)/g, ') ').replace(/\s+/g, ' ');
|
||||
fragment = fragment.trim();
|
||||
if (fragment.substring(0, 6) === 'event ') {
|
||||
@@ -12711,7 +12817,7 @@ var CoderArray = /** @class */ (function (_super) {
|
||||
count = value.length;
|
||||
result = uint256Coder.encode(count);
|
||||
}
|
||||
errors.checkArgumentCount(count, value.length, 'in coder array' + (this.localName ? (" " + this.localName) : ""));
|
||||
errors.checkArgumentCount(count, value.length, ' in coder array' + (this.localName ? (" " + this.localName) : ""));
|
||||
var coders = [];
|
||||
for (var i = 0; i < value.length; i++) {
|
||||
coders.push(this.coder);
|
||||
@@ -13746,6 +13852,7 @@ function mnemonicToEntropy(mnemonic, wordlist) {
|
||||
if (!wordlist) {
|
||||
wordlist = lang_en_1.langEn;
|
||||
}
|
||||
errors.checkNormalize();
|
||||
var words = wordlist.split(mnemonic);
|
||||
if ((words.length % 3) !== 0) {
|
||||
throw new Error('invalid mnemonic');
|
||||
@@ -14011,7 +14118,7 @@ var _DeployDescription = /** @class */ (function (_super) {
|
||||
value: bytecode
|
||||
});
|
||||
}
|
||||
errors.checkArgumentCount(params.length, this.inputs.length, 'in Interface constructor');
|
||||
errors.checkArgumentCount(params.length, this.inputs.length, ' in Interface constructor');
|
||||
try {
|
||||
return (bytecode + abi_coder_1.defaultAbiCoder.encode(this.inputs, params).substring(2));
|
||||
}
|
||||
@@ -14032,7 +14139,7 @@ var _FunctionDescription = /** @class */ (function (_super) {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
_FunctionDescription.prototype.encode = function (params) {
|
||||
errors.checkArgumentCount(params.length, this.inputs.length, 'in interface function ' + this.name);
|
||||
errors.checkArgumentCount(params.length, this.inputs.length, ' in interface function ' + this.name);
|
||||
try {
|
||||
return this.sighash + abi_coder_1.defaultAbiCoder.encode(this.inputs, params).substring(2);
|
||||
}
|
||||
@@ -14204,6 +14311,7 @@ function addMethod(method) {
|
||||
gas: method.gas,
|
||||
payable: (method.payable == null || !!method.payable),
|
||||
type: ((method.constant) ? 'call' : 'transaction'),
|
||||
name: method.name,
|
||||
signature: signature,
|
||||
sighash: sighash,
|
||||
});
|
||||
@@ -14294,10 +14402,10 @@ var Interface = /** @class */ (function () {
|
||||
return new _TransactionDescription({
|
||||
args: result,
|
||||
decode: func.decode,
|
||||
name: name,
|
||||
name: func.name,
|
||||
signature: func.signature,
|
||||
sighash: func.sighash,
|
||||
value: bignumber_1.bigNumberify(tx.value || null),
|
||||
value: bignumber_1.bigNumberify(tx.value || '0'),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -14409,39 +14517,78 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var errors = __importStar(require("../errors"));
|
||||
function ethDefaultProvider(network) {
|
||||
return function (providers) {
|
||||
var providerList = [];
|
||||
if (providers.InfuraProvider) {
|
||||
providerList.push(new providers.InfuraProvider(network));
|
||||
}
|
||||
if (providers.EtherscanProvider) {
|
||||
providerList.push(new providers.EtherscanProvider(network));
|
||||
}
|
||||
if (providerList.length === 0) {
|
||||
return null;
|
||||
}
|
||||
if (providers.FallbackProvider) {
|
||||
return new providers.FallbackProvider(providerList);
|
||||
;
|
||||
}
|
||||
return providerList[0];
|
||||
};
|
||||
}
|
||||
function etcDefaultProvider(url, network) {
|
||||
return function (providers) {
|
||||
if (providers.JsonRpcProvider) {
|
||||
return new providers.JsonRpcProvider(url, network);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
}
|
||||
var homestead = {
|
||||
chainId: 1,
|
||||
ensAddress: "0x314159265dd8dbb310642f98f50c066173c1259b",
|
||||
name: "homestead"
|
||||
name: "homestead",
|
||||
_defaultProvider: ethDefaultProvider('homestead')
|
||||
};
|
||||
var ropsten = {
|
||||
chainId: 3,
|
||||
ensAddress: "0x112234455c3a32fd11230c42e7bccd4a84e02010",
|
||||
name: "ropsten"
|
||||
name: "ropsten",
|
||||
_defaultProvider: ethDefaultProvider('ropsten')
|
||||
};
|
||||
var networks = {
|
||||
unspecified: {
|
||||
chainId: 0
|
||||
chainId: 0,
|
||||
name: 'unspecified'
|
||||
},
|
||||
homestead: homestead,
|
||||
mainnet: homestead,
|
||||
morden: {
|
||||
chainId: 2
|
||||
chainId: 2,
|
||||
name: 'morden'
|
||||
},
|
||||
ropsten: ropsten,
|
||||
testnet: ropsten,
|
||||
rinkeby: {
|
||||
chainId: 4,
|
||||
ensAddress: "0xe7410170f87102DF0055eB195163A03B7F2Bff4A"
|
||||
ensAddress: "0xe7410170f87102DF0055eB195163A03B7F2Bff4A",
|
||||
name: 'rinkeby',
|
||||
_defaultProvider: ethDefaultProvider('rinkeby')
|
||||
},
|
||||
kovan: {
|
||||
chainId: 42
|
||||
chainId: 42,
|
||||
name: 'kovan',
|
||||
_defaultProvider: ethDefaultProvider('kovan')
|
||||
},
|
||||
classic: {
|
||||
chainId: 61
|
||||
chainId: 61,
|
||||
name: 'classic',
|
||||
_defaultProvider: etcDefaultProvider('https://web3.gastracker.io', 'classic')
|
||||
},
|
||||
classicTestnet: {
|
||||
chainId: 62
|
||||
chainId: 62,
|
||||
name: 'classicTestnet',
|
||||
_defaultProvider: etcDefaultProvider('https://web3.gastracker.io/morden', 'classicTestnet')
|
||||
}
|
||||
};
|
||||
/**
|
||||
@@ -14451,18 +14598,19 @@ var networks = {
|
||||
* and verifies a network is a valid Network..
|
||||
*/
|
||||
function getNetwork(network) {
|
||||
// No network (null) or unspecified (chainId = 0)
|
||||
if (!network) {
|
||||
// No network (null)
|
||||
if (network == null) {
|
||||
return null;
|
||||
}
|
||||
if (typeof (network) === 'number') {
|
||||
for (var name in networks) {
|
||||
var n_1 = networks[name];
|
||||
for (var name_1 in networks) {
|
||||
var n_1 = networks[name_1];
|
||||
if (n_1.chainId === network) {
|
||||
return {
|
||||
name: name,
|
||||
name: n_1.name,
|
||||
chainId: n_1.chainId,
|
||||
ensAddress: n_1.ensAddress
|
||||
ensAddress: (n_1.ensAddress || null),
|
||||
_defaultProvider: (n_1._defaultProvider || null)
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -14477,9 +14625,10 @@ function getNetwork(network) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
name: network,
|
||||
name: n_2.name,
|
||||
chainId: n_2.chainId,
|
||||
ensAddress: n_2.ensAddress
|
||||
ensAddress: n_2.ensAddress,
|
||||
_defaultProvider: (n_2._defaultProvider || null)
|
||||
};
|
||||
}
|
||||
var n = networks[network.name];
|
||||
@@ -14494,11 +14643,12 @@ function getNetwork(network) {
|
||||
if (network.chainId !== 0 && network.chainId !== n.chainId) {
|
||||
errors.throwError('network chainId mismatch', errors.INVALID_ARGUMENT, { arg: 'network', value: network });
|
||||
}
|
||||
// Standard Network
|
||||
// Standard Network (allow overriding the ENS address)
|
||||
return {
|
||||
name: network.name,
|
||||
chainId: n.chainId,
|
||||
ensAddress: n.ensAddress
|
||||
ensAddress: (network.ensAddress || n.ensAddress || null),
|
||||
_defaultProvider: (network._defaultProvider || n._defaultProvider || null)
|
||||
};
|
||||
}
|
||||
exports.getNetwork = getNetwork;
|
||||
@@ -15893,6 +16043,7 @@ exports.parseEther = parseEther;
|
||||
'use strict';
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var constants_1 = require("../constants");
|
||||
var errors_1 = require("../errors");
|
||||
var bytes_1 = require("./bytes");
|
||||
///////////////////////////////
|
||||
var UnicodeNormalizationForm;
|
||||
@@ -15908,6 +16059,7 @@ var UnicodeNormalizationForm;
|
||||
function toUtf8Bytes(str, form) {
|
||||
if (form === void 0) { form = UnicodeNormalizationForm.current; }
|
||||
if (form != UnicodeNormalizationForm.current) {
|
||||
errors_1.checkNormalize();
|
||||
str = str.normalize(form);
|
||||
}
|
||||
var result = [];
|
||||
@@ -16076,7 +16228,7 @@ function parseBytes32String(bytes) {
|
||||
}
|
||||
exports.parseBytes32String = parseBytes32String;
|
||||
|
||||
},{"../constants":3,"./bytes":62}],84:[function(require,module,exports){
|
||||
},{"../constants":3,"../errors":5,"./bytes":62}],84:[function(require,module,exports){
|
||||
'use strict';
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
@@ -16178,6 +16330,9 @@ function fetchJson(connection, json, processFunc) {
|
||||
var jsonError = new Error('invalid json response');
|
||||
jsonError.orginialError = error;
|
||||
jsonError.responseText = request.responseText;
|
||||
if (json != null) {
|
||||
jsonError.requestBody = json;
|
||||
}
|
||||
jsonError.url = url;
|
||||
reject(jsonError);
|
||||
return;
|
||||
@@ -16203,7 +16358,7 @@ function fetchJson(connection, json, processFunc) {
|
||||
reject(error);
|
||||
};
|
||||
try {
|
||||
if (json) {
|
||||
if (json != null) {
|
||||
request.send(json);
|
||||
}
|
||||
else {
|
||||
|
||||
2
dist/ethers.min.js
vendored
2
dist/ethers.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/ethers.min.js.map
vendored
2
dist/ethers.min.js.map
vendored
File diff suppressed because one or more lines are too long
8
dist/ethers.types.txt
vendored
8
dist/ethers.types.txt
vendored
@@ -188,6 +188,7 @@ declare module 'ethers/errors' {
|
||||
export function checkNew(self: any, kind: any): void;
|
||||
export function checkArgumentCount(count: number, expectedCount: number, suffix?: string): void;
|
||||
export function setCensorship(censorship: boolean, permanent?: boolean): void;
|
||||
export function checkNormalize(): void;
|
||||
}
|
||||
|
||||
declare module 'ethers/providers' {
|
||||
@@ -261,7 +262,7 @@ declare module 'ethers/utils/shims' {
|
||||
}
|
||||
|
||||
declare module 'ethers/_version' {
|
||||
export const version = "4.0.7";
|
||||
export const version = "4.0.18";
|
||||
}
|
||||
|
||||
declare module 'ethers/utils/bignumber' {
|
||||
@@ -715,7 +716,9 @@ declare module 'ethers/providers/base-provider' {
|
||||
import { Transaction } from 'ethers/utils/transaction';
|
||||
import { Network, Networkish } from 'ethers/utils/networks';
|
||||
export class BaseProvider extends Provider {
|
||||
protected _emitted: any;
|
||||
protected _emitted: {
|
||||
[eventName: string]: number | 'pending';
|
||||
};
|
||||
/**
|
||||
* ready
|
||||
*
|
||||
@@ -923,6 +926,7 @@ declare module 'ethers/utils/networks' {
|
||||
name: string;
|
||||
chainId: number;
|
||||
ensAddress?: string;
|
||||
_defaultProvider?: (providers: any) => any;
|
||||
};
|
||||
export type Networkish = Network | string | number;
|
||||
/**
|
||||
|
||||
1
dist/shims.js
vendored
Normal file
1
dist/shims.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
errors.d.ts
vendored
1
errors.d.ts
vendored
@@ -14,3 +14,4 @@ export declare function throwError(message: string, code: string, params: any):
|
||||
export declare function checkNew(self: any, kind: any): void;
|
||||
export declare function checkArgumentCount(count: number, expectedCount: number, suffix?: string): void;
|
||||
export declare function setCensorship(censorship: boolean, permanent?: boolean): void;
|
||||
export declare function checkNormalize(): void;
|
||||
|
||||
20
errors.js
20
errors.js
@@ -108,3 +108,23 @@ function setCensorship(censorship, permanent) {
|
||||
_permanentCensorErrors = !!permanent;
|
||||
}
|
||||
exports.setCensorship = setCensorship;
|
||||
function checkNormalize() {
|
||||
try {
|
||||
// Make sure all forms of normalization are supported
|
||||
["NFD", "NFC", "NFKD", "NFKC"].forEach(function (form) {
|
||||
try {
|
||||
"test".normalize(form);
|
||||
}
|
||||
catch (error) {
|
||||
throw new Error('missing ' + form);
|
||||
}
|
||||
});
|
||||
if (String.fromCharCode(0xe9).normalize('NFD') !== String.fromCharCode(0x65, 0x0301)) {
|
||||
throw new Error('broken implementation');
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
throwError('platform missing String.prototype.normalize', exports.UNSUPPORTED_OPERATION, { operation: 'String.prototype.normalize', form: error.message });
|
||||
}
|
||||
}
|
||||
exports.checkNormalize = checkNormalize;
|
||||
|
||||
15
ethers.js
15
ethers.js
@@ -36,9 +36,16 @@ exports.version = _version_1.version;
|
||||
////////////////////////
|
||||
// Helper Functions
|
||||
function getDefaultProvider(network) {
|
||||
return new providers.FallbackProvider([
|
||||
new providers.InfuraProvider(network),
|
||||
new providers.EtherscanProvider(network),
|
||||
]);
|
||||
if (network == null) {
|
||||
network = 'homestead';
|
||||
}
|
||||
var n = utils.getNetwork(network);
|
||||
if (!n || !n._defaultProvider) {
|
||||
errors.throwError('unsupported getDefaultProvider network', errors.UNSUPPORTED_OPERATION, {
|
||||
operation: 'getDefaultProvider',
|
||||
network: network
|
||||
});
|
||||
}
|
||||
return n._defaultProvider(providers);
|
||||
}
|
||||
exports.getDefaultProvider = getDefaultProvider;
|
||||
|
||||
32
gulpfile.js
32
gulpfile.js
@@ -152,7 +152,9 @@ function taskBundle(name, options) {
|
||||
if (options.minify) {
|
||||
result = result.pipe(buffer())
|
||||
.pipe(sourcemaps.init({ loadMaps: true }))
|
||||
.pipe(uglify())
|
||||
.pipe(uglify({
|
||||
output: { ascii_only: true }
|
||||
}))
|
||||
.pipe(sourcemaps.write('./'))
|
||||
}
|
||||
|
||||
@@ -174,6 +176,30 @@ taskBundle("minified", { filename: "ethers.min.js", dest: 'dist', minify: true }
|
||||
// Creates dist/ethers.min.js
|
||||
taskBundle("minified-test", { filename: "ethers.min.js", dest: 'tests/dist', minify: true });
|
||||
|
||||
gulp.task('shims', function () {
|
||||
|
||||
var result = browserify({
|
||||
basedir: '.',
|
||||
debug: false,
|
||||
entries: [ './tests/shims/index.js' ],
|
||||
cache: { },
|
||||
packageCache: {},
|
||||
standalone: "_shims",
|
||||
insertGlobalVars: {
|
||||
process: function() { return; },
|
||||
}
|
||||
})
|
||||
.bundle()
|
||||
.pipe(source('shims.js'))
|
||||
.pipe(buffer())
|
||||
.pipe(uglify({
|
||||
output: { ascii_only: true }
|
||||
}))
|
||||
.pipe(gulp.dest('dist'));
|
||||
|
||||
return result;
|
||||
});
|
||||
|
||||
/*
|
||||
// Dump the TypeScript definitions to dist/types/
|
||||
gulp.task("types", function() {
|
||||
@@ -265,7 +291,9 @@ function taskLang(locale) {
|
||||
.bundle()
|
||||
.pipe(source("wordlist-" + locale + ".js"))
|
||||
.pipe(buffer())
|
||||
.pipe(uglify())
|
||||
.pipe(uglify({
|
||||
output: { ascii_only: true }
|
||||
}))
|
||||
.pipe(gulp.dest("dist"));
|
||||
});
|
||||
}
|
||||
|
||||
77
package-lock.json
generated
77
package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ethers",
|
||||
"version": "4.0.7",
|
||||
"version": "4.0.18",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@@ -69,9 +69,9 @@
|
||||
"integrity": "sha512-8TqvB0ReZWwtcd3LXq3YSrBoLyXFgBX/sBZfGye9+YS8zH7/g+i6QRIuiDmwBoTzcQ/pk89nZYTYU4c5akKkzw=="
|
||||
},
|
||||
"JSONStream": {
|
||||
"version": "1.3.3",
|
||||
"resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.3.tgz",
|
||||
"integrity": "sha512-3Sp6WZZ/lXl+nTDoGpGWHEpTnnC6X5fnkolYZR6nwIfzbxxvA8utPWe1gCt7i0m9uVGsSz2IS8K8mJ7HmlduMg==",
|
||||
"version": "1.3.5",
|
||||
"resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.5.tgz",
|
||||
"integrity": "sha512-E+iruNOY8VV9s4JEbe1aNEm6MiszPRr/UfcHMz0TQh1BXSxHK+ASV1R6W4HpjBhSeS+54PIsAMCBmwD06LLsqQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"jsonparse": "^1.2.0",
|
||||
@@ -95,13 +95,10 @@
|
||||
"dev": true
|
||||
},
|
||||
"acorn-dynamic-import": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/acorn-dynamic-import/-/acorn-dynamic-import-3.0.0.tgz",
|
||||
"integrity": "sha512-zVWV8Z8lislJoOKKqdNMOB+s6+XV5WERty8MnKBeFgwA+19XJjJHs2RP5dzM57FftIs+jQnRToLiWazKr6sSWg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"acorn": "^5.0.0"
|
||||
}
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/acorn-dynamic-import/-/acorn-dynamic-import-4.0.0.tgz",
|
||||
"integrity": "sha512-d3OEjQV4ROpoflsnUA8HozoIR504TFxNivYEUi6uwz0IYhBkTDXGuWlNdMtybRt3nqVx/L6XqMt0FxkXuWKZhw==",
|
||||
"dev": true
|
||||
},
|
||||
"acorn-jsx": {
|
||||
"version": "4.1.1",
|
||||
@@ -113,16 +110,31 @@
|
||||
}
|
||||
},
|
||||
"acorn-node": {
|
||||
"version": "1.5.2",
|
||||
"resolved": "https://registry.npmjs.org/acorn-node/-/acorn-node-1.5.2.tgz",
|
||||
"integrity": "sha512-krFKvw/d1F17AN3XZbybIUzEY4YEPNiGo05AfP3dBlfVKrMHETKpgjpuZkSF8qDNt9UkQcqj7am8yJLseklCMg==",
|
||||
"version": "1.6.2",
|
||||
"resolved": "https://registry.npmjs.org/acorn-node/-/acorn-node-1.6.2.tgz",
|
||||
"integrity": "sha512-rIhNEZuNI8ibQcL7ANm/mGyPukIaZsRNX9psFNQURyJW0nu6k8wjSDld20z6v2mDBWqX13pIEnk9gGZJHIlEXg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"acorn": "^5.7.1",
|
||||
"acorn-dynamic-import": "^3.0.0",
|
||||
"acorn": "^6.0.2",
|
||||
"acorn-dynamic-import": "^4.0.0",
|
||||
"acorn-walk": "^6.1.0",
|
||||
"xtend": "^4.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"acorn": {
|
||||
"version": "6.0.4",
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-6.0.4.tgz",
|
||||
"integrity": "sha512-VY4i5EKSKkofY2I+6QLTbTTN/UvEQPCo6eiwzzSaSWfpaDhOmStMCMod6wmuPciNq+XS0faCglFu2lHZpdHUtg==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"acorn-walk": {
|
||||
"version": "6.1.0",
|
||||
"resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-6.1.0.tgz",
|
||||
"integrity": "sha512-ugTb7Lq7u4GfWSqqpwE0bGyoBZNMTok/zDBXxfEG0QM50jNlGhIWjRC1pPN7bvV1anhF+bs+/gNcRw+o55Evbg==",
|
||||
"dev": true
|
||||
},
|
||||
"aes-js": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/aes-js/-/aes-js-3.0.0.tgz",
|
||||
@@ -783,9 +795,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"browserify": {
|
||||
"version": "16.2.2",
|
||||
"resolved": "https://registry.npmjs.org/browserify/-/browserify-16.2.2.tgz",
|
||||
"integrity": "sha512-fMES05wq1Oukts6ksGUU2TMVHHp06LyQt0SIwbXIHm7waSrQmNBZePsU0iM/4f94zbvb/wHma+D1YrdzWYnF/A==",
|
||||
"version": "16.2.3",
|
||||
"resolved": "https://registry.npmjs.org/browserify/-/browserify-16.2.3.tgz",
|
||||
"integrity": "sha512-zQt/Gd1+W+IY+h/xX2NYMW4orQWhqSwyV+xsblycTtpOuB27h1fZhhNQuipJ4t79ohw4P4mMem0jp/ZkISQtjQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"JSONStream": "^1.0.3",
|
||||
@@ -927,9 +939,9 @@
|
||||
}
|
||||
},
|
||||
"buffer": {
|
||||
"version": "5.2.0",
|
||||
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.2.0.tgz",
|
||||
"integrity": "sha512-nUJyfChH7PMJy75eRDCCKtszSEFokUNXC1hNVSe+o+VdcgvDPLs20k3v8UXI8ruRYAJiYtyRea8mYyqPxoHWDw==",
|
||||
"version": "5.2.1",
|
||||
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.2.1.tgz",
|
||||
"integrity": "sha512-c+Ko0loDaFfuPWiL02ls9Xd3GO3cPVmUobQ6t3rXNUk304u6hGq+8N/kFi+QEIKhzK3uwolVhLzszmfLmMLnqg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"base64-js": "^1.0.2",
|
||||
@@ -996,9 +1008,9 @@
|
||||
}
|
||||
},
|
||||
"cached-path-relative": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/cached-path-relative/-/cached-path-relative-1.0.1.tgz",
|
||||
"integrity": "sha1-0JxLUoAKpMB44t2BqGmqyQ0uVOc=",
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/cached-path-relative/-/cached-path-relative-1.0.2.tgz",
|
||||
"integrity": "sha512-5r2GqsoEb4qMTTN9J+WzXfjov+hjxT+j3u5K+kIVNIwAd99DLCJE9pBIMP1qVeybV6JiijL385Oz0DcYxfbOIg==",
|
||||
"dev": true
|
||||
},
|
||||
"caller-path": {
|
||||
@@ -5288,9 +5300,9 @@
|
||||
}
|
||||
},
|
||||
"pbkdf2": {
|
||||
"version": "3.0.16",
|
||||
"resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.0.16.tgz",
|
||||
"integrity": "sha512-y4CXP3thSxqf7c0qmOF+9UeOTrifiVTIM+u7NWlq+PRsHbr7r7dpCmvzrZxa96JJUNi0Y5w9VqG5ZNeCVMoDcA==",
|
||||
"version": "3.0.17",
|
||||
"resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.0.17.tgz",
|
||||
"integrity": "sha512-U/il5MsrZp7mGg3mSQfn742na2T+1/vHDCG5/iTI3X9MKUuYUZVLQhyRsg06mCgDBTd57TxzgZt7P+fYfjRLtA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"create-hash": "^1.1.2",
|
||||
@@ -5392,16 +5404,17 @@
|
||||
}
|
||||
},
|
||||
"public-encrypt": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/public-encrypt/-/public-encrypt-4.0.2.tgz",
|
||||
"integrity": "sha512-4kJ5Esocg8X3h8YgJsKAuoesBgB7mqH3eowiDzMUPKiRDDE7E/BqqZD1hnTByIaAFiwAw246YEltSq7tdrOH0Q==",
|
||||
"version": "4.0.3",
|
||||
"resolved": "https://registry.npmjs.org/public-encrypt/-/public-encrypt-4.0.3.tgz",
|
||||
"integrity": "sha512-zVpa8oKZSz5bTMTFClc1fQOnyyEzpl5ozpi1B5YcvBrdohMjH2rfsBtyXcuNuwjsDIXmBYlF2N5FlJYhR29t8Q==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"bn.js": "^4.1.0",
|
||||
"browserify-rsa": "^4.0.0",
|
||||
"create-hash": "^1.1.0",
|
||||
"parse-asn1": "^5.0.0",
|
||||
"randombytes": "^2.0.1"
|
||||
"randombytes": "^2.0.1",
|
||||
"safe-buffer": "^5.1.2"
|
||||
}
|
||||
},
|
||||
"pump": {
|
||||
|
||||
10
package.json
10
package.json
@@ -1,14 +1,14 @@
|
||||
{
|
||||
"name": "ethers",
|
||||
"version": "4.0.7",
|
||||
"version": "4.0.18",
|
||||
"description": "Ethereum wallet library.",
|
||||
"main": "./index.js",
|
||||
"types": "./index.d.ts",
|
||||
"scripts": {
|
||||
"build": "npm run dist-version && tsc -p ./tsconfig.json",
|
||||
"auto-build": "npm run build -- -w",
|
||||
"dist": "npm run dist-version && npm run build && gulp default minified && npm run dist-types",
|
||||
"dist-test": "gulp default-test minified-test",
|
||||
"dist": "npm run dist-version && npm run build && gulp default minified shims && npm run dist-types",
|
||||
"dist-test": "gulp default-test minified-test shims",
|
||||
"dist-bip39": "gulp bip39-es bip39-fr bip39-it bip39-ja bip39-ko bip39-zh",
|
||||
"dist-types": "dts-bundle --name ethers --main ./index.d.ts --out ./dist/ethers.types.txt",
|
||||
"dist-version": "node -e \"let v = require('./package.json').version; require('fs').writeFileSync('./src.ts/_version.ts', 'export const version = \\\"' + v +'\\\";\\n')\"",
|
||||
@@ -31,7 +31,7 @@
|
||||
"xmlhttprequest": "1.8.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"browserify": "^16.2.2",
|
||||
"browserify": "^16.2.3",
|
||||
"browserify-zlib": "^0.2.0",
|
||||
"dts-bundle": "^0.7.3",
|
||||
"eslint": "^5.0.1",
|
||||
@@ -53,7 +53,7 @@
|
||||
"vinyl-source-stream": "^2.0.0",
|
||||
"web3-providers-http": "1.0.0-beta.35"
|
||||
},
|
||||
"browser": "./dist/ethers.js",
|
||||
"browser": "./dist/ethers.min.js",
|
||||
"keywords": [
|
||||
"ethereum",
|
||||
"library",
|
||||
|
||||
4
providers/base-provider.d.ts
vendored
4
providers/base-provider.d.ts
vendored
@@ -7,7 +7,9 @@ import { Network, Networkish } from '../utils/networks';
|
||||
export declare class BaseProvider extends Provider {
|
||||
private _network;
|
||||
private _events;
|
||||
protected _emitted: any;
|
||||
protected _emitted: {
|
||||
[eventName: string]: number | 'pending';
|
||||
};
|
||||
private _pollingInterval;
|
||||
private _poller;
|
||||
private _lastBlockNumber;
|
||||
|
||||
@@ -79,9 +79,15 @@ function arrayOf(check) {
|
||||
return result;
|
||||
});
|
||||
}
|
||||
function checkHash(hash) {
|
||||
if (typeof (hash) === 'string' && bytes_1.hexDataLength(hash) === 32) {
|
||||
return hash.toLowerCase();
|
||||
function checkHash(hash, requirePrefix) {
|
||||
if (typeof (hash) === 'string') {
|
||||
// geth-etc does add a "0x" prefix on receipt.root
|
||||
if (!requirePrefix && hash.substring(0, 2) !== '0x') {
|
||||
hash = '0x' + hash;
|
||||
}
|
||||
if (bytes_1.hexDataLength(hash) === 32) {
|
||||
return hash.toLowerCase();
|
||||
}
|
||||
}
|
||||
errors.throwError('invalid hash', errors.INVALID_ARGUMENT, { arg: 'hash', value: hash });
|
||||
return null;
|
||||
@@ -202,6 +208,10 @@ function checkTransactionResponse(transaction) {
|
||||
}
|
||||
var result = check(formatTransaction, transaction);
|
||||
var networkId = transaction.networkId;
|
||||
// geth-etc returns chainId
|
||||
if (transaction.chainId != null && networkId == null && result.v == null) {
|
||||
networkId = transaction.chainId;
|
||||
}
|
||||
if (bytes_1.isHexString(networkId)) {
|
||||
networkId = bignumber_1.bigNumberify(networkId).toNumber();
|
||||
}
|
||||
@@ -375,12 +385,12 @@ function getEventTag(eventName) {
|
||||
return 'address:' + address_1.getAddress(eventName);
|
||||
}
|
||||
eventName = eventName.toLowerCase();
|
||||
if (eventName === 'block' || eventName === 'pending' || eventName === 'error') {
|
||||
return eventName;
|
||||
}
|
||||
else if (bytes_1.hexDataLength(eventName) === 32) {
|
||||
if (bytes_1.hexDataLength(eventName) === 32) {
|
||||
return 'tx:' + eventName;
|
||||
}
|
||||
if (eventName.indexOf(':') === -1) {
|
||||
return eventName;
|
||||
}
|
||||
}
|
||||
else if (Array.isArray(eventName)) {
|
||||
return 'filter::' + serializeTopics(eventName);
|
||||
@@ -405,6 +415,8 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
properties_1.defineReadOnly(_this, '_network', network);
|
||||
return network;
|
||||
}));
|
||||
// Squash any "unhandled promise" errors; the don't need to be handled
|
||||
_this.ready.catch(function (error) { });
|
||||
}
|
||||
else {
|
||||
var knownNetwork = networks_1.getNetwork((network == null) ? 'homestead' : network);
|
||||
@@ -422,11 +434,7 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
// Events being listened to
|
||||
_this._events = [];
|
||||
_this._pollingInterval = 4000;
|
||||
// We use this to track recent emitted events; for example, if we emit a "block" of 100
|
||||
// and we get a `getBlock(100)` request which would result in null, we should retry
|
||||
// until we get a response. This provides devs with a consistent view. Similarly for
|
||||
// transaction hashes.
|
||||
_this._emitted = { block: _this._lastBlockNumber };
|
||||
_this._emitted = { block: -2 };
|
||||
_this._fastQueryDate = 0;
|
||||
return _this;
|
||||
}
|
||||
@@ -438,25 +446,40 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
if (blockNumber === _this._lastBlockNumber) {
|
||||
return;
|
||||
}
|
||||
if (_this._lastBlockNumber === -2) {
|
||||
_this._lastBlockNumber = blockNumber - 1;
|
||||
// First polling cycle, trigger a "block" events
|
||||
if (_this._emitted.block === -2) {
|
||||
_this._emitted.block = blockNumber - 1;
|
||||
}
|
||||
// Notify all listener for each block that has passed
|
||||
for (var i = _this._lastBlockNumber + 1; i <= blockNumber; i++) {
|
||||
if (_this._emitted.block < i) {
|
||||
_this._emitted.block = i;
|
||||
for (var i = _this._emitted.block + 1; i <= blockNumber; i++) {
|
||||
_this.emit('block', i);
|
||||
}
|
||||
// The emitted block was updated, check for obsolete events
|
||||
if (_this._emitted.block !== blockNumber) {
|
||||
_this._emitted.block = blockNumber;
|
||||
Object.keys(_this._emitted).forEach(function (key) {
|
||||
// The block event does not expire
|
||||
if (key === 'block') {
|
||||
return;
|
||||
}
|
||||
// The block we were at when we emitted this event
|
||||
var eventBlockNumber = _this._emitted[key];
|
||||
// We cannot garbage collect pending transactions or blocks here
|
||||
// They should be garbage collected by the Provider when setting
|
||||
// "pending" events
|
||||
if (eventBlockNumber === 'pending') {
|
||||
return;
|
||||
}
|
||||
// Evict any transaction hashes or block hashes over 12 blocks
|
||||
// old, since they should not return null anyways
|
||||
Object.keys(_this._emitted).forEach(function (key) {
|
||||
if (key === 'block') {
|
||||
return;
|
||||
}
|
||||
if (_this._emitted[key] > i + 12) {
|
||||
delete _this._emitted[key];
|
||||
}
|
||||
});
|
||||
}
|
||||
_this.emit('block', i);
|
||||
if (blockNumber - eventBlockNumber > 12) {
|
||||
delete _this._emitted[key];
|
||||
}
|
||||
});
|
||||
}
|
||||
// First polling cycle
|
||||
if (_this._lastBlockNumber === -2) {
|
||||
_this._lastBlockNumber = blockNumber - 1;
|
||||
}
|
||||
// Sweep balances and remove addresses we no longer have events for
|
||||
var newBalances = {};
|
||||
@@ -482,25 +505,27 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
newBalances[address_2] = _this._balances[address_2];
|
||||
}
|
||||
_this.getBalance(address_2, 'latest').then(function (balance) {
|
||||
var lastBalance = this._balances[address_2];
|
||||
var lastBalance = _this._balances[address_2];
|
||||
if (lastBalance && balance.eq(lastBalance)) {
|
||||
return;
|
||||
}
|
||||
this._balances[address_2] = balance;
|
||||
this.emit(address_2, balance);
|
||||
_this._balances[address_2] = balance;
|
||||
_this.emit(address_2, balance);
|
||||
return null;
|
||||
}).catch(function (error) { _this.emit('error', error); });
|
||||
break;
|
||||
}
|
||||
case 'filter': {
|
||||
var address = comps[1];
|
||||
var topics = deserializeTopics(comps[2]);
|
||||
var filter_1 = {
|
||||
address: address,
|
||||
address: comps[1],
|
||||
fromBlock: _this._lastBlockNumber + 1,
|
||||
toBlock: blockNumber,
|
||||
topics: topics
|
||||
};
|
||||
if (!filter_1.address) {
|
||||
delete filter_1.address;
|
||||
}
|
||||
_this.getLogs(filter_1).then(function (logs) {
|
||||
if (logs.length === 0) {
|
||||
return;
|
||||
@@ -523,8 +548,10 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
this.doPoll();
|
||||
};
|
||||
BaseProvider.prototype.resetEventsBlock = function (blockNumber) {
|
||||
this._lastBlockNumber = blockNumber;
|
||||
this._doPoll();
|
||||
this._lastBlockNumber = blockNumber - 1;
|
||||
if (this.polling) {
|
||||
this._doPoll();
|
||||
}
|
||||
};
|
||||
Object.defineProperty(BaseProvider.prototype, "network", {
|
||||
get: function () {
|
||||
@@ -538,10 +565,7 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
};
|
||||
Object.defineProperty(BaseProvider.prototype, "blockNumber", {
|
||||
get: function () {
|
||||
if (this._lastBlockNumber < 0) {
|
||||
return null;
|
||||
}
|
||||
return this._lastBlockNumber;
|
||||
return this._fastBlockNumber;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
@@ -615,11 +639,14 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
// this will be used once we move to the WebSocket or other alternatives to polling
|
||||
BaseProvider.prototype.waitForTransaction = function (transactionHash, confirmations) {
|
||||
var _this = this;
|
||||
if (!confirmations) {
|
||||
if (confirmations == null) {
|
||||
confirmations = 1;
|
||||
}
|
||||
return web_1.poll(function () {
|
||||
return _this.getTransactionReceipt(transactionHash).then(function (receipt) {
|
||||
if (confirmations === 0) {
|
||||
return receipt;
|
||||
}
|
||||
if (receipt == null || receipt.confirmations < confirmations) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -737,10 +764,20 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
if (hash != null && tx.hash !== hash) {
|
||||
errors.throwError('Transaction hash mismatch from Provider.sendTransaction.', errors.UNKNOWN_ERROR, { expectedHash: tx.hash, returnedHash: hash });
|
||||
}
|
||||
this._emitted['t:' + tx.hash] = 'pending';
|
||||
// @TODO: (confirmations? number, timeout? number)
|
||||
result.wait = function (confirmations) {
|
||||
// We know this transaction *must* exist (whether it gets mined is
|
||||
// another story), so setting an emitted value forces us to
|
||||
// wait even if the node returns null for the receipt
|
||||
if (confirmations !== 0) {
|
||||
_this._emitted['t:' + tx.hash] = 'pending';
|
||||
}
|
||||
return _this.waitForTransaction(tx.hash, confirmations).then(function (receipt) {
|
||||
if (receipt == null && confirmations === 0) {
|
||||
return null;
|
||||
}
|
||||
// No longer pending, allow the polling loop to garbage collect this
|
||||
_this._emitted['t:' + tx.hash] = receipt.blockNumber;
|
||||
if (receipt.status === 0) {
|
||||
errors.throwError('transaction failed', errors.CALL_EXCEPTION, {
|
||||
transactionHash: tx.hash,
|
||||
@@ -793,12 +830,12 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
return properties_1.resolveProperties({ blockHashOrBlockTag: blockHashOrBlockTag }).then(function (_a) {
|
||||
var blockHashOrBlockTag = _a.blockHashOrBlockTag;
|
||||
try {
|
||||
var blockHash = bytes_1.hexlify(blockHashOrBlockTag);
|
||||
if (bytes_1.hexDataLength(blockHash) === 32) {
|
||||
var blockHash_1 = bytes_1.hexlify(blockHashOrBlockTag);
|
||||
if (bytes_1.hexDataLength(blockHash_1) === 32) {
|
||||
return web_1.poll(function () {
|
||||
return _this.perform('getBlock', { blockHash: blockHash, includeTransactions: !!includeTransactions }).then(function (block) {
|
||||
return _this.perform('getBlock', { blockHash: blockHash_1, includeTransactions: !!includeTransactions }).then(function (block) {
|
||||
if (block == null) {
|
||||
if (_this._emitted['b:' + blockHash] == null) {
|
||||
if (_this._emitted['b:' + blockHash_1] == null) {
|
||||
return null;
|
||||
}
|
||||
return undefined;
|
||||
@@ -818,7 +855,7 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
return web_1.poll(function () {
|
||||
return _this.perform('getBlock', { blockTag: blockTag_1, includeTransactions: !!includeTransactions }).then(function (block) {
|
||||
if (block == null) {
|
||||
if (blockNumber_1 > _this._emitted.block) {
|
||||
if (blockNumber_1 <= _this._emitted.block) {
|
||||
return undefined;
|
||||
}
|
||||
return null;
|
||||
@@ -837,7 +874,7 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
return this.ready.then(function () {
|
||||
return properties_1.resolveProperties({ transactionHash: transactionHash }).then(function (_a) {
|
||||
var transactionHash = _a.transactionHash;
|
||||
var params = { transactionHash: checkHash(transactionHash) };
|
||||
var params = { transactionHash: checkHash(transactionHash, true) };
|
||||
return web_1.poll(function () {
|
||||
return _this.perform('getTransaction', params).then(function (result) {
|
||||
if (result == null) {
|
||||
@@ -872,7 +909,7 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
return this.ready.then(function () {
|
||||
return properties_1.resolveProperties({ transactionHash: transactionHash }).then(function (_a) {
|
||||
var transactionHash = _a.transactionHash;
|
||||
var params = { transactionHash: checkHash(transactionHash) };
|
||||
var params = { transactionHash: checkHash(transactionHash, true) };
|
||||
return web_1.poll(function () {
|
||||
return _this.perform('getTransactionReceipt', params).then(function (result) {
|
||||
if (result == null) {
|
||||
|
||||
@@ -112,40 +112,52 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
return _this;
|
||||
}
|
||||
EtherscanProvider.prototype.perform = function (method, params) {
|
||||
var _this = this;
|
||||
var url = this.baseUrl;
|
||||
var apiKey = '';
|
||||
if (this.apiKey) {
|
||||
apiKey += '&apikey=' + this.apiKey;
|
||||
}
|
||||
var get = function (url, procFunc) {
|
||||
return web_1.fetchJson(url, null, procFunc || getJsonResult).then(function (result) {
|
||||
_this.emit('debug', {
|
||||
action: 'perform',
|
||||
request: url,
|
||||
response: result,
|
||||
provider: _this
|
||||
});
|
||||
return result;
|
||||
});
|
||||
};
|
||||
switch (method) {
|
||||
case 'getBlockNumber':
|
||||
url += '/api?module=proxy&action=eth_blockNumber' + apiKey;
|
||||
return web_1.fetchJson(url, null, getJsonResult);
|
||||
return get(url);
|
||||
case 'getGasPrice':
|
||||
url += '/api?module=proxy&action=eth_gasPrice' + apiKey;
|
||||
return web_1.fetchJson(url, null, getJsonResult);
|
||||
return get(url);
|
||||
case 'getBalance':
|
||||
// Returns base-10 result
|
||||
url += '/api?module=account&action=balance&address=' + params.address;
|
||||
url += '&tag=' + params.blockTag + apiKey;
|
||||
return web_1.fetchJson(url, null, getResult);
|
||||
return get(url, getResult);
|
||||
case 'getTransactionCount':
|
||||
url += '/api?module=proxy&action=eth_getTransactionCount&address=' + params.address;
|
||||
url += '&tag=' + params.blockTag + apiKey;
|
||||
return web_1.fetchJson(url, null, getJsonResult);
|
||||
return get(url);
|
||||
case 'getCode':
|
||||
url += '/api?module=proxy&action=eth_getCode&address=' + params.address;
|
||||
url += '&tag=' + params.blockTag + apiKey;
|
||||
return web_1.fetchJson(url, null, getJsonResult);
|
||||
return get(url, getJsonResult);
|
||||
case 'getStorageAt':
|
||||
url += '/api?module=proxy&action=eth_getStorageAt&address=' + params.address;
|
||||
url += '&position=' + params.position;
|
||||
url += '&tag=' + params.blockTag + apiKey;
|
||||
return web_1.fetchJson(url, null, getJsonResult);
|
||||
return get(url, getJsonResult);
|
||||
case 'sendTransaction':
|
||||
url += '/api?module=proxy&action=eth_sendRawTransaction&hex=' + params.signedTransaction;
|
||||
url += apiKey;
|
||||
return web_1.fetchJson(url, null, getJsonResult).catch(function (error) {
|
||||
return get(url).catch(function (error) {
|
||||
if (error.responseText) {
|
||||
// "Insufficient funds. The account you tried to send transaction from does not have enough funds. Required 21464000000000 and got: 0"
|
||||
if (error.responseText.toLowerCase().indexOf('insufficient funds') >= 0) {
|
||||
@@ -172,17 +184,17 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
url += '&boolean=false';
|
||||
}
|
||||
url += apiKey;
|
||||
return web_1.fetchJson(url, null, getJsonResult);
|
||||
return get(url);
|
||||
}
|
||||
throw new Error('getBlock by blockHash not implmeneted');
|
||||
case 'getTransaction':
|
||||
url += '/api?module=proxy&action=eth_getTransactionByHash&txhash=' + params.transactionHash;
|
||||
url += apiKey;
|
||||
return web_1.fetchJson(url, null, getJsonResult);
|
||||
return get(url);
|
||||
case 'getTransactionReceipt':
|
||||
url += '/api?module=proxy&action=eth_getTransactionReceipt&txhash=' + params.transactionHash;
|
||||
url += apiKey;
|
||||
return web_1.fetchJson(url, null, getJsonResult);
|
||||
return get(url);
|
||||
case 'call': {
|
||||
var transaction = getTransactionString(params.transaction);
|
||||
if (transaction) {
|
||||
@@ -194,7 +206,7 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
throw new Error('EtherscanProvider does not support blockTag for call');
|
||||
}
|
||||
url += apiKey;
|
||||
return web_1.fetchJson(url, null, getJsonResult);
|
||||
return get(url);
|
||||
}
|
||||
case 'estimateGas': {
|
||||
var transaction = getTransactionString(params.transaction);
|
||||
@@ -203,7 +215,7 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
}
|
||||
url += '/api?module=proxy&action=eth_estimateGas&' + transaction;
|
||||
url += apiKey;
|
||||
return web_1.fetchJson(url, null, getJsonResult);
|
||||
return get(url);
|
||||
}
|
||||
case 'getLogs':
|
||||
url += '/api?module=logs&action=getLogs';
|
||||
@@ -234,7 +246,7 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
}
|
||||
url += apiKey;
|
||||
var self = this;
|
||||
return web_1.fetchJson(url, null, getResult).then(function (logs) {
|
||||
return get(url, getResult).then(function (logs) {
|
||||
var txs = {};
|
||||
var seq = Promise.resolve();
|
||||
logs.forEach(function (log) {
|
||||
@@ -263,7 +275,7 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
}
|
||||
url += '/api?module=stats&action=ethprice';
|
||||
url += apiKey;
|
||||
return web_1.fetchJson(url, null, getResult).then(function (result) {
|
||||
return get(url, getResult).then(function (result) {
|
||||
return parseFloat(result.ethusd);
|
||||
});
|
||||
default:
|
||||
@@ -273,6 +285,7 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
};
|
||||
// @TODO: Allow startBlock and endBlock to be Promises
|
||||
EtherscanProvider.prototype.getHistory = function (addressOrName, startBlock, endBlock) {
|
||||
var _this = this;
|
||||
var url = this.baseUrl;
|
||||
var apiKey = '';
|
||||
if (this.apiKey) {
|
||||
@@ -290,6 +303,12 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
url += '&endblock=' + endBlock;
|
||||
url += '&sort=asc' + apiKey;
|
||||
return web_1.fetchJson(url, null, getResult).then(function (result) {
|
||||
_this.emit('debug', {
|
||||
action: 'getHistory',
|
||||
request: url,
|
||||
response: result,
|
||||
provider: _this
|
||||
});
|
||||
var output = [];
|
||||
result.forEach(function (tx) {
|
||||
['contractAddress', 'to'].forEach(function (key) {
|
||||
|
||||
@@ -40,7 +40,8 @@ function checkNetworks(networks) {
|
||||
// Matches!
|
||||
if (check.name === network.name &&
|
||||
check.chainId === network.chainId &&
|
||||
check.ensAddress === network.ensAddress) {
|
||||
((check.ensAddress === network.ensAddress) ||
|
||||
(check.ensAddress == null && network.ensAddress == null))) {
|
||||
return;
|
||||
}
|
||||
errors.throwError('provider mismatch', errors.INVALID_ARGUMENT, { arg: 'networks', value: networks });
|
||||
|
||||
@@ -25,7 +25,6 @@ var address_1 = require("../utils/address");
|
||||
var bytes_1 = require("../utils/bytes");
|
||||
var networks_1 = require("../utils/networks");
|
||||
var properties_1 = require("../utils/properties");
|
||||
var transaction_1 = require("../utils/transaction");
|
||||
var utf8_1 = require("../utils/utf8");
|
||||
var web_1 = require("../utils/web");
|
||||
function timer(timeout) {
|
||||
@@ -99,17 +98,28 @@ var JsonRpcSigner = /** @class */ (function (_super) {
|
||||
};
|
||||
JsonRpcSigner.prototype.sendTransaction = function (transaction) {
|
||||
var _this = this;
|
||||
// Once populateTransaction resolves, the from address will be populated from getAddress
|
||||
var from = null;
|
||||
var getAddress = this.getAddress().then(function (address) {
|
||||
transaction = properties_1.shallowCopy(transaction);
|
||||
var fromAddress = this.getAddress().then(function (address) {
|
||||
if (address) {
|
||||
from = address.toLowerCase();
|
||||
address = address.toLowerCase();
|
||||
}
|
||||
return from;
|
||||
return address;
|
||||
});
|
||||
return transaction_1.populateTransaction(transaction, this.provider, getAddress).then(function (tx) {
|
||||
// The JSON-RPC for eth_sendTransaction uses 90000 gas; if the user
|
||||
// wishes to use this, it is easy to specify explicitly, otherwise
|
||||
// we look it up for them.
|
||||
if (transaction.gasLimit == null) {
|
||||
var estimate = properties_1.shallowCopy(transaction);
|
||||
estimate.from = fromAddress;
|
||||
transaction.gasLimit = this.provider.estimateGas(estimate);
|
||||
}
|
||||
return Promise.all([
|
||||
properties_1.resolveProperties(transaction),
|
||||
fromAddress
|
||||
]).then(function (results) {
|
||||
var tx = results[0];
|
||||
var hexTx = JsonRpcProvider.hexlifyTransaction(tx);
|
||||
hexTx.from = from;
|
||||
hexTx.from = results[1];
|
||||
return _this.provider.send('eth_sendTransaction', [hexTx]).then(function (hash) {
|
||||
return web_1.poll(function () {
|
||||
return _this.provider.getTransaction(hash).then(function (tx) {
|
||||
@@ -217,13 +227,22 @@ var JsonRpcProvider = /** @class */ (function (_super) {
|
||||
});
|
||||
};
|
||||
JsonRpcProvider.prototype.send = function (method, params) {
|
||||
var _this = this;
|
||||
var request = {
|
||||
method: method,
|
||||
params: params,
|
||||
id: 42,
|
||||
jsonrpc: "2.0"
|
||||
};
|
||||
return web_1.fetchJson(this.connection, JSON.stringify(request), getResult);
|
||||
return web_1.fetchJson(this.connection, JSON.stringify(request), getResult).then(function (result) {
|
||||
_this.emit('debug', {
|
||||
action: 'send',
|
||||
request: request,
|
||||
response: result,
|
||||
provider: _this
|
||||
});
|
||||
return result;
|
||||
});
|
||||
};
|
||||
JsonRpcProvider.prototype.perform = function (method, params) {
|
||||
switch (method) {
|
||||
@@ -299,6 +318,7 @@ var JsonRpcProvider = /** @class */ (function (_super) {
|
||||
}
|
||||
var seq = Promise.resolve();
|
||||
hashes.forEach(function (hash) {
|
||||
// @TODO: This should be garbage collected at some point... How? When?
|
||||
self._emitted['t:' + hash.toLowerCase()] = 'pending';
|
||||
seq = seq.then(function () {
|
||||
return self.getTransaction(hash).then(function (tx) {
|
||||
|
||||
@@ -1 +1 @@
|
||||
export const version = "4.0.7";
|
||||
export const version = "4.0.18";
|
||||
|
||||
@@ -280,7 +280,7 @@ function runMethod(contract: Contract, functionName: string, estimateOnly: boole
|
||||
receipt.events = receipt.logs.map((log) => {
|
||||
let event: Event = (<Event>deepCopy(log));
|
||||
|
||||
let parsed = this.interface.parseLog(log);
|
||||
let parsed = contract.interface.parseLog(log);
|
||||
if (parsed) {
|
||||
event.args = parsed.values;
|
||||
event.decode = parsed.decode;
|
||||
@@ -288,12 +288,12 @@ function runMethod(contract: Contract, functionName: string, estimateOnly: boole
|
||||
event.eventSignature = parsed.signature;
|
||||
}
|
||||
|
||||
event.removeListener = () => { return this.provider; }
|
||||
event.removeListener = () => { return contract.provider; }
|
||||
event.getBlock = () => {
|
||||
return this.provider.getBlock(receipt.blockHash);
|
||||
return contract.provider.getBlock(receipt.blockHash);
|
||||
}
|
||||
event.getTransaction = () => {
|
||||
return this.provider.getTransaction(receipt.transactionHash);
|
||||
return contract.provider.getTransaction(receipt.transactionHash);
|
||||
}
|
||||
event.getTransactionReceipt = () => {
|
||||
return Promise.resolve(receipt);
|
||||
@@ -799,7 +799,7 @@ export class ContractFactory {
|
||||
});
|
||||
|
||||
// Make sure the call matches the constructor signature
|
||||
errors.checkArgumentCount(args.length, this.interface.deployFunction.inputs.length, 'in Contract constructor');
|
||||
errors.checkArgumentCount(args.length, this.interface.deployFunction.inputs.length, ' in Contract constructor');
|
||||
|
||||
// Set the data to the bytecode + the encoded constructor arguments
|
||||
tx.data = this.interface.deployFunction.encode(this.bytecode, args);
|
||||
|
||||
@@ -23,7 +23,7 @@ export const MISSING_NEW = 'MISSING_NEW';
|
||||
export const CALL_EXCEPTION = 'CALL_EXCEPTION';
|
||||
|
||||
// Invalid argument (e.g. value is incompatible with type) to a function:
|
||||
// - arg: The argument name that was invalid
|
||||
// - argument: The argument name that was invalid
|
||||
// - value: The value of the argument
|
||||
export const INVALID_ARGUMENT = 'INVALID_ARGUMENT';
|
||||
|
||||
@@ -116,9 +116,28 @@ export function checkArgumentCount(count: number, expectedCount: number, suffix?
|
||||
|
||||
export function setCensorship(censorship: boolean, permanent?: boolean): void {
|
||||
if (_permanentCensorErrors) {
|
||||
throwError('error censorship permanent', UNSUPPORTED_OPERATION, { operation: 'setCersorship' });
|
||||
throwError('error censorship permanent', UNSUPPORTED_OPERATION, { operation: 'setCensorship' });
|
||||
}
|
||||
|
||||
_censorErrors = !!censorship;
|
||||
_permanentCensorErrors = !!permanent;
|
||||
}
|
||||
|
||||
export function checkNormalize(): void {
|
||||
try {
|
||||
// Make sure all forms of normalization are supported
|
||||
["NFD", "NFC", "NFKD", "NFKC"].forEach((form) => {
|
||||
try {
|
||||
"test".normalize(form);
|
||||
} catch(error) {
|
||||
throw new Error('missing ' + form);
|
||||
}
|
||||
});
|
||||
|
||||
if (String.fromCharCode(0xe9).normalize('NFD') !== String.fromCharCode(0x65, 0x0301)) {
|
||||
throw new Error('broken implementation')
|
||||
}
|
||||
} catch (error) {
|
||||
throwError('platform missing String.prototype.normalize', UNSUPPORTED_OPERATION, { operation: 'String.prototype.normalize', form: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,10 +33,15 @@ import { ContractFunction, ContractTransaction, Event, EventFilter } from './con
|
||||
// Helper Functions
|
||||
|
||||
function getDefaultProvider(network?: utils.Network | string): providers.BaseProvider {
|
||||
return new providers.FallbackProvider([
|
||||
new providers.InfuraProvider(network),
|
||||
new providers.EtherscanProvider(network),
|
||||
]);
|
||||
if (network == null) { network = 'homestead'; }
|
||||
let n = utils.getNetwork(network);
|
||||
if (!n || !n._defaultProvider) {
|
||||
errors.throwError('unsupported getDefaultProvider network', errors.UNSUPPORTED_OPERATION, {
|
||||
operation: 'getDefaultProvider',
|
||||
network: network
|
||||
});
|
||||
}
|
||||
return n._defaultProvider(providers);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ export interface TransactionReceipt {
|
||||
export type TransactionRequest = {
|
||||
to?: string | Promise<string>,
|
||||
from?: string | Promise<string>,
|
||||
nonce?: number | string | Promise<number | string>,
|
||||
nonce?: BigNumberish | Promise<BigNumberish>,
|
||||
|
||||
gasLimit?: BigNumberish | Promise<BigNumberish>,
|
||||
gasPrice?: BigNumberish | Promise<BigNumberish>,
|
||||
|
||||
@@ -82,9 +82,13 @@ function arrayOf(check: CheckFunc): CheckFunc {
|
||||
});
|
||||
}
|
||||
|
||||
function checkHash(hash: any): string {
|
||||
if (typeof(hash) === 'string' && hexDataLength(hash) === 32) {
|
||||
return hash.toLowerCase();
|
||||
function checkHash(hash: any, requirePrefix?: boolean): string {
|
||||
if (typeof(hash) === 'string') {
|
||||
// geth-etc does add a "0x" prefix on receipt.root
|
||||
if (!requirePrefix && hash.substring(0, 2) !== '0x') { hash = '0x' + hash; }
|
||||
if (hexDataLength(hash) === 32) {
|
||||
return hash.toLowerCase();
|
||||
}
|
||||
}
|
||||
errors.throwError('invalid hash', errors.INVALID_ARGUMENT, { arg: 'hash', value: hash });
|
||||
return null;
|
||||
@@ -220,11 +224,15 @@ function checkTransactionResponse(transaction: any): TransactionResponse {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let result = check(formatTransaction, transaction);
|
||||
|
||||
let networkId = transaction.networkId;
|
||||
|
||||
// geth-etc returns chainId
|
||||
if (transaction.chainId != null && networkId == null && result.v == null) {
|
||||
networkId = transaction.chainId;
|
||||
}
|
||||
|
||||
if (isHexString(networkId)) {
|
||||
networkId = bigNumberify(networkId).toNumber();
|
||||
}
|
||||
@@ -475,10 +483,21 @@ export class BaseProvider extends Provider {
|
||||
private _network: Network;
|
||||
|
||||
private _events: Array<_Event>;
|
||||
protected _emitted: any;
|
||||
|
||||
// To help mitigate the eventually conssitent nature of the blockchain
|
||||
// we keep a mapping of events we emit. If we emit an event X, we expect
|
||||
// that a user should be able to query for that event in the callback,
|
||||
// if the node returns null, we stall the response until we get back a
|
||||
// meaningful value, since we may be hitting a re-org, or a node that
|
||||
// has not indexed the event yet.
|
||||
// Events:
|
||||
// - t:{hash} - Transaction hash
|
||||
// - b:{hash} - BlockHash
|
||||
// - block - The most recent emitted block
|
||||
protected _emitted: { [ eventName: string ]: number | 'pending' };
|
||||
|
||||
private _pollingInterval: number;
|
||||
private _poller: any; // @TODO: what does TypeScript thing setInterval returns?
|
||||
private _poller: any; // @TODO: what does TypeScript think setInterval returns?
|
||||
|
||||
private _lastBlockNumber: number;
|
||||
|
||||
@@ -511,6 +530,9 @@ export class BaseProvider extends Provider {
|
||||
return network;
|
||||
}));
|
||||
|
||||
// Squash any "unhandled promise" errors; the don't need to be handled
|
||||
this.ready.catch((error) => { });
|
||||
|
||||
} else {
|
||||
let knownNetwork = getNetwork((network == null) ? 'homestead': network);
|
||||
if (knownNetwork) {
|
||||
@@ -532,11 +554,7 @@ export class BaseProvider extends Provider {
|
||||
|
||||
this._pollingInterval = 4000;
|
||||
|
||||
// We use this to track recent emitted events; for example, if we emit a "block" of 100
|
||||
// and we get a `getBlock(100)` request which would result in null, we should retry
|
||||
// until we get a response. This provides devs with a consistent view. Similarly for
|
||||
// transaction hashes.
|
||||
this._emitted = { block: this._lastBlockNumber };
|
||||
this._emitted = { block: -2 };
|
||||
|
||||
this._fastQueryDate = 0;
|
||||
}
|
||||
@@ -548,24 +566,43 @@ export class BaseProvider extends Provider {
|
||||
// If the block hasn't changed, meh.
|
||||
if (blockNumber === this._lastBlockNumber) { return; }
|
||||
|
||||
if (this._lastBlockNumber === -2) { this._lastBlockNumber = blockNumber - 1; }
|
||||
// First polling cycle, trigger a "block" events
|
||||
if (this._emitted.block === -2) {
|
||||
this._emitted.block = blockNumber - 1;
|
||||
}
|
||||
|
||||
// Notify all listener for each block that has passed
|
||||
for (let i = this._lastBlockNumber + 1; i <= blockNumber; i++) {
|
||||
if (this._emitted.block < i) {
|
||||
this._emitted.block = i;
|
||||
for (let i = (<number>this._emitted.block) + 1; i <= blockNumber; i++) {
|
||||
this.emit('block', i);
|
||||
}
|
||||
|
||||
// The emitted block was updated, check for obsolete events
|
||||
if ((<number>this._emitted.block) !== blockNumber) {
|
||||
this._emitted.block = blockNumber;
|
||||
|
||||
Object.keys(this._emitted).forEach((key) => {
|
||||
// The block event does not expire
|
||||
if (key === 'block') { return; }
|
||||
|
||||
// The block we were at when we emitted this event
|
||||
let eventBlockNumber = this._emitted[key];
|
||||
|
||||
// We cannot garbage collect pending transactions or blocks here
|
||||
// They should be garbage collected by the Provider when setting
|
||||
// "pending" events
|
||||
if (eventBlockNumber === 'pending') { return; }
|
||||
|
||||
// Evict any transaction hashes or block hashes over 12 blocks
|
||||
// old, since they should not return null anyways
|
||||
Object.keys(this._emitted).forEach((key) => {
|
||||
if (key === 'block') { return; }
|
||||
if (blockNumber - eventBlockNumber > 12) {
|
||||
delete this._emitted[key];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (this._emitted[key] > i + 12) {
|
||||
delete this._emitted[key];
|
||||
}
|
||||
});
|
||||
}
|
||||
this.emit('block', i);
|
||||
// First polling cycle
|
||||
if (this._lastBlockNumber === -2) {
|
||||
this._lastBlockNumber = blockNumber - 1;
|
||||
}
|
||||
|
||||
// Sweep balances and remove addresses we no longer have events for
|
||||
@@ -583,6 +620,7 @@ export class BaseProvider extends Provider {
|
||||
this.emit(hash, receipt);
|
||||
return null;
|
||||
}).catch((error: Error) => { this.emit('error', error); });
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -591,13 +629,15 @@ export class BaseProvider extends Provider {
|
||||
if (this._balances[address]) {
|
||||
newBalances[address] = this._balances[address];
|
||||
}
|
||||
this.getBalance(address, 'latest').then(function(balance) {
|
||||
|
||||
this.getBalance(address, 'latest').then((balance) => {
|
||||
let lastBalance = this._balances[address];
|
||||
if (lastBalance && balance.eq(lastBalance)) { return; }
|
||||
this._balances[address] = balance;
|
||||
this.emit(address, balance);
|
||||
return null;
|
||||
}).catch((error: Error) => { this.emit('error', error); });
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -630,12 +670,13 @@ export class BaseProvider extends Provider {
|
||||
|
||||
return null;
|
||||
}).catch((error: Error) => { });
|
||||
|
||||
this.doPoll();
|
||||
}
|
||||
|
||||
resetEventsBlock(blockNumber: number): void {
|
||||
this._lastBlockNumber = blockNumber;
|
||||
this._doPoll();
|
||||
this._lastBlockNumber = blockNumber - 1;
|
||||
if (this.polling) { this._doPoll(); }
|
||||
}
|
||||
|
||||
get network(): Network {
|
||||
@@ -647,8 +688,7 @@ export class BaseProvider extends Provider {
|
||||
}
|
||||
|
||||
get blockNumber(): number {
|
||||
if (this._lastBlockNumber < 0) { return null; }
|
||||
return this._lastBlockNumber;
|
||||
return this._fastBlockNumber;
|
||||
}
|
||||
|
||||
get polling(): boolean {
|
||||
@@ -719,10 +759,13 @@ export class BaseProvider extends Provider {
|
||||
// this will be used once we move to the WebSocket or other alternatives to polling
|
||||
|
||||
waitForTransaction(transactionHash: string, confirmations?: number): Promise<TransactionReceipt> {
|
||||
if (!confirmations) { confirmations = 1; }
|
||||
if (confirmations == null) { confirmations = 1; }
|
||||
return poll(() => {
|
||||
return this.getTransactionReceipt(transactionHash).then((receipt) => {
|
||||
if (receipt == null || receipt.confirmations < confirmations) { return undefined; }
|
||||
if (confirmations === 0) { return receipt; }
|
||||
if (receipt == null || receipt.confirmations < confirmations) {
|
||||
return undefined;
|
||||
}
|
||||
return receipt;
|
||||
});
|
||||
}, { onceBlock: this });
|
||||
@@ -832,11 +875,22 @@ export class BaseProvider extends Provider {
|
||||
errors.throwError('Transaction hash mismatch from Provider.sendTransaction.', errors.UNKNOWN_ERROR, { expectedHash: tx.hash, returnedHash: hash });
|
||||
}
|
||||
|
||||
this._emitted['t:' + tx.hash] = 'pending';
|
||||
|
||||
// @TODO: (confirmations? number, timeout? number)
|
||||
result.wait = (confirmations?: number) => {
|
||||
|
||||
// We know this transaction *must* exist (whether it gets mined is
|
||||
// another story), so setting an emitted value forces us to
|
||||
// wait even if the node returns null for the receipt
|
||||
if (confirmations !== 0) {
|
||||
this._emitted['t:' + tx.hash] = 'pending';
|
||||
}
|
||||
|
||||
return this.waitForTransaction(tx.hash, confirmations).then((receipt) => {
|
||||
if (receipt == null && confirmations === 0) { return null; }
|
||||
|
||||
// No longer pending, allow the polling loop to garbage collect this
|
||||
this._emitted['t:' + tx.hash] = receipt.blockNumber;
|
||||
|
||||
if (receipt.status === 0) {
|
||||
errors.throwError('transaction failed', errors.CALL_EXCEPTION, {
|
||||
transactionHash: tx.hash,
|
||||
@@ -918,7 +972,7 @@ export class BaseProvider extends Provider {
|
||||
return poll(() => {
|
||||
return this.perform('getBlock', { blockTag: blockTag, includeTransactions: !!includeTransactions }).then((block) => {
|
||||
if (block == null) {
|
||||
if (blockNumber > this._emitted.block) {
|
||||
if (blockNumber <= this._emitted.block) {
|
||||
return undefined;
|
||||
}
|
||||
return null;
|
||||
@@ -936,7 +990,7 @@ export class BaseProvider extends Provider {
|
||||
getTransaction(transactionHash: string): Promise<TransactionResponse> {
|
||||
return this.ready.then(() => {
|
||||
return resolveProperties({ transactionHash: transactionHash }).then(({ transactionHash }) => {
|
||||
let params = { transactionHash: checkHash(transactionHash) };
|
||||
let params = { transactionHash: checkHash(transactionHash, true) };
|
||||
return poll(() => {
|
||||
return this.perform('getTransaction', params).then((result) => {
|
||||
if (result == null) {
|
||||
@@ -973,7 +1027,7 @@ export class BaseProvider extends Provider {
|
||||
getTransactionReceipt(transactionHash: string): Promise<TransactionReceipt> {
|
||||
return this.ready.then(() => {
|
||||
return resolveProperties({ transactionHash: transactionHash }).then(({ transactionHash }) => {
|
||||
let params = { transactionHash: checkHash(transactionHash) };
|
||||
let params = { transactionHash: checkHash(transactionHash, true) };
|
||||
return poll(() => {
|
||||
return this.perform('getTransactionReceipt', params).then((result) => {
|
||||
if (result == null) {
|
||||
|
||||
@@ -32,7 +32,8 @@ function checkNetworks(networks: Array<Network>): boolean {
|
||||
// Matches!
|
||||
if (check.name === network.name &&
|
||||
check.chainId === network.chainId &&
|
||||
check.ensAddress === network.ensAddress) { return; }
|
||||
((check.ensAddress === network.ensAddress) ||
|
||||
(check.ensAddress == null && network.ensAddress == null))) { return; }
|
||||
|
||||
errors.throwError(
|
||||
'provider mismatch',
|
||||
|
||||
@@ -12,8 +12,7 @@ import { getAddress } from '../utils/address';
|
||||
import { BigNumber } from '../utils/bignumber';
|
||||
import { hexlify, hexStripZeros } from '../utils/bytes';
|
||||
import { getNetwork } from '../utils/networks';
|
||||
import { checkProperties, defineReadOnly, shallowCopy } from '../utils/properties';
|
||||
import { populateTransaction } from '../utils/transaction';
|
||||
import { checkProperties, defineReadOnly, resolveProperties, shallowCopy } from '../utils/properties';
|
||||
import { toUtf8Bytes } from '../utils/utf8';
|
||||
import { fetchJson, poll } from '../utils/web';
|
||||
|
||||
@@ -103,17 +102,29 @@ export class JsonRpcSigner extends Signer {
|
||||
}
|
||||
|
||||
sendTransaction(transaction: TransactionRequest): Promise<TransactionResponse> {
|
||||
transaction = shallowCopy(transaction);
|
||||
|
||||
// Once populateTransaction resolves, the from address will be populated from getAddress
|
||||
let from: string = null;
|
||||
let getAddress = this.getAddress().then((address) => {
|
||||
if (address) { from = address.toLowerCase(); }
|
||||
return from;
|
||||
let fromAddress = this.getAddress().then((address) => {
|
||||
if (address) { address = address.toLowerCase(); }
|
||||
return address;
|
||||
});
|
||||
|
||||
return populateTransaction(transaction, this.provider, getAddress).then((tx) => {
|
||||
// The JSON-RPC for eth_sendTransaction uses 90000 gas; if the user
|
||||
// wishes to use this, it is easy to specify explicitly, otherwise
|
||||
// we look it up for them.
|
||||
if (transaction.gasLimit == null) {
|
||||
let estimate = shallowCopy(transaction);
|
||||
estimate.from = fromAddress;
|
||||
transaction.gasLimit = this.provider.estimateGas(estimate);
|
||||
}
|
||||
|
||||
return Promise.all([
|
||||
resolveProperties(transaction),
|
||||
fromAddress
|
||||
]).then((results) => {
|
||||
let tx = results[0];
|
||||
let hexTx = JsonRpcProvider.hexlifyTransaction(tx);
|
||||
hexTx.from = from;
|
||||
hexTx.from = results[1];
|
||||
return this.provider.send('eth_sendTransaction', [ hexTx ]).then((hash) => {
|
||||
return poll(() => {
|
||||
return this.provider.getTransaction(hash).then((tx: TransactionResponse) => {
|
||||
@@ -335,6 +346,7 @@ export class JsonRpcProvider extends BaseProvider {
|
||||
|
||||
var seq = Promise.resolve();
|
||||
hashes.forEach(function(hash) {
|
||||
// @TODO: This should be garbage collected at some point... How? When?
|
||||
self._emitted['t:' + hash.toLowerCase()] = 'pending';
|
||||
seq = seq.then(function() {
|
||||
return self.getTransaction(hash).then(function(tx) {
|
||||
|
||||
@@ -107,9 +107,12 @@ type ParseNode = {
|
||||
|
||||
|
||||
function parseParam(param: string, allowIndexed?: boolean): ParamType {
|
||||
|
||||
let originalParam = param;
|
||||
function throwError(i: number) {
|
||||
throw new Error('unexpected character "' + param[i] + '" at position ' + i + ' in "' + param + '"');
|
||||
throw new Error('unexpected character "' + originalParam[i] + '" at position ' + i + ' in "' + originalParam + '"');
|
||||
}
|
||||
param = param.replace(/\s/g, ' ');
|
||||
|
||||
var parent: ParseNode = { type: '', name: '', state: { allowType: true } };
|
||||
var node = parent;
|
||||
@@ -380,6 +383,7 @@ export function formatSignature(fragment: EventFragment | FunctionFragment): str
|
||||
export function parseSignature(fragment: string): EventFragment | FunctionFragment {
|
||||
if(typeof(fragment) === 'string') {
|
||||
// Make sure the "returns" is surrounded by a space and all whitespace is exactly one space
|
||||
fragment = fragment.replace(/\s/g, ' ');
|
||||
fragment = fragment.replace(/\(/g, ' (').replace(/\)/g, ') ').replace(/\s+/g, ' ');
|
||||
fragment = fragment.trim();
|
||||
|
||||
@@ -844,7 +848,7 @@ class CoderArray extends Coder {
|
||||
result = uint256Coder.encode(count);
|
||||
}
|
||||
|
||||
errors.checkArgumentCount(count, value.length, 'in coder array' + (this.localName? (" "+ this.localName): ""));
|
||||
errors.checkArgumentCount(count, value.length, ' in coder array' + (this.localName? (" "+ this.localName): ""));
|
||||
|
||||
var coders = [];
|
||||
for (var i = 0; i < value.length; i++) { coders.push(this.coder); }
|
||||
|
||||
@@ -47,7 +47,6 @@ function _bnify(value: BigNumber): BN.BN {
|
||||
return new BN.BN(hex.substring(2), 16);
|
||||
}
|
||||
|
||||
|
||||
export type BigNumberish = BigNumber | string | number | Arrayish;
|
||||
|
||||
export class BigNumber implements Hexable {
|
||||
@@ -108,6 +107,13 @@ export class BigNumber implements Hexable {
|
||||
return toBigNumber(_bnify(this).toTwos(value));
|
||||
}
|
||||
|
||||
abs(): BigNumber {
|
||||
if (this._hex[0] === '-') {
|
||||
return toBigNumber(_bnify(this).mul(BN_1));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
add(other: BigNumberish): BigNumber {
|
||||
return toBigNumber(_bnify(this).add(toBN(other)));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
import * as errors from '../errors';
|
||||
|
||||
import { concat, hexlify } from './bytes';
|
||||
import { toUtf8Bytes } from './utf8';
|
||||
import { keccak256 } from './keccak256';
|
||||
@@ -11,11 +13,18 @@ import { Arrayish } from './bytes';
|
||||
|
||||
///////////////////////////////
|
||||
|
||||
var Zeros = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
||||
var Partition = new RegExp("^((.*)\\.)?([^.]+)$");
|
||||
var UseSTD3ASCIIRules = new RegExp("^[a-z0-9.-]*$");
|
||||
const Zeros = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
||||
const Partition = new RegExp("^((.*)\\.)?([^.]+)$");
|
||||
const UseSTD3ASCIIRules = new RegExp("^[a-z0-9.-]*$");
|
||||
|
||||
export function namehash(name: string): string {
|
||||
if (typeof(name) !== 'string') {
|
||||
errors.throwError('invalid address - ' + String(name), errors.INVALID_ARGUMENT, {
|
||||
argument: 'name',
|
||||
value: name
|
||||
});
|
||||
}
|
||||
|
||||
name = name.toLowerCase();
|
||||
|
||||
// Supporting the full UTF-8 space requires additional (and large)
|
||||
@@ -23,13 +32,16 @@ export function namehash(name: string): string {
|
||||
// It should be fairly easy in the future to support systems with
|
||||
// String.normalize, but that is future work.
|
||||
if (!name.match(UseSTD3ASCIIRules)) {
|
||||
throw new Error('contains invalid UseSTD3ASCIIRules characters');
|
||||
errors.throwError('contains invalid UseSTD3ASCIIRules characters', errors.INVALID_ARGUMENT, {
|
||||
argument: 'name',
|
||||
value: name
|
||||
});
|
||||
}
|
||||
|
||||
var result: string | Uint8Array = Zeros;
|
||||
let result: string | Uint8Array = Zeros;
|
||||
while (name.length) {
|
||||
var partition = name.match(Partition);
|
||||
var label = toUtf8Bytes(partition[3]);
|
||||
let partition = name.match(Partition);
|
||||
let label = toUtf8Bytes(partition[3]);
|
||||
result = keccak256(concat([result, keccak256(label)]));
|
||||
|
||||
name = partition[2] || '';
|
||||
@@ -44,11 +56,10 @@ export function id(text: string): string {
|
||||
}
|
||||
|
||||
export function hashMessage(message: Arrayish | string): string {
|
||||
var payload = concat([
|
||||
return keccak256(concat([
|
||||
toUtf8Bytes('\x19Ethereum Signed Message:\n'),
|
||||
toUtf8Bytes(String(message.length)),
|
||||
((typeof(message) === 'string') ? toUtf8Bytes(message): message)
|
||||
]);
|
||||
return keccak256(payload);
|
||||
]));
|
||||
}
|
||||
|
||||
|
||||
@@ -201,6 +201,8 @@ export function mnemonicToSeed(mnemonic: string, password?: string): string {
|
||||
export function mnemonicToEntropy(mnemonic: string, wordlist?: Wordlist): string {
|
||||
if (!wordlist) { wordlist = langEn; }
|
||||
|
||||
errors.checkNormalize();
|
||||
|
||||
var words = wordlist.split(mnemonic);
|
||||
if ((words.length % 3) !== 0) { throw new Error('invalid mnemonic'); }
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { AbiCoder, defaultAbiCoder, formatSignature, formatParamType, parseSigna
|
||||
import { getAddress, getContractAddress, getIcapAddress } from './address';
|
||||
import * as base64 from './base64';
|
||||
import { BigNumber, bigNumberify } from './bignumber';
|
||||
import { arrayify, concat, hexDataSlice, hexDataLength, hexlify, hexStripZeros, hexZeroPad, joinSignature, padZeros, splitSignature, stripZeros } from './bytes';
|
||||
import { arrayify, concat, hexDataSlice, hexDataLength, hexlify, hexStripZeros, hexZeroPad, isHexString, joinSignature, padZeros, splitSignature, stripZeros } from './bytes';
|
||||
import { hashMessage, id, namehash } from './hash';
|
||||
import * as HDNode from './hdnode';
|
||||
import { Interface } from './interface';
|
||||
@@ -84,6 +84,7 @@ export {
|
||||
bigNumberify,
|
||||
|
||||
hexlify,
|
||||
isHexString,
|
||||
hexStripZeros,
|
||||
hexZeroPad,
|
||||
hexDataLength,
|
||||
|
||||
@@ -103,7 +103,7 @@ class _DeployDescription extends Description implements DeployDescription {
|
||||
});
|
||||
}
|
||||
|
||||
errors.checkArgumentCount(params.length, this.inputs.length, 'in Interface constructor');
|
||||
errors.checkArgumentCount(params.length, this.inputs.length, ' in Interface constructor');
|
||||
|
||||
try {
|
||||
return (bytecode + defaultAbiCoder.encode(this.inputs, params).substring(2));
|
||||
@@ -132,7 +132,7 @@ class _FunctionDescription extends Description implements FunctionDescription {
|
||||
readonly gas: BigNumber;
|
||||
|
||||
encode(params: Array<any>): string {
|
||||
errors.checkArgumentCount(params.length, this.inputs.length, 'in interface function ' + this.name);
|
||||
errors.checkArgumentCount(params.length, this.inputs.length, ' in interface function ' + this.name);
|
||||
|
||||
try {
|
||||
return this.sighash + defaultAbiCoder.encode(this.inputs, params).substring(2);
|
||||
@@ -320,6 +320,7 @@ function addMethod(method: any): void {
|
||||
payable: (method.payable == null || !!method.payable),
|
||||
type: ((method.constant) ? 'call': 'transaction'),
|
||||
|
||||
name: method.name,
|
||||
signature: signature,
|
||||
sighash: sighash,
|
||||
});
|
||||
@@ -433,10 +434,10 @@ export class Interface {
|
||||
return new _TransactionDescription({
|
||||
args: result,
|
||||
decode: func.decode,
|
||||
name: name,
|
||||
name: func.name,
|
||||
signature: func.signature,
|
||||
sighash: func.sighash,
|
||||
value: bigNumberify(tx.value || null),
|
||||
value: bigNumberify(tx.value || '0'),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,33 +7,69 @@ export type Network = {
|
||||
name: string,
|
||||
chainId: number,
|
||||
ensAddress?: string,
|
||||
_defaultProvider?: (providers: any) => any
|
||||
}
|
||||
|
||||
export type Networkish = Network | string | number;
|
||||
|
||||
function ethDefaultProvider(network: string): (providers: any) => any {
|
||||
return function(providers: any): any {
|
||||
let providerList: Array<any> = [];
|
||||
|
||||
if (providers.InfuraProvider) {
|
||||
providerList.push(new providers.InfuraProvider(network));
|
||||
}
|
||||
|
||||
if (providers.EtherscanProvider) {
|
||||
providerList.push(new providers.EtherscanProvider(network));
|
||||
}
|
||||
|
||||
if (providerList.length === 0) { return null; }
|
||||
|
||||
if (providers.FallbackProvider) {
|
||||
return new providers.FallbackProvider(providerList);;
|
||||
}
|
||||
|
||||
return providerList[0];
|
||||
}
|
||||
}
|
||||
|
||||
function etcDefaultProvider(url: string, network: string): (providers: any) => any {
|
||||
return function(providers: any): any {
|
||||
if (providers.JsonRpcProvider) {
|
||||
return new providers.JsonRpcProvider(url, network);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const homestead: Network = {
|
||||
chainId: 1,
|
||||
ensAddress: "0x314159265dd8dbb310642f98f50c066173c1259b",
|
||||
name: "homestead"
|
||||
name: "homestead",
|
||||
_defaultProvider: ethDefaultProvider('homestead')
|
||||
};
|
||||
|
||||
const ropsten: Network = {
|
||||
chainId: 3,
|
||||
ensAddress: "0x112234455c3a32fd11230c42e7bccd4a84e02010",
|
||||
name: "ropsten"
|
||||
name: "ropsten",
|
||||
_defaultProvider: ethDefaultProvider('ropsten')
|
||||
};
|
||||
|
||||
const networks: { [name: string]: { chainId: number, ensAddress?: string } } = {
|
||||
const networks: { [name: string]: Network } = {
|
||||
unspecified: {
|
||||
chainId: 0
|
||||
chainId: 0,
|
||||
name: 'unspecified'
|
||||
},
|
||||
|
||||
homestead: homestead,
|
||||
mainnet: homestead,
|
||||
|
||||
morden: {
|
||||
chainId: 2
|
||||
chainId: 2,
|
||||
name: 'morden'
|
||||
},
|
||||
|
||||
ropsten: ropsten,
|
||||
@@ -41,19 +77,27 @@ const networks: { [name: string]: { chainId: number, ensAddress?: string } } = {
|
||||
|
||||
rinkeby: {
|
||||
chainId: 4,
|
||||
ensAddress: "0xe7410170f87102DF0055eB195163A03B7F2Bff4A"
|
||||
ensAddress: "0xe7410170f87102DF0055eB195163A03B7F2Bff4A",
|
||||
name: 'rinkeby',
|
||||
_defaultProvider: ethDefaultProvider('rinkeby')
|
||||
},
|
||||
|
||||
kovan: {
|
||||
chainId: 42
|
||||
chainId: 42,
|
||||
name: 'kovan',
|
||||
_defaultProvider: ethDefaultProvider('kovan')
|
||||
},
|
||||
|
||||
classic: {
|
||||
chainId: 61
|
||||
chainId: 61,
|
||||
name: 'classic',
|
||||
_defaultProvider: etcDefaultProvider('https://web3.gastracker.io', 'classic')
|
||||
},
|
||||
|
||||
classicTestnet: {
|
||||
chainId: 62
|
||||
chainId: 62,
|
||||
name: 'classicTestnet',
|
||||
_defaultProvider: etcDefaultProvider('https://web3.gastracker.io/morden', 'classicTestnet')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,17 +108,18 @@ const networks: { [name: string]: { chainId: number, ensAddress?: string } } = {
|
||||
* and verifies a network is a valid Network..
|
||||
*/
|
||||
export function getNetwork(network: Networkish): Network {
|
||||
// No network (null) or unspecified (chainId = 0)
|
||||
if (!network) { return null; }
|
||||
// No network (null)
|
||||
if (network == null) { return null; }
|
||||
|
||||
if (typeof(network) === 'number') {
|
||||
for (var name in networks) {
|
||||
for (let name in networks) {
|
||||
let n = networks[name];
|
||||
if (n.chainId === network) {
|
||||
return {
|
||||
name: name,
|
||||
name: n.name,
|
||||
chainId: n.chainId,
|
||||
ensAddress: n.ensAddress
|
||||
ensAddress: (n.ensAddress || null),
|
||||
_defaultProvider: (n._defaultProvider || null)
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -89,9 +134,10 @@ export function getNetwork(network: Networkish): Network {
|
||||
let n = networks[network];
|
||||
if (n == null) { return null; }
|
||||
return {
|
||||
name: network,
|
||||
name: n.name,
|
||||
chainId: n.chainId,
|
||||
ensAddress: n.ensAddress
|
||||
ensAddress: n.ensAddress,
|
||||
_defaultProvider: (n._defaultProvider || null)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -110,10 +156,11 @@ export function getNetwork(network: Networkish): Network {
|
||||
errors.throwError('network chainId mismatch', errors.INVALID_ARGUMENT, { arg: 'network', value: network });
|
||||
}
|
||||
|
||||
// Standard Network
|
||||
// Standard Network (allow overriding the ENS address)
|
||||
return {
|
||||
name: network.name,
|
||||
chainId: n.chainId,
|
||||
ensAddress: n.ensAddress
|
||||
ensAddress: (network.ensAddress || n.ensAddress || null),
|
||||
_defaultProvider: (network._defaultProvider || n._defaultProvider || null)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
import { HashZero } from '../constants';
|
||||
|
||||
import { checkNormalize } from '../errors';
|
||||
import { arrayify, concat, hexlify } from './bytes';
|
||||
|
||||
///////////////////////////////
|
||||
@@ -23,6 +23,7 @@ export enum UnicodeNormalizationForm {
|
||||
export function toUtf8Bytes(str: string, form: UnicodeNormalizationForm = UnicodeNormalizationForm.current): Uint8Array {
|
||||
|
||||
if (form != UnicodeNormalizationForm.current) {
|
||||
checkNormalize();
|
||||
str = str.normalize(form);
|
||||
}
|
||||
|
||||
|
||||
@@ -135,6 +135,9 @@ export function fetchJson(connection: string | ConnectionInfo, json: string, pro
|
||||
let jsonError: any = new Error('invalid json response');
|
||||
jsonError.orginialError = error;
|
||||
jsonError.responseText = request.responseText;
|
||||
if (json != null) {
|
||||
jsonError.requestBody = json;
|
||||
}
|
||||
jsonError.url = url;
|
||||
reject(jsonError);
|
||||
return;
|
||||
@@ -163,7 +166,7 @@ export function fetchJson(connection: string | ConnectionInfo, json: string, pro
|
||||
}
|
||||
|
||||
try {
|
||||
if (json) {
|
||||
if (json != null) {
|
||||
request.send(json);
|
||||
} else {
|
||||
request.send();
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -132,9 +132,7 @@ class LangJa extends Wordlist {
|
||||
}
|
||||
|
||||
split(mnemonic: string): Array<string> {
|
||||
if (!mnemonic.normalize) {
|
||||
errors.throwError('Japanese is unsupported on this platform; missing String.prototype.normalize', errors.UNSUPPORTED_OPERATION, { operation: 'String.prototype.normalize' });
|
||||
}
|
||||
errors.checkNormalize();
|
||||
return mnemonic.split(/(?:\u3000| )+/g);
|
||||
}
|
||||
|
||||
|
||||
99
tests/shims/base64.js
Normal file
99
tests/shims/base64.js
Normal file
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
* See: https://github.com/MaxArt2501/base64-js
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 MaxArt2501
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
(function (root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define([], function() {factory(root);});
|
||||
} else factory(root);
|
||||
// node.js has always supported base64 conversions, while browsers that support
|
||||
// web workers support base64 too, but you may never know.
|
||||
})(typeof exports !== "undefined" ? exports : this, function(root) {
|
||||
if (root.atob) {
|
||||
// Some browsers' implementation of atob doesn't support whitespaces
|
||||
// in the encoded string (notably, IE). This wraps the native atob
|
||||
// in a function that strips the whitespaces.
|
||||
// The original function can be retrieved in atob.original
|
||||
try {
|
||||
root.atob(" ");
|
||||
} catch(e) {
|
||||
root.atob = (function(atob) {
|
||||
var func = function(string) {
|
||||
return atob(String(string).replace(/[\t\n\f\r ]+/g, ""));
|
||||
};
|
||||
func.original = atob;
|
||||
return func;
|
||||
})(root.atob);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// base64 character set, plus padding character (=)
|
||||
var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
|
||||
// Regular expression to check formal correctness of base64 encoded strings
|
||||
b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
|
||||
|
||||
root.btoa = function(string) {
|
||||
string = String(string);
|
||||
var bitmap, a, b, c,
|
||||
result = "", i = 0,
|
||||
rest = string.length % 3; // To determine the final padding
|
||||
|
||||
for (; i < string.length;) {
|
||||
if ((a = string.charCodeAt(i++)) > 255
|
||||
|| (b = string.charCodeAt(i++)) > 255
|
||||
|| (c = string.charCodeAt(i++)) > 255)
|
||||
throw new TypeError("Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.");
|
||||
|
||||
bitmap = (a << 16) | (b << 8) | c;
|
||||
result += b64.charAt(bitmap >> 18 & 63) + b64.charAt(bitmap >> 12 & 63)
|
||||
+ b64.charAt(bitmap >> 6 & 63) + b64.charAt(bitmap & 63);
|
||||
}
|
||||
|
||||
// If there's need of padding, replace the last 'A's with equal signs
|
||||
return rest ? result.slice(0, rest - 3) + "===".substring(rest) : result;
|
||||
};
|
||||
|
||||
root.atob = function(string) {
|
||||
// atob can work with strings with whitespaces, even inside the encoded part,
|
||||
// but only \t, \n, \f, \r and ' ', which can be stripped.
|
||||
string = String(string).replace(/[\t\n\f\r ]+/g, "");
|
||||
if (!b64re.test(string))
|
||||
throw new TypeError("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");
|
||||
|
||||
// Adding the padding if missing, for semplicity
|
||||
string += "==".slice(2 - (string.length & 3));
|
||||
var bitmap, result = "", r1, r2, i = 0;
|
||||
for (; i < string.length;) {
|
||||
bitmap = b64.indexOf(string.charAt(i++)) << 18 | b64.indexOf(string.charAt(i++)) << 12
|
||||
| (r1 = b64.indexOf(string.charAt(i++))) << 6 | (r2 = b64.indexOf(string.charAt(i++)));
|
||||
|
||||
result += r1 === 64 ? String.fromCharCode(bitmap >> 16 & 255)
|
||||
: r2 === 64 ? String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255)
|
||||
: String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255, bitmap & 255);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
});
|
||||
73
tests/shims/index.js
Normal file
73
tests/shims/index.js
Normal file
@@ -0,0 +1,73 @@
|
||||
'use strict';
|
||||
|
||||
var shims = [];
|
||||
|
||||
// Shim String.prototype.normalize
|
||||
try {
|
||||
var missing = [];
|
||||
|
||||
// Some platforms are missing certain normalization forms
|
||||
var forms = ["NFD", "NFC", "NFKD", "NFKC"];
|
||||
for (var i = 0; i < forms.length; i++) {
|
||||
try {
|
||||
"test".normalize(forms[i]);
|
||||
} catch(error) {
|
||||
missing.push(forms[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (missing.length) {
|
||||
shims.push("String.prototype.normalize (missing: " + missing.join(", ") + ")");
|
||||
throw new Error('bad normalize');
|
||||
}
|
||||
|
||||
// Some platforms have a native normalize, but it is broken; so we force our shim
|
||||
if (String.fromCharCode(0xe9).normalize('NFD') !== String.fromCharCode(0x65, 0x0301)) {
|
||||
shims.push("String.prototype.normalize (broken)");
|
||||
throw new Error('bad normalize');
|
||||
}
|
||||
} catch (error) {
|
||||
var unorm = require('./unorm.js');
|
||||
String.prototype.normalize = function(form) {
|
||||
var func = unorm[(form || 'NFC').toLowerCase()];
|
||||
if (!func) { throw new RangeError('invalid form - ' + form); }
|
||||
return func(this);
|
||||
}
|
||||
}
|
||||
|
||||
// Shim atob and btoa
|
||||
var base64 = require('./base64.js');
|
||||
if (!global.atob) {
|
||||
shims.push("atob");
|
||||
global.atob = base64.atob;
|
||||
}
|
||||
if (!global.btoa) {
|
||||
shims.push("btoa");
|
||||
global.btoa = base64.btoa;
|
||||
}
|
||||
|
||||
// Shim Promise
|
||||
// @TODO: Check first?
|
||||
var promise = require('./es6-promise.auto.js');
|
||||
|
||||
// Shim ArrayBuffer.isView
|
||||
if (!ArrayBuffer.isView) {
|
||||
shims.push("ArrayBuffer.isView");
|
||||
ArrayBuffer.isView = function(obj) {
|
||||
// @TODO: This should probably check various instanceof aswell
|
||||
return !!(obj.buffer);
|
||||
}
|
||||
}
|
||||
|
||||
// Shim nextTick
|
||||
if (!global.nextTick) {
|
||||
shims.push("nextTick");
|
||||
global.nextTick = function (callback) { setTimeout(callback, 0); }
|
||||
}
|
||||
|
||||
if (shims.length) {
|
||||
console.log("Shims Injected:");
|
||||
for (var i = 0; i < shims.length; i++) {
|
||||
console.log(' - ' + shims[i]);
|
||||
}
|
||||
}
|
||||
@@ -231,6 +231,36 @@ describe('Test Interface Signatures', function() {
|
||||
'derived the correct signature hash');
|
||||
})
|
||||
});
|
||||
|
||||
it('derives correct description for human-readable ABI', function() {
|
||||
var iface = new Interface([ "function transfer(address from, uint amount)" ]);
|
||||
[
|
||||
"transfer",
|
||||
"transfer(address,uint256)"
|
||||
].forEach(function(key) {
|
||||
var descr = iface.functions[key];
|
||||
assert.equal(descr.name, "transfer", "incorrect name key - " + key);
|
||||
assert.equal(descr.signature, "transfer(address,uint256)", "incorrect signature key - " + key);
|
||||
assert.equal(descr.sighash, "0xa9059cbb", "incorrect sighash key - " + key);
|
||||
});
|
||||
});
|
||||
|
||||
// See: https://github.com/ethers-io/ethers.js/issues/370
|
||||
it ('parses transaction function', function() {
|
||||
var iface = new Interface([ "function transfer(address from, uint amount)" ]);
|
||||
|
||||
// Transaction: 0x820cc57bc77be44d8f4f024a18e18f64a8b6e62a82a3d7897db5970dbe181ba1
|
||||
var rawTx = "0xf8aa028502540be4008316e36094334eec1482109bd802d9e72a447848de3bcc106380b844a9059cbb000000000000000000000000851b9167b7cbf772d38efaf89705b35022880a070000000000000000000000000000000000000000000000000de0b6b3a764000026a03200bf26e5f10f7eda59c0aad9adc2334dda79e785b9b004342524d97a66fca9a0450b07a4dc450bb472e08f8370350fa365fcef6db1a95309ae4c06c9d0748092";
|
||||
var tx = ethers.utils.parseTransaction(rawTx);
|
||||
|
||||
var descr = iface.parseTransaction(tx);
|
||||
assert.equal(descr.args[0], '0x851b9167B7cbf772D38eFaf89705b35022880A07', 'parsed tx - args[0]');
|
||||
assert.equal(descr.args[1].toString(), '1000000000000000000', 'parsed tx - args[1]');
|
||||
assert.equal(descr.name, 'transfer', 'parsed tx - name');
|
||||
assert.equal(descr.signature, 'transfer(address,uint256)', 'parsed tx - signature');
|
||||
assert.equal(descr.sighash, '0xa9059cbb', 'parsed tx - sighash');
|
||||
assert.equal(descr.value.toString(), '0', 'parsed tx - value');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Test Number Coder', function() {
|
||||
|
||||
@@ -327,3 +327,24 @@ describe('Test Bytes32String coder', function() {
|
||||
assert.equal(str2, str, "parsed correctly");
|
||||
});
|
||||
});
|
||||
|
||||
describe('Test BigNumber', function() {
|
||||
it("computes absoltue values", function() {
|
||||
function testAbs(test) {
|
||||
var value = ethers.utils.bigNumberify(test.value);
|
||||
var expected = ethers.utils.bigNumberify(test.expected);
|
||||
assert.ok(value.abs().eq(expected), 'BigNumber.abs - ' + test.value);
|
||||
}
|
||||
|
||||
[
|
||||
{ value: "0x0", expected: "0x0" },
|
||||
{ value: "-0x0", expected: "0x0" },
|
||||
{ value: "0x5", expected: "0x5" },
|
||||
{ value: "-0x5", expected: "0x5" },
|
||||
{ value: "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", expected: "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" },
|
||||
{ value: "-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", expected: "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" },
|
||||
{ value: "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", expected: "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" },
|
||||
{ value: "-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", expected: "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" },
|
||||
].forEach(testAbs);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -11,37 +11,7 @@
|
||||
<body>
|
||||
<div id="mocha"></div>
|
||||
<script src="../node_modules/mocha/mocha.js"></script>
|
||||
|
||||
<!--
|
||||
Shim for PhantomJS: Promise
|
||||
See: https://github.com/stefanpenner/es6-promise
|
||||
-->
|
||||
<script src="./dist/es6-promise.auto.js"></script>
|
||||
|
||||
<!--
|
||||
Shim for String.prototype.normalize
|
||||
See: https://github.com/walling/unorm
|
||||
-->
|
||||
<script src="./dist/unorm.js"></script>
|
||||
|
||||
<!--
|
||||
Shims for PhantomJS
|
||||
-->
|
||||
<script type="text/javascript">
|
||||
|
||||
// ArrayBuffer.isView
|
||||
if (!ArrayBuffer.isView) {
|
||||
ArrayBuffer.isView = function(obj) {
|
||||
// @TODO: This should probably check various instanceof aswell
|
||||
return !!(obj.buffer);
|
||||
}
|
||||
}
|
||||
|
||||
// nextTick
|
||||
if (!window.nextTick) {
|
||||
window.nextTick = function (callback) { setTimeout(callback, 0); }
|
||||
}
|
||||
</script>
|
||||
<script src="../dist/shims.js"></script>
|
||||
|
||||
<!-- Inject the mocha describe and it functions -->
|
||||
<script type="text/javascript">
|
||||
|
||||
@@ -51,9 +51,11 @@ function verifyType(type) {
|
||||
return type;
|
||||
}
|
||||
function parseParam(param, allowIndexed) {
|
||||
var originalParam = param;
|
||||
function throwError(i) {
|
||||
throw new Error('unexpected character "' + param[i] + '" at position ' + i + ' in "' + param + '"');
|
||||
throw new Error('unexpected character "' + originalParam[i] + '" at position ' + i + ' in "' + originalParam + '"');
|
||||
}
|
||||
param = param.replace(/\s/g, ' ');
|
||||
var parent = { type: '', name: '', state: { allowType: true } };
|
||||
var node = parent;
|
||||
for (var i = 0; i < param.length; i++) {
|
||||
@@ -298,6 +300,7 @@ exports.formatSignature = formatSignature;
|
||||
function parseSignature(fragment) {
|
||||
if (typeof (fragment) === 'string') {
|
||||
// Make sure the "returns" is surrounded by a space and all whitespace is exactly one space
|
||||
fragment = fragment.replace(/\s/g, ' ');
|
||||
fragment = fragment.replace(/\(/g, ' (').replace(/\)/g, ') ').replace(/\s+/g, ' ');
|
||||
fragment = fragment.trim();
|
||||
if (fragment.substring(0, 6) === 'event ') {
|
||||
@@ -733,7 +736,7 @@ var CoderArray = /** @class */ (function (_super) {
|
||||
count = value.length;
|
||||
result = uint256Coder.encode(count);
|
||||
}
|
||||
errors.checkArgumentCount(count, value.length, 'in coder array' + (this.localName ? (" " + this.localName) : ""));
|
||||
errors.checkArgumentCount(count, value.length, ' in coder array' + (this.localName ? (" " + this.localName) : ""));
|
||||
var coders = [];
|
||||
for (var i = 0; i < value.length; i++) {
|
||||
coders.push(this.coder);
|
||||
|
||||
@@ -166,6 +166,7 @@ function mnemonicToEntropy(mnemonic, wordlist) {
|
||||
if (!wordlist) {
|
||||
wordlist = lang_en_1.langEn;
|
||||
}
|
||||
errors.checkNormalize();
|
||||
var words = wordlist.split(mnemonic);
|
||||
if ((words.length % 3) !== 0) {
|
||||
throw new Error('invalid mnemonic');
|
||||
|
||||
@@ -56,7 +56,7 @@ var _DeployDescription = /** @class */ (function (_super) {
|
||||
value: bytecode
|
||||
});
|
||||
}
|
||||
errors.checkArgumentCount(params.length, this.inputs.length, 'in Interface constructor');
|
||||
errors.checkArgumentCount(params.length, this.inputs.length, ' in Interface constructor');
|
||||
try {
|
||||
return (bytecode + abi_coder_1.defaultAbiCoder.encode(this.inputs, params).substring(2));
|
||||
}
|
||||
@@ -77,7 +77,7 @@ var _FunctionDescription = /** @class */ (function (_super) {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
_FunctionDescription.prototype.encode = function (params) {
|
||||
errors.checkArgumentCount(params.length, this.inputs.length, 'in interface function ' + this.name);
|
||||
errors.checkArgumentCount(params.length, this.inputs.length, ' in interface function ' + this.name);
|
||||
try {
|
||||
return this.sighash + abi_coder_1.defaultAbiCoder.encode(this.inputs, params).substring(2);
|
||||
}
|
||||
@@ -249,6 +249,7 @@ function addMethod(method) {
|
||||
gas: method.gas,
|
||||
payable: (method.payable == null || !!method.payable),
|
||||
type: ((method.constant) ? 'call' : 'transaction'),
|
||||
name: method.name,
|
||||
signature: signature,
|
||||
sighash: sighash,
|
||||
});
|
||||
@@ -339,10 +340,10 @@ var Interface = /** @class */ (function () {
|
||||
return new _TransactionDescription({
|
||||
args: result,
|
||||
decode: func.decode,
|
||||
name: name,
|
||||
name: func.name,
|
||||
signature: func.signature,
|
||||
sighash: func.sighash,
|
||||
value: bignumber_1.bigNumberify(tx.value || null),
|
||||
value: bignumber_1.bigNumberify(tx.value || '0'),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
1
utils/networks.d.ts
vendored
1
utils/networks.d.ts
vendored
@@ -2,6 +2,7 @@ export declare type Network = {
|
||||
name: string;
|
||||
chainId: number;
|
||||
ensAddress?: string;
|
||||
_defaultProvider?: (providers: any) => any;
|
||||
};
|
||||
export declare type Networkish = Network | string | number;
|
||||
/**
|
||||
|
||||
@@ -8,39 +8,78 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var errors = __importStar(require("../errors"));
|
||||
function ethDefaultProvider(network) {
|
||||
return function (providers) {
|
||||
var providerList = [];
|
||||
if (providers.InfuraProvider) {
|
||||
providerList.push(new providers.InfuraProvider(network));
|
||||
}
|
||||
if (providers.EtherscanProvider) {
|
||||
providerList.push(new providers.EtherscanProvider(network));
|
||||
}
|
||||
if (providerList.length === 0) {
|
||||
return null;
|
||||
}
|
||||
if (providers.FallbackProvider) {
|
||||
return new providers.FallbackProvider(providerList);
|
||||
;
|
||||
}
|
||||
return providerList[0];
|
||||
};
|
||||
}
|
||||
function etcDefaultProvider(url, network) {
|
||||
return function (providers) {
|
||||
if (providers.JsonRpcProvider) {
|
||||
return new providers.JsonRpcProvider(url, network);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
}
|
||||
var homestead = {
|
||||
chainId: 1,
|
||||
ensAddress: "0x314159265dd8dbb310642f98f50c066173c1259b",
|
||||
name: "homestead"
|
||||
name: "homestead",
|
||||
_defaultProvider: ethDefaultProvider('homestead')
|
||||
};
|
||||
var ropsten = {
|
||||
chainId: 3,
|
||||
ensAddress: "0x112234455c3a32fd11230c42e7bccd4a84e02010",
|
||||
name: "ropsten"
|
||||
name: "ropsten",
|
||||
_defaultProvider: ethDefaultProvider('ropsten')
|
||||
};
|
||||
var networks = {
|
||||
unspecified: {
|
||||
chainId: 0
|
||||
chainId: 0,
|
||||
name: 'unspecified'
|
||||
},
|
||||
homestead: homestead,
|
||||
mainnet: homestead,
|
||||
morden: {
|
||||
chainId: 2
|
||||
chainId: 2,
|
||||
name: 'morden'
|
||||
},
|
||||
ropsten: ropsten,
|
||||
testnet: ropsten,
|
||||
rinkeby: {
|
||||
chainId: 4,
|
||||
ensAddress: "0xe7410170f87102DF0055eB195163A03B7F2Bff4A"
|
||||
ensAddress: "0xe7410170f87102DF0055eB195163A03B7F2Bff4A",
|
||||
name: 'rinkeby',
|
||||
_defaultProvider: ethDefaultProvider('rinkeby')
|
||||
},
|
||||
kovan: {
|
||||
chainId: 42
|
||||
chainId: 42,
|
||||
name: 'kovan',
|
||||
_defaultProvider: ethDefaultProvider('kovan')
|
||||
},
|
||||
classic: {
|
||||
chainId: 61
|
||||
chainId: 61,
|
||||
name: 'classic',
|
||||
_defaultProvider: etcDefaultProvider('https://web3.gastracker.io', 'classic')
|
||||
},
|
||||
classicTestnet: {
|
||||
chainId: 62
|
||||
chainId: 62,
|
||||
name: 'classicTestnet',
|
||||
_defaultProvider: etcDefaultProvider('https://web3.gastracker.io/morden', 'classicTestnet')
|
||||
}
|
||||
};
|
||||
/**
|
||||
@@ -50,18 +89,19 @@ var networks = {
|
||||
* and verifies a network is a valid Network..
|
||||
*/
|
||||
function getNetwork(network) {
|
||||
// No network (null) or unspecified (chainId = 0)
|
||||
if (!network) {
|
||||
// No network (null)
|
||||
if (network == null) {
|
||||
return null;
|
||||
}
|
||||
if (typeof (network) === 'number') {
|
||||
for (var name in networks) {
|
||||
var n_1 = networks[name];
|
||||
for (var name_1 in networks) {
|
||||
var n_1 = networks[name_1];
|
||||
if (n_1.chainId === network) {
|
||||
return {
|
||||
name: name,
|
||||
name: n_1.name,
|
||||
chainId: n_1.chainId,
|
||||
ensAddress: n_1.ensAddress
|
||||
ensAddress: (n_1.ensAddress || null),
|
||||
_defaultProvider: (n_1._defaultProvider || null)
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -76,9 +116,10 @@ function getNetwork(network) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
name: network,
|
||||
name: n_2.name,
|
||||
chainId: n_2.chainId,
|
||||
ensAddress: n_2.ensAddress
|
||||
ensAddress: n_2.ensAddress,
|
||||
_defaultProvider: (n_2._defaultProvider || null)
|
||||
};
|
||||
}
|
||||
var n = networks[network.name];
|
||||
@@ -93,11 +134,12 @@ function getNetwork(network) {
|
||||
if (network.chainId !== 0 && network.chainId !== n.chainId) {
|
||||
errors.throwError('network chainId mismatch', errors.INVALID_ARGUMENT, { arg: 'network', value: network });
|
||||
}
|
||||
// Standard Network
|
||||
// Standard Network (allow overriding the ENS address)
|
||||
return {
|
||||
name: network.name,
|
||||
chainId: n.chainId,
|
||||
ensAddress: n.ensAddress
|
||||
ensAddress: (network.ensAddress || n.ensAddress || null),
|
||||
_defaultProvider: (network._defaultProvider || n._defaultProvider || null)
|
||||
};
|
||||
}
|
||||
exports.getNetwork = getNetwork;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var constants_1 = require("../constants");
|
||||
var errors_1 = require("../errors");
|
||||
var bytes_1 = require("./bytes");
|
||||
///////////////////////////////
|
||||
var UnicodeNormalizationForm;
|
||||
@@ -16,6 +17,7 @@ var UnicodeNormalizationForm;
|
||||
function toUtf8Bytes(str, form) {
|
||||
if (form === void 0) { form = UnicodeNormalizationForm.current; }
|
||||
if (form != UnicodeNormalizationForm.current) {
|
||||
errors_1.checkNormalize();
|
||||
str = str.normalize(form);
|
||||
}
|
||||
var result = [];
|
||||
|
||||
@@ -99,6 +99,9 @@ function fetchJson(connection, json, processFunc) {
|
||||
var jsonError = new Error('invalid json response');
|
||||
jsonError.orginialError = error;
|
||||
jsonError.responseText = request.responseText;
|
||||
if (json != null) {
|
||||
jsonError.requestBody = json;
|
||||
}
|
||||
jsonError.url = url;
|
||||
reject(jsonError);
|
||||
return;
|
||||
@@ -124,7 +127,7 @@ function fetchJson(connection, json, processFunc) {
|
||||
reject(error);
|
||||
};
|
||||
try {
|
||||
if (json) {
|
||||
if (json != null) {
|
||||
request.send(json);
|
||||
}
|
||||
else {
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -131,9 +131,7 @@ var LangJa = /** @class */ (function (_super) {
|
||||
return wordlist.indexOf(word);
|
||||
};
|
||||
LangJa.prototype.split = function (mnemonic) {
|
||||
if (!mnemonic.normalize) {
|
||||
errors.throwError('Japanese is unsupported on this platform; missing String.prototype.normalize', errors.UNSUPPORTED_OPERATION, { operation: 'String.prototype.normalize' });
|
||||
}
|
||||
errors.checkNormalize();
|
||||
return mnemonic.split(/(?:\u3000| )+/g);
|
||||
};
|
||||
LangJa.prototype.join = function (words) {
|
||||
|
||||
Reference in New Issue
Block a user