Compare commits

..

22 Commits

Author SHA1 Message Date
Richard Moore
384fc328f2 No longer use hard-coded id of 42 in Web3Provider. 2019-06-21 19:17:55 -04:00
Richard Moore
055694ae61 Updated dist files. 2019-06-10 02:00:55 -04:00
Richard Moore
edf59d2c26 Updatd dist files. 2019-06-10 01:59:51 -04:00
Richard Moore
92c978e5c2 Fixed error in throwing an error for ABI decode (#539). 2019-06-10 01:57:03 -04:00
Richard Moore
34397fa2aa Updated dist files. 2019-05-24 19:41:38 -04:00
Richard Moore
19587eea3f Warn on deprecated INFURA API Token; use Project ID instead (#462). 2019-05-24 14:56:47 -04:00
Richard Moore
4a9373e773 Fixed typo in error message (#470). 2019-05-24 14:48:01 -04:00
Richard Moore
2997bae935 Export poll function (#514). 2019-05-24 14:38:54 -04:00
Richard Moore
b0bd9ee162 Updated dist files. 2019-05-23 18:58:05 -04:00
Richard Moore
7075c8c235 Fixed error message for unconfigured ENS names (#504). 2019-05-23 18:51:08 -04:00
Richard Moore
a4a532fe8e Fixed security recommendations (development deps only; not a problem, but quiets automatic audits). 2019-05-14 18:11:45 -04:00
Richard Moore
77c771bf76 Updated dist files. 2019-05-14 17:45:13 -04:00
Richard Moore
c93b48920e Increment JSON-RPC ID for JsonRpcProviders for environments that unsafely manage callbacks (#489). 2019-04-18 13:49:37 +02:00
Richard Moore
04c92bb8d5 Updated dist files. 2019-03-08 14:29:59 -05:00
Richard Moore
16c9745326 Added goerli to InfuraProvider (#421). 2019-03-08 14:28:39 -05:00
Richard Moore
05648177aa Updated dist files. 2019-02-15 13:44:33 -05:00
Richard Moore
f318fd9cf1 Added fastRetry to polling for JsonRpcSigner to improve polling for sent transactions (#402). 2019-02-15 13:42:12 -05:00
Richard Moore
c15a89832b Fix waitForTransaction delay (#424). 2019-02-15 13:32:08 -05:00
Richard Moore
94b0abc240 Updated dist files. 2019-02-12 00:56:38 -05:00
Richard Moore
72edcd054f Fixed waitForTransaction and removeListener (#410). 2019-02-12 00:54:32 -05:00
Richard Moore
e4a2f8ac6c Updated BIP39 list in readme. 2019-02-11 19:24:48 -05:00
Richard Moore
c6d7b31a84 Updated dist files. 2019-02-11 19:24:27 -05:00
33 changed files with 671 additions and 506 deletions

View File

@@ -9,7 +9,7 @@ Complete Ethereum wallet implementation and utilities in JavaScript (and TypeScr
- Keep your private keys in your client, **safe** and sound
- Import and export **JSON wallets** (Geth, Parity and crowdsale)
- Import and export BIP 39 **mnemonic phrases** (12 word backup phrases) and **HD Wallets** (English, Italian, Japanese, Korean, Simplified Chinese, Traditional Chinese; more coming soon)
- Import and export BIP 39 **mnemonic phrases** (12 word backup phrases) and **HD Wallets** (English, French, Italian, Japanese, Korean, Simplified Chinese, Spanish, Traditional Chinese)
- Meta-classes create JavaScript objects from any contract ABI, including **ABIv2** and **Human-Readable ABI**
- Connect to Ethereum nodes over [JSON-RPC](https://github.com/ethereum/wiki/wiki/JSON-RPC), [INFURA](https://infura.io), [Etherscan](https://etherscan.io), or [MetaMask](https://metamask.io)
- **ENS names** are first-class citizens; they can be used anywhere an Ethereum addresses can be used

2
_version.d.ts vendored
View File

@@ -1 +1 @@
export declare const version = "4.0.24";
export declare const version = "4.0.30";

View File

@@ -1,3 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.version = "4.0.24";
exports.version = "4.0.30";

5
contract.d.ts vendored
View File

@@ -1,7 +1,7 @@
import { BigNumber } from './utils/bignumber';
import { Indexed, Interface } from './utils/interface';
import { UnsignedTransaction } from './utils/transaction';
import { Provider } from './providers/abstract-provider';
import { BlockTag, Provider } from './providers/abstract-provider';
import { Signer } from './abstract-signer';
import { Arrayish } from './utils/bytes';
import { ParamType } from './utils/abi-coder';
@@ -50,9 +50,10 @@ export declare class Contract {
readonly [name: string]: ContractFunction | any;
readonly addressPromise: Promise<string>;
readonly deployTransaction: TransactionResponse;
private _deployed;
private _deployedPromise;
constructor(addressOrName: string, contractInterface: Array<string | ParamType> | string | Interface, signerOrProvider: Signer | Provider);
deployed(): Promise<Contract>;
_deployed(blockTag?: BlockTag): Promise<Contract>;
fallback(overrides?: TransactionRequest): Promise<TransactionResponse>;
connect(signerOrProvider: Signer | Provider | string): Contract;
attach(addressOrName: string): Contract;

View File

@@ -135,8 +135,7 @@ function runMethod(contract, functionName, estimateOnly) {
errors.throwError('cannot override ' + key, errors.UNSUPPORTED_OPERATION, { operation: key });
}
});
// Send to the contract address (after checking the contract is deployed)
tx.to = contract.deployed().then(function () {
tx.to = contract._deployed(blockTag).then(function () {
return contract.addressPromise;
});
return resolveAddresses(contract.provider, params, method.inputs).then(function (params) {
@@ -332,11 +331,14 @@ var Contract = /** @class */ (function () {
}
// @TODO: Allow timeout?
Contract.prototype.deployed = function () {
return this._deployed();
};
Contract.prototype._deployed = function (blockTag) {
var _this = this;
if (!this._deployed) {
if (!this._deployedPromise) {
// If we were just deployed, we know the transaction we should occur in
if (this.deployTransaction) {
this._deployed = this.deployTransaction.wait().then(function () {
this._deployedPromise = this.deployTransaction.wait().then(function () {
return _this;
});
}
@@ -344,7 +346,7 @@ var Contract = /** @class */ (function () {
// @TODO: Once we allow a timeout to be passed in, we will wait
// up to that many blocks for getCode
// Otherwise, poll for our code to be deployed
this._deployed = this.provider.getCode(this.address).then(function (code) {
this._deployedPromise = this.provider.getCode(this.address, blockTag).then(function (code) {
if (code === '0x') {
errors.throwError('contract not deployed', errors.UNSUPPORTED_OPERATION, {
contractAddress: _this.address,
@@ -355,7 +357,7 @@ var Contract = /** @class */ (function () {
});
}
}
return this._deployed;
return this._deployedPromise;
};
// @TODO:
// estimateFallback(overrides?: TransactionRequest): Promise<BigNumber>

123
dist/ethers.js vendored
View File

@@ -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.24";
exports.version = "4.0.30";
},{}],2:[function(require,module,exports){
"use strict";
@@ -183,8 +183,7 @@ function runMethod(contract, functionName, estimateOnly) {
errors.throwError('cannot override ' + key, errors.UNSUPPORTED_OPERATION, { operation: key });
}
});
// Send to the contract address (after checking the contract is deployed)
tx.to = contract.deployed().then(function () {
tx.to = contract._deployed(blockTag).then(function () {
return contract.addressPromise;
});
return resolveAddresses(contract.provider, params, method.inputs).then(function (params) {
@@ -380,11 +379,14 @@ var Contract = /** @class */ (function () {
}
// @TODO: Allow timeout?
Contract.prototype.deployed = function () {
return this._deployed();
};
Contract.prototype._deployed = function (blockTag) {
var _this = this;
if (!this._deployed) {
if (!this._deployedPromise) {
// If we were just deployed, we know the transaction we should occur in
if (this.deployTransaction) {
this._deployed = this.deployTransaction.wait().then(function () {
this._deployedPromise = this.deployTransaction.wait().then(function () {
return _this;
});
}
@@ -392,7 +394,7 @@ var Contract = /** @class */ (function () {
// @TODO: Once we allow a timeout to be passed in, we will wait
// up to that many blocks for getCode
// Otherwise, poll for our code to be deployed
this._deployed = this.provider.getCode(this.address).then(function (code) {
this._deployedPromise = this.provider.getCode(this.address, blockTag).then(function (code) {
if (code === '0x') {
errors.throwError('contract not deployed', errors.UNSUPPORTED_OPERATION, {
contractAddress: _this.address,
@@ -403,7 +405,7 @@ var Contract = /** @class */ (function () {
});
}
}
return this._deployed;
return this._deployedPromise;
};
// @TODO:
// estimateFallback(overrides?: TransactionRequest): Promise<BigNumber>
@@ -10074,6 +10076,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
var address_1 = require("../utils/address");
var bignumber_1 = require("../utils/bignumber");
var bytes_1 = require("../utils/bytes");
var constants_1 = require("../constants");
var hash_1 = require("../utils/hash");
var networks_1 = require("../utils/networks");
var properties_1 = require("../utils/properties");
@@ -10710,17 +10713,21 @@ var BaseProvider = /** @class */ (function (_super) {
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;
}
return this.getTransactionReceipt(transactionHash).then(function (receipt) {
if (confirmations === 0 || (receipt && receipt.confirmations >= confirmations)) {
return receipt;
});
}, { onceBlock: this });
}
return (new Promise(function (resolve) {
var handler = function (receipt) {
if (receipt.confirmations < confirmations) {
return;
}
_this.removeListener(transactionHash, handler);
resolve(receipt);
};
_this.on(transactionHash, handler);
}));
});
};
BaseProvider.prototype.getBlockNumber = function () {
var _this = this;
@@ -10748,7 +10755,7 @@ var BaseProvider = /** @class */ (function (_super) {
return this.ready.then(function () {
return properties_1.resolveProperties({ addressOrName: addressOrName, blockTag: blockTag }).then(function (_a) {
var addressOrName = _a.addressOrName, blockTag = _a.blockTag;
return _this.resolveName(addressOrName).then(function (address) {
return _this._getAddress(addressOrName).then(function (address) {
var params = { address: address, blockTag: checkBlockTag(blockTag) };
return _this.perform('getBalance', params).then(function (result) {
return bignumber_1.bigNumberify(result);
@@ -10762,7 +10769,7 @@ var BaseProvider = /** @class */ (function (_super) {
return this.ready.then(function () {
return properties_1.resolveProperties({ addressOrName: addressOrName, blockTag: blockTag }).then(function (_a) {
var addressOrName = _a.addressOrName, blockTag = _a.blockTag;
return _this.resolveName(addressOrName).then(function (address) {
return _this._getAddress(addressOrName).then(function (address) {
var params = { address: address, blockTag: checkBlockTag(blockTag) };
return _this.perform('getTransactionCount', params).then(function (result) {
return bignumber_1.bigNumberify(result).toNumber();
@@ -10776,7 +10783,7 @@ var BaseProvider = /** @class */ (function (_super) {
return this.ready.then(function () {
return properties_1.resolveProperties({ addressOrName: addressOrName, blockTag: blockTag }).then(function (_a) {
var addressOrName = _a.addressOrName, blockTag = _a.blockTag;
return _this.resolveName(addressOrName).then(function (address) {
return _this._getAddress(addressOrName).then(function (address) {
var params = { address: address, blockTag: checkBlockTag(blockTag) };
return _this.perform('getCode', params).then(function (result) {
return bytes_1.hexlify(result);
@@ -10790,7 +10797,7 @@ var BaseProvider = /** @class */ (function (_super) {
return this.ready.then(function () {
return properties_1.resolveProperties({ addressOrName: addressOrName, position: position, blockTag: blockTag }).then(function (_a) {
var addressOrName = _a.addressOrName, position = _a.position, blockTag = _a.blockTag;
return _this.resolveName(addressOrName).then(function (address) {
return _this._getAddress(addressOrName).then(function (address) {
var params = {
address: address,
blockTag: checkBlockTag(blockTag),
@@ -11033,6 +11040,14 @@ var BaseProvider = /** @class */ (function (_super) {
});
});
};
BaseProvider.prototype._getAddress = function (addressOrName) {
return this.resolveName(addressOrName).then(function (address) {
if (address == null) {
errors.throwError("ENS name not configured", errors.UNSUPPORTED_OPERATION, { operation: "resolveName(" + JSON.stringify(addressOrName) + ")" });
}
return address;
});
};
// @TODO: Could probably use resolveProperties instead?
BaseProvider.prototype._resolveNames = function (object, keys) {
var promises = [];
@@ -11041,7 +11056,7 @@ var BaseProvider = /** @class */ (function (_super) {
if (result[key] == null) {
return;
}
promises.push(this.resolveName(result[key]).then(function (address) {
promises.push(this._getAddress(result[key]).then(function (address) {
result[key] = address;
return;
}));
@@ -11064,7 +11079,11 @@ var BaseProvider = /** @class */ (function (_super) {
if (bytes_1.hexDataLength(data) !== 32) {
return null;
}
return address_1.getAddress(bytes_1.hexDataSlice(data, 12));
var address = address_1.getAddress(bytes_1.hexDataSlice(data, 12));
if (address === constants_1.AddressZero) {
return null;
}
return address;
});
});
};
@@ -11085,6 +11104,9 @@ var BaseProvider = /** @class */ (function (_super) {
var nodeHash = hash_1.namehash(name);
// Get the addr from the resovler
return this._getResolver(name).then(function (resolverAddress) {
if (resolverAddress == null) {
return null;
}
// keccak256('addr(bytes32)')
var data = '0x3b3b57de' + nodeHash.substring(2);
var transaction = { to: resolverAddress, data: data };
@@ -11095,7 +11117,7 @@ var BaseProvider = /** @class */ (function (_super) {
return null;
}
var address = address_1.getAddress(bytes_1.hexDataSlice(data, 12));
if (address === '0x0000000000000000000000000000000000000000') {
if (address === constants_1.AddressZero) {
return null;
}
return address;
@@ -11223,13 +11245,19 @@ var BaseProvider = /** @class */ (function (_super) {
});
};
BaseProvider.prototype.removeAllListeners = function (eventName) {
var eventTag = getEventTag(eventName);
this._events = this._events.filter(function (event) {
return (event.tag !== eventTag);
});
if (eventName === 'pending') {
if (eventName == null) {
this._events = [];
this._stopPending();
}
else {
var eventTag_1 = getEventTag(eventName);
this._events = this._events.filter(function (event) {
return (event.tag !== eventTag_1);
});
if (eventName === 'pending') {
this._stopPending();
}
}
if (this._events.length === 0) {
this.polling = false;
}
@@ -11239,13 +11267,13 @@ var BaseProvider = /** @class */ (function (_super) {
var found = false;
var eventTag = getEventTag(eventName);
this._events = this._events.filter(function (event) {
if (event.tag !== eventTag) {
if (event.tag !== eventTag || event.listener != listener) {
return true;
}
if (found) {
return true;
}
found = false;
found = true;
return false;
});
if (eventName === 'pending' && this.listenerCount('pending') === 0) {
@@ -11261,7 +11289,7 @@ var BaseProvider = /** @class */ (function (_super) {
exports.BaseProvider = BaseProvider;
properties_1.defineReadOnly(abstract_provider_1.Provider, 'inherits', properties_1.inheritable(abstract_provider_1.Provider));
},{"../errors":5,"../utils/address":59,"../utils/bignumber":62,"../utils/bytes":63,"../utils/hash":64,"../utils/networks":71,"../utils/properties":73,"../utils/rlp":75,"../utils/transaction":82,"../utils/utf8":84,"../utils/web":85,"./abstract-provider":49}],51:[function(require,module,exports){
},{"../constants":3,"../errors":5,"../utils/address":59,"../utils/bignumber":62,"../utils/bytes":63,"../utils/hash":64,"../utils/networks":71,"../utils/properties":73,"../utils/rlp":75,"../utils/transaction":82,"../utils/utf8":84,"../utils/web":85,"./abstract-provider":49}],51:[function(require,module,exports){
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
@@ -11789,6 +11817,9 @@ var InfuraProvider = /** @class */ (function (_super) {
case 'rinkeby':
host = 'rinkeby.infura.io';
break;
case 'goerli':
host = 'goerli.infura.io';
break;
case 'kovan':
host = 'kovan.infura.io';
break;
@@ -11806,6 +11837,7 @@ var InfuraProvider = /** @class */ (function (_super) {
// Legacy API Access Token
}
else {
errors.warn("The legacy INFURA apiAccesToken API is deprecated; please upgrade to a Project ID instead (see INFURA dshboard; https://infura.io)");
_this = _super.call(this, 'https://' + host + '/' + projectId, standard) || this;
properties_1.defineReadOnly(_this, 'apiAccessToken', projectId);
properties_1.defineReadOnly(_this, 'projectId', null);
@@ -11884,6 +11916,10 @@ function getLowerCase(value) {
return value;
}
var _constructorGuard = {};
// Some environments (Trust Wallet and company) use a global map
// to track JSON-RPC ID, so we try to keep IDs unique across all
// connections. See #489.
var _nextId = 42;
var JsonRpcSigner = /** @class */ (function (_super) {
__extends(JsonRpcSigner, _super);
function JsonRpcSigner(constructorGuard, provider, addressOrIndex) {
@@ -11988,7 +12024,7 @@ var JsonRpcSigner = /** @class */ (function (_super) {
}
return _this.provider._wrapTransaction(tx, hash);
});
}, { onceBlock: _this.provider }).catch(function (error) {
}, { fastRetry: 250, onceBlock: _this.provider }).catch(function (error) {
error.transactionHash = hash;
throw error;
});
@@ -12070,7 +12106,7 @@ var JsonRpcProvider = /** @class */ (function (_super) {
var request = {
method: method,
params: params,
id: 42,
id: (_nextId++),
jsonrpc: "2.0"
};
return web_1.fetchJson(this.connection, JSON.stringify(request), getResult).then(function (result) {
@@ -12796,7 +12832,7 @@ var CoderFixedBytes = /** @class */ (function (_super) {
};
CoderFixedBytes.prototype.decode = function (data, offset) {
if (data.length < offset + 32) {
errors.throwError('insufficient data for ' + name + ' type', errors.INVALID_ARGUMENT, {
errors.throwError('insufficient data for ' + this.name + ' type', errors.INVALID_ARGUMENT, {
arg: this.localName,
coderType: this.name,
value: bytes_1.hexlify(data.slice(offset, offset + 32))
@@ -14522,6 +14558,7 @@ exports.formatUnits = units_1.formatUnits;
exports.parseUnits = units_1.parseUnits;
var web_1 = require("./web");
exports.fetchJson = web_1.fetchJson;
exports.poll = web_1.poll;
////////////////////////
// Enums
var hmac_1 = require("./hmac");
@@ -15056,12 +15093,7 @@ var networks = {
chainId: 5,
ensAddress: "0x112234455c3a32fd11230c42e7bccd4a84e02010",
name: "goerli",
_defaultProvider: function (providers) {
if (providers.EtherscanProvider) {
return new providers.EtherscanProvider("goerli");
}
return null;
}
_defaultProvider: ethDefaultProvider('goerli')
},
kovan: {
chainId: 42,
@@ -16714,7 +16746,7 @@ function parseBytes32String(bytes) {
throw new Error('invalid bytes32 - not 32 bytes long');
}
if (data[31] !== 0) {
throw new Error('invalid bytes32 sdtring - no null terminator');
throw new Error('invalid bytes32 string - no null terminator');
}
// Find the null termination
var length = 31;
@@ -16908,6 +16940,7 @@ function poll(func, options) {
}
}, options.timeout);
}
var fastTimeout = options.fastRetry || null;
var attempt = 0;
function check() {
return func().then(function (result) {
@@ -16930,6 +16963,12 @@ function poll(func, options) {
if (timeout > options.ceiling) {
timeout = options.ceiling;
}
// Fast Timeout, means we quickly try again the first time
if (fastTimeout) {
attempt--;
timeout = fastTimeout;
fastTimeout = null;
}
setTimeout(check, timeout);
}
return null;

2
dist/ethers.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

13
dist/ethers.types.txt vendored
View File

@@ -26,7 +26,7 @@ declare module 'ethers/contract' {
import { BigNumber } from 'ethers/utils/bignumber';
import { Indexed, Interface } from 'ethers/utils/interface';
import { UnsignedTransaction } from 'ethers/utils/transaction';
import { Provider } from 'ethers/providers/abstract-provider';
import { BlockTag, Provider } from 'ethers/providers/abstract-provider';
import { Signer } from 'ethers/abstract-signer';
import { Arrayish } from 'ethers/utils/bytes';
import { ParamType } from 'ethers/utils/abi-coder';
@@ -77,6 +77,7 @@ declare module 'ethers/contract' {
readonly deployTransaction: TransactionResponse;
constructor(addressOrName: string, contractInterface: Array<string | ParamType> | string | Interface, signerOrProvider: Signer | Provider);
deployed(): Promise<Contract>;
_deployed(blockTag?: BlockTag): Promise<Contract>;
fallback(overrides?: TransactionRequest): Promise<TransactionResponse>;
connect(signerOrProvider: Signer | Provider | string): Contract;
attach(addressOrName: string): Contract;
@@ -231,7 +232,7 @@ declare module 'ethers/utils' {
import { parse as parseTransaction, serialize as serializeTransaction } from 'ethers/utils/transaction';
import { formatBytes32String, parseBytes32String, toUtf8Bytes, toUtf8String } from 'ethers/utils/utf8';
import { commify, formatEther, parseEther, formatUnits, parseUnits } from 'ethers/utils/units';
import { fetchJson } from 'ethers/utils/web';
import { fetchJson, poll } from 'ethers/utils/web';
import { SupportedAlgorithms } from 'ethers/utils/hmac';
import { UnicodeNormalizationForm } from 'ethers/utils/utf8';
import { CoerceFunc, EventFragment, FunctionFragment, ParamType } from 'ethers/utils/abi-coder';
@@ -243,7 +244,7 @@ declare module 'ethers/utils' {
import { ConnectionInfo, OnceBlockable, PollOptions } from 'ethers/utils/web';
import { EncryptOptions, ProgressCallback } from 'ethers/utils/secret-storage';
import { Wordlist } from 'ethers/utils/wordlist';
export { AbiCoder, defaultAbiCoder, formatSignature, formatParamType, parseSignature, parseParamType, RLP, fetchJson, getNetwork, checkProperties, deepCopy, defineReadOnly, resolveProperties, shallowCopy, arrayify, concat, padZeros, stripZeros, HDNode, SigningKey, Interface, base64, BigNumber, bigNumberify, hexlify, isHexString, hexStripZeros, hexZeroPad, hexDataLength, hexDataSlice, toUtf8Bytes, toUtf8String, formatBytes32String, parseBytes32String, hashMessage, namehash, id, getAddress, getIcapAddress, getContractAddress, formatEther, parseEther, formatUnits, parseUnits, commify, keccak256, sha256, randomBytes, solidityPack, solidityKeccak256, soliditySha256, splitSignature, joinSignature, parseTransaction, populateTransaction, serializeTransaction, getJsonWalletAddress, computeAddress, computePublicKey, recoverAddress, recoverPublicKey, verifyMessage, SupportedAlgorithms, UnicodeNormalizationForm, CoerceFunc, EventFragment, FunctionFragment, ParamType, BigNumberish, Arrayish, Hexable, Signature, Indexed, DeployDescription, EventDescription, FunctionDescription, LogDescription, TransactionDescription, Network, Networkish, Transaction, UnsignedTransaction, ConnectionInfo, OnceBlockable, PollOptions, EncryptOptions, ProgressCallback, Wordlist, };
export { AbiCoder, defaultAbiCoder, formatSignature, formatParamType, parseSignature, parseParamType, RLP, fetchJson, getNetwork, checkProperties, deepCopy, defineReadOnly, resolveProperties, shallowCopy, arrayify, concat, padZeros, stripZeros, HDNode, SigningKey, Interface, base64, BigNumber, bigNumberify, hexlify, isHexString, hexStripZeros, hexZeroPad, hexDataLength, hexDataSlice, toUtf8Bytes, toUtf8String, formatBytes32String, parseBytes32String, hashMessage, namehash, id, getAddress, getIcapAddress, getContractAddress, formatEther, parseEther, formatUnits, parseUnits, commify, keccak256, sha256, randomBytes, solidityPack, solidityKeccak256, soliditySha256, splitSignature, joinSignature, parseTransaction, populateTransaction, serializeTransaction, getJsonWalletAddress, computeAddress, computePublicKey, recoverAddress, recoverPublicKey, verifyMessage, poll, SupportedAlgorithms, UnicodeNormalizationForm, CoerceFunc, EventFragment, FunctionFragment, ParamType, BigNumberish, Arrayish, Hexable, Signature, Indexed, DeployDescription, EventDescription, FunctionDescription, LogDescription, TransactionDescription, Network, Networkish, Transaction, UnsignedTransaction, ConnectionInfo, OnceBlockable, PollOptions, EncryptOptions, ProgressCallback, Wordlist, };
}
declare module 'ethers/wordlists' {
@@ -265,7 +266,7 @@ declare module 'ethers/utils/shims' {
}
declare module 'ethers/_version' {
export const version = "4.0.24";
export const version = "4.0.30";
}
declare module 'ethers/utils/bignumber' {
@@ -770,6 +771,7 @@ declare module 'ethers/providers/base-provider' {
getTransactionReceipt(transactionHash: string): Promise<TransactionReceipt>;
getLogs(filter: Filter | FilterByBlock): Promise<Array<Log>>;
getEtherPrice(): Promise<number>;
_getAddress(addressOrName: string): Promise<string>;
resolveName(name: string | Promise<string>): Promise<string>;
lookupAddress(address: string | Promise<string>): Promise<string>;
static checkTransactionResponse(transaction: any): TransactionResponse;
@@ -783,7 +785,7 @@ declare module 'ethers/providers/base-provider' {
emit(eventName: EventType, ...args: Array<any>): boolean;
listenerCount(eventName?: EventType): number;
listeners(eventName: EventType): Array<Listener>;
removeAllListeners(eventName: EventType): Provider;
removeAllListeners(eventName?: EventType): Provider;
removeListener(eventName: EventType, listener: Listener): Provider;
}
}
@@ -1040,6 +1042,7 @@ declare module 'ethers/utils/web' {
ceiling?: number;
interval?: number;
onceBlock?: OnceBlockable;
fastRetry?: number;
};
export function fetchJson(connection: string | ConnectionInfo, json: string, processFunc: (value: any) => any): Promise<any>;
export function poll(func: () => Promise<any>, options?: PollOptions): Promise<any>;

768
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "ethers",
"version": "4.0.24",
"version": "4.0.30",
"description": "Ethereum wallet library.",
"main": "./index.js",
"types": "./index.d.ts",
@@ -34,7 +34,7 @@
"browserify": "^16.2.3",
"browserify-zlib": "^0.2.0",
"dts-bundle": "^0.7.3",
"eslint": "^5.0.1",
"eslint": "^5.16.0",
"eslint-plugin-promise": "^3.8.0",
"ethereumjs-tx": "^1.3.5",
"ethereumjs-util": "^5.2.0",

View File

@@ -53,6 +53,7 @@ export declare class BaseProvider extends Provider {
getTransactionReceipt(transactionHash: string): Promise<TransactionReceipt>;
getLogs(filter: Filter | FilterByBlock): Promise<Array<Log>>;
getEtherPrice(): Promise<number>;
_getAddress(addressOrName: string): Promise<string>;
private _resolveNames;
private _getResolver;
resolveName(name: string | Promise<string>): Promise<string>;
@@ -69,6 +70,6 @@ export declare class BaseProvider extends Provider {
emit(eventName: EventType, ...args: Array<any>): boolean;
listenerCount(eventName?: EventType): number;
listeners(eventName: EventType): Array<Listener>;
removeAllListeners(eventName: EventType): Provider;
removeAllListeners(eventName?: EventType): Provider;
removeListener(eventName: EventType, listener: Listener): Provider;
}

View File

@@ -20,6 +20,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
var address_1 = require("../utils/address");
var bignumber_1 = require("../utils/bignumber");
var bytes_1 = require("../utils/bytes");
var constants_1 = require("../constants");
var hash_1 = require("../utils/hash");
var networks_1 = require("../utils/networks");
var properties_1 = require("../utils/properties");
@@ -656,17 +657,21 @@ var BaseProvider = /** @class */ (function (_super) {
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;
}
return this.getTransactionReceipt(transactionHash).then(function (receipt) {
if (confirmations === 0 || (receipt && receipt.confirmations >= confirmations)) {
return receipt;
});
}, { onceBlock: this });
}
return (new Promise(function (resolve) {
var handler = function (receipt) {
if (receipt.confirmations < confirmations) {
return;
}
_this.removeListener(transactionHash, handler);
resolve(receipt);
};
_this.on(transactionHash, handler);
}));
});
};
BaseProvider.prototype.getBlockNumber = function () {
var _this = this;
@@ -694,7 +699,7 @@ var BaseProvider = /** @class */ (function (_super) {
return this.ready.then(function () {
return properties_1.resolveProperties({ addressOrName: addressOrName, blockTag: blockTag }).then(function (_a) {
var addressOrName = _a.addressOrName, blockTag = _a.blockTag;
return _this.resolveName(addressOrName).then(function (address) {
return _this._getAddress(addressOrName).then(function (address) {
var params = { address: address, blockTag: checkBlockTag(blockTag) };
return _this.perform('getBalance', params).then(function (result) {
return bignumber_1.bigNumberify(result);
@@ -708,7 +713,7 @@ var BaseProvider = /** @class */ (function (_super) {
return this.ready.then(function () {
return properties_1.resolveProperties({ addressOrName: addressOrName, blockTag: blockTag }).then(function (_a) {
var addressOrName = _a.addressOrName, blockTag = _a.blockTag;
return _this.resolveName(addressOrName).then(function (address) {
return _this._getAddress(addressOrName).then(function (address) {
var params = { address: address, blockTag: checkBlockTag(blockTag) };
return _this.perform('getTransactionCount', params).then(function (result) {
return bignumber_1.bigNumberify(result).toNumber();
@@ -722,7 +727,7 @@ var BaseProvider = /** @class */ (function (_super) {
return this.ready.then(function () {
return properties_1.resolveProperties({ addressOrName: addressOrName, blockTag: blockTag }).then(function (_a) {
var addressOrName = _a.addressOrName, blockTag = _a.blockTag;
return _this.resolveName(addressOrName).then(function (address) {
return _this._getAddress(addressOrName).then(function (address) {
var params = { address: address, blockTag: checkBlockTag(blockTag) };
return _this.perform('getCode', params).then(function (result) {
return bytes_1.hexlify(result);
@@ -736,7 +741,7 @@ var BaseProvider = /** @class */ (function (_super) {
return this.ready.then(function () {
return properties_1.resolveProperties({ addressOrName: addressOrName, position: position, blockTag: blockTag }).then(function (_a) {
var addressOrName = _a.addressOrName, position = _a.position, blockTag = _a.blockTag;
return _this.resolveName(addressOrName).then(function (address) {
return _this._getAddress(addressOrName).then(function (address) {
var params = {
address: address,
blockTag: checkBlockTag(blockTag),
@@ -979,6 +984,14 @@ var BaseProvider = /** @class */ (function (_super) {
});
});
};
BaseProvider.prototype._getAddress = function (addressOrName) {
return this.resolveName(addressOrName).then(function (address) {
if (address == null) {
errors.throwError("ENS name not configured", errors.UNSUPPORTED_OPERATION, { operation: "resolveName(" + JSON.stringify(addressOrName) + ")" });
}
return address;
});
};
// @TODO: Could probably use resolveProperties instead?
BaseProvider.prototype._resolveNames = function (object, keys) {
var promises = [];
@@ -987,7 +1000,7 @@ var BaseProvider = /** @class */ (function (_super) {
if (result[key] == null) {
return;
}
promises.push(this.resolveName(result[key]).then(function (address) {
promises.push(this._getAddress(result[key]).then(function (address) {
result[key] = address;
return;
}));
@@ -1010,7 +1023,11 @@ var BaseProvider = /** @class */ (function (_super) {
if (bytes_1.hexDataLength(data) !== 32) {
return null;
}
return address_1.getAddress(bytes_1.hexDataSlice(data, 12));
var address = address_1.getAddress(bytes_1.hexDataSlice(data, 12));
if (address === constants_1.AddressZero) {
return null;
}
return address;
});
});
};
@@ -1031,6 +1048,9 @@ var BaseProvider = /** @class */ (function (_super) {
var nodeHash = hash_1.namehash(name);
// Get the addr from the resovler
return this._getResolver(name).then(function (resolverAddress) {
if (resolverAddress == null) {
return null;
}
// keccak256('addr(bytes32)')
var data = '0x3b3b57de' + nodeHash.substring(2);
var transaction = { to: resolverAddress, data: data };
@@ -1041,7 +1061,7 @@ var BaseProvider = /** @class */ (function (_super) {
return null;
}
var address = address_1.getAddress(bytes_1.hexDataSlice(data, 12));
if (address === '0x0000000000000000000000000000000000000000') {
if (address === constants_1.AddressZero) {
return null;
}
return address;
@@ -1169,13 +1189,19 @@ var BaseProvider = /** @class */ (function (_super) {
});
};
BaseProvider.prototype.removeAllListeners = function (eventName) {
var eventTag = getEventTag(eventName);
this._events = this._events.filter(function (event) {
return (event.tag !== eventTag);
});
if (eventName === 'pending') {
if (eventName == null) {
this._events = [];
this._stopPending();
}
else {
var eventTag_1 = getEventTag(eventName);
this._events = this._events.filter(function (event) {
return (event.tag !== eventTag_1);
});
if (eventName === 'pending') {
this._stopPending();
}
}
if (this._events.length === 0) {
this.polling = false;
}
@@ -1185,13 +1211,13 @@ var BaseProvider = /** @class */ (function (_super) {
var found = false;
var eventTag = getEventTag(eventName);
this._events = this._events.filter(function (event) {
if (event.tag !== eventTag) {
if (event.tag !== eventTag || event.listener != listener) {
return true;
}
if (found) {
return true;
}
found = false;
found = true;
return false;
});
if (eventName === 'pending' && this.listenerCount('pending') === 0) {

View File

@@ -42,6 +42,9 @@ var InfuraProvider = /** @class */ (function (_super) {
case 'rinkeby':
host = 'rinkeby.infura.io';
break;
case 'goerli':
host = 'goerli.infura.io';
break;
case 'kovan':
host = 'kovan.infura.io';
break;
@@ -59,6 +62,7 @@ var InfuraProvider = /** @class */ (function (_super) {
// Legacy API Access Token
}
else {
errors.warn("The legacy INFURA apiAccesToken API is deprecated; please upgrade to a Project ID instead (see INFURA dshboard; https://infura.io)");
_this = _super.call(this, 'https://' + host + '/' + projectId, standard) || this;
properties_1.defineReadOnly(_this, 'apiAccessToken', projectId);
properties_1.defineReadOnly(_this, 'projectId', null);

View File

@@ -51,6 +51,10 @@ function getLowerCase(value) {
return value;
}
var _constructorGuard = {};
// Some environments (Trust Wallet and company) use a global map
// to track JSON-RPC ID, so we try to keep IDs unique across all
// connections. See #489.
var _nextId = 42;
var JsonRpcSigner = /** @class */ (function (_super) {
__extends(JsonRpcSigner, _super);
function JsonRpcSigner(constructorGuard, provider, addressOrIndex) {
@@ -155,7 +159,7 @@ var JsonRpcSigner = /** @class */ (function (_super) {
}
return _this.provider._wrapTransaction(tx, hash);
});
}, { onceBlock: _this.provider }).catch(function (error) {
}, { fastRetry: 250, onceBlock: _this.provider }).catch(function (error) {
error.transactionHash = hash;
throw error;
});
@@ -237,7 +241,7 @@ var JsonRpcProvider = /** @class */ (function (_super) {
var request = {
method: method,
params: params,
id: 42,
id: (_nextId++),
jsonrpc: "2.0"
};
return web_1.fetchJson(this.connection, JSON.stringify(request), getResult).then(function (result) {

View File

@@ -1 +1 @@
export const version = "4.0.24";
export const version = "4.0.30";

View File

@@ -3,6 +3,7 @@
import { getAddress, getContractAddress } from '../utils/address';
import { BigNumber, bigNumberify } from '../utils/bignumber';
import { hexDataLength, hexDataSlice, hexlify, hexStripZeros, isHexString, stripZeros } from '../utils/bytes';
import { AddressZero } from "../constants";
import { namehash } from '../utils/hash';
import { getNetwork } from '../utils/networks';
import { defineReadOnly, inheritable, resolveProperties, shallowCopy } from '../utils/properties';
@@ -776,15 +777,21 @@ export class BaseProvider extends Provider {
waitForTransaction(transactionHash: string, confirmations?: number): Promise<TransactionReceipt> {
if (confirmations == null) { confirmations = 1; }
return poll(() => {
return this.getTransactionReceipt(transactionHash).then((receipt) => {
if (confirmations === 0) { return receipt; }
if (receipt == null || receipt.confirmations < confirmations) {
return undefined;
}
return this.getTransactionReceipt(transactionHash).then((receipt) => {
if (confirmations === 0 || (receipt && receipt.confirmations >= confirmations)) {
return receipt;
});
}, { onceBlock: this });
}
return <Promise<TransactionReceipt>>(new Promise((resolve) => {
let handler = (receipt: TransactionReceipt) => {
if (receipt.confirmations < confirmations) { return; }
this.removeListener(transactionHash, handler);
resolve(receipt);
}
this.on(transactionHash, handler);
}));
});
}
getBlockNumber(): Promise<number> {
@@ -810,7 +817,7 @@ export class BaseProvider extends Provider {
getBalance(addressOrName: string | Promise<string>, blockTag?: BlockTag | Promise<BlockTag>): Promise<BigNumber> {
return this.ready.then(() => {
return resolveProperties({ addressOrName: addressOrName, blockTag: blockTag }).then(({ addressOrName, blockTag }) => {
return this.resolveName(addressOrName).then((address) => {
return this._getAddress(addressOrName).then((address) => {
let params = { address: address, blockTag: checkBlockTag(blockTag) };
return this.perform('getBalance', params).then((result) => {
return bigNumberify(result);
@@ -823,7 +830,7 @@ export class BaseProvider extends Provider {
getTransactionCount(addressOrName: string | Promise<string>, blockTag?: BlockTag | Promise<BlockTag>): Promise<number> {
return this.ready.then(() => {
return resolveProperties({ addressOrName: addressOrName, blockTag: blockTag }).then(({ addressOrName, blockTag }) => {
return this.resolveName(addressOrName).then((address) => {
return this._getAddress(addressOrName).then((address) => {
let params = { address: address, blockTag: checkBlockTag(blockTag) };
return this.perform('getTransactionCount', params).then((result) => {
return bigNumberify(result).toNumber();
@@ -836,7 +843,7 @@ export class BaseProvider extends Provider {
getCode(addressOrName: string | Promise<string>, blockTag?: BlockTag | Promise<BlockTag>): Promise<string> {
return this.ready.then(() => {
return resolveProperties({ addressOrName: addressOrName, blockTag: blockTag }).then(({ addressOrName, blockTag }) => {
return this.resolveName(addressOrName).then((address) => {
return this._getAddress(addressOrName).then((address) => {
let params = {address: address, blockTag: checkBlockTag(blockTag)};
return this.perform('getCode', params).then((result) => {
return hexlify(result);
@@ -849,7 +856,7 @@ export class BaseProvider extends Provider {
getStorageAt(addressOrName: string | Promise<string>, position: BigNumberish | Promise<BigNumberish>, blockTag?: BlockTag | Promise<BlockTag>): Promise<string> {
return this.ready.then(() => {
return resolveProperties({ addressOrName: addressOrName, position: position, blockTag: blockTag }).then(({ addressOrName, position, blockTag }) => {
return this.resolveName(addressOrName).then((address) => {
return this._getAddress(addressOrName).then((address) => {
let params = {
address: address,
blockTag: checkBlockTag(blockTag),
@@ -1102,6 +1109,15 @@ export class BaseProvider extends Provider {
});
}
_getAddress(addressOrName: string): Promise<string> {
return this.resolveName(addressOrName).then((address) => {
if (address == null) {
errors.throwError("ENS name not configured", errors.UNSUPPORTED_OPERATION, { operation: "resolveName(" + JSON.stringify(addressOrName) + ")" });
}
return address;
});
}
// @TODO: Could probably use resolveProperties instead?
private _resolveNames(object: any, keys: Array<string>): Promise<{ [key: string]: string }> {
let promises: Array<Promise<void>> = [];
@@ -1110,7 +1126,7 @@ export class BaseProvider extends Provider {
keys.forEach(function(key) {
if (result[key] == null) { return; }
promises.push(this.resolveName(result[key]).then((address: string) => {
promises.push(this._getAddress(result[key]).then((address: string) => {
result[key] = address;
return;
}));
@@ -1137,10 +1153,11 @@ export class BaseProvider extends Provider {
let transaction = { to: network.ensAddress, data: data };
return this.call(transaction).then((data) => {
// extract the address from the data
if (hexDataLength(data) !== 32) { return null; }
return getAddress(hexDataSlice(data, 12));
let address = getAddress(hexDataSlice(data, 12));
if (address === AddressZero) { return null; }
return address;
});
});
}
@@ -1165,6 +1182,7 @@ export class BaseProvider extends Provider {
// Get the addr from the resovler
return this._getResolver(name).then(function(resolverAddress) {
if (resolverAddress == null) { return null; }
// keccak256('addr(bytes32)')
let data = '0x3b3b57de' + nodeHash.substring(2);
@@ -1175,7 +1193,7 @@ export class BaseProvider extends Provider {
}).then(function(data) {
if (hexDataLength(data) !== 32) { return null; }
let address = getAddress(hexDataSlice(data, 12));
if (address === '0x0000000000000000000000000000000000000000') { return null; }
if (address === AddressZero) { return null; }
return address;
});
}
@@ -1306,13 +1324,18 @@ export class BaseProvider extends Provider {
});
}
removeAllListeners(eventName: EventType): Provider {
let eventTag = getEventTag(eventName);
this._events = this._events.filter((event) => {
return (event.tag !== eventTag);
});
removeAllListeners(eventName?: EventType): Provider {
if (eventName == null) {
this._events = [ ];
this._stopPending();
} else {
let eventTag = getEventTag(eventName);
this._events = this._events.filter((event) => {
return (event.tag !== eventTag);
});
if (eventName === 'pending') { this._stopPending(); }
}
if (eventName === 'pending') { this._stopPending(); }
if (this._events.length === 0) { this.polling = false; }
return this;
@@ -1323,9 +1346,9 @@ export class BaseProvider extends Provider {
let eventTag = getEventTag(eventName);
this._events = this._events.filter((event) => {
if (event.tag !== eventTag) { return true; }
if (event.tag !== eventTag || event.listener != listener) { return true; }
if (found) { return true; }
found = false;
found = true;
return false;
});

View File

@@ -32,6 +32,9 @@ export class InfuraProvider extends JsonRpcProvider {
case 'rinkeby':
host = 'rinkeby.infura.io';
break;
case 'goerli':
host = 'goerli.infura.io';
break;
case 'kovan':
host = 'kovan.infura.io';
break;
@@ -50,6 +53,7 @@ export class InfuraProvider extends JsonRpcProvider {
// Legacy API Access Token
} else {
errors.warn("The legacy INFURA apiAccesToken API is deprecated; please upgrade to a Project ID instead (see INFURA dshboard; https://infura.io)");
super('https://' + host + '/' + projectId, standard);
defineReadOnly(this, 'apiAccessToken', projectId);
defineReadOnly(this, 'projectId', null);

View File

@@ -50,6 +50,11 @@ function getLowerCase(value: string): string {
const _constructorGuard = {};
// Some environments (Trust Wallet and company) use a global map
// to track JSON-RPC ID, so we try to keep IDs unique across all
// connections. See #489.
let _nextId = 42;
export class JsonRpcSigner extends Signer {
readonly provider: JsonRpcProvider;
private _index: number;
@@ -158,7 +163,7 @@ export class JsonRpcSigner extends Signer {
if (tx === null) { return undefined; }
return this.provider._wrapTransaction(tx, hash);
});
}, { onceBlock: this.provider }).catch((error: Error) => {
}, { fastRetry: 250, onceBlock: this.provider }).catch((error: Error) => {
(<any>error).transactionHash = hash;
throw error;
});
@@ -250,7 +255,7 @@ export class JsonRpcProvider extends BaseProvider {
let request = {
method: method,
params: params,
id: 42,
id: (_nextId++),
jsonrpc: "2.0"
};

View File

@@ -27,6 +27,8 @@ utils.defineProperty(Web3Signer, 'onchange', {
*/
let _nextId = 42;
export class Web3Provider extends JsonRpcProvider {
readonly _web3Provider: AsyncSendable;
private _sendAsync: (request: any, callback: (error: any, response: any) => void) => void;
@@ -65,10 +67,10 @@ export class Web3Provider extends JsonRpcProvider {
}
return new Promise((resolve, reject) => {
var request = {
let request = {
method: method,
params: params,
id: 42,
id: (_nextId++),
jsonrpc: "2.0"
};
@@ -80,7 +82,7 @@ export class Web3Provider extends JsonRpcProvider {
if (result.error) {
// @TODO: not any
var error: any = new Error(result.error.message);
let error: any = new Error(result.error.message);
error.code = result.error.code;
error.data = result.error.data;
reject(error);

View File

@@ -574,7 +574,7 @@ class CoderFixedBytes extends Coder {
decode(data: Uint8Array, offset: number): DecodedResult {
if (data.length < offset + 32) {
errors.throwError('insufficient data for ' + name + ' type', errors.INVALID_ARGUMENT, {
errors.throwError('insufficient data for ' + this.name + ' type', errors.INVALID_ARGUMENT, {
arg: this.localName,
coderType: this.name,
value: hexlify(data.slice(offset, offset + 32))

View File

@@ -22,7 +22,7 @@ import { populateTransaction } from './transaction';
import { parse as parseTransaction, serialize as serializeTransaction } from './transaction';
import { formatBytes32String, parseBytes32String, toUtf8Bytes, toUtf8String } from './utf8';
import { commify, formatEther, parseEther, formatUnits, parseUnits } from './units';
import { fetchJson } from './web';
import { fetchJson, poll } from './web';
////////////////////////
@@ -136,6 +136,8 @@ export {
recoverPublicKey,
verifyMessage,
poll,
////////////////////////
// Enums

View File

@@ -86,12 +86,7 @@ const networks: { [name: string]: Network } = {
chainId: 5,
ensAddress: "0x112234455c3a32fd11230c42e7bccd4a84e02010",
name: "goerli",
_defaultProvider: (providers: any): any => {
if (providers.EtherscanProvider) {
return new providers.EtherscanProvider("goerli");
}
return null;
}
_defaultProvider: ethDefaultProvider('goerli')
},
kovan: {

View File

@@ -190,7 +190,7 @@ export function parseBytes32String(bytes: Arrayish): string {
// Must be 32 bytes with a null-termination
if (data.length !== 32) { throw new Error('invalid bytes32 - not 32 bytes long'); }
if (data[31] !== 0) { throw new Error('invalid bytes32 sdtring - no null terminator'); }
if (data[31] !== 0) { throw new Error('invalid bytes32 string - no null terminator'); }
// Find the null termination
let length = 31;

View File

@@ -28,7 +28,8 @@ export type PollOptions = {
floor?: number,
ceiling?: number,
interval?: number,
onceBlock?: OnceBlockable
onceBlock?: OnceBlockable,
fastRetry?: number
};
@@ -208,6 +209,8 @@ export function poll(func: () => Promise<any>, options?: PollOptions): Promise<a
}, options.timeout)
}
let fastTimeout = options.fastRetry || null;
let attempt = 0;
function check() {
return func().then(function(result) {
@@ -227,6 +230,13 @@ export function poll(func: () => Promise<any>, options?: PollOptions): Promise<a
if (timeout < options.floor) { timeout = options.floor; }
if (timeout > options.ceiling) { timeout = options.ceiling; }
// Fast Timeout, means we quickly try again the first time
if (fastTimeout) {
attempt--;
timeout = fastTimeout;
fastTimeout = null;
}
setTimeout(check, timeout);
}

View File

@@ -414,12 +414,6 @@ function testProvider(providerName, networkName) {
['default', 'homestead', 'ropsten', 'rinkeby', 'kovan', 'goerli'].forEach(function(networkName) {
['getDefaultProvider', 'InfuraProvider', 'EtherscanProvider', 'Web3Provider'].forEach(function(providerName) {
if (networkName === "goerli") {
if (providerName === "InfuraProvider" || providerName === "Web3Provider") {
return;
}
}
// @TODO: Remove this! Temporary because Etherscan is down
//if (providerName === 'EtherscanProvider') {
// console.log("******** Remove this soon! Etherscan is having issues.");

View File

@@ -480,7 +480,7 @@ var CoderFixedBytes = /** @class */ (function (_super) {
};
CoderFixedBytes.prototype.decode = function (data, offset) {
if (data.length < offset + 32) {
errors.throwError('insufficient data for ' + name + ' type', errors.INVALID_ARGUMENT, {
errors.throwError('insufficient data for ' + this.name + ' type', errors.INVALID_ARGUMENT, {
arg: this.localName,
coderType: this.name,
value: bytes_1.hexlify(data.slice(offset, offset + 32))

4
utils/index.d.ts vendored
View File

@@ -20,7 +20,7 @@ import { populateTransaction } from './transaction';
import { parse as parseTransaction, serialize as serializeTransaction } from './transaction';
import { formatBytes32String, parseBytes32String, toUtf8Bytes, toUtf8String } from './utf8';
import { commify, formatEther, parseEther, formatUnits, parseUnits } from './units';
import { fetchJson } from './web';
import { fetchJson, poll } from './web';
import { SupportedAlgorithms } from './hmac';
import { UnicodeNormalizationForm } from './utf8';
import { CoerceFunc, EventFragment, FunctionFragment, ParamType } from './abi-coder';
@@ -32,4 +32,4 @@ import { Transaction, UnsignedTransaction } from './transaction';
import { ConnectionInfo, OnceBlockable, PollOptions } from './web';
import { EncryptOptions, ProgressCallback } from './secret-storage';
import { Wordlist } from './wordlist';
export { AbiCoder, defaultAbiCoder, formatSignature, formatParamType, parseSignature, parseParamType, RLP, fetchJson, getNetwork, checkProperties, deepCopy, defineReadOnly, resolveProperties, shallowCopy, arrayify, concat, padZeros, stripZeros, HDNode, SigningKey, Interface, base64, BigNumber, bigNumberify, hexlify, isHexString, hexStripZeros, hexZeroPad, hexDataLength, hexDataSlice, toUtf8Bytes, toUtf8String, formatBytes32String, parseBytes32String, hashMessage, namehash, id, getAddress, getIcapAddress, getContractAddress, formatEther, parseEther, formatUnits, parseUnits, commify, keccak256, sha256, randomBytes, solidityPack, solidityKeccak256, soliditySha256, splitSignature, joinSignature, parseTransaction, populateTransaction, serializeTransaction, getJsonWalletAddress, computeAddress, computePublicKey, recoverAddress, recoverPublicKey, verifyMessage, SupportedAlgorithms, UnicodeNormalizationForm, CoerceFunc, EventFragment, FunctionFragment, ParamType, BigNumberish, Arrayish, Hexable, Signature, Indexed, DeployDescription, EventDescription, FunctionDescription, LogDescription, TransactionDescription, Network, Networkish, Transaction, UnsignedTransaction, ConnectionInfo, OnceBlockable, PollOptions, EncryptOptions, ProgressCallback, Wordlist, };
export { AbiCoder, defaultAbiCoder, formatSignature, formatParamType, parseSignature, parseParamType, RLP, fetchJson, getNetwork, checkProperties, deepCopy, defineReadOnly, resolveProperties, shallowCopy, arrayify, concat, padZeros, stripZeros, HDNode, SigningKey, Interface, base64, BigNumber, bigNumberify, hexlify, isHexString, hexStripZeros, hexZeroPad, hexDataLength, hexDataSlice, toUtf8Bytes, toUtf8String, formatBytes32String, parseBytes32String, hashMessage, namehash, id, getAddress, getIcapAddress, getContractAddress, formatEther, parseEther, formatUnits, parseUnits, commify, keccak256, sha256, randomBytes, solidityPack, solidityKeccak256, soliditySha256, splitSignature, joinSignature, parseTransaction, populateTransaction, serializeTransaction, getJsonWalletAddress, computeAddress, computePublicKey, recoverAddress, recoverPublicKey, verifyMessage, poll, SupportedAlgorithms, UnicodeNormalizationForm, CoerceFunc, EventFragment, FunctionFragment, ParamType, BigNumberish, Arrayish, Hexable, Signature, Indexed, DeployDescription, EventDescription, FunctionDescription, LogDescription, TransactionDescription, Network, Networkish, Transaction, UnsignedTransaction, ConnectionInfo, OnceBlockable, PollOptions, EncryptOptions, ProgressCallback, Wordlist, };

View File

@@ -92,6 +92,7 @@ exports.formatUnits = units_1.formatUnits;
exports.parseUnits = units_1.parseUnits;
var web_1 = require("./web");
exports.fetchJson = web_1.fetchJson;
exports.poll = web_1.poll;
////////////////////////
// Enums
var hmac_1 = require("./hmac");

View File

@@ -70,12 +70,7 @@ var networks = {
chainId: 5,
ensAddress: "0x112234455c3a32fd11230c42e7bccd4a84e02010",
name: "goerli",
_defaultProvider: function (providers) {
if (providers.EtherscanProvider) {
return new providers.EtherscanProvider("goerli");
}
return null;
}
_defaultProvider: ethDefaultProvider('goerli')
},
kovan: {
chainId: 42,

View File

@@ -174,7 +174,7 @@ function parseBytes32String(bytes) {
throw new Error('invalid bytes32 - not 32 bytes long');
}
if (data[31] !== 0) {
throw new Error('invalid bytes32 sdtring - no null terminator');
throw new Error('invalid bytes32 string - no null terminator');
}
// Find the null termination
var length = 31;

1
utils/web.d.ts vendored
View File

@@ -17,6 +17,7 @@ export declare type PollOptions = {
ceiling?: number;
interval?: number;
onceBlock?: OnceBlockable;
fastRetry?: number;
};
export declare function fetchJson(connection: string | ConnectionInfo, json: string, processFunc: (value: any) => any): Promise<any>;
export declare function poll(func: () => Promise<any>, options?: PollOptions): Promise<any>;

View File

@@ -179,6 +179,7 @@ function poll(func, options) {
}
}, options.timeout);
}
var fastTimeout = options.fastRetry || null;
var attempt = 0;
function check() {
return func().then(function (result) {
@@ -201,6 +202,12 @@ function poll(func, options) {
if (timeout > options.ceiling) {
timeout = options.ceiling;
}
// Fast Timeout, means we quickly try again the first time
if (fastTimeout) {
attempt--;
timeout = fastTimeout;
fastTimeout = null;
}
setTimeout(check, timeout);
}
return null;