forked from tornado-packages/ethers.js
Compare commits
41 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5f720ace6 | ||
|
|
9f201c386e | ||
|
|
700dd34137 | ||
|
|
f2dd977de4 | ||
|
|
5f013216c5 | ||
|
|
eac0805435 | ||
|
|
e5bee7e5a3 | ||
|
|
442553620a | ||
|
|
6d08968b87 | ||
|
|
c2ce59f95e | ||
|
|
f3ec27b95f | ||
|
|
c88cb5ea90 | ||
|
|
99a21660ab | ||
|
|
4bc62a1e8a | ||
|
|
26eb6cc01a | ||
|
|
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 |
2
_version.d.ts
vendored
2
_version.d.ts
vendored
@@ -1 +1 @@
|
||||
export declare const version = "4.0.10";
|
||||
export declare const version = "4.0.22";
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.version = "4.0.10";
|
||||
exports.version = "4.0.22";
|
||||
|
||||
23
contract.js
23
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];
|
||||
@@ -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);
|
||||
@@ -305,7 +304,6 @@ var Contract = /** @class */ (function () {
|
||||
}
|
||||
return address;
|
||||
}).catch(function (error) {
|
||||
console.log('ERROR: Cannot find Contract - ' + addressOrName);
|
||||
throw error;
|
||||
}));
|
||||
}
|
||||
@@ -324,7 +322,7 @@ var Contract = /** @class */ (function () {
|
||||
properties_1.defineReadOnly(_this, name, run);
|
||||
}
|
||||
else {
|
||||
console.log('WARNING: Multiple definitions for ' + name);
|
||||
errors.warn('WARNING: Multiple definitions for ' + name);
|
||||
}
|
||||
if (_this.functions[name] == null) {
|
||||
properties_1.defineReadOnly(_this.functions, name, run);
|
||||
@@ -556,12 +554,19 @@ var Contract = /** @class */ (function () {
|
||||
}).map(function (event) { return event.listener; });
|
||||
};
|
||||
Contract.prototype.removeAllListeners = function (eventName) {
|
||||
var _this = this;
|
||||
if (!this.provider) {
|
||||
return this;
|
||||
}
|
||||
var eventFilter = this._getEventFilter(eventName);
|
||||
this._events = this._events.filter(function (event) {
|
||||
return event.eventFilter.eventTag !== eventFilter.eventTag;
|
||||
// Keep all other events
|
||||
if (event.eventFilter.eventTag !== eventFilter.eventTag) {
|
||||
return true;
|
||||
}
|
||||
// Deregister this event from the provider and filter it out
|
||||
_this.provider.removeListener(event.eventFilter.filter, event.wrappedListener);
|
||||
return false;
|
||||
});
|
||||
return this;
|
||||
};
|
||||
@@ -655,7 +660,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;
|
||||
|
||||
472
dist/ethers.js
vendored
472
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.10";
|
||||
exports.version = "4.0.22";
|
||||
|
||||
},{}],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];
|
||||
@@ -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);
|
||||
@@ -353,7 +352,6 @@ var Contract = /** @class */ (function () {
|
||||
}
|
||||
return address;
|
||||
}).catch(function (error) {
|
||||
console.log('ERROR: Cannot find Contract - ' + addressOrName);
|
||||
throw error;
|
||||
}));
|
||||
}
|
||||
@@ -372,7 +370,7 @@ var Contract = /** @class */ (function () {
|
||||
properties_1.defineReadOnly(_this, name, run);
|
||||
}
|
||||
else {
|
||||
console.log('WARNING: Multiple definitions for ' + name);
|
||||
errors.warn('WARNING: Multiple definitions for ' + name);
|
||||
}
|
||||
if (_this.functions[name] == null) {
|
||||
properties_1.defineReadOnly(_this.functions, name, run);
|
||||
@@ -604,12 +602,19 @@ var Contract = /** @class */ (function () {
|
||||
}).map(function (event) { return event.listener; });
|
||||
};
|
||||
Contract.prototype.removeAllListeners = function (eventName) {
|
||||
var _this = this;
|
||||
if (!this.provider) {
|
||||
return this;
|
||||
}
|
||||
var eventFilter = this._getEventFilter(eventName);
|
||||
this._events = this._events.filter(function (event) {
|
||||
return event.eventFilter.eventTag !== eventFilter.eventTag;
|
||||
// Keep all other events
|
||||
if (event.eventFilter.eventTag !== eventFilter.eventTag) {
|
||||
return true;
|
||||
}
|
||||
// Deregister this event from the provider and filter it out
|
||||
_this.provider.removeListener(event.eventFilter.filter, event.wrappedListener);
|
||||
return false;
|
||||
});
|
||||
return this;
|
||||
};
|
||||
@@ -703,7 +708,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;
|
||||
@@ -771,7 +776,7 @@ exports.MISSING_NEW = 'MISSING_NEW';
|
||||
// - reason: The reason (only for EIP848 "Error(string)")
|
||||
exports.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
|
||||
exports.INVALID_ARGUMENT = 'INVALID_ARGUMENT';
|
||||
// Missing argument to a function:
|
||||
@@ -855,7 +860,7 @@ function checkArgumentCount(count, expectedCount, suffix) {
|
||||
exports.checkArgumentCount = checkArgumentCount;
|
||||
function setCensorship(censorship, permanent) {
|
||||
if (_permanentCensorErrors) {
|
||||
throwError('error censorship permanent', exports.UNSUPPORTED_OPERATION, { operation: 'setCersorship' });
|
||||
throwError('error censorship permanent', exports.UNSUPPORTED_OPERATION, { operation: 'setCensorship' });
|
||||
}
|
||||
_censorErrors = !!censorship;
|
||||
_permanentCensorErrors = !!permanent;
|
||||
@@ -863,15 +868,57 @@ function setCensorship(censorship, 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');
|
||||
throw new Error('broken implementation');
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
throwError('platform missing String.prototype.normalize', exports.UNSUPPORTED_OPERATION, { operation: 'String.prototype.normalize' });
|
||||
throwError('platform missing String.prototype.normalize', exports.UNSUPPORTED_OPERATION, { operation: 'String.prototype.normalize', form: error.message });
|
||||
}
|
||||
}
|
||||
exports.checkNormalize = checkNormalize;
|
||||
var LogLevels = { debug: 1, "default": 2, info: 2, warn: 3, error: 4, off: 5 };
|
||||
var LogLevel = LogLevels["default"];
|
||||
function setLogLevel(logLevel) {
|
||||
var level = LogLevels[logLevel];
|
||||
if (level == null) {
|
||||
warn("invliad log level - " + logLevel);
|
||||
return;
|
||||
}
|
||||
LogLevel = level;
|
||||
}
|
||||
exports.setLogLevel = setLogLevel;
|
||||
function log(logLevel, args) {
|
||||
if (LogLevel > LogLevels[logLevel]) {
|
||||
return;
|
||||
}
|
||||
console.log.apply(console, args);
|
||||
}
|
||||
function warn() {
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
log("warn", args);
|
||||
}
|
||||
exports.warn = warn;
|
||||
function info() {
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
log("info", args);
|
||||
}
|
||||
exports.info = info;
|
||||
|
||||
},{"./_version":1}],6:[function(require,module,exports){
|
||||
'use strict';
|
||||
@@ -912,10 +959,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;
|
||||
|
||||
@@ -9933,9 +9987,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;
|
||||
@@ -10056,6 +10116,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();
|
||||
}
|
||||
@@ -10124,6 +10188,8 @@ function checkTransactionReceiptLog(log) {
|
||||
return check(formatTransactionReceiptLog, log);
|
||||
}
|
||||
var formatTransactionReceipt = {
|
||||
to: allowNull(address_1.getAddress, null),
|
||||
from: address_1.getAddress,
|
||||
contractAddress: allowNull(address_1.getAddress, null),
|
||||
transactionIndex: checkNumber,
|
||||
root: allowNull(checkHash),
|
||||
@@ -10259,6 +10325,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);
|
||||
@@ -10276,11 +10344,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;
|
||||
}
|
||||
@@ -10292,28 +10356,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;
|
||||
}
|
||||
var _loop_1 = function (i) {
|
||||
if (_this._emitted.block < i) {
|
||||
_this._emitted.block = i;
|
||||
// Notify all listener for each block that has passed
|
||||
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);
|
||||
};
|
||||
// Notify all listener for each block that has passed
|
||||
for (var i = _this._lastBlockNumber + 1; i <= blockNumber; i++) {
|
||||
_loop_1(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 = {};
|
||||
@@ -10339,12 +10415,12 @@ 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;
|
||||
@@ -10382,8 +10458,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 () {
|
||||
@@ -10397,10 +10475,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
|
||||
@@ -10474,11 +10549,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;
|
||||
}
|
||||
@@ -10596,10 +10674,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,
|
||||
@@ -10677,7 +10765,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;
|
||||
@@ -10696,7 +10784,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) {
|
||||
@@ -10731,7 +10819,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) {
|
||||
@@ -10910,7 +10998,7 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
return null;
|
||||
};
|
||||
BaseProvider.prototype._startPending = function () {
|
||||
console.log('WARNING: this provider does not support pending events');
|
||||
errors.warn('WARNING: this provider does not support pending events');
|
||||
};
|
||||
BaseProvider.prototype._stopPending = function () {
|
||||
};
|
||||
@@ -11394,7 +11482,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 });
|
||||
@@ -11505,16 +11594,21 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var json_rpc_provider_1 = require("./json-rpc-provider");
|
||||
var bytes_1 = require("../utils/bytes");
|
||||
var networks_1 = require("../utils/networks");
|
||||
var properties_1 = require("../utils/properties");
|
||||
var errors = __importStar(require("../errors"));
|
||||
var defaultProjectId = "7d0d81d0919f4f05b9ab6634be01ee73";
|
||||
var InfuraProvider = /** @class */ (function (_super) {
|
||||
__extends(InfuraProvider, _super);
|
||||
function InfuraProvider(network, apiAccessToken) {
|
||||
function InfuraProvider(network, projectId) {
|
||||
var _this = this;
|
||||
network = networks_1.getNetwork((network == null) ? 'homestead' : network);
|
||||
var standard = networks_1.getNetwork((network == null) ? 'homestead' : network);
|
||||
if (projectId == null) {
|
||||
projectId = defaultProjectId;
|
||||
}
|
||||
var host = null;
|
||||
switch (network.name) {
|
||||
switch (standard.name) {
|
||||
case 'homestead':
|
||||
host = 'mainnet.infura.io';
|
||||
break;
|
||||
@@ -11528,19 +11622,31 @@ var InfuraProvider = /** @class */ (function (_super) {
|
||||
host = 'kovan.infura.io';
|
||||
break;
|
||||
default:
|
||||
throw new Error('unsupported network');
|
||||
errors.throwError('unsupported network', errors.INVALID_ARGUMENT, {
|
||||
argument: "network",
|
||||
value: network
|
||||
});
|
||||
}
|
||||
// New-style Project ID
|
||||
if (bytes_1.isHexString("0x" + projectId, 16)) {
|
||||
_this = _super.call(this, 'https://' + host + '/v3/' + projectId, standard) || this;
|
||||
properties_1.defineReadOnly(_this, 'apiAccessToken', null);
|
||||
properties_1.defineReadOnly(_this, 'projectId', projectId);
|
||||
// Legacy API Access Token
|
||||
}
|
||||
else {
|
||||
_this = _super.call(this, 'https://' + host + '/' + projectId, standard) || this;
|
||||
properties_1.defineReadOnly(_this, 'apiAccessToken', projectId);
|
||||
properties_1.defineReadOnly(_this, 'projectId', null);
|
||||
}
|
||||
_this = _super.call(this, 'https://' + host + '/' + (apiAccessToken || ''), network) || this;
|
||||
errors.checkNew(_this, InfuraProvider);
|
||||
properties_1.defineReadOnly(_this, 'apiAccessToken', apiAccessToken || null);
|
||||
return _this;
|
||||
}
|
||||
InfuraProvider.prototype._startPending = function () {
|
||||
console.log('WARNING: INFURA does not support pending filters');
|
||||
errors.warn('WARNING: INFURA does not support pending filters');
|
||||
};
|
||||
InfuraProvider.prototype.getSigner = function (address) {
|
||||
errors.throwError('INFURA does not support signing', errors.UNSUPPORTED_OPERATION, { operation: 'getSigner' });
|
||||
return null;
|
||||
return errors.throwError('INFURA does not support signing', errors.UNSUPPORTED_OPERATION, { operation: 'getSigner' });
|
||||
};
|
||||
InfuraProvider.prototype.listAccounts = function () {
|
||||
return Promise.resolve([]);
|
||||
@@ -11549,7 +11655,7 @@ var InfuraProvider = /** @class */ (function (_super) {
|
||||
}(json_rpc_provider_1.JsonRpcProvider));
|
||||
exports.InfuraProvider = InfuraProvider;
|
||||
|
||||
},{"../errors":5,"../utils/networks":70,"../utils/properties":72,"./json-rpc-provider":56}],55:[function(require,module,exports){
|
||||
},{"../errors":5,"../utils/bytes":62,"../utils/networks":70,"../utils/properties":72,"./json-rpc-provider":56}],55:[function(require,module,exports){
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
|
||||
@@ -11581,7 +11687,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) {
|
||||
@@ -11653,31 +11758,32 @@ var JsonRpcSigner = /** @class */ (function (_super) {
|
||||
JsonRpcSigner.prototype.getTransactionCount = function (blockTag) {
|
||||
return this.provider.getTransactionCount(this.getAddress(), blockTag);
|
||||
};
|
||||
JsonRpcSigner.prototype.sendTransaction = function (transaction) {
|
||||
JsonRpcSigner.prototype.sendUncheckedTransaction = 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) {
|
||||
if (tx === null) {
|
||||
return undefined;
|
||||
}
|
||||
return _this.provider._wrapTransaction(tx, hash);
|
||||
});
|
||||
}, { onceBlock: _this.provider }).catch(function (error) {
|
||||
error.transactionHash = hash;
|
||||
throw error;
|
||||
});
|
||||
return hash;
|
||||
}, function (error) {
|
||||
if (error.responseText) {
|
||||
// See: JsonRpcProvider.sendTransaction (@TODO: Expose a ._throwError??)
|
||||
@@ -11701,6 +11807,22 @@ var JsonRpcSigner = /** @class */ (function (_super) {
|
||||
});
|
||||
});
|
||||
};
|
||||
JsonRpcSigner.prototype.sendTransaction = function (transaction) {
|
||||
var _this = this;
|
||||
return this.sendUncheckedTransaction(transaction).then(function (hash) {
|
||||
return web_1.poll(function () {
|
||||
return _this.provider.getTransaction(hash).then(function (tx) {
|
||||
if (tx === null) {
|
||||
return undefined;
|
||||
}
|
||||
return _this.provider._wrapTransaction(tx, hash);
|
||||
});
|
||||
}, { onceBlock: _this.provider }).catch(function (error) {
|
||||
error.transactionHash = hash;
|
||||
throw error;
|
||||
});
|
||||
});
|
||||
};
|
||||
JsonRpcSigner.prototype.signMessage = function (message) {
|
||||
var _this = this;
|
||||
var data = ((typeof (message) === 'string') ? utf8_1.toUtf8Bytes(message) : message);
|
||||
@@ -11864,6 +11986,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) {
|
||||
@@ -11932,7 +12055,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 ||
|
||||
@@ -12073,9 +12196,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++) {
|
||||
@@ -12216,7 +12341,7 @@ function parseSignatureEvent(fragment) {
|
||||
case '':
|
||||
break;
|
||||
default:
|
||||
console.log('unknown modifier: ' + modifier);
|
||||
errors.info('unknown modifier: ' + modifier);
|
||||
}
|
||||
});
|
||||
if (abi.name && !abi.name.match(regexIdentifier)) {
|
||||
@@ -12280,7 +12405,7 @@ function parseSignatureFunction(fragment) {
|
||||
case '':
|
||||
break;
|
||||
default:
|
||||
console.log('unknown modifier: ' + modifier);
|
||||
errors.info('unknown modifier: ' + modifier);
|
||||
}
|
||||
});
|
||||
// We have outputs
|
||||
@@ -12320,6 +12445,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 ') {
|
||||
@@ -12755,7 +12881,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);
|
||||
@@ -13237,6 +13363,12 @@ var BigNumber = /** @class */ (function () {
|
||||
BigNumber.prototype.toTwos = function (value) {
|
||||
return toBigNumber(_bnify(this).toTwos(value));
|
||||
};
|
||||
BigNumber.prototype.abs = function () {
|
||||
if (this._hex[0] === '-') {
|
||||
return toBigNumber(_bnify(this).mul(BN_1));
|
||||
}
|
||||
return this;
|
||||
};
|
||||
BigNumber.prototype.add = function (other) {
|
||||
return toBigNumber(_bnify(this).add(toBN(other)));
|
||||
};
|
||||
@@ -13580,7 +13712,15 @@ exports.joinSignature = joinSignature;
|
||||
|
||||
},{"../errors":5}],63:[function(require,module,exports){
|
||||
'use strict';
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var errors = __importStar(require("../errors"));
|
||||
var bytes_1 = require("./bytes");
|
||||
var utf8_1 = require("./utf8");
|
||||
var keccak256_1 = require("./keccak256");
|
||||
@@ -13589,13 +13729,22 @@ var Zeros = new Uint8Array([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.-]*$");
|
||||
function namehash(name) {
|
||||
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)
|
||||
// libraries, so for now we simply do not support them.
|
||||
// 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 = Zeros;
|
||||
while (name.length) {
|
||||
@@ -13612,16 +13761,15 @@ function id(text) {
|
||||
}
|
||||
exports.id = id;
|
||||
function hashMessage(message) {
|
||||
var payload = bytes_1.concat([
|
||||
return keccak256_1.keccak256(bytes_1.concat([
|
||||
utf8_1.toUtf8Bytes('\x19Ethereum Signed Message:\n'),
|
||||
utf8_1.toUtf8Bytes(String(message.length)),
|
||||
((typeof (message) === 'string') ? utf8_1.toUtf8Bytes(message) : message)
|
||||
]);
|
||||
return keccak256_1.keccak256(payload);
|
||||
]));
|
||||
}
|
||||
exports.hashMessage = hashMessage;
|
||||
|
||||
},{"./bytes":62,"./keccak256":69,"./utf8":83}],64:[function(require,module,exports){
|
||||
},{"../errors":5,"./bytes":62,"./keccak256":69,"./utf8":83}],64:[function(require,module,exports){
|
||||
'use strict';
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
@@ -13699,7 +13847,7 @@ var HDNode = /** @class */ (function () {
|
||||
var mnemonic = this.mnemonic;
|
||||
var path = this.path;
|
||||
if (path) {
|
||||
path += '/' + index;
|
||||
path += '/' + (index & ~HardenedBit);
|
||||
}
|
||||
if (index & HardenedBit) {
|
||||
// Data = 0x00 || ser_256(k_par)
|
||||
@@ -13928,6 +14076,7 @@ exports.hexDataLength = bytes_1.hexDataLength;
|
||||
exports.hexlify = bytes_1.hexlify;
|
||||
exports.hexStripZeros = bytes_1.hexStripZeros;
|
||||
exports.hexZeroPad = bytes_1.hexZeroPad;
|
||||
exports.isHexString = bytes_1.isHexString;
|
||||
exports.joinSignature = bytes_1.joinSignature;
|
||||
exports.padZeros = bytes_1.padZeros;
|
||||
exports.splitSignature = bytes_1.splitSignature;
|
||||
@@ -14056,7 +14205,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));
|
||||
}
|
||||
@@ -14077,7 +14226,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);
|
||||
}
|
||||
@@ -14249,12 +14398,18 @@ function addMethod(method) {
|
||||
gas: method.gas,
|
||||
payable: (method.payable == null || !!method.payable),
|
||||
type: ((method.constant) ? 'call' : 'transaction'),
|
||||
name: method.name,
|
||||
signature: signature,
|
||||
sighash: sighash,
|
||||
});
|
||||
// Expose the first (and hopefully unique named function
|
||||
if (method.name && this.functions[method.name] == null) {
|
||||
properties_1.defineReadOnly(this.functions, method.name, description);
|
||||
// Expose the first (and hopefully unique named function)
|
||||
if (method.name) {
|
||||
if (this.functions[method.name] == null) {
|
||||
properties_1.defineReadOnly(this.functions, method.name, description);
|
||||
}
|
||||
else {
|
||||
errors.warn('WARNING: Multiple definitions for ' + method.name);
|
||||
}
|
||||
}
|
||||
// Expose all methods by their signature, for overloaded functions
|
||||
if (this.functions[description.signature] == null) {
|
||||
@@ -14285,7 +14440,7 @@ function addMethod(method) {
|
||||
// Nothing to do for fallback
|
||||
break;
|
||||
default:
|
||||
console.log('WARNING: unsupported ABI type - ' + method.type);
|
||||
errors.warn('WARNING: unsupported ABI type - ' + method.type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -14339,10 +14494,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'),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -14454,39 +14609,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')
|
||||
}
|
||||
};
|
||||
/**
|
||||
@@ -14496,18 +14690,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)
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -14522,9 +14717,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];
|
||||
@@ -14539,11 +14735,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;
|
||||
@@ -15378,6 +15575,7 @@ function encrypt(privateKey, password, options, progressCallback) {
|
||||
gethFilename: ('UTC--' + timestamp + '--' + data.address),
|
||||
mnemonicCounter: bytes_1.hexlify(mnemonicIv).substring(2),
|
||||
mnemonicCiphertext: bytes_1.hexlify(mnemonicCiphertext).substring(2),
|
||||
path: path,
|
||||
version: "0.1"
|
||||
};
|
||||
}
|
||||
@@ -15693,7 +15891,7 @@ function parse(rawTransaction) {
|
||||
tx.v = bignumber_1.bigNumberify(transaction[6]).toNumber();
|
||||
}
|
||||
catch (error) {
|
||||
console.log(error);
|
||||
errors.info(error);
|
||||
return tx;
|
||||
}
|
||||
tx.r = bytes_1.hexZeroPad(transaction[7], 32);
|
||||
@@ -15722,7 +15920,7 @@ function parse(rawTransaction) {
|
||||
tx.from = secp256k1_1.recoverAddress(digest, { r: bytes_1.hexlify(tx.r), s: bytes_1.hexlify(tx.s), recoveryParam: recoveryParam });
|
||||
}
|
||||
catch (error) {
|
||||
console.log(error);
|
||||
errors.info(error);
|
||||
}
|
||||
tx.hash = keccak256_1.keccak256(rawTransaction);
|
||||
}
|
||||
@@ -16225,6 +16423,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;
|
||||
@@ -16250,7 +16451,7 @@ function fetchJson(connection, json, processFunc) {
|
||||
reject(error);
|
||||
};
|
||||
try {
|
||||
if (json) {
|
||||
if (json != null) {
|
||||
request.send(json);
|
||||
}
|
||||
else {
|
||||
@@ -16455,7 +16656,7 @@ var Wallet = /** @class */ (function (_super) {
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Wallet.prototype, "path", {
|
||||
get: function () { return this.signingKey.mnemonic; },
|
||||
get: function () { return this.signingKey.path; },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
@@ -16501,6 +16702,13 @@ var Wallet = /** @class */ (function (_super) {
|
||||
};
|
||||
Wallet.prototype.sendTransaction = function (transaction) {
|
||||
var _this = this;
|
||||
if (!this.provider) {
|
||||
throw new Error('missing provider');
|
||||
}
|
||||
if (transaction.nonce == null) {
|
||||
transaction = properties_1.shallowCopy(transaction);
|
||||
transaction.nonce = this.getTransactionCount("pending");
|
||||
}
|
||||
return transaction_1.populateTransaction(transaction, this.provider, this.address).then(function (tx) {
|
||||
return _this.sign(tx).then(function (signedTransaction) {
|
||||
return _this.provider.sendTransaction(signedTransaction);
|
||||
|
||||
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
23
dist/ethers.types.txt
vendored
23
dist/ethers.types.txt
vendored
@@ -189,6 +189,9 @@ declare module 'ethers/errors' {
|
||||
export function checkArgumentCount(count: number, expectedCount: number, suffix?: string): void;
|
||||
export function setCensorship(censorship: boolean, permanent?: boolean): void;
|
||||
export function checkNormalize(): void;
|
||||
export function setLogLevel(logLevel: string): void;
|
||||
export function warn(...args: Array<any>): void;
|
||||
export function info(...args: Array<any>): void;
|
||||
}
|
||||
|
||||
declare module 'ethers/providers' {
|
||||
@@ -210,7 +213,7 @@ declare module 'ethers/utils' {
|
||||
import { getAddress, getContractAddress, getIcapAddress } from 'ethers/utils/address';
|
||||
import * as base64 from 'ethers/utils/base64';
|
||||
import { BigNumber, bigNumberify } from 'ethers/utils/bignumber';
|
||||
import { arrayify, concat, hexDataSlice, hexDataLength, hexlify, hexStripZeros, hexZeroPad, joinSignature, padZeros, splitSignature, stripZeros } from 'ethers/utils/bytes';
|
||||
import { arrayify, concat, hexDataSlice, hexDataLength, hexlify, hexStripZeros, hexZeroPad, isHexString, joinSignature, padZeros, splitSignature, stripZeros } from 'ethers/utils/bytes';
|
||||
import { hashMessage, id, namehash } from 'ethers/utils/hash';
|
||||
import * as HDNode from 'ethers/utils/hdnode';
|
||||
import { Interface } from 'ethers/utils/interface';
|
||||
@@ -240,7 +243,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, 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, 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' {
|
||||
@@ -262,7 +265,7 @@ declare module 'ethers/utils/shims' {
|
||||
}
|
||||
|
||||
declare module 'ethers/_version' {
|
||||
export const version = "4.0.10";
|
||||
export const version = "4.0.22";
|
||||
}
|
||||
|
||||
declare module 'ethers/utils/bignumber' {
|
||||
@@ -273,6 +276,7 @@ declare module 'ethers/utils/bignumber' {
|
||||
constructor(value: BigNumberish);
|
||||
fromTwos(value: number): BigNumber;
|
||||
toTwos(value: number): BigNumber;
|
||||
abs(): BigNumber;
|
||||
add(other: BigNumberish): BigNumber;
|
||||
sub(other: BigNumberish): BigNumber;
|
||||
div(other: BigNumberish): BigNumber;
|
||||
@@ -483,6 +487,8 @@ declare module 'ethers/providers/abstract-provider' {
|
||||
logIndex?: number;
|
||||
}
|
||||
export interface TransactionReceipt {
|
||||
to?: string;
|
||||
from?: string;
|
||||
contractAddress?: string;
|
||||
transactionIndex?: number;
|
||||
root?: string;
|
||||
@@ -500,7 +506,7 @@ declare module 'ethers/providers/abstract-provider' {
|
||||
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>;
|
||||
data?: Arrayish | Promise<Arrayish>;
|
||||
@@ -716,7 +722,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
|
||||
*
|
||||
@@ -809,7 +817,8 @@ declare module 'ethers/providers/infura-provider' {
|
||||
import { Networkish } from 'ethers/utils/networks';
|
||||
export class InfuraProvider extends JsonRpcProvider {
|
||||
readonly apiAccessToken: string;
|
||||
constructor(network?: Networkish, apiAccessToken?: string);
|
||||
readonly projectId: string;
|
||||
constructor(network?: Networkish, projectId?: string);
|
||||
protected _startPending(): void;
|
||||
getSigner(address?: string): JsonRpcSigner;
|
||||
listAccounts(): Promise<Array<string>>;
|
||||
@@ -830,6 +839,7 @@ declare module 'ethers/providers/json-rpc-provider' {
|
||||
getAddress(): Promise<string>;
|
||||
getBalance(blockTag?: BlockTag): Promise<BigNumber>;
|
||||
getTransactionCount(blockTag?: BlockTag): Promise<number>;
|
||||
sendUncheckedTransaction(transaction: TransactionRequest): Promise<string>;
|
||||
sendTransaction(transaction: TransactionRequest): Promise<TransactionResponse>;
|
||||
signMessage(message: Arrayish | string): Promise<string>;
|
||||
unlock(password: string): Promise<boolean>;
|
||||
@@ -924,6 +934,7 @@ declare module 'ethers/utils/networks' {
|
||||
name: string;
|
||||
chainId: number;
|
||||
ensAddress?: string;
|
||||
_defaultProvider?: (providers: any) => any;
|
||||
};
|
||||
export type Networkish = Network | string | number;
|
||||
/**
|
||||
|
||||
2
dist/shims.js
vendored
2
dist/shims.js
vendored
File diff suppressed because one or more lines are too long
3
errors.d.ts
vendored
3
errors.d.ts
vendored
@@ -15,3 +15,6 @@ 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;
|
||||
export declare function setLogLevel(logLevel: string): void;
|
||||
export declare function warn(...args: Array<any>): void;
|
||||
export declare function info(...args: Array<any>): void;
|
||||
|
||||
50
errors.js
50
errors.js
@@ -18,7 +18,7 @@ exports.MISSING_NEW = 'MISSING_NEW';
|
||||
// - reason: The reason (only for EIP848 "Error(string)")
|
||||
exports.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
|
||||
exports.INVALID_ARGUMENT = 'INVALID_ARGUMENT';
|
||||
// Missing argument to a function:
|
||||
@@ -102,7 +102,7 @@ function checkArgumentCount(count, expectedCount, suffix) {
|
||||
exports.checkArgumentCount = checkArgumentCount;
|
||||
function setCensorship(censorship, permanent) {
|
||||
if (_permanentCensorErrors) {
|
||||
throwError('error censorship permanent', exports.UNSUPPORTED_OPERATION, { operation: 'setCersorship' });
|
||||
throwError('error censorship permanent', exports.UNSUPPORTED_OPERATION, { operation: 'setCensorship' });
|
||||
}
|
||||
_censorErrors = !!censorship;
|
||||
_permanentCensorErrors = !!permanent;
|
||||
@@ -110,12 +110,54 @@ function setCensorship(censorship, 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');
|
||||
throw new Error('broken implementation');
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
throwError('platform missing String.prototype.normalize', exports.UNSUPPORTED_OPERATION, { operation: 'String.prototype.normalize' });
|
||||
throwError('platform missing String.prototype.normalize', exports.UNSUPPORTED_OPERATION, { operation: 'String.prototype.normalize', form: error.message });
|
||||
}
|
||||
}
|
||||
exports.checkNormalize = checkNormalize;
|
||||
var LogLevels = { debug: 1, "default": 2, info: 2, warn: 3, error: 4, off: 5 };
|
||||
var LogLevel = LogLevels["default"];
|
||||
function setLogLevel(logLevel) {
|
||||
var level = LogLevels[logLevel];
|
||||
if (level == null) {
|
||||
warn("invliad log level - " + logLevel);
|
||||
return;
|
||||
}
|
||||
LogLevel = level;
|
||||
}
|
||||
exports.setLogLevel = setLogLevel;
|
||||
function log(logLevel, args) {
|
||||
if (LogLevel > LogLevels[logLevel]) {
|
||||
return;
|
||||
}
|
||||
console.log.apply(console, args);
|
||||
}
|
||||
function warn() {
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
log("warn", args);
|
||||
}
|
||||
exports.warn = warn;
|
||||
function info() {
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
log("info", args);
|
||||
}
|
||||
exports.info = info;
|
||||
|
||||
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;
|
||||
|
||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ethers",
|
||||
"version": "4.0.10",
|
||||
"version": "4.0.22",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ethers",
|
||||
"version": "4.0.10",
|
||||
"version": "4.0.22",
|
||||
"description": "Ethereum wallet library.",
|
||||
"main": "./index.js",
|
||||
"types": "./index.d.ts",
|
||||
|
||||
4
providers/abstract-provider.d.ts
vendored
4
providers/abstract-provider.d.ts
vendored
@@ -37,6 +37,8 @@ export interface Log {
|
||||
logIndex?: number;
|
||||
}
|
||||
export interface TransactionReceipt {
|
||||
to?: string;
|
||||
from?: string;
|
||||
contractAddress?: string;
|
||||
transactionIndex?: number;
|
||||
root?: string;
|
||||
@@ -54,7 +56,7 @@ export interface TransactionReceipt {
|
||||
export declare 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>;
|
||||
data?: Arrayish | Promise<Arrayish>;
|
||||
|
||||
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();
|
||||
}
|
||||
@@ -270,6 +280,8 @@ function checkTransactionReceiptLog(log) {
|
||||
return check(formatTransactionReceiptLog, log);
|
||||
}
|
||||
var formatTransactionReceipt = {
|
||||
to: allowNull(address_1.getAddress, null),
|
||||
from: address_1.getAddress,
|
||||
contractAddress: allowNull(address_1.getAddress, null),
|
||||
transactionIndex: checkNumber,
|
||||
root: allowNull(checkHash),
|
||||
@@ -405,6 +417,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 +436,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,28 +448,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;
|
||||
}
|
||||
var _loop_1 = function (i) {
|
||||
if (_this._emitted.block < i) {
|
||||
_this._emitted.block = i;
|
||||
// Notify all listener for each block that has passed
|
||||
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);
|
||||
};
|
||||
// Notify all listener for each block that has passed
|
||||
for (var i = _this._lastBlockNumber + 1; i <= blockNumber; i++) {
|
||||
_loop_1(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 = {};
|
||||
@@ -485,12 +507,12 @@ 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;
|
||||
@@ -528,8 +550,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 () {
|
||||
@@ -543,10 +567,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
|
||||
@@ -620,11 +641,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;
|
||||
}
|
||||
@@ -742,10 +766,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,
|
||||
@@ -823,7 +857,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;
|
||||
@@ -842,7 +876,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) {
|
||||
@@ -877,7 +911,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) {
|
||||
@@ -1056,7 +1090,7 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
return null;
|
||||
};
|
||||
BaseProvider.prototype._startPending = function () {
|
||||
console.log('WARNING: this provider does not support pending events');
|
||||
errors.warn('WARNING: this provider does not support pending events');
|
||||
};
|
||||
BaseProvider.prototype._stopPending = function () {
|
||||
};
|
||||
|
||||
@@ -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 });
|
||||
|
||||
3
providers/infura-provider.d.ts
vendored
3
providers/infura-provider.d.ts
vendored
@@ -2,7 +2,8 @@ import { JsonRpcProvider, JsonRpcSigner } from './json-rpc-provider';
|
||||
import { Networkish } from '../utils/networks';
|
||||
export declare class InfuraProvider extends JsonRpcProvider {
|
||||
readonly apiAccessToken: string;
|
||||
constructor(network?: Networkish, apiAccessToken?: string);
|
||||
readonly projectId: string;
|
||||
constructor(network?: Networkish, projectId?: string);
|
||||
protected _startPending(): void;
|
||||
getSigner(address?: string): JsonRpcSigner;
|
||||
listAccounts(): Promise<Array<string>>;
|
||||
|
||||
@@ -18,16 +18,21 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var json_rpc_provider_1 = require("./json-rpc-provider");
|
||||
var bytes_1 = require("../utils/bytes");
|
||||
var networks_1 = require("../utils/networks");
|
||||
var properties_1 = require("../utils/properties");
|
||||
var errors = __importStar(require("../errors"));
|
||||
var defaultProjectId = "7d0d81d0919f4f05b9ab6634be01ee73";
|
||||
var InfuraProvider = /** @class */ (function (_super) {
|
||||
__extends(InfuraProvider, _super);
|
||||
function InfuraProvider(network, apiAccessToken) {
|
||||
function InfuraProvider(network, projectId) {
|
||||
var _this = this;
|
||||
network = networks_1.getNetwork((network == null) ? 'homestead' : network);
|
||||
var standard = networks_1.getNetwork((network == null) ? 'homestead' : network);
|
||||
if (projectId == null) {
|
||||
projectId = defaultProjectId;
|
||||
}
|
||||
var host = null;
|
||||
switch (network.name) {
|
||||
switch (standard.name) {
|
||||
case 'homestead':
|
||||
host = 'mainnet.infura.io';
|
||||
break;
|
||||
@@ -41,19 +46,31 @@ var InfuraProvider = /** @class */ (function (_super) {
|
||||
host = 'kovan.infura.io';
|
||||
break;
|
||||
default:
|
||||
throw new Error('unsupported network');
|
||||
errors.throwError('unsupported network', errors.INVALID_ARGUMENT, {
|
||||
argument: "network",
|
||||
value: network
|
||||
});
|
||||
}
|
||||
// New-style Project ID
|
||||
if (bytes_1.isHexString("0x" + projectId, 16)) {
|
||||
_this = _super.call(this, 'https://' + host + '/v3/' + projectId, standard) || this;
|
||||
properties_1.defineReadOnly(_this, 'apiAccessToken', null);
|
||||
properties_1.defineReadOnly(_this, 'projectId', projectId);
|
||||
// Legacy API Access Token
|
||||
}
|
||||
else {
|
||||
_this = _super.call(this, 'https://' + host + '/' + projectId, standard) || this;
|
||||
properties_1.defineReadOnly(_this, 'apiAccessToken', projectId);
|
||||
properties_1.defineReadOnly(_this, 'projectId', null);
|
||||
}
|
||||
_this = _super.call(this, 'https://' + host + '/' + (apiAccessToken || ''), network) || this;
|
||||
errors.checkNew(_this, InfuraProvider);
|
||||
properties_1.defineReadOnly(_this, 'apiAccessToken', apiAccessToken || null);
|
||||
return _this;
|
||||
}
|
||||
InfuraProvider.prototype._startPending = function () {
|
||||
console.log('WARNING: INFURA does not support pending filters');
|
||||
errors.warn('WARNING: INFURA does not support pending filters');
|
||||
};
|
||||
InfuraProvider.prototype.getSigner = function (address) {
|
||||
errors.throwError('INFURA does not support signing', errors.UNSUPPORTED_OPERATION, { operation: 'getSigner' });
|
||||
return null;
|
||||
return errors.throwError('INFURA does not support signing', errors.UNSUPPORTED_OPERATION, { operation: 'getSigner' });
|
||||
};
|
||||
InfuraProvider.prototype.listAccounts = function () {
|
||||
return Promise.resolve([]);
|
||||
|
||||
@@ -29,7 +29,9 @@ var IpcProvider = /** @class */ (function (_super) {
|
||||
function IpcProvider(path, network) {
|
||||
var _this = this;
|
||||
if (path == null) {
|
||||
errors.throwError('missing path', errors.MISSING_ARGUMENT, { arg: 'path' });
|
||||
errors.throwError('missing path', errors.MISSING_ARGUMENT, {
|
||||
argument: 'path'
|
||||
});
|
||||
}
|
||||
_this = _super.call(this, 'ipc://' + path, network) || this;
|
||||
errors.checkNew(_this, IpcProvider);
|
||||
@@ -50,10 +52,14 @@ var IpcProvider = /** @class */ (function (_super) {
|
||||
jsonrpc: "2.0"
|
||||
});
|
||||
return new Promise(function (resolve, reject) {
|
||||
var response = Buffer.alloc(0);
|
||||
var stream = net_1.default.connect(_this.path);
|
||||
stream.on('data', function (data) {
|
||||
response = Buffer.concat([response, data]);
|
||||
});
|
||||
stream.on("end", function () {
|
||||
try {
|
||||
resolve(JSON.parse(data.toString('utf8')).result);
|
||||
resolve(JSON.parse(response.toString('utf8')).result);
|
||||
// @TODO: Better pull apart the error
|
||||
stream.destroy();
|
||||
}
|
||||
@@ -62,9 +68,6 @@ var IpcProvider = /** @class */ (function (_super) {
|
||||
stream.destroy();
|
||||
}
|
||||
});
|
||||
stream.on('end', function () {
|
||||
stream.destroy();
|
||||
});
|
||||
stream.on('error', function (error) {
|
||||
reject(error);
|
||||
stream.destroy();
|
||||
|
||||
1
providers/json-rpc-provider.d.ts
vendored
1
providers/json-rpc-provider.d.ts
vendored
@@ -13,6 +13,7 @@ export declare class JsonRpcSigner extends Signer {
|
||||
getAddress(): Promise<string>;
|
||||
getBalance(blockTag?: BlockTag): Promise<BigNumber>;
|
||||
getTransactionCount(blockTag?: BlockTag): Promise<number>;
|
||||
sendUncheckedTransaction(transaction: TransactionRequest): Promise<string>;
|
||||
sendTransaction(transaction: TransactionRequest): Promise<TransactionResponse>;
|
||||
signMessage(message: Arrayish | string): Promise<string>;
|
||||
unlock(password: string): Promise<boolean>;
|
||||
|
||||
@@ -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) {
|
||||
@@ -97,31 +96,32 @@ var JsonRpcSigner = /** @class */ (function (_super) {
|
||||
JsonRpcSigner.prototype.getTransactionCount = function (blockTag) {
|
||||
return this.provider.getTransactionCount(this.getAddress(), blockTag);
|
||||
};
|
||||
JsonRpcSigner.prototype.sendTransaction = function (transaction) {
|
||||
JsonRpcSigner.prototype.sendUncheckedTransaction = 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) {
|
||||
if (tx === null) {
|
||||
return undefined;
|
||||
}
|
||||
return _this.provider._wrapTransaction(tx, hash);
|
||||
});
|
||||
}, { onceBlock: _this.provider }).catch(function (error) {
|
||||
error.transactionHash = hash;
|
||||
throw error;
|
||||
});
|
||||
return hash;
|
||||
}, function (error) {
|
||||
if (error.responseText) {
|
||||
// See: JsonRpcProvider.sendTransaction (@TODO: Expose a ._throwError??)
|
||||
@@ -145,6 +145,22 @@ var JsonRpcSigner = /** @class */ (function (_super) {
|
||||
});
|
||||
});
|
||||
};
|
||||
JsonRpcSigner.prototype.sendTransaction = function (transaction) {
|
||||
var _this = this;
|
||||
return this.sendUncheckedTransaction(transaction).then(function (hash) {
|
||||
return web_1.poll(function () {
|
||||
return _this.provider.getTransaction(hash).then(function (tx) {
|
||||
if (tx === null) {
|
||||
return undefined;
|
||||
}
|
||||
return _this.provider._wrapTransaction(tx, hash);
|
||||
});
|
||||
}, { onceBlock: _this.provider }).catch(function (error) {
|
||||
error.transactionHash = hash;
|
||||
throw error;
|
||||
});
|
||||
});
|
||||
};
|
||||
JsonRpcSigner.prototype.signMessage = function (message) {
|
||||
var _this = this;
|
||||
var data = ((typeof (message) === 'string') ? utf8_1.toUtf8Bytes(message) : message);
|
||||
@@ -308,6 +324,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.10";
|
||||
export const version = "4.0.22";
|
||||
|
||||
@@ -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);
|
||||
@@ -411,7 +411,6 @@ export class Contract {
|
||||
if (address == null) { throw new Error('name not found'); }
|
||||
return address;
|
||||
}).catch((error: Error) => {
|
||||
console.log('ERROR: Cannot find Contract - ' + addressOrName);
|
||||
throw error;
|
||||
}));
|
||||
} else {
|
||||
@@ -429,7 +428,7 @@ export class Contract {
|
||||
if ((<any>this)[name] == null) {
|
||||
defineReadOnly(this, name, run);
|
||||
} else {
|
||||
console.log('WARNING: Multiple definitions for ' + name);
|
||||
errors.warn('WARNING: Multiple definitions for ' + name);
|
||||
}
|
||||
|
||||
if (this.functions[name] == null) {
|
||||
@@ -697,7 +696,15 @@ export class Contract {
|
||||
|
||||
let eventFilter = this._getEventFilter(eventName);
|
||||
this._events = this._events.filter((event) => {
|
||||
return event.eventFilter.eventTag !== eventFilter.eventTag
|
||||
|
||||
// Keep all other events
|
||||
if (event.eventFilter.eventTag !== eventFilter.eventTag) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Deregister this event from the provider and filter it out
|
||||
this.provider.removeListener(event.eventFilter.filter, event.wrappedListener);
|
||||
return false;
|
||||
});
|
||||
|
||||
return this;
|
||||
|
||||
@@ -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,7 +116,7 @@ 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;
|
||||
@@ -125,10 +125,44 @@ export function setCensorship(censorship: boolean, permanent?: boolean): void {
|
||||
|
||||
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')
|
||||
throw new Error('broken implementation')
|
||||
}
|
||||
} catch (error) {
|
||||
throwError('platform missing String.prototype.normalize', UNSUPPORTED_OPERATION, { operation: 'String.prototype.normalize' });
|
||||
throwError('platform missing String.prototype.normalize', UNSUPPORTED_OPERATION, { operation: 'String.prototype.normalize', form: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
const LogLevels: { [ name: string ]: number } = { debug: 1, "default": 2, info: 2, warn: 3, error: 4, off: 5 };
|
||||
let LogLevel = LogLevels["default"];
|
||||
|
||||
export function setLogLevel(logLevel: string): void {
|
||||
let level = LogLevels[logLevel];
|
||||
if (level == null) {
|
||||
warn("invliad log level - " + logLevel);
|
||||
return;
|
||||
}
|
||||
LogLevel = level;
|
||||
}
|
||||
|
||||
function log(logLevel: string, args: Array<any>): void {
|
||||
if (LogLevel > LogLevels[logLevel]) { return; }
|
||||
console.log.apply(console, args);
|
||||
}
|
||||
|
||||
export function warn(...args: Array<any>): void {
|
||||
log("warn", args);
|
||||
}
|
||||
|
||||
export function info(...args: Array<any>): void {
|
||||
log("info", args);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -60,6 +60,8 @@ export interface Log {
|
||||
}
|
||||
|
||||
export interface TransactionReceipt {
|
||||
to?: string;
|
||||
from?: string;
|
||||
contractAddress?: string,
|
||||
transactionIndex?: number,
|
||||
root?: string,
|
||||
@@ -78,7 +80,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();
|
||||
}
|
||||
@@ -306,6 +314,8 @@ function checkTransactionReceiptLog(log: any): any {
|
||||
}
|
||||
|
||||
const formatTransactionReceipt = {
|
||||
to: allowNull(getAddress, null),
|
||||
from: allowNull(getAddress, null), // Gaanche does not populate this (#400)
|
||||
contractAddress: allowNull(getAddress, null),
|
||||
transactionIndex: checkNumber,
|
||||
root: allowNull(checkHash),
|
||||
@@ -522,6 +532,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) {
|
||||
@@ -751,8 +764,9 @@ export class BaseProvider extends Provider {
|
||||
if (confirmations == null) { confirmations = 1; }
|
||||
return poll(() => {
|
||||
return this.getTransactionReceipt(transactionHash).then((receipt) => {
|
||||
if (receipt == null && confirmations !== 0) {
|
||||
if (receipt.confirmations < confirmations) { return undefined; }
|
||||
if (confirmations === 0) { return receipt; }
|
||||
if (receipt == null || receipt.confirmations < confirmations) {
|
||||
return undefined;
|
||||
}
|
||||
return receipt;
|
||||
});
|
||||
@@ -874,6 +888,7 @@ export class BaseProvider extends Provider {
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -977,7 +992,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) {
|
||||
@@ -1014,7 +1029,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) {
|
||||
@@ -1211,7 +1226,7 @@ export class BaseProvider extends Provider {
|
||||
}
|
||||
|
||||
protected _startPending(): void {
|
||||
console.log('WARNING: this provider does not support pending events');
|
||||
errors.warn('WARNING: this provider does not support pending events');
|
||||
}
|
||||
|
||||
protected _stopPending(): void {
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { JsonRpcProvider, JsonRpcSigner } from './json-rpc-provider';
|
||||
|
||||
import { isHexString } from "../utils/bytes";
|
||||
import { getNetwork } from '../utils/networks';
|
||||
import { defineReadOnly } from '../utils/properties';
|
||||
|
||||
@@ -10,14 +11,18 @@ import { Networkish } from '../utils/networks';
|
||||
|
||||
import * as errors from '../errors';
|
||||
|
||||
const defaultProjectId = "7d0d81d0919f4f05b9ab6634be01ee73";
|
||||
|
||||
export class InfuraProvider extends JsonRpcProvider {
|
||||
readonly apiAccessToken: string;
|
||||
readonly projectId: string;
|
||||
|
||||
constructor(network?: Networkish, apiAccessToken?: string) {
|
||||
network = getNetwork((network == null) ? 'homestead': network);
|
||||
constructor(network?: Networkish, projectId?: string) {
|
||||
let standard = getNetwork((network == null) ? 'homestead': network);
|
||||
if (projectId == null) { projectId = defaultProjectId; }
|
||||
|
||||
var host = null;
|
||||
switch(network.name) {
|
||||
let host = null;
|
||||
switch(standard.name) {
|
||||
case 'homestead':
|
||||
host = 'mainnet.infura.io';
|
||||
break;
|
||||
@@ -31,26 +36,38 @@ export class InfuraProvider extends JsonRpcProvider {
|
||||
host = 'kovan.infura.io';
|
||||
break;
|
||||
default:
|
||||
throw new Error('unsupported network');
|
||||
errors.throwError('unsupported network', errors.INVALID_ARGUMENT, {
|
||||
argument: "network",
|
||||
value: network
|
||||
});
|
||||
}
|
||||
|
||||
super('https://' + host + '/' + (apiAccessToken || ''), network);
|
||||
errors.checkNew(this, InfuraProvider);
|
||||
// New-style Project ID
|
||||
if (isHexString("0x" + projectId, 16)) {
|
||||
super('https://' + host + '/v3/' + projectId, standard);
|
||||
defineReadOnly(this, 'apiAccessToken', null);
|
||||
defineReadOnly(this, 'projectId', projectId);
|
||||
|
||||
defineReadOnly(this, 'apiAccessToken', apiAccessToken || null);
|
||||
// Legacy API Access Token
|
||||
} else {
|
||||
super('https://' + host + '/' + projectId, standard);
|
||||
defineReadOnly(this, 'apiAccessToken', projectId);
|
||||
defineReadOnly(this, 'projectId', null);
|
||||
}
|
||||
|
||||
errors.checkNew(this, InfuraProvider);
|
||||
}
|
||||
|
||||
protected _startPending(): void {
|
||||
console.log('WARNING: INFURA does not support pending filters');
|
||||
errors.warn('WARNING: INFURA does not support pending filters');
|
||||
}
|
||||
|
||||
getSigner(address?: string): JsonRpcSigner {
|
||||
errors.throwError(
|
||||
return errors.throwError(
|
||||
'INFURA does not support signing',
|
||||
errors.UNSUPPORTED_OPERATION,
|
||||
{ operation: 'getSigner' }
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
listAccounts(): Promise<Array<string>> {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
import net from 'net';
|
||||
|
||||
@@ -10,12 +11,15 @@ import { Networkish } from '../utils/networks';
|
||||
|
||||
import * as errors from '../errors';
|
||||
|
||||
|
||||
export class IpcProvider extends JsonRpcProvider {
|
||||
readonly path: string;
|
||||
|
||||
constructor(path: string, network?: Networkish) {
|
||||
if (path == null) {
|
||||
errors.throwError('missing path', errors.MISSING_ARGUMENT, { arg: 'path' });
|
||||
errors.throwError('missing path', errors.MISSING_ARGUMENT, {
|
||||
argument: 'path'
|
||||
});
|
||||
}
|
||||
|
||||
super('ipc://' + path, network);
|
||||
@@ -32,7 +36,7 @@ export class IpcProvider extends JsonRpcProvider {
|
||||
// advantage we are aiming for now is security. This simplifies
|
||||
// multiplexing requests (since we do not need to multiplex).
|
||||
|
||||
var payload = JSON.stringify({
|
||||
let payload = JSON.stringify({
|
||||
method: method,
|
||||
params: params,
|
||||
id: 42,
|
||||
@@ -40,10 +44,17 @@ export class IpcProvider extends JsonRpcProvider {
|
||||
});
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
var stream = net.connect(this.path);
|
||||
stream.on('data', function(data) {
|
||||
let response = Buffer.alloc(0);
|
||||
|
||||
let stream = net.connect(this.path);
|
||||
|
||||
stream.on('data', (data) => {
|
||||
response = Buffer.concat([ response, data ]);
|
||||
});
|
||||
|
||||
stream.on("end", () => {
|
||||
try {
|
||||
resolve(JSON.parse(data.toString('utf8')).result);
|
||||
resolve(JSON.parse(response.toString('utf8')).result);
|
||||
// @TODO: Better pull apart the error
|
||||
stream.destroy();
|
||||
} catch (error) {
|
||||
@@ -52,14 +63,11 @@ export class IpcProvider extends JsonRpcProvider {
|
||||
}
|
||||
});
|
||||
|
||||
stream.on('end', function() {
|
||||
stream.destroy();
|
||||
});
|
||||
|
||||
stream.on('error', function(error) {
|
||||
stream.on('error', (error) => {
|
||||
reject(error);
|
||||
stream.destroy();
|
||||
});
|
||||
|
||||
stream.write(payload);
|
||||
stream.end();
|
||||
});
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -35,7 +34,7 @@ function timer(timeout: number): Promise<any> {
|
||||
function getResult(payload: { error?: { code?: number, data?: any, message?: string }, result?: any }): any {
|
||||
if (payload.error) {
|
||||
// @TODO: not any
|
||||
var error: any = new Error(payload.error.message);
|
||||
let error: any = new Error(payload.error.message);
|
||||
error.code = payload.error.code;
|
||||
error.data = payload.error.data;
|
||||
throw error;
|
||||
@@ -102,28 +101,32 @@ export class JsonRpcSigner extends Signer {
|
||||
return this.provider.getTransactionCount(this.getAddress(), blockTag);
|
||||
}
|
||||
|
||||
sendTransaction(transaction: TransactionRequest): Promise<TransactionResponse> {
|
||||
sendUncheckedTransaction(transaction: TransactionRequest): Promise<string> {
|
||||
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) => {
|
||||
if (tx === null) { return undefined; }
|
||||
return this.provider._wrapTransaction(tx, hash);
|
||||
});
|
||||
}, { onceBlock: this.provider }).catch((error: Error) => {
|
||||
(<any>error).transactionHash = hash;
|
||||
throw error;
|
||||
});
|
||||
return hash;
|
||||
}, (error) => {
|
||||
if (error.responseText) {
|
||||
// See: JsonRpcProvider.sendTransaction (@TODO: Expose a ._throwError??)
|
||||
@@ -148,8 +151,22 @@ export class JsonRpcSigner extends Signer {
|
||||
});
|
||||
}
|
||||
|
||||
sendTransaction(transaction: TransactionRequest): Promise<TransactionResponse> {
|
||||
return this.sendUncheckedTransaction(transaction).then((hash) => {
|
||||
return poll(() => {
|
||||
return this.provider.getTransaction(hash).then((tx: TransactionResponse) => {
|
||||
if (tx === null) { return undefined; }
|
||||
return this.provider._wrapTransaction(tx, hash);
|
||||
});
|
||||
}, { onceBlock: this.provider }).catch((error: Error) => {
|
||||
(<any>error).transactionHash = hash;
|
||||
throw error;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
signMessage(message: Arrayish | string): Promise<string> {
|
||||
var data = ((typeof(message) === 'string') ? toUtf8Bytes(message): message);
|
||||
let data = ((typeof(message) === 'string') ? toUtf8Bytes(message): message);
|
||||
return this.getAddress().then((address) => {
|
||||
|
||||
// https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
|
||||
@@ -158,7 +175,7 @@ export class JsonRpcSigner extends Signer {
|
||||
}
|
||||
|
||||
unlock(password: string): Promise<boolean> {
|
||||
var provider = this.provider;
|
||||
let provider = this.provider;
|
||||
|
||||
return this.getAddress().then(function(address) {
|
||||
return provider.send('personal_unlockAccount', [ address.toLowerCase(), password, null ]);
|
||||
@@ -323,9 +340,9 @@ export class JsonRpcProvider extends BaseProvider {
|
||||
|
||||
protected _startPending(): void {
|
||||
if (this._pendingFilter != null) { return; }
|
||||
var self = this;
|
||||
let self = this;
|
||||
|
||||
var pendingFilter: Promise<number> = this.send('eth_newPendingTransactionFilter', []);
|
||||
let pendingFilter: Promise<number> = this.send('eth_newPendingTransactionFilter', []);
|
||||
this._pendingFilter = pendingFilter;
|
||||
|
||||
pendingFilter.then(function(filterId) {
|
||||
@@ -333,7 +350,7 @@ export class JsonRpcProvider extends BaseProvider {
|
||||
self.send('eth_getFilterChanges', [ filterId ]).then(function(hashes: Array<string>) {
|
||||
if (self._pendingFilter != pendingFilter) { return null; }
|
||||
|
||||
var seq = Promise.resolve();
|
||||
let seq = Promise.resolve();
|
||||
hashes.forEach(function(hash) {
|
||||
// @TODO: This should be garbage collected at some point... How? When?
|
||||
self._emitted['t:' + hash.toLowerCase()] = 'pending';
|
||||
|
||||
@@ -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;
|
||||
@@ -263,7 +266,7 @@ function parseSignatureEvent(fragment: string): EventFragment {
|
||||
case '':
|
||||
break;
|
||||
default:
|
||||
console.log('unknown modifier: ' + modifier);
|
||||
errors.info('unknown modifier: ' + modifier);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -333,7 +336,7 @@ function parseSignatureFunction(fragment: string): FunctionFragment {
|
||||
case '':
|
||||
break;
|
||||
default:
|
||||
console.log('unknown modifier: ' + modifier);
|
||||
errors.info('unknown modifier: ' + modifier);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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);
|
||||
]));
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ export class HDNode {
|
||||
// Base path
|
||||
var mnemonic = this.mnemonic;
|
||||
var path = this.path;
|
||||
if (path) { path += '/' + index; }
|
||||
if (path) { path += '/' + (index & ~HardenedBit); }
|
||||
|
||||
if (index & HardenedBit) {
|
||||
// Data = 0x00 || ser_256(k_par)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -320,13 +320,18 @@ function addMethod(method: any): void {
|
||||
payable: (method.payable == null || !!method.payable),
|
||||
type: ((method.constant) ? 'call': 'transaction'),
|
||||
|
||||
name: method.name,
|
||||
signature: signature,
|
||||
sighash: sighash,
|
||||
});
|
||||
|
||||
// Expose the first (and hopefully unique named function
|
||||
if (method.name && this.functions[method.name] == null) {
|
||||
defineReadOnly(this.functions, method.name, description);
|
||||
// Expose the first (and hopefully unique named function)
|
||||
if (method.name) {
|
||||
if (this.functions[method.name] == null) {
|
||||
defineReadOnly(this.functions, method.name, description);
|
||||
} else {
|
||||
errors.warn('WARNING: Multiple definitions for ' + method.name);
|
||||
}
|
||||
}
|
||||
|
||||
// Expose all methods by their signature, for overloaded functions
|
||||
@@ -367,7 +372,7 @@ function addMethod(method: any): void {
|
||||
break;
|
||||
|
||||
default:
|
||||
console.log('WARNING: unsupported ABI type - ' + method.type);
|
||||
errors.warn('WARNING: unsupported ABI type - ' + method.type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -433,10 +438,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)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -438,6 +438,7 @@ export function encrypt(privateKey: Arrayish | SigningKey, password: Arrayish |
|
||||
gethFilename: ('UTC--' + timestamp + '--' + data.address),
|
||||
mnemonicCounter: hexlify(mnemonicIv).substring(2),
|
||||
mnemonicCiphertext: hexlify(mnemonicCiphertext).substring(2),
|
||||
path: path,
|
||||
version: "0.1"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ export function parse(rawTransaction: Arrayish): Transaction {
|
||||
tx.v = bigNumberify(transaction[6]).toNumber();
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
errors.info(error);
|
||||
return tx;
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ export function parse(rawTransaction: Arrayish): Transaction {
|
||||
try {
|
||||
tx.from = recoverAddress(digest, { r: hexlify(tx.r), s: hexlify(tx.s), recoveryParam: recoveryParam });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
errors.info(error);
|
||||
}
|
||||
|
||||
tx.hash = keccak256(rawTransaction);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -47,7 +47,7 @@ export class Wallet extends AbstractSigner {
|
||||
get address(): string { return this.signingKey.address; }
|
||||
|
||||
get mnemonic(): string { return this.signingKey.mnemonic; }
|
||||
get path(): string { return this.signingKey.mnemonic; }
|
||||
get path(): string { return this.signingKey.path; }
|
||||
|
||||
get privateKey(): string { return this.signingKey.privateKey; }
|
||||
|
||||
@@ -62,7 +62,6 @@ export class Wallet extends AbstractSigner {
|
||||
return new Wallet(this.signingKey, provider);
|
||||
}
|
||||
|
||||
|
||||
getAddress(): Promise<string> {
|
||||
return Promise.resolve(this.address);
|
||||
}
|
||||
@@ -91,6 +90,13 @@ export class Wallet extends AbstractSigner {
|
||||
}
|
||||
|
||||
sendTransaction(transaction: TransactionRequest): Promise<TransactionResponse> {
|
||||
if (!this.provider) { throw new Error('missing provider'); }
|
||||
|
||||
if (transaction.nonce == null) {
|
||||
transaction = shallowCopy(transaction);
|
||||
transaction.nonce = this.getTransactionCount("pending");
|
||||
}
|
||||
|
||||
return populateTransaction(transaction, this.provider, this.address).then((tx) => {
|
||||
return this.sign(tx).then((signedTransaction) => {
|
||||
return this.provider.sendTransaction(signedTransaction);
|
||||
|
||||
@@ -1,14 +1,33 @@
|
||||
'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');
|
||||
console.log("Broken String.prototype.normalize... Forcing shim.");
|
||||
String.prototype.normalize = function(form) {
|
||||
var func = unorm[(form || 'NFC').toLowerCase()];
|
||||
if (!func) { throw new RangeError('invalid form - ' + form); }
|
||||
@@ -18,14 +37,22 @@ try {
|
||||
|
||||
// Shim atob and btoa
|
||||
var base64 = require('./base64.js');
|
||||
if (!global.atob) { global.atob = base64.atob; }
|
||||
if (!global.btoa) { global.btoa = base64.btoa; }
|
||||
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);
|
||||
@@ -34,6 +61,13 @@ if (!ArrayBuffer.isView) {
|
||||
|
||||
// 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() {
|
||||
|
||||
@@ -53,6 +53,7 @@ var blockchainData = {
|
||||
blockNumber: 0x3c92b5,
|
||||
contractAddress: null,
|
||||
cumulativeGasUsed: 0x1cca2e,
|
||||
from: "0x18C6045651826824FEBBD39d8560584078d1b247",
|
||||
gasUsed:0x14bb7,
|
||||
logs: [
|
||||
{
|
||||
@@ -78,11 +79,12 @@ var blockchainData = {
|
||||
transactionLogIndex: 0x1
|
||||
}
|
||||
],
|
||||
"logsBloom": "0x00000000000000040000000000100000010000000000000040000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000200000010000000004000000000000000000000000000000000002000000000000000000000000400000000020000000000000000000000000000000000000004000000000000000000000000000000000000000000000000801000000000000000000000020000000000040000000040000000000000000002000000004000000000000000000000000000000000000000000000010000000000000000000000000000000000200000000000000000",
|
||||
"root": "0x9b550a9a640ce50331b64504ef87aaa7e2aaf97344acb6ff111f879b319d2590",
|
||||
"status": null,
|
||||
"transactionHash": "0xc6fcb7d00d536e659a4559d2de29afa9e364094438fef3e72ba80728ce1cb616",
|
||||
"transactionIndex": 0x39
|
||||
logsBloom: "0x00000000000000040000000000100000010000000000000040000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000200000010000000004000000000000000000000000000000000002000000000000000000000000400000000020000000000000000000000000000000000000004000000000000000000000000000000000000000000000000801000000000000000000000020000000000040000000040000000000000000002000000004000000000000000000000000000000000000000000000010000000000000000000000000000000000200000000000000000",
|
||||
root: "0x9b550a9a640ce50331b64504ef87aaa7e2aaf97344acb6ff111f879b319d2590",
|
||||
status: null,
|
||||
to: "0x6090A6e47849629b7245Dfa1Ca21D94cd15878Ef",
|
||||
transactionHash: "0xc6fcb7d00d536e659a4559d2de29afa9e364094438fef3e72ba80728ce1cb616",
|
||||
transactionIndex: 0x39,
|
||||
},
|
||||
transactionReceiptByzantium: {
|
||||
byzantium: true,
|
||||
@@ -90,6 +92,7 @@ var blockchainData = {
|
||||
blockNumber: 0x444f76,
|
||||
contractAddress: null,
|
||||
cumulativeGasUsed: 0x15bfe7,
|
||||
from: "0x18C6045651826824FEBBD39d8560584078d1b247",
|
||||
gasUsed: 0x1b968,
|
||||
logs: [
|
||||
{
|
||||
@@ -106,6 +109,7 @@ var blockchainData = {
|
||||
],
|
||||
logsBloom: "0x00000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000200000000000000008000000000000000000000000000000000000000000000000000000000000000010000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000800000000000000000800000000000000000000000000000000000000",
|
||||
status:1,
|
||||
to: "0xb90E64082D00437e65A76d4c8187596BC213480a",
|
||||
transactionHash: "0x7f1c6a58dc880438236d0b0a4ae166e9e9a038dbea8ec074149bd8b176332cac",
|
||||
transactionIndex: 0x1e
|
||||
}
|
||||
@@ -170,6 +174,7 @@ var blockchainData = {
|
||||
blockNumber: 0x1564d8,
|
||||
contractAddress: null,
|
||||
cumulativeGasUsed: bigNumberify("0x80b9"),
|
||||
from: "0xb346D5019EeafC028CfC01A5f789399C2314ae8D",
|
||||
gasUsed: bigNumberify("0x80b9"),
|
||||
logs: [
|
||||
{
|
||||
@@ -186,6 +191,7 @@ var blockchainData = {
|
||||
],
|
||||
logsBloom: "0x00000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000010000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||
root: "0xf1c3506ab619ac1b5e8f1ca355b16d6b9a1b7436b2960b0e9ec9a91f4238b5cc",
|
||||
to: "0x6fC21092DA55B392b045eD78F4732bff3C580e2c",
|
||||
transactionHash: "0x55c477790b105e69e98afadf0505cbda606414b0187356137132bf24945016ce",
|
||||
transactionIndex: 0x0
|
||||
},
|
||||
@@ -195,6 +201,7 @@ var blockchainData = {
|
||||
blockNumber: 0x1e1e3b,
|
||||
contractAddress: null,
|
||||
cumulativeGasUsed: bigNumberify("0x4142f"),
|
||||
from: "0xdc8F20170C0946ACCF9627b3EB1513CFD1c0499f",
|
||||
gasUsed: bigNumberify("0x1eb6d"),
|
||||
logs:[
|
||||
{
|
||||
@@ -211,6 +218,7 @@ var blockchainData = {
|
||||
],
|
||||
logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000080000000202000000",
|
||||
status: 1,
|
||||
to: "0xB70560a43A9aBf6ea2016F40a3e84B8821E134c5",
|
||||
transactionHash: "0xf724f1d6813f13fb523c5f6af6261d06d41138dd094fff723e09fb0f893f03e6",
|
||||
transactionIndex: 0x2
|
||||
},
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -31,7 +31,7 @@ describe('Test JSON Wallets', function() {
|
||||
// A few extra test cases to test encrypting/decrypting
|
||||
['one', 'two', 'three'].forEach(function(i) {
|
||||
var password = 'foobar' + i;
|
||||
var wallet = new Wallet(utils.randomHexString('test-' + i, 32));
|
||||
var wallet = Wallet.createRandom({ path: "m/56'/82", extraEntropy: utils.randomHexString('test-' + i, 32) });
|
||||
it('encrypts and decrypts a random wallet - ' + i, function() {
|
||||
this.timeout(1200000);
|
||||
|
||||
@@ -39,6 +39,10 @@ describe('Test JSON Wallets', function() {
|
||||
return Wallet.fromEncryptedJson(json, password).then(function(decryptedWallet) {
|
||||
assert.equal(decryptedWallet.address, wallet.address,
|
||||
'decrypted wallet - ' + wallet.privateKey);
|
||||
assert.equal(decryptedWallet.mnemonic, wallet.mnemonic,
|
||||
"decrypted wallet menonic - " + wallet.privateKey);
|
||||
assert.equal(decryptedWallet.path, wallet.path,
|
||||
"decrypted wallet path - " + wallet.privateKey);
|
||||
return decryptedWallet.encrypt(password).then(function(encryptedWallet) {
|
||||
var parsedWallet = JSON.parse(encryptedWallet);
|
||||
assert.equal(decryptedWallet.address.toLowerCase().substring(2), parsedWallet.address,
|
||||
|
||||
@@ -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++) {
|
||||
@@ -194,7 +196,7 @@ function parseSignatureEvent(fragment) {
|
||||
case '':
|
||||
break;
|
||||
default:
|
||||
console.log('unknown modifier: ' + modifier);
|
||||
errors.info('unknown modifier: ' + modifier);
|
||||
}
|
||||
});
|
||||
if (abi.name && !abi.name.match(regexIdentifier)) {
|
||||
@@ -258,7 +260,7 @@ function parseSignatureFunction(fragment) {
|
||||
case '':
|
||||
break;
|
||||
default:
|
||||
console.log('unknown modifier: ' + modifier);
|
||||
errors.info('unknown modifier: ' + modifier);
|
||||
}
|
||||
});
|
||||
// We have outputs
|
||||
@@ -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);
|
||||
|
||||
1
utils/bignumber.d.ts
vendored
1
utils/bignumber.d.ts
vendored
@@ -6,6 +6,7 @@ export declare class BigNumber implements Hexable {
|
||||
constructor(value: BigNumberish);
|
||||
fromTwos(value: number): BigNumber;
|
||||
toTwos(value: number): BigNumber;
|
||||
abs(): BigNumber;
|
||||
add(other: BigNumberish): BigNumber;
|
||||
sub(other: BigNumberish): BigNumber;
|
||||
div(other: BigNumberish): BigNumber;
|
||||
|
||||
@@ -105,6 +105,12 @@ var BigNumber = /** @class */ (function () {
|
||||
BigNumber.prototype.toTwos = function (value) {
|
||||
return toBigNumber(_bnify(this).toTwos(value));
|
||||
};
|
||||
BigNumber.prototype.abs = function () {
|
||||
if (this._hex[0] === '-') {
|
||||
return toBigNumber(_bnify(this).mul(BN_1));
|
||||
}
|
||||
return this;
|
||||
};
|
||||
BigNumber.prototype.add = function (other) {
|
||||
return toBigNumber(_bnify(this).add(toBN(other)));
|
||||
};
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
'use strict';
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var errors = __importStar(require("../errors"));
|
||||
var bytes_1 = require("./bytes");
|
||||
var utf8_1 = require("./utf8");
|
||||
var keccak256_1 = require("./keccak256");
|
||||
@@ -8,13 +16,22 @@ var Zeros = new Uint8Array([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.-]*$");
|
||||
function namehash(name) {
|
||||
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)
|
||||
// libraries, so for now we simply do not support them.
|
||||
// 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 = Zeros;
|
||||
while (name.length) {
|
||||
@@ -31,11 +48,10 @@ function id(text) {
|
||||
}
|
||||
exports.id = id;
|
||||
function hashMessage(message) {
|
||||
var payload = bytes_1.concat([
|
||||
return keccak256_1.keccak256(bytes_1.concat([
|
||||
utf8_1.toUtf8Bytes('\x19Ethereum Signed Message:\n'),
|
||||
utf8_1.toUtf8Bytes(String(message.length)),
|
||||
((typeof (message) === 'string') ? utf8_1.toUtf8Bytes(message) : message)
|
||||
]);
|
||||
return keccak256_1.keccak256(payload);
|
||||
]));
|
||||
}
|
||||
exports.hashMessage = hashMessage;
|
||||
|
||||
@@ -75,7 +75,7 @@ var HDNode = /** @class */ (function () {
|
||||
var mnemonic = this.mnemonic;
|
||||
var path = this.path;
|
||||
if (path) {
|
||||
path += '/' + index;
|
||||
path += '/' + (index & ~HardenedBit);
|
||||
}
|
||||
if (index & HardenedBit) {
|
||||
// Data = 0x00 || ser_256(k_par)
|
||||
|
||||
4
utils/index.d.ts
vendored
4
utils/index.d.ts
vendored
@@ -2,7 +2,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';
|
||||
@@ -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, 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, 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, };
|
||||
|
||||
@@ -31,6 +31,7 @@ exports.hexDataLength = bytes_1.hexDataLength;
|
||||
exports.hexlify = bytes_1.hexlify;
|
||||
exports.hexStripZeros = bytes_1.hexStripZeros;
|
||||
exports.hexZeroPad = bytes_1.hexZeroPad;
|
||||
exports.isHexString = bytes_1.isHexString;
|
||||
exports.joinSignature = bytes_1.joinSignature;
|
||||
exports.padZeros = bytes_1.padZeros;
|
||||
exports.splitSignature = bytes_1.splitSignature;
|
||||
|
||||
@@ -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,12 +249,18 @@ function addMethod(method) {
|
||||
gas: method.gas,
|
||||
payable: (method.payable == null || !!method.payable),
|
||||
type: ((method.constant) ? 'call' : 'transaction'),
|
||||
name: method.name,
|
||||
signature: signature,
|
||||
sighash: sighash,
|
||||
});
|
||||
// Expose the first (and hopefully unique named function
|
||||
if (method.name && this.functions[method.name] == null) {
|
||||
properties_1.defineReadOnly(this.functions, method.name, description);
|
||||
// Expose the first (and hopefully unique named function)
|
||||
if (method.name) {
|
||||
if (this.functions[method.name] == null) {
|
||||
properties_1.defineReadOnly(this.functions, method.name, description);
|
||||
}
|
||||
else {
|
||||
errors.warn('WARNING: Multiple definitions for ' + method.name);
|
||||
}
|
||||
}
|
||||
// Expose all methods by their signature, for overloaded functions
|
||||
if (this.functions[description.signature] == null) {
|
||||
@@ -285,7 +291,7 @@ function addMethod(method) {
|
||||
// Nothing to do for fallback
|
||||
break;
|
||||
default:
|
||||
console.log('WARNING: unsupported ABI type - ' + method.type);
|
||||
errors.warn('WARNING: unsupported ABI type - ' + method.type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -339,10 +345,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;
|
||||
|
||||
@@ -384,6 +384,7 @@ function encrypt(privateKey, password, options, progressCallback) {
|
||||
gethFilename: ('UTC--' + timestamp + '--' + data.address),
|
||||
mnemonicCounter: bytes_1.hexlify(mnemonicIv).substring(2),
|
||||
mnemonicCiphertext: bytes_1.hexlify(mnemonicCiphertext).substring(2),
|
||||
path: path,
|
||||
version: "0.1"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ function parse(rawTransaction) {
|
||||
tx.v = bignumber_1.bigNumberify(transaction[6]).toNumber();
|
||||
}
|
||||
catch (error) {
|
||||
console.log(error);
|
||||
errors.info(error);
|
||||
return tx;
|
||||
}
|
||||
tx.r = bytes_1.hexZeroPad(transaction[7], 32);
|
||||
@@ -138,7 +138,7 @@ function parse(rawTransaction) {
|
||||
tx.from = secp256k1_1.recoverAddress(digest, { r: bytes_1.hexlify(tx.r), s: bytes_1.hexlify(tx.s), recoveryParam: recoveryParam });
|
||||
}
|
||||
catch (error) {
|
||||
console.log(error);
|
||||
errors.info(error);
|
||||
}
|
||||
tx.hash = keccak256_1.keccak256(rawTransaction);
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -57,7 +57,7 @@ var Wallet = /** @class */ (function (_super) {
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Wallet.prototype, "path", {
|
||||
get: function () { return this.signingKey.mnemonic; },
|
||||
get: function () { return this.signingKey.path; },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
@@ -103,6 +103,13 @@ var Wallet = /** @class */ (function (_super) {
|
||||
};
|
||||
Wallet.prototype.sendTransaction = function (transaction) {
|
||||
var _this = this;
|
||||
if (!this.provider) {
|
||||
throw new Error('missing provider');
|
||||
}
|
||||
if (transaction.nonce == null) {
|
||||
transaction = properties_1.shallowCopy(transaction);
|
||||
transaction.nonce = this.getTransactionCount("pending");
|
||||
}
|
||||
return transaction_1.populateTransaction(transaction, this.provider, this.address).then(function (tx) {
|
||||
return _this.sign(tx).then(function (signedTransaction) {
|
||||
return _this.provider.sendTransaction(signedTransaction);
|
||||
|
||||
Reference in New Issue
Block a user