Updated dist files.

This commit is contained in:
Richard Moore 2018-10-14 19:05:38 -04:00
parent d54609a458
commit fa68385cfe
No known key found for this signature in database
GPG Key ID: 525F70A6FCABC295
19 changed files with 231 additions and 165 deletions

2
_version.d.ts vendored

@ -1 +1 @@
export declare const version = "4.0.6"; export declare const version = "4.0.7";

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

181
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){ (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"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.version = "4.0.6"; exports.version = "4.0.7";
},{}],2:[function(require,module,exports){ },{}],2:[function(require,module,exports){
"use strict"; "use strict";
@ -10938,6 +10938,9 @@ var BaseProvider = /** @class */ (function (_super) {
result = true; result = true;
return !(event.once); return !(event.once);
}); });
if (this.listenerCount() === 0) {
this.polling = false;
}
return result; return result;
}; };
BaseProvider.prototype.listenerCount = function (eventName) { BaseProvider.prototype.listenerCount = function (eventName) {
@ -11538,13 +11541,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
// See: https://github.com/ethereum/wiki/wiki/JSON-RPC // See: https://github.com/ethereum/wiki/wiki/JSON-RPC
var base_provider_1 = require("./base-provider"); var base_provider_1 = require("./base-provider");
var abstract_signer_1 = require("../abstract-signer"); var abstract_signer_1 = require("../abstract-signer");
var errors = __importStar(require("../errors"));
var address_1 = require("../utils/address"); var address_1 = require("../utils/address");
var bytes_1 = require("../utils/bytes"); var bytes_1 = require("../utils/bytes");
var networks_1 = require("../utils/networks"); var networks_1 = require("../utils/networks");
var properties_1 = require("../utils/properties"); var properties_1 = require("../utils/properties");
var transaction_1 = require("../utils/transaction");
var utf8_1 = require("../utils/utf8"); var utf8_1 = require("../utils/utf8");
var web_1 = require("../utils/web"); var web_1 = require("../utils/web");
var errors = __importStar(require("../errors"));
function timer(timeout) { function timer(timeout) {
return new Promise(function (resolve) { return new Promise(function (resolve) {
setTimeout(function () { setTimeout(function () {
@ -11595,14 +11599,6 @@ var JsonRpcSigner = /** @class */ (function (_super) {
} }
return _this; return _this;
} }
/* May add back in the future; for now it is considered confusing. :)
get address(): string {
if (!this._address) {
errors.throwError('no sync sync address available; use getAddress', errors.UNSUPPORTED_OPERATION, { operation: 'address' });
}
return this._address
}
*/
JsonRpcSigner.prototype.getAddress = function () { JsonRpcSigner.prototype.getAddress = function () {
var _this = this; var _this = this;
if (this._address) { if (this._address) {
@ -11624,20 +11620,18 @@ var JsonRpcSigner = /** @class */ (function (_super) {
}; };
JsonRpcSigner.prototype.sendTransaction = function (transaction) { JsonRpcSigner.prototype.sendTransaction = function (transaction) {
var _this = this; var _this = this;
var tx = properties_1.shallowCopy(transaction); // Once populateTransaction resolves, the from address will be populated from getAddress
if (tx.from == null) { var from = null;
tx.from = this.getAddress().then(function (address) { var getAddress = this.getAddress().then(function (address) {
if (!address) { if (address) {
return null; from = address.toLowerCase();
} }
return address.toLowerCase(); return from;
}); });
} return transaction_1.populateTransaction(transaction, this.provider, getAddress).then(function (tx) {
if (transaction.gasLimit == null) { var hexTx = JsonRpcProvider.hexlifyTransaction(tx);
tx.gasLimit = this.provider.estimateGas(tx); hexTx.from = from;
} return _this.provider.send('eth_sendTransaction', [hexTx]).then(function (hash) {
return properties_1.resolveProperties(tx).then(function (tx) {
return _this.provider.send('eth_sendTransaction', [JsonRpcProvider.hexlifyTransaction(tx)]).then(function (hash) {
return web_1.poll(function () { return web_1.poll(function () {
return _this.provider.getTransaction(hash).then(function (tx) { return _this.provider.getTransaction(hash).then(function (tx) {
if (tx === null) { if (tx === null) {
@ -11860,20 +11854,18 @@ var JsonRpcProvider = /** @class */ (function (_super) {
// NOTE: This allows a TransactionRequest, but all values should be resolved // NOTE: This allows a TransactionRequest, but all values should be resolved
// before this is called // before this is called
JsonRpcProvider.hexlifyTransaction = function (transaction, allowExtra) { JsonRpcProvider.hexlifyTransaction = function (transaction, allowExtra) {
if (!allowExtra) { // Check only allowed properties are given
allowExtra = {}; var allowed = properties_1.shallowCopy(allowedTransactionKeys);
} if (allowExtra) {
for (var key in transaction) { for (var key in allowExtra) {
if (!allowedTransactionKeys[key] && !allowExtra[key]) { if (allowExtra[key]) {
errors.throwError('invalid key - ' + key, errors.INVALID_ARGUMENT, { allowed[key] = true;
argument: 'transaction',
value: transaction,
key: key
});
} }
} }
}
properties_1.checkProperties(transaction, allowed);
var result = {}; var result = {};
// Some nodes (INFURA ropsten; INFURA mainnet is fine) don't like extra zeros. // Some nodes (INFURA ropsten; INFURA mainnet is fine) don't like leading zeros.
['gasLimit', 'gasPrice', 'nonce', 'value'].forEach(function (key) { ['gasLimit', 'gasPrice', 'nonce', 'value'].forEach(function (key) {
if (transaction[key] == null) { if (transaction[key] == null) {
return; return;
@ -11896,7 +11888,7 @@ var JsonRpcProvider = /** @class */ (function (_super) {
}(base_provider_1.BaseProvider)); }(base_provider_1.BaseProvider));
exports.JsonRpcProvider = JsonRpcProvider; exports.JsonRpcProvider = JsonRpcProvider;
},{"../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){ },{"../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){
'use strict'; 'use strict';
var __extends = (this && this.__extends) || (function () { var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf || var extendStatics = Object.setPrototypeOf ||
@ -13918,6 +13910,7 @@ exports.randomBytes = random_bytes_1.randomBytes;
var networks_1 = require("./networks"); var networks_1 = require("./networks");
exports.getNetwork = networks_1.getNetwork; exports.getNetwork = networks_1.getNetwork;
var properties_1 = require("./properties"); var properties_1 = require("./properties");
exports.checkProperties = properties_1.checkProperties;
exports.deepCopy = properties_1.deepCopy; exports.deepCopy = properties_1.deepCopy;
exports.defineReadOnly = properties_1.defineReadOnly; exports.defineReadOnly = properties_1.defineReadOnly;
exports.resolveProperties = properties_1.resolveProperties; exports.resolveProperties = properties_1.resolveProperties;
@ -13933,8 +13926,10 @@ exports.verifyMessage = secp256k1_1.verifyMessage;
var signing_key_1 = require("./signing-key"); var signing_key_1 = require("./signing-key");
exports.SigningKey = signing_key_1.SigningKey; exports.SigningKey = signing_key_1.SigningKey;
var transaction_1 = require("./transaction"); var transaction_1 = require("./transaction");
exports.parseTransaction = transaction_1.parse; exports.populateTransaction = transaction_1.populateTransaction;
exports.serializeTransaction = transaction_1.serialize; var transaction_2 = require("./transaction");
exports.parseTransaction = transaction_2.parse;
exports.serializeTransaction = transaction_2.serialize;
var utf8_1 = require("./utf8"); var utf8_1 = require("./utf8");
exports.formatBytes32String = utf8_1.formatBytes32String; exports.formatBytes32String = utf8_1.formatBytes32String;
exports.parseBytes32String = utf8_1.parseBytes32String; exports.parseBytes32String = utf8_1.parseBytes32String;
@ -14557,7 +14552,15 @@ exports.pbkdf2 = pbkdf2;
},{"../utils/bytes":62,"./hmac":65}],72:[function(require,module,exports){ },{"../utils/bytes":62,"./hmac":65}],72:[function(require,module,exports){
'use strict'; '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 }); Object.defineProperty(exports, "__esModule", { value: true });
var errors = __importStar(require("../errors"));
function defineReadOnly(object, name, value) { function defineReadOnly(object, name, value) {
Object.defineProperty(object, name, { Object.defineProperty(object, name, {
enumerable: true, enumerable: true,
@ -14596,6 +14599,24 @@ function resolveProperties(object) {
}); });
} }
exports.resolveProperties = resolveProperties; exports.resolveProperties = resolveProperties;
function checkProperties(object, properties) {
if (!object || typeof (object) !== 'object') {
errors.throwError('invalid object', errors.INVALID_ARGUMENT, {
argument: 'object',
value: object
});
}
Object.keys(object).forEach(function (key) {
if (!properties[key]) {
errors.throwError('invalid object key - ' + key, errors.INVALID_ARGUMENT, {
argument: 'transaction',
value: object,
key: key
});
}
});
}
exports.checkProperties = checkProperties;
function shallowCopy(object) { function shallowCopy(object) {
var result = {}; var result = {};
for (var key in object) { for (var key in object) {
@ -14669,7 +14690,7 @@ function inheritable(parent) {
} }
exports.inheritable = inheritable; exports.inheritable = inheritable;
},{}],73:[function(require,module,exports){ },{"../errors":5}],73:[function(require,module,exports){
(function (global){ (function (global){
'use strict'; 'use strict';
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
@ -15532,7 +15553,9 @@ var address_1 = require("./address");
var bignumber_1 = require("./bignumber"); var bignumber_1 = require("./bignumber");
var bytes_1 = require("./bytes"); var bytes_1 = require("./bytes");
var keccak256_1 = require("./keccak256"); var keccak256_1 = require("./keccak256");
var properties_1 = require("./properties");
var RLP = __importStar(require("./rlp")); var RLP = __importStar(require("./rlp"));
var abstract_provider_1 = require("../providers/abstract-provider");
/////////////////////////////// ///////////////////////////////
function handleAddress(value) { function handleAddress(value) {
if (value === '0x') { if (value === '0x') {
@ -15554,7 +15577,11 @@ var transactionFields = [
{ name: 'value', maxLength: 32 }, { name: 'value', maxLength: 32 },
{ name: 'data' }, { name: 'data' },
]; ];
var allowedTransactionKeys = {
chainId: true, data: true, gasLimit: true, gasPrice: true, nonce: true, to: true, value: true
};
function serialize(transaction, signature) { function serialize(transaction, signature) {
properties_1.checkProperties(transaction, allowedTransactionKeys);
var raw = []; var raw = [];
transactionFields.forEach(function (fieldInfo) { transactionFields.forEach(function (fieldInfo) {
var value = transaction[fieldInfo.name] || ([]); var value = transaction[fieldInfo.name] || ([]);
@ -15657,8 +15684,37 @@ function parse(rawTransaction) {
return tx; return tx;
} }
exports.parse = parse; exports.parse = parse;
function populateTransaction(transaction, provider, from) {
if (!abstract_provider_1.Provider.isProvider(provider)) {
errors.throwError('missing provider', errors.INVALID_ARGUMENT, {
argument: 'provider',
value: provider
});
}
properties_1.checkProperties(transaction, allowedTransactionKeys);
var tx = properties_1.shallowCopy(transaction);
if (tx.to != null) {
tx.to = provider.resolveName(tx.to);
}
if (tx.gasPrice == null) {
tx.gasPrice = provider.getGasPrice();
}
if (tx.nonce == null) {
tx.nonce = provider.getTransactionCount(from);
}
if (tx.gasLimit == null) {
var estimate = properties_1.shallowCopy(tx);
estimate.from = from;
tx.gasLimit = provider.estimateGas(estimate);
}
if (tx.chainId == null) {
tx.chainId = provider.getNetwork().then(function (network) { return network.chainId; });
}
return properties_1.resolveProperties(tx);
}
exports.populateTransaction = populateTransaction;
},{"../constants":3,"../errors":5,"./address":59,"./bignumber":61,"./bytes":62,"./keccak256":69,"./rlp":74,"./secp256k1":75}],82:[function(require,module,exports){ },{"../constants":3,"../errors":5,"../providers/abstract-provider":49,"./address":59,"./bignumber":61,"./bytes":62,"./keccak256":69,"./properties":72,"./rlp":74,"./secp256k1":75}],82:[function(require,module,exports){
'use strict'; 'use strict';
var __importStar = (this && this.__importStar) || function (mod) { var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod; if (mod && mod.__esModule) return mod;
@ -16032,6 +16088,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
var xmlhttprequest_1 = require("xmlhttprequest"); var xmlhttprequest_1 = require("xmlhttprequest");
var base64_1 = require("./base64"); var base64_1 = require("./base64");
var properties_1 = require("./properties");
var utf8_1 = require("./utf8"); var utf8_1 = require("./utf8");
var errors = __importStar(require("../errors")); var errors = __importStar(require("../errors"));
function fetchJson(connection, json, processFunc) { function fetchJson(connection, json, processFunc) {
@ -16167,6 +16224,7 @@ function poll(func, options) {
if (!options) { if (!options) {
options = {}; options = {};
} }
options = properties_1.shallowCopy(options);
if (options.floor == null) { if (options.floor == null) {
options.floor = 0; options.floor = 0;
} }
@ -16233,7 +16291,7 @@ function poll(func, options) {
} }
exports.poll = poll; exports.poll = poll;
},{"../errors":5,"./base64":60,"./utf8":83,"xmlhttprequest":48}],85:[function(require,module,exports){ },{"../errors":5,"./base64":60,"./properties":72,"./utf8":83,"xmlhttprequest":48}],85:[function(require,module,exports){
(function (global){ (function (global){
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
@ -16324,9 +16382,6 @@ var transaction_1 = require("./utils/transaction");
var abstract_signer_1 = require("./abstract-signer"); var abstract_signer_1 = require("./abstract-signer");
var abstract_provider_1 = require("./providers/abstract-provider"); var abstract_provider_1 = require("./providers/abstract-provider");
var errors = __importStar(require("./errors")); var errors = __importStar(require("./errors"));
var allowedTransactionKeys = {
chainId: true, data: true, gasLimit: true, gasPrice: true, nonce: true, to: true, value: true
};
var Wallet = /** @class */ (function (_super) { var Wallet = /** @class */ (function (_super) {
__extends(Wallet, _super); __extends(Wallet, _super);
function Wallet(privateKey, provider) { function Wallet(privateKey, provider) {
@ -16376,19 +16431,10 @@ var Wallet = /** @class */ (function (_super) {
}; };
Wallet.prototype.sign = function (transaction) { Wallet.prototype.sign = function (transaction) {
var _this = this; var _this = this;
for (var key in transaction) {
if (!allowedTransactionKeys[key]) {
errors.throwError('unsupported transaction property - ' + key, errors.INVALID_ARGUMENT, {
argument: 'transaction',
value: transaction,
key: key
});
}
}
return properties_1.resolveProperties(transaction).then(function (tx) { return properties_1.resolveProperties(transaction).then(function (tx) {
var rawTx = transaction_1.serialize(tx); var rawTx = transaction_1.serialize(tx);
var signature = _this.signingKey.signDigest(keccak256_1.keccak256(rawTx)); var signature = _this.signingKey.signDigest(keccak256_1.keccak256(rawTx));
return Promise.resolve(transaction_1.serialize(tx, signature)); return transaction_1.serialize(tx, signature);
}); });
}; };
Wallet.prototype.signMessage = function (message) { Wallet.prototype.signMessage = function (message) {
@ -16407,31 +16453,12 @@ var Wallet = /** @class */ (function (_super) {
return this.provider.getTransactionCount(this.address, blockTag); return this.provider.getTransactionCount(this.address, blockTag);
}; };
Wallet.prototype.sendTransaction = function (transaction) { Wallet.prototype.sendTransaction = function (transaction) {
if (!this.provider) { var _this = this;
throw new Error('missing provider'); return transaction_1.populateTransaction(transaction, this.provider, this.address).then(function (tx) {
} return _this.sign(tx).then(function (signedTransaction) {
if (!transaction || typeof (transaction) !== 'object') { return _this.provider.sendTransaction(signedTransaction);
throw new Error('invalid transaction object'); });
} });
var tx = properties_1.shallowCopy(transaction);
if (tx.to != null) {
tx.to = this.provider.resolveName(tx.to);
}
if (tx.gasPrice == null) {
tx.gasPrice = this.provider.getGasPrice();
}
if (tx.nonce == null) {
tx.nonce = this.getTransactionCount();
}
if (tx.gasLimit == null) {
var estimate = properties_1.shallowCopy(tx);
estimate.from = this.getAddress();
tx.gasLimit = this.provider.estimateGas(estimate);
}
if (tx.chainId == null) {
tx.chainId = this.provider.getNetwork().then(function (network) { return network.chainId; });
}
return this.provider.sendTransaction(this.sign(tx));
}; };
Wallet.prototype.encrypt = function (password, options, progressCallback) { Wallet.prototype.encrypt = function (password, options, progressCallback) {
if (typeof (options) === 'function' && !progressCallback) { if (typeof (options) === 'function' && !progressCallback) {

2
dist/ethers.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

12
dist/ethers.types.txt vendored

@ -219,10 +219,11 @@ declare module 'ethers/utils' {
import { keccak256 as solidityKeccak256, pack as solidityPack, sha256 as soliditySha256 } from 'ethers/utils/solidity'; import { keccak256 as solidityKeccak256, pack as solidityPack, sha256 as soliditySha256 } from 'ethers/utils/solidity';
import { randomBytes } from 'ethers/utils/random-bytes'; import { randomBytes } from 'ethers/utils/random-bytes';
import { getNetwork } from 'ethers/utils/networks'; import { getNetwork } from 'ethers/utils/networks';
import { deepCopy, defineReadOnly, resolveProperties, shallowCopy } from 'ethers/utils/properties'; import { checkProperties, deepCopy, defineReadOnly, resolveProperties, shallowCopy } from 'ethers/utils/properties';
import * as RLP from 'ethers/utils/rlp'; import * as RLP from 'ethers/utils/rlp';
import { computeAddress, computePublicKey, recoverAddress, recoverPublicKey, verifyMessage } from 'ethers/utils/secp256k1'; import { computeAddress, computePublicKey, recoverAddress, recoverPublicKey, verifyMessage } from 'ethers/utils/secp256k1';
import { SigningKey } from 'ethers/utils/signing-key'; import { SigningKey } from 'ethers/utils/signing-key';
import { populateTransaction } from 'ethers/utils/transaction';
import { parse as parseTransaction, serialize as serializeTransaction } from 'ethers/utils/transaction'; import { parse as parseTransaction, serialize as serializeTransaction } from 'ethers/utils/transaction';
import { formatBytes32String, parseBytes32String, toUtf8Bytes, toUtf8String } from 'ethers/utils/utf8'; import { formatBytes32String, parseBytes32String, toUtf8Bytes, toUtf8String } from 'ethers/utils/utf8';
import { commify, formatEther, parseEther, formatUnits, parseUnits } from 'ethers/utils/units'; import { commify, formatEther, parseEther, formatUnits, parseUnits } from 'ethers/utils/units';
@ -238,7 +239,7 @@ declare module 'ethers/utils' {
import { ConnectionInfo, OnceBlockable, PollOptions } from 'ethers/utils/web'; import { ConnectionInfo, OnceBlockable, PollOptions } from 'ethers/utils/web';
import { EncryptOptions, ProgressCallback } from 'ethers/utils/secret-storage'; import { EncryptOptions, ProgressCallback } from 'ethers/utils/secret-storage';
import { Wordlist } from 'ethers/utils/wordlist'; import { Wordlist } from 'ethers/utils/wordlist';
export { AbiCoder, defaultAbiCoder, formatSignature, formatParamType, parseSignature, parseParamType, RLP, fetchJson, getNetwork, 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, 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, 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' { declare module 'ethers/wordlists' {
@ -260,7 +261,7 @@ declare module 'ethers/utils/shims' {
} }
declare module 'ethers/_version' { declare module 'ethers/_version' {
export const version = "4.0.6"; export const version = "4.0.7";
} }
declare module 'ethers/utils/bignumber' { declare module 'ethers/utils/bignumber' {
@ -412,6 +413,7 @@ declare module 'ethers/utils/transaction' {
import { BigNumber } from 'ethers/utils/bignumber'; import { BigNumber } from 'ethers/utils/bignumber';
import { Arrayish, Signature } from 'ethers/utils/bytes'; import { Arrayish, Signature } from 'ethers/utils/bytes';
import { BigNumberish } from 'ethers/utils/bignumber'; import { BigNumberish } from 'ethers/utils/bignumber';
import { Provider } from 'ethers/providers/abstract-provider';
export type UnsignedTransaction = { export type UnsignedTransaction = {
to?: string; to?: string;
nonce?: number; nonce?: number;
@ -437,6 +439,7 @@ declare module 'ethers/utils/transaction' {
} }
export function serialize(transaction: UnsignedTransaction, signature?: Arrayish | Signature): string; export function serialize(transaction: UnsignedTransaction, signature?: Arrayish | Signature): string;
export function parse(rawTransaction: Arrayish): Transaction; export function parse(rawTransaction: Arrayish): Transaction;
export function populateTransaction(transaction: any, provider: Provider, from: string | Promise<string>): Promise<Transaction>;
} }
declare module 'ethers/providers/abstract-provider' { declare module 'ethers/providers/abstract-provider' {
@ -936,6 +939,9 @@ declare module 'ethers/utils/properties' {
export function setType(object: any, type: string): void; export function setType(object: any, type: string): void;
export function isType(object: any, type: string): boolean; export function isType(object: any, type: string): boolean;
export function resolveProperties(object: any): Promise<any>; export function resolveProperties(object: any): Promise<any>;
export function checkProperties(object: any, properties: {
[name: string]: boolean;
}): void;
export function shallowCopy(object: any): any; export function shallowCopy(object: any): any;
export function deepCopy(object: any, frozen?: boolean): any; export function deepCopy(object: any, frozen?: boolean): any;
export function inheritable(parent: any): (child: any) => void; export function inheritable(parent: any): (child: any) => void;

2
package-lock.json generated

@ -1,6 +1,6 @@
{ {
"name": "ethers", "name": "ethers",
"version": "4.0.6", "version": "4.0.7",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

@ -1,6 +1,6 @@
{ {
"name": "ethers", "name": "ethers",
"version": "4.0.6", "version": "4.0.7",
"description": "Ethereum wallet library.", "description": "Ethereum wallet library.",
"main": "./index.js", "main": "./index.js",
"types": "./index.d.ts", "types": "./index.d.ts",

@ -1095,6 +1095,9 @@ var BaseProvider = /** @class */ (function (_super) {
result = true; result = true;
return !(event.once); return !(event.once);
}); });
if (this.listenerCount() === 0) {
this.polling = false;
}
return result; return result;
}; };
BaseProvider.prototype.listenerCount = function (eventName) { BaseProvider.prototype.listenerCount = function (eventName) {

@ -20,13 +20,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
// See: https://github.com/ethereum/wiki/wiki/JSON-RPC // See: https://github.com/ethereum/wiki/wiki/JSON-RPC
var base_provider_1 = require("./base-provider"); var base_provider_1 = require("./base-provider");
var abstract_signer_1 = require("../abstract-signer"); var abstract_signer_1 = require("../abstract-signer");
var errors = __importStar(require("../errors"));
var address_1 = require("../utils/address"); var address_1 = require("../utils/address");
var bytes_1 = require("../utils/bytes"); var bytes_1 = require("../utils/bytes");
var networks_1 = require("../utils/networks"); var networks_1 = require("../utils/networks");
var properties_1 = require("../utils/properties"); var properties_1 = require("../utils/properties");
var transaction_1 = require("../utils/transaction");
var utf8_1 = require("../utils/utf8"); var utf8_1 = require("../utils/utf8");
var web_1 = require("../utils/web"); var web_1 = require("../utils/web");
var errors = __importStar(require("../errors"));
function timer(timeout) { function timer(timeout) {
return new Promise(function (resolve) { return new Promise(function (resolve) {
setTimeout(function () { setTimeout(function () {
@ -77,14 +78,6 @@ var JsonRpcSigner = /** @class */ (function (_super) {
} }
return _this; return _this;
} }
/* May add back in the future; for now it is considered confusing. :)
get address(): string {
if (!this._address) {
errors.throwError('no sync sync address available; use getAddress', errors.UNSUPPORTED_OPERATION, { operation: 'address' });
}
return this._address
}
*/
JsonRpcSigner.prototype.getAddress = function () { JsonRpcSigner.prototype.getAddress = function () {
var _this = this; var _this = this;
if (this._address) { if (this._address) {
@ -106,20 +99,18 @@ var JsonRpcSigner = /** @class */ (function (_super) {
}; };
JsonRpcSigner.prototype.sendTransaction = function (transaction) { JsonRpcSigner.prototype.sendTransaction = function (transaction) {
var _this = this; var _this = this;
var tx = properties_1.shallowCopy(transaction); // Once populateTransaction resolves, the from address will be populated from getAddress
if (tx.from == null) { var from = null;
tx.from = this.getAddress().then(function (address) { var getAddress = this.getAddress().then(function (address) {
if (!address) { if (address) {
return null; from = address.toLowerCase();
} }
return address.toLowerCase(); return from;
}); });
} return transaction_1.populateTransaction(transaction, this.provider, getAddress).then(function (tx) {
if (transaction.gasLimit == null) { var hexTx = JsonRpcProvider.hexlifyTransaction(tx);
tx.gasLimit = this.provider.estimateGas(tx); hexTx.from = from;
} return _this.provider.send('eth_sendTransaction', [hexTx]).then(function (hash) {
return properties_1.resolveProperties(tx).then(function (tx) {
return _this.provider.send('eth_sendTransaction', [JsonRpcProvider.hexlifyTransaction(tx)]).then(function (hash) {
return web_1.poll(function () { return web_1.poll(function () {
return _this.provider.getTransaction(hash).then(function (tx) { return _this.provider.getTransaction(hash).then(function (tx) {
if (tx === null) { if (tx === null) {
@ -342,20 +333,18 @@ var JsonRpcProvider = /** @class */ (function (_super) {
// NOTE: This allows a TransactionRequest, but all values should be resolved // NOTE: This allows a TransactionRequest, but all values should be resolved
// before this is called // before this is called
JsonRpcProvider.hexlifyTransaction = function (transaction, allowExtra) { JsonRpcProvider.hexlifyTransaction = function (transaction, allowExtra) {
if (!allowExtra) { // Check only allowed properties are given
allowExtra = {}; var allowed = properties_1.shallowCopy(allowedTransactionKeys);
} if (allowExtra) {
for (var key in transaction) { for (var key in allowExtra) {
if (!allowedTransactionKeys[key] && !allowExtra[key]) { if (allowExtra[key]) {
errors.throwError('invalid key - ' + key, errors.INVALID_ARGUMENT, { allowed[key] = true;
argument: 'transaction',
value: transaction,
key: key
});
} }
} }
}
properties_1.checkProperties(transaction, allowed);
var result = {}; var result = {};
// Some nodes (INFURA ropsten; INFURA mainnet is fine) don't like extra zeros. // Some nodes (INFURA ropsten; INFURA mainnet is fine) don't like leading zeros.
['gasLimit', 'gasPrice', 'nonce', 'value'].forEach(function (key) { ['gasLimit', 'gasPrice', 'nonce', 'value'].forEach(function (key) {
if (transaction[key] == null) { if (transaction[key] == null) {
return; return;

@ -1 +1 @@
export const version = "4.0.6"; export const version = "4.0.7";

5
utils/index.d.ts vendored

@ -12,10 +12,11 @@ import { sha256 } from './sha2';
import { keccak256 as solidityKeccak256, pack as solidityPack, sha256 as soliditySha256 } from './solidity'; import { keccak256 as solidityKeccak256, pack as solidityPack, sha256 as soliditySha256 } from './solidity';
import { randomBytes } from './random-bytes'; import { randomBytes } from './random-bytes';
import { getNetwork } from './networks'; import { getNetwork } from './networks';
import { deepCopy, defineReadOnly, resolveProperties, shallowCopy } from './properties'; import { checkProperties, deepCopy, defineReadOnly, resolveProperties, shallowCopy } from './properties';
import * as RLP from './rlp'; import * as RLP from './rlp';
import { computeAddress, computePublicKey, recoverAddress, recoverPublicKey, verifyMessage } from './secp256k1'; import { computeAddress, computePublicKey, recoverAddress, recoverPublicKey, verifyMessage } from './secp256k1';
import { SigningKey } from './signing-key'; import { SigningKey } from './signing-key';
import { populateTransaction } from './transaction';
import { parse as parseTransaction, serialize as serializeTransaction } from './transaction'; import { parse as parseTransaction, serialize as serializeTransaction } from './transaction';
import { formatBytes32String, parseBytes32String, toUtf8Bytes, toUtf8String } from './utf8'; import { formatBytes32String, parseBytes32String, toUtf8Bytes, toUtf8String } from './utf8';
import { commify, formatEther, parseEther, formatUnits, parseUnits } from './units'; import { commify, formatEther, parseEther, formatUnits, parseUnits } from './units';
@ -31,4 +32,4 @@ import { Transaction, UnsignedTransaction } from './transaction';
import { ConnectionInfo, OnceBlockable, PollOptions } from './web'; import { ConnectionInfo, OnceBlockable, PollOptions } from './web';
import { EncryptOptions, ProgressCallback } from './secret-storage'; import { EncryptOptions, ProgressCallback } from './secret-storage';
import { Wordlist } from './wordlist'; import { Wordlist } from './wordlist';
export { AbiCoder, defaultAbiCoder, formatSignature, formatParamType, parseSignature, parseParamType, RLP, fetchJson, getNetwork, 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, 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, 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, };

@ -58,6 +58,7 @@ exports.randomBytes = random_bytes_1.randomBytes;
var networks_1 = require("./networks"); var networks_1 = require("./networks");
exports.getNetwork = networks_1.getNetwork; exports.getNetwork = networks_1.getNetwork;
var properties_1 = require("./properties"); var properties_1 = require("./properties");
exports.checkProperties = properties_1.checkProperties;
exports.deepCopy = properties_1.deepCopy; exports.deepCopy = properties_1.deepCopy;
exports.defineReadOnly = properties_1.defineReadOnly; exports.defineReadOnly = properties_1.defineReadOnly;
exports.resolveProperties = properties_1.resolveProperties; exports.resolveProperties = properties_1.resolveProperties;
@ -73,8 +74,10 @@ exports.verifyMessage = secp256k1_1.verifyMessage;
var signing_key_1 = require("./signing-key"); var signing_key_1 = require("./signing-key");
exports.SigningKey = signing_key_1.SigningKey; exports.SigningKey = signing_key_1.SigningKey;
var transaction_1 = require("./transaction"); var transaction_1 = require("./transaction");
exports.parseTransaction = transaction_1.parse; exports.populateTransaction = transaction_1.populateTransaction;
exports.serializeTransaction = transaction_1.serialize; var transaction_2 = require("./transaction");
exports.parseTransaction = transaction_2.parse;
exports.serializeTransaction = transaction_2.serialize;
var utf8_1 = require("./utf8"); var utf8_1 = require("./utf8");
exports.formatBytes32String = utf8_1.formatBytes32String; exports.formatBytes32String = utf8_1.formatBytes32String;
exports.parseBytes32String = utf8_1.parseBytes32String; exports.parseBytes32String = utf8_1.parseBytes32String;

@ -2,6 +2,9 @@ export declare function defineReadOnly(object: any, name: string, value: any): v
export declare function setType(object: any, type: string): void; export declare function setType(object: any, type: string): void;
export declare function isType(object: any, type: string): boolean; export declare function isType(object: any, type: string): boolean;
export declare function resolveProperties(object: any): Promise<any>; export declare function resolveProperties(object: any): Promise<any>;
export declare function checkProperties(object: any, properties: {
[name: string]: boolean;
}): void;
export declare function shallowCopy(object: any): any; export declare function shallowCopy(object: any): any;
export declare function deepCopy(object: any, frozen?: boolean): any; export declare function deepCopy(object: any, frozen?: boolean): any;
export declare function inheritable(parent: any): (child: any) => void; export declare function inheritable(parent: any): (child: any) => void;

@ -1,5 +1,13 @@
'use strict'; '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 }); Object.defineProperty(exports, "__esModule", { value: true });
var errors = __importStar(require("../errors"));
function defineReadOnly(object, name, value) { function defineReadOnly(object, name, value) {
Object.defineProperty(object, name, { Object.defineProperty(object, name, {
enumerable: true, enumerable: true,
@ -38,6 +46,24 @@ function resolveProperties(object) {
}); });
} }
exports.resolveProperties = resolveProperties; exports.resolveProperties = resolveProperties;
function checkProperties(object, properties) {
if (!object || typeof (object) !== 'object') {
errors.throwError('invalid object', errors.INVALID_ARGUMENT, {
argument: 'object',
value: object
});
}
Object.keys(object).forEach(function (key) {
if (!properties[key]) {
errors.throwError('invalid object key - ' + key, errors.INVALID_ARGUMENT, {
argument: 'transaction',
value: object,
key: key
});
}
});
}
exports.checkProperties = checkProperties;
function shallowCopy(object) { function shallowCopy(object) {
var result = {}; var result = {};
for (var key in object) { for (var key in object) {

@ -1,6 +1,7 @@
import { BigNumber } from './bignumber'; import { BigNumber } from './bignumber';
import { Arrayish, Signature } from './bytes'; import { Arrayish, Signature } from './bytes';
import { BigNumberish } from './bignumber'; import { BigNumberish } from './bignumber';
import { Provider } from '../providers/abstract-provider';
export declare type UnsignedTransaction = { export declare type UnsignedTransaction = {
to?: string; to?: string;
nonce?: number; nonce?: number;
@ -26,3 +27,4 @@ export interface Transaction {
} }
export declare function serialize(transaction: UnsignedTransaction, signature?: Arrayish | Signature): string; export declare function serialize(transaction: UnsignedTransaction, signature?: Arrayish | Signature): string;
export declare function parse(rawTransaction: Arrayish): Transaction; export declare function parse(rawTransaction: Arrayish): Transaction;
export declare function populateTransaction(transaction: any, provider: Provider, from: string | Promise<string>): Promise<Transaction>;

@ -14,7 +14,9 @@ var address_1 = require("./address");
var bignumber_1 = require("./bignumber"); var bignumber_1 = require("./bignumber");
var bytes_1 = require("./bytes"); var bytes_1 = require("./bytes");
var keccak256_1 = require("./keccak256"); var keccak256_1 = require("./keccak256");
var properties_1 = require("./properties");
var RLP = __importStar(require("./rlp")); var RLP = __importStar(require("./rlp"));
var abstract_provider_1 = require("../providers/abstract-provider");
/////////////////////////////// ///////////////////////////////
function handleAddress(value) { function handleAddress(value) {
if (value === '0x') { if (value === '0x') {
@ -36,7 +38,11 @@ var transactionFields = [
{ name: 'value', maxLength: 32 }, { name: 'value', maxLength: 32 },
{ name: 'data' }, { name: 'data' },
]; ];
var allowedTransactionKeys = {
chainId: true, data: true, gasLimit: true, gasPrice: true, nonce: true, to: true, value: true
};
function serialize(transaction, signature) { function serialize(transaction, signature) {
properties_1.checkProperties(transaction, allowedTransactionKeys);
var raw = []; var raw = [];
transactionFields.forEach(function (fieldInfo) { transactionFields.forEach(function (fieldInfo) {
var value = transaction[fieldInfo.name] || ([]); var value = transaction[fieldInfo.name] || ([]);
@ -139,3 +145,32 @@ function parse(rawTransaction) {
return tx; return tx;
} }
exports.parse = parse; exports.parse = parse;
function populateTransaction(transaction, provider, from) {
if (!abstract_provider_1.Provider.isProvider(provider)) {
errors.throwError('missing provider', errors.INVALID_ARGUMENT, {
argument: 'provider',
value: provider
});
}
properties_1.checkProperties(transaction, allowedTransactionKeys);
var tx = properties_1.shallowCopy(transaction);
if (tx.to != null) {
tx.to = provider.resolveName(tx.to);
}
if (tx.gasPrice == null) {
tx.gasPrice = provider.getGasPrice();
}
if (tx.nonce == null) {
tx.nonce = provider.getTransactionCount(from);
}
if (tx.gasLimit == null) {
var estimate = properties_1.shallowCopy(tx);
estimate.from = from;
tx.gasLimit = provider.estimateGas(estimate);
}
if (tx.chainId == null) {
tx.chainId = provider.getNetwork().then(function (network) { return network.chainId; });
}
return properties_1.resolveProperties(tx);
}
exports.populateTransaction = populateTransaction;

@ -9,6 +9,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
var xmlhttprequest_1 = require("xmlhttprequest"); var xmlhttprequest_1 = require("xmlhttprequest");
var base64_1 = require("./base64"); var base64_1 = require("./base64");
var properties_1 = require("./properties");
var utf8_1 = require("./utf8"); var utf8_1 = require("./utf8");
var errors = __importStar(require("../errors")); var errors = __importStar(require("../errors"));
function fetchJson(connection, json, processFunc) { function fetchJson(connection, json, processFunc) {
@ -144,6 +145,7 @@ function poll(func, options) {
if (!options) { if (!options) {
options = {}; options = {};
} }
options = properties_1.shallowCopy(options);
if (options.floor == null) { if (options.floor == null) {
options.floor = 0; options.floor = 0;
} }

@ -31,9 +31,6 @@ var transaction_1 = require("./utils/transaction");
var abstract_signer_1 = require("./abstract-signer"); var abstract_signer_1 = require("./abstract-signer");
var abstract_provider_1 = require("./providers/abstract-provider"); var abstract_provider_1 = require("./providers/abstract-provider");
var errors = __importStar(require("./errors")); var errors = __importStar(require("./errors"));
var allowedTransactionKeys = {
chainId: true, data: true, gasLimit: true, gasPrice: true, nonce: true, to: true, value: true
};
var Wallet = /** @class */ (function (_super) { var Wallet = /** @class */ (function (_super) {
__extends(Wallet, _super); __extends(Wallet, _super);
function Wallet(privateKey, provider) { function Wallet(privateKey, provider) {
@ -83,19 +80,10 @@ var Wallet = /** @class */ (function (_super) {
}; };
Wallet.prototype.sign = function (transaction) { Wallet.prototype.sign = function (transaction) {
var _this = this; var _this = this;
for (var key in transaction) {
if (!allowedTransactionKeys[key]) {
errors.throwError('unsupported transaction property - ' + key, errors.INVALID_ARGUMENT, {
argument: 'transaction',
value: transaction,
key: key
});
}
}
return properties_1.resolveProperties(transaction).then(function (tx) { return properties_1.resolveProperties(transaction).then(function (tx) {
var rawTx = transaction_1.serialize(tx); var rawTx = transaction_1.serialize(tx);
var signature = _this.signingKey.signDigest(keccak256_1.keccak256(rawTx)); var signature = _this.signingKey.signDigest(keccak256_1.keccak256(rawTx));
return Promise.resolve(transaction_1.serialize(tx, signature)); return transaction_1.serialize(tx, signature);
}); });
}; };
Wallet.prototype.signMessage = function (message) { Wallet.prototype.signMessage = function (message) {
@ -114,31 +102,12 @@ var Wallet = /** @class */ (function (_super) {
return this.provider.getTransactionCount(this.address, blockTag); return this.provider.getTransactionCount(this.address, blockTag);
}; };
Wallet.prototype.sendTransaction = function (transaction) { Wallet.prototype.sendTransaction = function (transaction) {
if (!this.provider) { var _this = this;
throw new Error('missing provider'); return transaction_1.populateTransaction(transaction, this.provider, this.address).then(function (tx) {
} return _this.sign(tx).then(function (signedTransaction) {
if (!transaction || typeof (transaction) !== 'object') { return _this.provider.sendTransaction(signedTransaction);
throw new Error('invalid transaction object'); });
} });
var tx = properties_1.shallowCopy(transaction);
if (tx.to != null) {
tx.to = this.provider.resolveName(tx.to);
}
if (tx.gasPrice == null) {
tx.gasPrice = this.provider.getGasPrice();
}
if (tx.nonce == null) {
tx.nonce = this.getTransactionCount();
}
if (tx.gasLimit == null) {
var estimate = properties_1.shallowCopy(tx);
estimate.from = this.getAddress();
tx.gasLimit = this.provider.estimateGas(estimate);
}
if (tx.chainId == null) {
tx.chainId = this.provider.getNetwork().then(function (network) { return network.chainId; });
}
return this.provider.sendTransaction(this.sign(tx));
}; };
Wallet.prototype.encrypt = function (password, options, progressCallback) { Wallet.prototype.encrypt = function (password, options, progressCallback) {
if (typeof (options) === 'function' && !progressCallback) { if (typeof (options) === 'function' && !progressCallback) {