Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
28a52cd485 | ||
|
|
3a19f43844 | ||
|
|
4852e837d2 | ||
|
|
fa68385cfe |
2
_version.d.ts
vendored
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";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.version = "4.0.6";
|
||||
exports.version = "4.0.7";
|
||||
|
||||
185
dist/ethers.js
vendored
185
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.6";
|
||||
exports.version = "4.0.7";
|
||||
|
||||
},{}],2:[function(require,module,exports){
|
||||
"use strict";
|
||||
@@ -10938,6 +10938,9 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
result = true;
|
||||
return !(event.once);
|
||||
});
|
||||
if (this.listenerCount() === 0) {
|
||||
this.polling = false;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
BaseProvider.prototype.listenerCount = function (eventName) {
|
||||
@@ -11538,13 +11541,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
// See: https://github.com/ethereum/wiki/wiki/JSON-RPC
|
||||
var base_provider_1 = require("./base-provider");
|
||||
var abstract_signer_1 = require("../abstract-signer");
|
||||
var errors = __importStar(require("../errors"));
|
||||
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");
|
||||
var errors = __importStar(require("../errors"));
|
||||
function timer(timeout) {
|
||||
return new Promise(function (resolve) {
|
||||
setTimeout(function () {
|
||||
@@ -11595,14 +11599,6 @@ var JsonRpcSigner = /** @class */ (function (_super) {
|
||||
}
|
||||
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 () {
|
||||
var _this = this;
|
||||
if (this._address) {
|
||||
@@ -11624,20 +11620,18 @@ var JsonRpcSigner = /** @class */ (function (_super) {
|
||||
};
|
||||
JsonRpcSigner.prototype.sendTransaction = function (transaction) {
|
||||
var _this = this;
|
||||
var tx = properties_1.shallowCopy(transaction);
|
||||
if (tx.from == null) {
|
||||
tx.from = this.getAddress().then(function (address) {
|
||||
if (!address) {
|
||||
return null;
|
||||
}
|
||||
return address.toLowerCase();
|
||||
});
|
||||
}
|
||||
if (transaction.gasLimit == null) {
|
||||
tx.gasLimit = this.provider.estimateGas(tx);
|
||||
}
|
||||
return properties_1.resolveProperties(tx).then(function (tx) {
|
||||
return _this.provider.send('eth_sendTransaction', [JsonRpcProvider.hexlifyTransaction(tx)]).then(function (hash) {
|
||||
// Once populateTransaction resolves, the from address will be populated from getAddress
|
||||
var from = null;
|
||||
var getAddress = this.getAddress().then(function (address) {
|
||||
if (address) {
|
||||
from = address.toLowerCase();
|
||||
}
|
||||
return from;
|
||||
});
|
||||
return transaction_1.populateTransaction(transaction, this.provider, getAddress).then(function (tx) {
|
||||
var hexTx = JsonRpcProvider.hexlifyTransaction(tx);
|
||||
hexTx.from = from;
|
||||
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) {
|
||||
@@ -11860,20 +11854,18 @@ var JsonRpcProvider = /** @class */ (function (_super) {
|
||||
// NOTE: This allows a TransactionRequest, but all values should be resolved
|
||||
// before this is called
|
||||
JsonRpcProvider.hexlifyTransaction = function (transaction, allowExtra) {
|
||||
if (!allowExtra) {
|
||||
allowExtra = {};
|
||||
}
|
||||
for (var key in transaction) {
|
||||
if (!allowedTransactionKeys[key] && !allowExtra[key]) {
|
||||
errors.throwError('invalid key - ' + key, errors.INVALID_ARGUMENT, {
|
||||
argument: 'transaction',
|
||||
value: transaction,
|
||||
key: key
|
||||
});
|
||||
// Check only allowed properties are given
|
||||
var allowed = properties_1.shallowCopy(allowedTransactionKeys);
|
||||
if (allowExtra) {
|
||||
for (var key in allowExtra) {
|
||||
if (allowExtra[key]) {
|
||||
allowed[key] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
properties_1.checkProperties(transaction, allowed);
|
||||
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) {
|
||||
if (transaction[key] == null) {
|
||||
return;
|
||||
@@ -11896,7 +11888,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/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';
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = Object.setPrototypeOf ||
|
||||
@@ -13918,6 +13910,7 @@ exports.randomBytes = random_bytes_1.randomBytes;
|
||||
var networks_1 = require("./networks");
|
||||
exports.getNetwork = networks_1.getNetwork;
|
||||
var properties_1 = require("./properties");
|
||||
exports.checkProperties = properties_1.checkProperties;
|
||||
exports.deepCopy = properties_1.deepCopy;
|
||||
exports.defineReadOnly = properties_1.defineReadOnly;
|
||||
exports.resolveProperties = properties_1.resolveProperties;
|
||||
@@ -13933,8 +13926,10 @@ exports.verifyMessage = secp256k1_1.verifyMessage;
|
||||
var signing_key_1 = require("./signing-key");
|
||||
exports.SigningKey = signing_key_1.SigningKey;
|
||||
var transaction_1 = require("./transaction");
|
||||
exports.parseTransaction = transaction_1.parse;
|
||||
exports.serializeTransaction = transaction_1.serialize;
|
||||
exports.populateTransaction = transaction_1.populateTransaction;
|
||||
var transaction_2 = require("./transaction");
|
||||
exports.parseTransaction = transaction_2.parse;
|
||||
exports.serializeTransaction = transaction_2.serialize;
|
||||
var utf8_1 = require("./utf8");
|
||||
exports.formatBytes32String = utf8_1.formatBytes32String;
|
||||
exports.parseBytes32String = utf8_1.parseBytes32String;
|
||||
@@ -14557,7 +14552,15 @@ exports.pbkdf2 = pbkdf2;
|
||||
|
||||
},{"../utils/bytes":62,"./hmac":65}],72:[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"));
|
||||
function defineReadOnly(object, name, value) {
|
||||
Object.defineProperty(object, name, {
|
||||
enumerable: true,
|
||||
@@ -14596,6 +14599,24 @@ function resolveProperties(object) {
|
||||
});
|
||||
}
|
||||
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) {
|
||||
var result = {};
|
||||
for (var key in object) {
|
||||
@@ -14669,7 +14690,7 @@ function inheritable(parent) {
|
||||
}
|
||||
exports.inheritable = inheritable;
|
||||
|
||||
},{}],73:[function(require,module,exports){
|
||||
},{"../errors":5}],73:[function(require,module,exports){
|
||||
(function (global){
|
||||
'use strict';
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
@@ -15532,7 +15553,9 @@ var address_1 = require("./address");
|
||||
var bignumber_1 = require("./bignumber");
|
||||
var bytes_1 = require("./bytes");
|
||||
var keccak256_1 = require("./keccak256");
|
||||
var properties_1 = require("./properties");
|
||||
var RLP = __importStar(require("./rlp"));
|
||||
var abstract_provider_1 = require("../providers/abstract-provider");
|
||||
///////////////////////////////
|
||||
function handleAddress(value) {
|
||||
if (value === '0x') {
|
||||
@@ -15554,7 +15577,11 @@ var transactionFields = [
|
||||
{ name: 'value', maxLength: 32 },
|
||||
{ name: 'data' },
|
||||
];
|
||||
var allowedTransactionKeys = {
|
||||
chainId: true, data: true, gasLimit: true, gasPrice: true, nonce: true, to: true, value: true
|
||||
};
|
||||
function serialize(transaction, signature) {
|
||||
properties_1.checkProperties(transaction, allowedTransactionKeys);
|
||||
var raw = [];
|
||||
transactionFields.forEach(function (fieldInfo) {
|
||||
var value = transaction[fieldInfo.name] || ([]);
|
||||
@@ -15657,8 +15684,37 @@ function parse(rawTransaction) {
|
||||
return tx;
|
||||
}
|
||||
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';
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
@@ -16032,6 +16088,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var xmlhttprequest_1 = require("xmlhttprequest");
|
||||
var base64_1 = require("./base64");
|
||||
var properties_1 = require("./properties");
|
||||
var utf8_1 = require("./utf8");
|
||||
var errors = __importStar(require("../errors"));
|
||||
function fetchJson(connection, json, processFunc) {
|
||||
@@ -16167,6 +16224,7 @@ function poll(func, options) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
options = properties_1.shallowCopy(options);
|
||||
if (options.floor == null) {
|
||||
options.floor = 0;
|
||||
}
|
||||
@@ -16233,7 +16291,7 @@ function poll(func, options) {
|
||||
}
|
||||
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){
|
||||
"use strict";
|
||||
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_provider_1 = require("./providers/abstract-provider");
|
||||
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) {
|
||||
__extends(Wallet, _super);
|
||||
function Wallet(privateKey, provider) {
|
||||
@@ -16376,19 +16431,10 @@ var Wallet = /** @class */ (function (_super) {
|
||||
};
|
||||
Wallet.prototype.sign = function (transaction) {
|
||||
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) {
|
||||
var rawTx = transaction_1.serialize(tx);
|
||||
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) {
|
||||
@@ -16407,31 +16453,12 @@ var Wallet = /** @class */ (function (_super) {
|
||||
return this.provider.getTransactionCount(this.address, blockTag);
|
||||
};
|
||||
Wallet.prototype.sendTransaction = function (transaction) {
|
||||
if (!this.provider) {
|
||||
throw new Error('missing provider');
|
||||
}
|
||||
if (!transaction || typeof (transaction) !== 'object') {
|
||||
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));
|
||||
var _this = this;
|
||||
return transaction_1.populateTransaction(transaction, this.provider, this.address).then(function (tx) {
|
||||
return _this.sign(tx).then(function (signedTransaction) {
|
||||
return _this.provider.sendTransaction(signedTransaction);
|
||||
});
|
||||
});
|
||||
};
|
||||
Wallet.prototype.encrypt = function (password, options, progressCallback) {
|
||||
if (typeof (options) === 'function' && !progressCallback) {
|
||||
|
||||
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
12
dist/ethers.types.txt
vendored
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 { randomBytes } from 'ethers/utils/random-bytes';
|
||||
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 { computeAddress, computePublicKey, recoverAddress, recoverPublicKey, verifyMessage } from 'ethers/utils/secp256k1';
|
||||
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 { formatBytes32String, parseBytes32String, toUtf8Bytes, toUtf8String } from 'ethers/utils/utf8';
|
||||
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 { EncryptOptions, ProgressCallback } from 'ethers/utils/secret-storage';
|
||||
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' {
|
||||
@@ -260,7 +261,7 @@ declare module 'ethers/utils/shims' {
|
||||
}
|
||||
|
||||
declare module 'ethers/_version' {
|
||||
export const version = "4.0.6";
|
||||
export const version = "4.0.7";
|
||||
}
|
||||
|
||||
declare module 'ethers/utils/bignumber' {
|
||||
@@ -412,6 +413,7 @@ declare module 'ethers/utils/transaction' {
|
||||
import { BigNumber } from 'ethers/utils/bignumber';
|
||||
import { Arrayish, Signature } from 'ethers/utils/bytes';
|
||||
import { BigNumberish } from 'ethers/utils/bignumber';
|
||||
import { Provider } from 'ethers/providers/abstract-provider';
|
||||
export type UnsignedTransaction = {
|
||||
to?: string;
|
||||
nonce?: number;
|
||||
@@ -437,6 +439,7 @@ declare module 'ethers/utils/transaction' {
|
||||
}
|
||||
export function serialize(transaction: UnsignedTransaction, signature?: Arrayish | Signature): string;
|
||||
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' {
|
||||
@@ -936,6 +939,9 @@ declare module 'ethers/utils/properties' {
|
||||
export function setType(object: any, type: string): void;
|
||||
export function isType(object: any, type: string): boolean;
|
||||
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 deepCopy(object: any, frozen?: boolean): any;
|
||||
export function inheritable(parent: any): (child: any) => void;
|
||||
|
||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ethers",
|
||||
"version": "4.0.6",
|
||||
"version": "4.0.7",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ethers",
|
||||
"version": "4.0.6",
|
||||
"version": "4.0.7",
|
||||
"description": "Ethereum wallet library.",
|
||||
"main": "./index.js",
|
||||
"types": "./index.d.ts",
|
||||
|
||||
@@ -1095,6 +1095,9 @@ var BaseProvider = /** @class */ (function (_super) {
|
||||
result = true;
|
||||
return !(event.once);
|
||||
});
|
||||
if (this.listenerCount() === 0) {
|
||||
this.polling = false;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
BaseProvider.prototype.listenerCount = function (eventName) {
|
||||
|
||||
@@ -20,13 +20,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
// See: https://github.com/ethereum/wiki/wiki/JSON-RPC
|
||||
var base_provider_1 = require("./base-provider");
|
||||
var abstract_signer_1 = require("../abstract-signer");
|
||||
var errors = __importStar(require("../errors"));
|
||||
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");
|
||||
var errors = __importStar(require("../errors"));
|
||||
function timer(timeout) {
|
||||
return new Promise(function (resolve) {
|
||||
setTimeout(function () {
|
||||
@@ -77,14 +78,6 @@ var JsonRpcSigner = /** @class */ (function (_super) {
|
||||
}
|
||||
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 () {
|
||||
var _this = this;
|
||||
if (this._address) {
|
||||
@@ -106,20 +99,18 @@ var JsonRpcSigner = /** @class */ (function (_super) {
|
||||
};
|
||||
JsonRpcSigner.prototype.sendTransaction = function (transaction) {
|
||||
var _this = this;
|
||||
var tx = properties_1.shallowCopy(transaction);
|
||||
if (tx.from == null) {
|
||||
tx.from = this.getAddress().then(function (address) {
|
||||
if (!address) {
|
||||
return null;
|
||||
}
|
||||
return address.toLowerCase();
|
||||
});
|
||||
}
|
||||
if (transaction.gasLimit == null) {
|
||||
tx.gasLimit = this.provider.estimateGas(tx);
|
||||
}
|
||||
return properties_1.resolveProperties(tx).then(function (tx) {
|
||||
return _this.provider.send('eth_sendTransaction', [JsonRpcProvider.hexlifyTransaction(tx)]).then(function (hash) {
|
||||
// Once populateTransaction resolves, the from address will be populated from getAddress
|
||||
var from = null;
|
||||
var getAddress = this.getAddress().then(function (address) {
|
||||
if (address) {
|
||||
from = address.toLowerCase();
|
||||
}
|
||||
return from;
|
||||
});
|
||||
return transaction_1.populateTransaction(transaction, this.provider, getAddress).then(function (tx) {
|
||||
var hexTx = JsonRpcProvider.hexlifyTransaction(tx);
|
||||
hexTx.from = from;
|
||||
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) {
|
||||
@@ -342,20 +333,18 @@ var JsonRpcProvider = /** @class */ (function (_super) {
|
||||
// NOTE: This allows a TransactionRequest, but all values should be resolved
|
||||
// before this is called
|
||||
JsonRpcProvider.hexlifyTransaction = function (transaction, allowExtra) {
|
||||
if (!allowExtra) {
|
||||
allowExtra = {};
|
||||
}
|
||||
for (var key in transaction) {
|
||||
if (!allowedTransactionKeys[key] && !allowExtra[key]) {
|
||||
errors.throwError('invalid key - ' + key, errors.INVALID_ARGUMENT, {
|
||||
argument: 'transaction',
|
||||
value: transaction,
|
||||
key: key
|
||||
});
|
||||
// Check only allowed properties are given
|
||||
var allowed = properties_1.shallowCopy(allowedTransactionKeys);
|
||||
if (allowExtra) {
|
||||
for (var key in allowExtra) {
|
||||
if (allowExtra[key]) {
|
||||
allowed[key] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
properties_1.checkProperties(transaction, allowed);
|
||||
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) {
|
||||
if (transaction[key] == null) {
|
||||
return;
|
||||
|
||||
@@ -1 +1 @@
|
||||
export const version = "4.0.6";
|
||||
export const version = "4.0.7";
|
||||
|
||||
@@ -158,9 +158,10 @@ function runMethod(contract: Contract, functionName: string, estimateOnly: boole
|
||||
|
||||
if (tx.blockTag != null) {
|
||||
blockTag = tx.blockTag;
|
||||
delete tx.blockTag;
|
||||
}
|
||||
|
||||
delete tx.blockTag;
|
||||
|
||||
// Check for unexpected keys (e.g. using "gas" instead of "gasLimit")
|
||||
for (let key in tx) {
|
||||
if (!allowedTransactionKeys[key]) {
|
||||
|
||||
@@ -38,10 +38,10 @@ import { Network, Networkish } from '../utils/networks';
|
||||
|
||||
// @TODO: not any?
|
||||
function check(format: any, object: any): any {
|
||||
var result: any = {};
|
||||
for (var key in format) {
|
||||
let result: any = {};
|
||||
for (let key in format) {
|
||||
try {
|
||||
var value = format[key](object[key]);
|
||||
let value = format[key](object[key]);
|
||||
if (value !== undefined) { result[key] = value; }
|
||||
} catch (error) {
|
||||
error.checkKey = key;
|
||||
@@ -72,7 +72,7 @@ function arrayOf(check: CheckFunc): CheckFunc {
|
||||
return (function(array: any): Array<any> {
|
||||
if (!Array.isArray(array)) { throw new Error('not an array'); }
|
||||
|
||||
var result: any = [];
|
||||
let result: any = [];
|
||||
|
||||
array.forEach(function(value) {
|
||||
result.push(check(value));
|
||||
@@ -204,7 +204,7 @@ function checkTransactionResponse(transaction: any): TransactionResponse {
|
||||
|
||||
// Very loose providers (e.g. TestRPC) don't provide a signature or raw
|
||||
if (transaction.v && transaction.r && transaction.s) {
|
||||
var raw = [
|
||||
let raw = [
|
||||
stripZeros(hexlify(transaction.nonce)),
|
||||
stripZeros(hexlify(transaction.gasPrice)),
|
||||
stripZeros(hexlify(transaction.gasLimit)),
|
||||
@@ -221,9 +221,9 @@ function checkTransactionResponse(transaction: any): TransactionResponse {
|
||||
}
|
||||
|
||||
|
||||
var result = check(formatTransaction, transaction);
|
||||
let result = check(formatTransaction, transaction);
|
||||
|
||||
var networkId = transaction.networkId;
|
||||
let networkId = transaction.networkId;
|
||||
|
||||
if (isHexString(networkId)) {
|
||||
networkId = bigNumberify(networkId).toNumber();
|
||||
@@ -324,7 +324,7 @@ function checkTransactionReceipt(transactionReceipt: any): TransactionReceipt {
|
||||
//var status = transactionReceipt.status;
|
||||
//var root = transactionReceipt.root;
|
||||
|
||||
var result: TransactionReceipt = check(formatTransactionReceipt, transactionReceipt);
|
||||
let result: TransactionReceipt = check(formatTransactionReceipt, transactionReceipt);
|
||||
result.logs.forEach(function(entry, index) {
|
||||
if (entry.transactionLogIndex == null) {
|
||||
entry.transactionLogIndex = index;
|
||||
@@ -425,13 +425,14 @@ function getEventTag(eventName: EventType): string {
|
||||
|
||||
eventName = eventName.toLowerCase();
|
||||
|
||||
if (eventName === 'block' || eventName === 'pending' || eventName === 'error') {
|
||||
return eventName;
|
||||
|
||||
} else if (hexDataLength(eventName) === 32) {
|
||||
if (hexDataLength(eventName) === 32) {
|
||||
return 'tx:' + eventName;
|
||||
}
|
||||
|
||||
if (eventName.indexOf(':') === -1) {
|
||||
return eventName;
|
||||
}
|
||||
|
||||
} else if (Array.isArray(eventName)) {
|
||||
return 'filter::' + serializeTopics(eventName);
|
||||
|
||||
@@ -550,7 +551,7 @@ export class BaseProvider extends Provider {
|
||||
if (this._lastBlockNumber === -2) { this._lastBlockNumber = blockNumber - 1; }
|
||||
|
||||
// Notify all listener for each block that has passed
|
||||
for (var i = this._lastBlockNumber + 1; i <= blockNumber; i++) {
|
||||
for (let i = this._lastBlockNumber + 1; i <= blockNumber; i++) {
|
||||
if (this._emitted.block < i) {
|
||||
this._emitted.block = i;
|
||||
|
||||
@@ -568,7 +569,7 @@ export class BaseProvider extends Provider {
|
||||
}
|
||||
|
||||
// Sweep balances and remove addresses we no longer have events for
|
||||
var newBalances: any = {};
|
||||
let newBalances: any = {};
|
||||
|
||||
// Find all transaction hashes we are waiting on
|
||||
this._events.forEach((event) => {
|
||||
@@ -591,7 +592,7 @@ export class BaseProvider extends Provider {
|
||||
newBalances[address] = this._balances[address];
|
||||
}
|
||||
this.getBalance(address, 'latest').then(function(balance) {
|
||||
var lastBalance = this._balances[address];
|
||||
let lastBalance = this._balances[address];
|
||||
if (lastBalance && balance.eq(lastBalance)) { return; }
|
||||
this._balances[address] = balance;
|
||||
this.emit(address, balance);
|
||||
@@ -601,14 +602,14 @@ export class BaseProvider extends Provider {
|
||||
}
|
||||
|
||||
case 'filter': {
|
||||
let address = comps[1];
|
||||
let topics = deserializeTopics(comps[2]);
|
||||
let filter = {
|
||||
address: address,
|
||||
address: comps[1],
|
||||
fromBlock: this._lastBlockNumber + 1,
|
||||
toBlock: blockNumber,
|
||||
topics: topics
|
||||
}
|
||||
if (!filter.address) { delete filter.address; }
|
||||
this.getLogs(filter).then((logs) => {
|
||||
if (logs.length === 0) { return; }
|
||||
logs.forEach((log: Log) => {
|
||||
@@ -751,7 +752,7 @@ export class BaseProvider extends Provider {
|
||||
return this.ready.then(() => {
|
||||
return resolveProperties({ addressOrName: addressOrName, blockTag: blockTag }).then(({ addressOrName, blockTag }) => {
|
||||
return this.resolveName(addressOrName).then((address) => {
|
||||
var params = { address: address, blockTag: checkBlockTag(blockTag) };
|
||||
let params = { address: address, blockTag: checkBlockTag(blockTag) };
|
||||
return this.perform('getBalance', params).then((result) => {
|
||||
return bigNumberify(result);
|
||||
});
|
||||
@@ -764,7 +765,7 @@ export class BaseProvider extends Provider {
|
||||
return this.ready.then(() => {
|
||||
return resolveProperties({ addressOrName: addressOrName, blockTag: blockTag }).then(({ addressOrName, blockTag }) => {
|
||||
return this.resolveName(addressOrName).then((address) => {
|
||||
var params = { address: address, blockTag: checkBlockTag(blockTag) };
|
||||
let params = { address: address, blockTag: checkBlockTag(blockTag) };
|
||||
return this.perform('getTransactionCount', params).then((result) => {
|
||||
return bigNumberify(result).toNumber();
|
||||
});
|
||||
@@ -777,7 +778,7 @@ export class BaseProvider extends Provider {
|
||||
return this.ready.then(() => {
|
||||
return resolveProperties({ addressOrName: addressOrName, blockTag: blockTag }).then(({ addressOrName, blockTag }) => {
|
||||
return this.resolveName(addressOrName).then((address) => {
|
||||
var params = {address: address, blockTag: checkBlockTag(blockTag)};
|
||||
let params = {address: address, blockTag: checkBlockTag(blockTag)};
|
||||
return this.perform('getCode', params).then((result) => {
|
||||
return hexlify(result);
|
||||
});
|
||||
@@ -790,7 +791,7 @@ export class BaseProvider extends Provider {
|
||||
return this.ready.then(() => {
|
||||
return resolveProperties({ addressOrName: addressOrName, position: position, blockTag: blockTag }).then(({ addressOrName, position, blockTag }) => {
|
||||
return this.resolveName(addressOrName).then((address) => {
|
||||
var params = {
|
||||
let params = {
|
||||
address: address,
|
||||
blockTag: checkBlockTag(blockTag),
|
||||
position: hexStripZeros(hexlify(position)),
|
||||
@@ -806,7 +807,7 @@ export class BaseProvider extends Provider {
|
||||
sendTransaction(signedTransaction: string | Promise<string>): Promise<TransactionResponse> {
|
||||
return this.ready.then(() => {
|
||||
return resolveProperties({ signedTransaction: signedTransaction }).then(({ signedTransaction }) => {
|
||||
var params = { signedTransaction: hexlify(signedTransaction) };
|
||||
let params = { signedTransaction: hexlify(signedTransaction) };
|
||||
return this.perform('sendTransaction', params).then((hash) => {
|
||||
return this._wrapTransaction(parseTransaction(signedTransaction), hash);
|
||||
}, function (error) {
|
||||
@@ -876,7 +877,7 @@ export class BaseProvider extends Provider {
|
||||
return this.ready.then(() => {
|
||||
return resolveProperties(tx).then((tx) => {
|
||||
return this._resolveNames(tx, [ 'to', 'from' ]).then((tx) => {
|
||||
var params = { transaction: checkTransactionRequest(tx) };
|
||||
let params = { transaction: checkTransactionRequest(tx) };
|
||||
return this.perform('estimateGas', params).then((result) => {
|
||||
return bigNumberify(result);
|
||||
});
|
||||
@@ -889,7 +890,7 @@ export class BaseProvider extends Provider {
|
||||
return this.ready.then(() => {
|
||||
return resolveProperties({ blockHashOrBlockTag: blockHashOrBlockTag }).then(({ blockHashOrBlockTag }) => {
|
||||
try {
|
||||
var blockHash = hexlify(blockHashOrBlockTag);
|
||||
let blockHash = hexlify(blockHashOrBlockTag);
|
||||
if (hexDataLength(blockHash) === 32) {
|
||||
return poll(() => {
|
||||
return this.perform('getBlock', { blockHash: blockHash, includeTransactions: !!includeTransactions }).then((block) => {
|
||||
@@ -1013,7 +1014,7 @@ export class BaseProvider extends Provider {
|
||||
return this.ready.then(() => {
|
||||
return resolveProperties(filter).then((filter) => {
|
||||
return this._resolveNames(filter, ['address']).then((filter) => {
|
||||
var params = { filter: checkFilter(filter) };
|
||||
let params = { filter: checkFilter(filter) };
|
||||
return this.perform('getLogs', params).then((result) => {
|
||||
return arrayOf(checkLog)(result);
|
||||
});
|
||||
@@ -1033,9 +1034,9 @@ export class BaseProvider extends Provider {
|
||||
|
||||
// @TODO: Could probably use resolveProperties instead?
|
||||
private _resolveNames(object: any, keys: Array<string>): Promise<{ [key: string]: string }> {
|
||||
var promises: Array<Promise<void>> = [];
|
||||
let promises: Array<Promise<void>> = [];
|
||||
|
||||
var result: { [key: string ]: string } = shallowCopy(object);
|
||||
let result: { [key: string ]: string } = shallowCopy(object);
|
||||
|
||||
keys.forEach(function(key) {
|
||||
if (result[key] == null) { return; }
|
||||
@@ -1062,8 +1063,8 @@ export class BaseProvider extends Provider {
|
||||
}
|
||||
|
||||
// keccak256('resolver(bytes32)')
|
||||
var data = '0x0178b8bf' + namehash(name).substring(2);
|
||||
var transaction = { to: network.ensAddress, data: data };
|
||||
let data = '0x0178b8bf' + namehash(name).substring(2);
|
||||
let transaction = { to: network.ensAddress, data: data };
|
||||
|
||||
return this.call(transaction).then((data) => {
|
||||
|
||||
@@ -1088,22 +1089,22 @@ export class BaseProvider extends Provider {
|
||||
return Promise.resolve(getAddress(name));
|
||||
} catch (error) { }
|
||||
|
||||
var self = this;
|
||||
let self = this;
|
||||
|
||||
var nodeHash = namehash(name);
|
||||
let nodeHash = namehash(name);
|
||||
|
||||
// Get the addr from the resovler
|
||||
return this._getResolver(name).then(function(resolverAddress) {
|
||||
|
||||
// keccak256('addr(bytes32)')
|
||||
var data = '0x3b3b57de' + nodeHash.substring(2);
|
||||
var transaction = { to: resolverAddress, data: data };
|
||||
let data = '0x3b3b57de' + nodeHash.substring(2);
|
||||
let transaction = { to: resolverAddress, data: data };
|
||||
return self.call(transaction);
|
||||
|
||||
// extract the address from the data
|
||||
}).then(function(data) {
|
||||
if (hexDataLength(data) !== 32) { return null; }
|
||||
var address = getAddress(hexDataSlice(data, 12));
|
||||
let address = getAddress(hexDataSlice(data, 12));
|
||||
if (address === '0x0000000000000000000000000000000000000000') { return null; }
|
||||
return address;
|
||||
});
|
||||
@@ -1118,17 +1119,17 @@ export class BaseProvider extends Provider {
|
||||
|
||||
address = getAddress(address);
|
||||
|
||||
var name = address.substring(2) + '.addr.reverse'
|
||||
var nodehash = namehash(name);
|
||||
let name = address.substring(2) + '.addr.reverse'
|
||||
let nodehash = namehash(name);
|
||||
|
||||
var self = this;
|
||||
let self = this;
|
||||
|
||||
return this._getResolver(name).then(function(resolverAddress) {
|
||||
if (!resolverAddress) { return null; }
|
||||
|
||||
// keccak('name(bytes32)')
|
||||
var data = '0x691f3431' + nodehash.substring(2);
|
||||
var transaction = { to: resolverAddress, data: data };
|
||||
let data = '0x691f3431' + nodehash.substring(2);
|
||||
let transaction = { to: resolverAddress, data: data };
|
||||
return self.call(transaction);
|
||||
|
||||
}).then(function(data) {
|
||||
@@ -1140,12 +1141,12 @@ export class BaseProvider extends Provider {
|
||||
data = data.substring(64);
|
||||
|
||||
if (data.length < 64) { return null; }
|
||||
var length = bigNumberify('0x' + data.substring(0, 64)).toNumber();
|
||||
let length = bigNumberify('0x' + data.substring(0, 64)).toNumber();
|
||||
data = data.substring(64);
|
||||
|
||||
if (2 * length > data.length) { return null; }
|
||||
|
||||
var name = toUtf8String('0x' + data.substring(0, 2 * length));
|
||||
let name = toUtf8String('0x' + data.substring(0, 2 * length));
|
||||
|
||||
// Make sure the reverse record matches the foward record
|
||||
return self.resolveName(name).then(function(addr) {
|
||||
|
||||
@@ -113,43 +113,55 @@ export class EtherscanProvider extends BaseProvider{
|
||||
let apiKey = '';
|
||||
if (this.apiKey) { apiKey += '&apikey=' + this.apiKey; }
|
||||
|
||||
let get = (url: string, procFunc?: (value: any) => any) => {
|
||||
return fetchJson(url, null, procFunc || getJsonResult).then((result) => {
|
||||
this.emit('debug', {
|
||||
action: 'perform',
|
||||
request: url,
|
||||
response: result,
|
||||
provider: this
|
||||
});
|
||||
return result;
|
||||
});
|
||||
};
|
||||
|
||||
switch (method) {
|
||||
case 'getBlockNumber':
|
||||
url += '/api?module=proxy&action=eth_blockNumber' + apiKey;
|
||||
return fetchJson(url, null, getJsonResult);
|
||||
return get(url);
|
||||
|
||||
case 'getGasPrice':
|
||||
url += '/api?module=proxy&action=eth_gasPrice' + apiKey;
|
||||
return fetchJson(url, null, getJsonResult);
|
||||
return get(url);
|
||||
|
||||
case 'getBalance':
|
||||
// Returns base-10 result
|
||||
url += '/api?module=account&action=balance&address=' + params.address;
|
||||
url += '&tag=' + params.blockTag + apiKey;
|
||||
return fetchJson(url, null, getResult);
|
||||
return get(url, getResult);
|
||||
|
||||
case 'getTransactionCount':
|
||||
url += '/api?module=proxy&action=eth_getTransactionCount&address=' + params.address;
|
||||
url += '&tag=' + params.blockTag + apiKey;
|
||||
return fetchJson(url, null, getJsonResult);
|
||||
return get(url);
|
||||
|
||||
|
||||
case 'getCode':
|
||||
url += '/api?module=proxy&action=eth_getCode&address=' + params.address;
|
||||
url += '&tag=' + params.blockTag + apiKey;
|
||||
return fetchJson(url, null, getJsonResult);
|
||||
return get(url, getJsonResult);
|
||||
|
||||
case 'getStorageAt':
|
||||
url += '/api?module=proxy&action=eth_getStorageAt&address=' + params.address;
|
||||
url += '&position=' + params.position;
|
||||
url += '&tag=' + params.blockTag + apiKey;
|
||||
return fetchJson(url, null, getJsonResult);
|
||||
return get(url, getJsonResult);
|
||||
|
||||
|
||||
case 'sendTransaction':
|
||||
url += '/api?module=proxy&action=eth_sendRawTransaction&hex=' + params.signedTransaction;
|
||||
url += apiKey;
|
||||
return fetchJson(url, null, getJsonResult).catch((error) => {
|
||||
return get(url).catch((error) => {
|
||||
if (error.responseText) {
|
||||
// "Insufficient funds. The account you tried to send transaction from does not have enough funds. Required 21464000000000 and got: 0"
|
||||
if (error.responseText.toLowerCase().indexOf('insufficient funds') >= 0) {
|
||||
@@ -176,19 +188,19 @@ export class EtherscanProvider extends BaseProvider{
|
||||
url += '&boolean=false';
|
||||
}
|
||||
url += apiKey;
|
||||
return fetchJson(url, null, getJsonResult);
|
||||
return get(url);
|
||||
}
|
||||
throw new Error('getBlock by blockHash not implmeneted');
|
||||
|
||||
case 'getTransaction':
|
||||
url += '/api?module=proxy&action=eth_getTransactionByHash&txhash=' + params.transactionHash;
|
||||
url += apiKey;
|
||||
return fetchJson(url, null, getJsonResult);
|
||||
return get(url);
|
||||
|
||||
case 'getTransactionReceipt':
|
||||
url += '/api?module=proxy&action=eth_getTransactionReceipt&txhash=' + params.transactionHash;
|
||||
url += apiKey;
|
||||
return fetchJson(url, null, getJsonResult);
|
||||
return get(url);
|
||||
|
||||
|
||||
case 'call': {
|
||||
@@ -200,7 +212,7 @@ export class EtherscanProvider extends BaseProvider{
|
||||
throw new Error('EtherscanProvider does not support blockTag for call');
|
||||
}
|
||||
url += apiKey;
|
||||
return fetchJson(url, null, getJsonResult);
|
||||
return get(url);
|
||||
}
|
||||
|
||||
case 'estimateGas': {
|
||||
@@ -208,7 +220,7 @@ export class EtherscanProvider extends BaseProvider{
|
||||
if (transaction) { transaction = '&' + transaction; }
|
||||
url += '/api?module=proxy&action=eth_estimateGas&' + transaction;
|
||||
url += apiKey;
|
||||
return fetchJson(url, null, getJsonResult);
|
||||
return get(url);
|
||||
}
|
||||
|
||||
case 'getLogs':
|
||||
@@ -244,7 +256,7 @@ export class EtherscanProvider extends BaseProvider{
|
||||
url += apiKey;
|
||||
|
||||
var self = this;
|
||||
return fetchJson(url, null, getResult).then(function(logs: Array<any>) {
|
||||
return get(url, getResult).then(function(logs: Array<any>) {
|
||||
var txs: { [hash: string]: string } = {};
|
||||
|
||||
var seq = Promise.resolve();
|
||||
@@ -272,7 +284,7 @@ export class EtherscanProvider extends BaseProvider{
|
||||
if (this.network.name !== 'homestead') { return Promise.resolve(0.0); }
|
||||
url += '/api?module=stats&action=ethprice';
|
||||
url += apiKey;
|
||||
return fetchJson(url, null, getResult).then(function(result) {
|
||||
return get(url, getResult).then(function(result) {
|
||||
return parseFloat(result.ethusd);
|
||||
});
|
||||
|
||||
@@ -301,6 +313,12 @@ export class EtherscanProvider extends BaseProvider{
|
||||
url += '&sort=asc' + apiKey;
|
||||
|
||||
return fetchJson(url, null, getResult).then((result: Array<any>) => {
|
||||
this.emit('debug', {
|
||||
action: 'getHistory',
|
||||
request: url,
|
||||
response: result,
|
||||
provider: this
|
||||
});
|
||||
var output: Array<TransactionResponse> = [];
|
||||
result.forEach((tx) => {
|
||||
['contractAddress', 'to'].forEach(function(key) {
|
||||
|
||||
@@ -230,14 +230,22 @@ export class JsonRpcProvider extends BaseProvider {
|
||||
}
|
||||
|
||||
send(method: string, params: any): Promise<any> {
|
||||
var request = {
|
||||
let request = {
|
||||
method: method,
|
||||
params: params,
|
||||
id: 42,
|
||||
jsonrpc: "2.0"
|
||||
};
|
||||
|
||||
return fetchJson(this.connection, JSON.stringify(request), getResult);
|
||||
return fetchJson(this.connection, JSON.stringify(request), getResult).then((result) => {
|
||||
this.emit('debug', {
|
||||
action: 'send',
|
||||
request: request,
|
||||
response: result,
|
||||
provider: this
|
||||
});
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
perform(method: string, params: any): Promise<any> {
|
||||
|
||||
5
utils/index.d.ts
vendored
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 { randomBytes } from './random-bytes';
|
||||
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 { computeAddress, computePublicKey, recoverAddress, recoverPublicKey, verifyMessage } from './secp256k1';
|
||||
import { SigningKey } from './signing-key';
|
||||
import { populateTransaction } from './transaction';
|
||||
import { parse as parseTransaction, serialize as serializeTransaction } from './transaction';
|
||||
import { formatBytes32String, parseBytes32String, toUtf8Bytes, toUtf8String } from './utf8';
|
||||
import { commify, formatEther, parseEther, formatUnits, parseUnits } from './units';
|
||||
@@ -31,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, 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");
|
||||
exports.getNetwork = networks_1.getNetwork;
|
||||
var properties_1 = require("./properties");
|
||||
exports.checkProperties = properties_1.checkProperties;
|
||||
exports.deepCopy = properties_1.deepCopy;
|
||||
exports.defineReadOnly = properties_1.defineReadOnly;
|
||||
exports.resolveProperties = properties_1.resolveProperties;
|
||||
@@ -73,8 +74,10 @@ exports.verifyMessage = secp256k1_1.verifyMessage;
|
||||
var signing_key_1 = require("./signing-key");
|
||||
exports.SigningKey = signing_key_1.SigningKey;
|
||||
var transaction_1 = require("./transaction");
|
||||
exports.parseTransaction = transaction_1.parse;
|
||||
exports.serializeTransaction = transaction_1.serialize;
|
||||
exports.populateTransaction = transaction_1.populateTransaction;
|
||||
var transaction_2 = require("./transaction");
|
||||
exports.parseTransaction = transaction_2.parse;
|
||||
exports.serializeTransaction = transaction_2.serialize;
|
||||
var utf8_1 = require("./utf8");
|
||||
exports.formatBytes32String = utf8_1.formatBytes32String;
|
||||
exports.parseBytes32String = utf8_1.parseBytes32String;
|
||||
|
||||
3
utils/properties.d.ts
vendored
3
utils/properties.d.ts
vendored
@@ -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 isType(object: any, type: string): boolean;
|
||||
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 deepCopy(object: any, frozen?: boolean): any;
|
||||
export declare function inheritable(parent: any): (child: any) => void;
|
||||
|
||||
@@ -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"));
|
||||
function defineReadOnly(object, name, value) {
|
||||
Object.defineProperty(object, name, {
|
||||
enumerable: true,
|
||||
@@ -38,6 +46,24 @@ function resolveProperties(object) {
|
||||
});
|
||||
}
|
||||
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) {
|
||||
var result = {};
|
||||
for (var key in object) {
|
||||
|
||||
2
utils/transaction.d.ts
vendored
2
utils/transaction.d.ts
vendored
@@ -1,6 +1,7 @@
|
||||
import { BigNumber } from './bignumber';
|
||||
import { Arrayish, Signature } from './bytes';
|
||||
import { BigNumberish } from './bignumber';
|
||||
import { Provider } from '../providers/abstract-provider';
|
||||
export declare type UnsignedTransaction = {
|
||||
to?: string;
|
||||
nonce?: number;
|
||||
@@ -26,3 +27,4 @@ export interface Transaction {
|
||||
}
|
||||
export declare function serialize(transaction: UnsignedTransaction, signature?: Arrayish | Signature): string;
|
||||
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 bytes_1 = require("./bytes");
|
||||
var keccak256_1 = require("./keccak256");
|
||||
var properties_1 = require("./properties");
|
||||
var RLP = __importStar(require("./rlp"));
|
||||
var abstract_provider_1 = require("../providers/abstract-provider");
|
||||
///////////////////////////////
|
||||
function handleAddress(value) {
|
||||
if (value === '0x') {
|
||||
@@ -36,7 +38,11 @@ var transactionFields = [
|
||||
{ name: 'value', maxLength: 32 },
|
||||
{ name: 'data' },
|
||||
];
|
||||
var allowedTransactionKeys = {
|
||||
chainId: true, data: true, gasLimit: true, gasPrice: true, nonce: true, to: true, value: true
|
||||
};
|
||||
function serialize(transaction, signature) {
|
||||
properties_1.checkProperties(transaction, allowedTransactionKeys);
|
||||
var raw = [];
|
||||
transactionFields.forEach(function (fieldInfo) {
|
||||
var value = transaction[fieldInfo.name] || ([]);
|
||||
@@ -139,3 +145,32 @@ function parse(rawTransaction) {
|
||||
return tx;
|
||||
}
|
||||
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 });
|
||||
var xmlhttprequest_1 = require("xmlhttprequest");
|
||||
var base64_1 = require("./base64");
|
||||
var properties_1 = require("./properties");
|
||||
var utf8_1 = require("./utf8");
|
||||
var errors = __importStar(require("../errors"));
|
||||
function fetchJson(connection, json, processFunc) {
|
||||
@@ -144,6 +145,7 @@ function poll(func, options) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
options = properties_1.shallowCopy(options);
|
||||
if (options.floor == null) {
|
||||
options.floor = 0;
|
||||
}
|
||||
|
||||
45
wallet.js
45
wallet.js
@@ -31,9 +31,6 @@ var transaction_1 = require("./utils/transaction");
|
||||
var abstract_signer_1 = require("./abstract-signer");
|
||||
var abstract_provider_1 = require("./providers/abstract-provider");
|
||||
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) {
|
||||
__extends(Wallet, _super);
|
||||
function Wallet(privateKey, provider) {
|
||||
@@ -83,19 +80,10 @@ var Wallet = /** @class */ (function (_super) {
|
||||
};
|
||||
Wallet.prototype.sign = function (transaction) {
|
||||
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) {
|
||||
var rawTx = transaction_1.serialize(tx);
|
||||
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) {
|
||||
@@ -114,31 +102,12 @@ var Wallet = /** @class */ (function (_super) {
|
||||
return this.provider.getTransactionCount(this.address, blockTag);
|
||||
};
|
||||
Wallet.prototype.sendTransaction = function (transaction) {
|
||||
if (!this.provider) {
|
||||
throw new Error('missing provider');
|
||||
}
|
||||
if (!transaction || typeof (transaction) !== 'object') {
|
||||
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));
|
||||
var _this = this;
|
||||
return transaction_1.populateTransaction(transaction, this.provider, this.address).then(function (tx) {
|
||||
return _this.sign(tx).then(function (signedTransaction) {
|
||||
return _this.provider.sendTransaction(signedTransaction);
|
||||
});
|
||||
});
|
||||
};
|
||||
Wallet.prototype.encrypt = function (password, options, progressCallback) {
|
||||
if (typeof (options) === 'function' && !progressCallback) {
|
||||
|
||||
Reference in New Issue
Block a user