Updated dist files.
This commit is contained in:
parent
5f3ceec6f9
commit
937194b5ee
@ -8,14 +8,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var interface_1 = require("./interface");
|
||||
var provider_1 = require("../providers/provider");
|
||||
var wallet_1 = require("../wallet/wallet");
|
||||
var abi_coder_1 = require("../utils/abi-coder");
|
||||
var address_1 = require("../utils/address");
|
||||
var bignumber_1 = require("../utils/bignumber");
|
||||
var bytes_1 = require("../utils/bytes");
|
||||
var properties_1 = require("../utils/properties");
|
||||
var web_1 = require("../utils/web");
|
||||
var types_1 = require("../utils/types");
|
||||
var errors = __importStar(require("../utils/errors"));
|
||||
var allowedTransactionKeys = {
|
||||
data: true, from: true, gasLimit: true, gasPrice: true, nonce: true, to: true, value: true
|
||||
@ -169,11 +168,11 @@ var Contract = /** @class */ (function () {
|
||||
else {
|
||||
properties_1.defineReadOnly(this, 'interface', new interface_1.Interface(contractInterface));
|
||||
}
|
||||
if (signerOrProvider instanceof wallet_1.Signer) {
|
||||
if (signerOrProvider instanceof types_1.Signer) {
|
||||
properties_1.defineReadOnly(this, 'provider', signerOrProvider.provider);
|
||||
properties_1.defineReadOnly(this, 'signer', signerOrProvider);
|
||||
}
|
||||
else if (signerOrProvider instanceof provider_1.Provider) {
|
||||
else if (signerOrProvider instanceof types_1.MinimalProvider) {
|
||||
properties_1.defineReadOnly(this, 'provider', signerOrProvider);
|
||||
properties_1.defineReadOnly(this, 'signer', null);
|
||||
}
|
||||
@ -204,15 +203,25 @@ var Contract = /** @class */ (function () {
|
||||
}
|
||||
this._events = [];
|
||||
properties_1.defineReadOnly(this, 'address', addressOrName);
|
||||
properties_1.defineReadOnly(this, 'addressPromise', this.provider.resolveName(addressOrName).then(function (address) {
|
||||
if (address == null) {
|
||||
throw new Error('name not found');
|
||||
if (this.provider) {
|
||||
properties_1.defineReadOnly(this, 'addressPromise', this.provider.resolveName(addressOrName).then(function (address) {
|
||||
if (address == null) {
|
||||
throw new Error('name not found');
|
||||
}
|
||||
return address;
|
||||
}).catch(function (error) {
|
||||
console.log('ERROR: Cannot find Contract - ' + addressOrName);
|
||||
throw error;
|
||||
}));
|
||||
}
|
||||
else {
|
||||
try {
|
||||
properties_1.defineReadOnly(this, 'addressPromise', Promise.resolve(address_1.getAddress(addressOrName)));
|
||||
}
|
||||
return address;
|
||||
}).catch(function (error) {
|
||||
console.log('ERROR: Cannot find Contract - ' + addressOrName);
|
||||
throw error;
|
||||
}));
|
||||
catch (error) {
|
||||
errors.throwError('provider is required to use non-address contract address', errors.INVALID_ARGUMENT, { argument: 'addressOrName', value: addressOrName });
|
||||
}
|
||||
}
|
||||
Object.keys(this.interface.functions).forEach(function (name) {
|
||||
var run = runMethod(_this, name, false);
|
||||
if (_this[name] == null) {
|
||||
@ -227,14 +236,6 @@ var Contract = /** @class */ (function () {
|
||||
}
|
||||
});
|
||||
}
|
||||
Object.defineProperty(Contract.prototype, "onerror", {
|
||||
get: function () { return this._onerror; },
|
||||
set: function (callback) {
|
||||
this._onerror = callback;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
// @TODO: Allow timeout?
|
||||
Contract.prototype.deployed = function () {
|
||||
var _this = this;
|
||||
|
@ -25,9 +25,20 @@ var bytes_1 = require("../utils/bytes");
|
||||
var hash_1 = require("../utils/hash");
|
||||
var keccak256_1 = require("../utils/keccak256");
|
||||
var properties_1 = require("../utils/properties");
|
||||
var types_1 = require("../utils/types");
|
||||
exports.Indexed = types_1.Indexed;
|
||||
var errors = __importStar(require("../utils/errors"));
|
||||
var Description = /** @class */ (function () {
|
||||
function Description(info) {
|
||||
var _Indexed = /** @class */ (function (_super) {
|
||||
__extends(_Indexed, _super);
|
||||
function _Indexed(hash) {
|
||||
var _this = _super.call(this) || this;
|
||||
properties_1.defineReadOnly(_this, 'hash', hash);
|
||||
return _this;
|
||||
}
|
||||
return _Indexed;
|
||||
}(types_1.Indexed));
|
||||
var _Description = /** @class */ (function () {
|
||||
function _Description(info) {
|
||||
for (var key in info) {
|
||||
var value = info[key];
|
||||
if (value != null && typeof (value) === 'object') {
|
||||
@ -38,23 +49,14 @@ var Description = /** @class */ (function () {
|
||||
}
|
||||
}
|
||||
}
|
||||
return Description;
|
||||
return _Description;
|
||||
}());
|
||||
exports.Description = Description;
|
||||
var Indexed = /** @class */ (function (_super) {
|
||||
__extends(Indexed, _super);
|
||||
function Indexed() {
|
||||
var _DeployDescription = /** @class */ (function (_super) {
|
||||
__extends(_DeployDescription, _super);
|
||||
function _DeployDescription() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
return Indexed;
|
||||
}(Description));
|
||||
exports.Indexed = Indexed;
|
||||
var DeployDescription = /** @class */ (function (_super) {
|
||||
__extends(DeployDescription, _super);
|
||||
function DeployDescription() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
DeployDescription.prototype.encode = function (bytecode, params) {
|
||||
_DeployDescription.prototype.encode = function (bytecode, params) {
|
||||
if (!bytes_1.isHexString(bytecode)) {
|
||||
errors.throwError('invalid contract bytecode', errors.INVALID_ARGUMENT, {
|
||||
arg: 'bytecode',
|
||||
@ -74,15 +76,14 @@ var DeployDescription = /** @class */ (function (_super) {
|
||||
}
|
||||
return null;
|
||||
};
|
||||
return DeployDescription;
|
||||
}(Description));
|
||||
exports.DeployDescription = DeployDescription;
|
||||
var FunctionDescription = /** @class */ (function (_super) {
|
||||
__extends(FunctionDescription, _super);
|
||||
function FunctionDescription() {
|
||||
return _DeployDescription;
|
||||
}(_Description));
|
||||
var _FunctionDescription = /** @class */ (function (_super) {
|
||||
__extends(_FunctionDescription, _super);
|
||||
function _FunctionDescription() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
FunctionDescription.prototype.encode = function (params) {
|
||||
_FunctionDescription.prototype.encode = function (params) {
|
||||
errors.checkArgumentCount(params.length, this.inputs.length, 'in interface function ' + this.name);
|
||||
try {
|
||||
return this.sighash + abi_coder_1.defaultAbiCoder.encode(this.inputs, params).substring(2);
|
||||
@ -96,7 +97,7 @@ var FunctionDescription = /** @class */ (function (_super) {
|
||||
}
|
||||
return null;
|
||||
};
|
||||
FunctionDescription.prototype.decode = function (data) {
|
||||
_FunctionDescription.prototype.decode = function (data) {
|
||||
try {
|
||||
return abi_coder_1.defaultAbiCoder.decode(this.outputs, bytes_1.arrayify(data));
|
||||
}
|
||||
@ -110,22 +111,21 @@ var FunctionDescription = /** @class */ (function (_super) {
|
||||
});
|
||||
}
|
||||
};
|
||||
return FunctionDescription;
|
||||
}(Description));
|
||||
exports.FunctionDescription = FunctionDescription;
|
||||
return _FunctionDescription;
|
||||
}(_Description));
|
||||
var Result = /** @class */ (function (_super) {
|
||||
__extends(Result, _super);
|
||||
function Result() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
return Result;
|
||||
}(Description));
|
||||
var EventDescription = /** @class */ (function (_super) {
|
||||
__extends(EventDescription, _super);
|
||||
function EventDescription() {
|
||||
}(_Description));
|
||||
var _EventDescription = /** @class */ (function (_super) {
|
||||
__extends(_EventDescription, _super);
|
||||
function _EventDescription() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
EventDescription.prototype.encodeTopics = function (params) {
|
||||
_EventDescription.prototype.encodeTopics = function (params) {
|
||||
var _this = this;
|
||||
if (params.length > this.inputs.length) {
|
||||
errors.throwError('too many arguments for ' + this.name, errors.UNEXPECTED_ARGUMENT, { maxCount: params.length, expectedCount: this.inputs.length });
|
||||
@ -165,7 +165,7 @@ var EventDescription = /** @class */ (function (_super) {
|
||||
}
|
||||
return topics;
|
||||
};
|
||||
EventDescription.prototype.decode = function (data, topics) {
|
||||
_EventDescription.prototype.decode = function (data, topics) {
|
||||
// Strip the signature off of non-anonymous topics
|
||||
if (topics != null && !this.anonymous) {
|
||||
topics = topics.slice(1);
|
||||
@ -198,10 +198,10 @@ var EventDescription = /** @class */ (function (_super) {
|
||||
this.inputs.forEach(function (input, index) {
|
||||
if (input.indexed) {
|
||||
if (topics == null) {
|
||||
result[index] = new Indexed({ type: 'indexed', hash: null });
|
||||
result[index] = new _Indexed(null);
|
||||
}
|
||||
else if (inputDynamic[index]) {
|
||||
result[index] = new Indexed({ type: 'indexed', hash: resultIndexed[indexedIndex++] });
|
||||
result[index] = new _Indexed(resultIndexed[indexedIndex++]);
|
||||
}
|
||||
else {
|
||||
result[index] = resultIndexed[indexedIndex++];
|
||||
@ -217,30 +217,29 @@ var EventDescription = /** @class */ (function (_super) {
|
||||
result.length = this.inputs.length;
|
||||
return result;
|
||||
};
|
||||
return EventDescription;
|
||||
}(Description));
|
||||
exports.EventDescription = EventDescription;
|
||||
return _EventDescription;
|
||||
}(_Description));
|
||||
var TransactionDescription = /** @class */ (function (_super) {
|
||||
__extends(TransactionDescription, _super);
|
||||
function TransactionDescription() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
return TransactionDescription;
|
||||
}(Description));
|
||||
}(_Description));
|
||||
var LogDescription = /** @class */ (function (_super) {
|
||||
__extends(LogDescription, _super);
|
||||
function LogDescription() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
return LogDescription;
|
||||
}(Description));
|
||||
}(_Description));
|
||||
function addMethod(method) {
|
||||
switch (method.type) {
|
||||
case 'constructor': {
|
||||
var description = new DeployDescription({
|
||||
var description = new _DeployDescription({
|
||||
inputs: method.inputs,
|
||||
payable: (method.payable == null || !!method.payable),
|
||||
type: 'deploy'
|
||||
type: "deploy"
|
||||
});
|
||||
if (!this.deployFunction) {
|
||||
this.deployFunction = description;
|
||||
@ -250,7 +249,7 @@ function addMethod(method) {
|
||||
case 'function': {
|
||||
var signature = abi_coder_1.formatSignature(method).replace(/tuple/g, '');
|
||||
var sighash = hash_1.id(signature).substring(0, 10);
|
||||
var description = new FunctionDescription({
|
||||
var description = new _FunctionDescription({
|
||||
inputs: method.inputs,
|
||||
outputs: method.outputs,
|
||||
payable: (method.payable == null || !!method.payable),
|
||||
@ -270,7 +269,7 @@ function addMethod(method) {
|
||||
}
|
||||
case 'event': {
|
||||
var signature = abi_coder_1.formatSignature(method).replace(/tuple/g, '');
|
||||
var description = new EventDescription({
|
||||
var description = new _EventDescription({
|
||||
name: method.name,
|
||||
signature: signature,
|
||||
inputs: method.inputs,
|
||||
|
20
index.js
20
index.js
@ -1,7 +1,4 @@
|
||||
'use strict';
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
@ -13,14 +10,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var contracts_1 = require("./contracts");
|
||||
exports.Contract = contracts_1.Contract;
|
||||
exports.Interface = contracts_1.Interface;
|
||||
var providers_1 = __importDefault(require("./providers"));
|
||||
exports.providers = providers_1.default;
|
||||
var providers = __importStar(require("./providers"));
|
||||
exports.providers = providers;
|
||||
var errors = __importStar(require("./utils/errors"));
|
||||
exports.errors = errors;
|
||||
var networks_1 = require("./providers/networks");
|
||||
exports.getNetwork = networks_1.getNetwork;
|
||||
var utils_1 = __importDefault(require("./utils"));
|
||||
exports.utils = utils_1.default;
|
||||
var types = __importStar(require("./utils/types"));
|
||||
exports.types = types;
|
||||
var utils = __importStar(require("./utils"));
|
||||
exports.utils = utils;
|
||||
var wallet_1 = require("./wallet");
|
||||
exports.HDNode = wallet_1.HDNode;
|
||||
exports.SigningKey = wallet_1.SigningKey;
|
||||
@ -29,7 +28,7 @@ var wordlists = __importStar(require("./wordlists"));
|
||||
exports.wordlists = wordlists;
|
||||
var _version_1 = require("./_version");
|
||||
exports.version = _version_1.version;
|
||||
var constants = utils_1.default.constants;
|
||||
var constants = utils.constants;
|
||||
exports.constants = constants;
|
||||
exports.default = {
|
||||
Wallet: wallet_1.Wallet,
|
||||
@ -38,10 +37,11 @@ exports.default = {
|
||||
Contract: contracts_1.Contract,
|
||||
Interface: contracts_1.Interface,
|
||||
getNetwork: networks_1.getNetwork,
|
||||
providers: providers_1.default,
|
||||
providers: providers,
|
||||
types: types,
|
||||
errors: errors,
|
||||
constants: constants,
|
||||
utils: utils_1.default,
|
||||
utils: utils,
|
||||
wordlists: wordlists,
|
||||
version: _version_1.version
|
||||
};
|
||||
|
@ -273,7 +273,7 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
if (tx.creates == null && tx.contractAddress != null) {
|
||||
tx.creates = tx.contractAddress;
|
||||
}
|
||||
var item = provider_1.checkTransactionResponse(tx);
|
||||
var item = provider_1.Provider.checkTransactionResponse(tx);
|
||||
if (tx.timeStamp) {
|
||||
item.timestamp = parseInt(tx.timeStamp);
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ var infura_provider_1 = require("./infura-provider");
|
||||
exports.InfuraProvider = infura_provider_1.InfuraProvider;
|
||||
var json_rpc_provider_1 = require("./json-rpc-provider");
|
||||
exports.JsonRpcProvider = json_rpc_provider_1.JsonRpcProvider;
|
||||
exports.JsonRpcSigner = json_rpc_provider_1.JsonRpcSigner;
|
||||
var web3_provider_1 = require("./web3-provider");
|
||||
exports.Web3Provider = web3_provider_1.Web3Provider;
|
||||
function getDefaultProvider(network) {
|
||||
@ -29,5 +30,6 @@ exports.default = {
|
||||
InfuraProvider: infura_provider_1.InfuraProvider,
|
||||
JsonRpcProvider: json_rpc_provider_1.JsonRpcProvider,
|
||||
Web3Provider: web3_provider_1.Web3Provider,
|
||||
IpcProvider: ipc_provider_1.IpcProvider
|
||||
IpcProvider: ipc_provider_1.IpcProvider,
|
||||
JsonRpcSigner: json_rpc_provider_1.JsonRpcSigner
|
||||
};
|
||||
|
@ -20,10 +20,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
// See: https://github.com/ethereum/wiki/wiki/JSON-RPC
|
||||
var networks_1 = require("./networks");
|
||||
var provider_1 = require("./provider");
|
||||
var wallet_1 = require("../wallet/wallet");
|
||||
var address_1 = require("../utils/address");
|
||||
var bytes_1 = require("../utils/bytes");
|
||||
var properties_1 = require("../utils/properties");
|
||||
var types_1 = require("../utils/types");
|
||||
var utf8_1 = require("../utils/utf8");
|
||||
var web_1 = require("../utils/web");
|
||||
var errors = __importStar(require("../utils/errors"));
|
||||
@ -44,33 +44,6 @@ function getResult(payload) {
|
||||
}
|
||||
return payload.result;
|
||||
}
|
||||
// Convert an ethers.js transaction into a JSON-RPC transaction
|
||||
// - gasLimit => gas
|
||||
// - All values hexlified
|
||||
// - All numeric values zero-striped
|
||||
// @TODO: Not any, a dictionary of string to strings
|
||||
function hexlifyTransaction(transaction) {
|
||||
var result = {};
|
||||
// Some nodes (INFURA ropsten; INFURA mainnet is fine) don't like extra zeros.
|
||||
['gasLimit', 'gasPrice', 'nonce', 'value'].forEach(function (key) {
|
||||
if (transaction[key] == null) {
|
||||
return;
|
||||
}
|
||||
var value = bytes_1.hexStripZeros(bytes_1.hexlify(transaction[key]));
|
||||
if (key === 'gasLimit') {
|
||||
key = 'gas';
|
||||
}
|
||||
result[key] = value;
|
||||
});
|
||||
['from', 'to', 'data'].forEach(function (key) {
|
||||
if (transaction[key] == null) {
|
||||
return;
|
||||
}
|
||||
result[key] = bytes_1.hexlify(transaction[key]);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
exports.hexlifyTransaction = hexlifyTransaction;
|
||||
function getLowerCase(value) {
|
||||
if (value) {
|
||||
return value.toLowerCase();
|
||||
@ -128,7 +101,7 @@ var JsonRpcSigner = /** @class */ (function (_super) {
|
||||
});
|
||||
}
|
||||
return properties_1.resolveProperties(tx).then(function (tx) {
|
||||
tx = hexlifyTransaction(tx);
|
||||
tx = JsonRpcProvider.hexlifyTransaction(tx);
|
||||
return _this.provider.send('eth_sendTransaction', [tx]).then(function (hash) {
|
||||
return web_1.poll(function () {
|
||||
return _this.provider.getTransaction(hash).then(function (tx) {
|
||||
@ -159,7 +132,7 @@ var JsonRpcSigner = /** @class */ (function (_super) {
|
||||
});
|
||||
};
|
||||
return JsonRpcSigner;
|
||||
}(wallet_1.Signer));
|
||||
}(types_1.Signer));
|
||||
exports.JsonRpcSigner = JsonRpcSigner;
|
||||
var JsonRpcProvider = /** @class */ (function (_super) {
|
||||
__extends(JsonRpcProvider, _super);
|
||||
@ -250,9 +223,9 @@ var JsonRpcProvider = /** @class */ (function (_super) {
|
||||
case 'getTransactionReceipt':
|
||||
return this.send('eth_getTransactionReceipt', [params.transactionHash]);
|
||||
case 'call':
|
||||
return this.send('eth_call', [hexlifyTransaction(params.transaction), 'latest']);
|
||||
return this.send('eth_call', [JsonRpcProvider.hexlifyTransaction(params.transaction), 'latest']);
|
||||
case 'estimateGas':
|
||||
return this.send('eth_estimateGas', [hexlifyTransaction(params.transaction)]);
|
||||
return this.send('eth_estimateGas', [JsonRpcProvider.hexlifyTransaction(params.transaction)]);
|
||||
case 'getLogs':
|
||||
if (params.filter && params.filter.address != null) {
|
||||
params.filter.address = getLowerCase(params.filter.address);
|
||||
@ -306,6 +279,32 @@ var JsonRpcProvider = /** @class */ (function (_super) {
|
||||
JsonRpcProvider.prototype._stopPending = function () {
|
||||
this._pendingFilter = null;
|
||||
};
|
||||
// Convert an ethers.js transaction into a JSON-RPC transaction
|
||||
// - gasLimit => gas
|
||||
// - All values hexlified
|
||||
// - All numeric values zero-striped
|
||||
// @TODO: Not any, a dictionary of string to strings
|
||||
JsonRpcProvider.hexlifyTransaction = function (transaction) {
|
||||
var result = {};
|
||||
// Some nodes (INFURA ropsten; INFURA mainnet is fine) don't like extra zeros.
|
||||
['gasLimit', 'gasPrice', 'nonce', 'value'].forEach(function (key) {
|
||||
if (transaction[key] == null) {
|
||||
return;
|
||||
}
|
||||
var value = bytes_1.hexStripZeros(bytes_1.hexlify(transaction[key]));
|
||||
if (key === 'gasLimit') {
|
||||
key = 'gas';
|
||||
}
|
||||
result[key] = value;
|
||||
});
|
||||
['from', 'to', 'data'].forEach(function (key) {
|
||||
if (transaction[key] == null) {
|
||||
return;
|
||||
}
|
||||
result[key] = bytes_1.hexlify(transaction[key]);
|
||||
});
|
||||
return result;
|
||||
};
|
||||
return JsonRpcProvider;
|
||||
}(provider_1.Provider));
|
||||
exports.JsonRpcProvider = JsonRpcProvider;
|
||||
|
@ -1,4 +1,14 @@
|
||||
'use strict';
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
@ -17,9 +27,8 @@ var rlp_1 = require("../utils/rlp");
|
||||
var transaction_1 = require("../utils/transaction");
|
||||
var utf8_1 = require("../utils/utf8");
|
||||
var web_1 = require("../utils/web");
|
||||
var types_1 = require("../utils/types");
|
||||
var errors = __importStar(require("../utils/errors"));
|
||||
;
|
||||
;
|
||||
//////////////////////////////
|
||||
// Request and Response Checking
|
||||
// @TODO: not any?
|
||||
@ -230,7 +239,6 @@ function checkTransactionResponse(transaction) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
exports.checkTransactionResponse = checkTransactionResponse;
|
||||
var formatTransactionRequest = {
|
||||
from: allowNull(address_1.getAddress),
|
||||
nonce: allowNull(checkNumber),
|
||||
@ -369,12 +377,13 @@ function getEventTag(eventName) {
|
||||
}
|
||||
throw new Error('invalid event - ' + eventName);
|
||||
}
|
||||
var Provider = /** @class */ (function () {
|
||||
var Provider = /** @class */ (function (_super) {
|
||||
__extends(Provider, _super);
|
||||
function Provider(network) {
|
||||
var _this = this;
|
||||
errors.checkNew(this, Provider);
|
||||
var _this = _super.call(this) || this;
|
||||
errors.checkNew(_this, Provider);
|
||||
if (network instanceof Promise) {
|
||||
properties_1.defineReadOnly(this, 'ready', network.then(function (network) {
|
||||
properties_1.defineReadOnly(_this, 'ready', network.then(function (network) {
|
||||
properties_1.defineReadOnly(_this, '_network', network);
|
||||
return network;
|
||||
}));
|
||||
@ -382,24 +391,25 @@ var Provider = /** @class */ (function () {
|
||||
else {
|
||||
var knownNetwork = networks_1.getNetwork((network == null) ? 'homestead' : network);
|
||||
if (knownNetwork) {
|
||||
properties_1.defineReadOnly(this, '_network', knownNetwork);
|
||||
properties_1.defineReadOnly(this, 'ready', Promise.resolve(this._network));
|
||||
properties_1.defineReadOnly(_this, '_network', knownNetwork);
|
||||
properties_1.defineReadOnly(_this, 'ready', Promise.resolve(_this._network));
|
||||
}
|
||||
else {
|
||||
errors.throwError('invalid network', errors.INVALID_ARGUMENT, { arg: 'network', value: network });
|
||||
}
|
||||
}
|
||||
this._lastBlockNumber = -2;
|
||||
_this._lastBlockNumber = -2;
|
||||
// Balances being watched for changes
|
||||
this._balances = {};
|
||||
_this._balances = {};
|
||||
// Events being listened to
|
||||
this._events = [];
|
||||
this._pollingInterval = 4000;
|
||||
_this._events = [];
|
||||
_this._pollingInterval = 4000;
|
||||
// We use this to track recent emitted events; for example, if we emit a "block" of 100
|
||||
// and we get a `getBlock(100)` request which would result in null, we should retry
|
||||
// until we get a response. This provides devs with a consistent view. Similarly for
|
||||
// transaction hashes.
|
||||
this._emitted = { block: this._lastBlockNumber };
|
||||
_this._emitted = { block: _this._lastBlockNumber };
|
||||
return _this;
|
||||
}
|
||||
Provider.prototype._doPoll = function () {
|
||||
var _this = this;
|
||||
@ -776,7 +786,7 @@ var Provider = /** @class */ (function () {
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
return checkTransactionResponse(result);
|
||||
return Provider.checkTransactionResponse(result);
|
||||
});
|
||||
}, { onceBlock: _this });
|
||||
});
|
||||
@ -937,6 +947,9 @@ var Provider = /** @class */ (function () {
|
||||
});
|
||||
});
|
||||
};
|
||||
Provider.checkTransactionResponse = function (transaction) {
|
||||
return checkTransactionResponse(transaction);
|
||||
};
|
||||
Provider.prototype.doPoll = function () {
|
||||
};
|
||||
Provider.prototype.perform = function (method, params) {
|
||||
@ -1042,7 +1055,7 @@ var Provider = /** @class */ (function () {
|
||||
return this;
|
||||
};
|
||||
return Provider;
|
||||
}());
|
||||
}(types_1.MinimalProvider));
|
||||
exports.Provider = Provider;
|
||||
// See: https://github.com/isaacs/inherits/blob/master/inherits_browser.js
|
||||
function inherits(ctor, superCtor) {
|
||||
|
10
providers/types.js
Normal file
10
providers/types.js
Normal file
@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var provider_1 = require("./provider");
|
||||
exports.Block = provider_1.Block;
|
||||
exports.BlockTag = provider_1.BlockTag;
|
||||
exports.Filter = provider_1.Filter;
|
||||
exports.Log = provider_1.Log;
|
||||
exports.TransactionReceipt = provider_1.TransactionReceipt;
|
||||
exports.TransactionRequest = provider_1.TransactionRequest;
|
||||
exports.TransactionResponse = provider_1.TransactionResponse;
|
@ -200,7 +200,7 @@ describe('Test Contract Events', function() {
|
||||
|
||||
test.normalizedValues.forEach(function(expected, index) {
|
||||
if (test.indexed[index]) {
|
||||
assert.ok((parsed[index].type === 'indexed' && parsed[index].hash == null), 'parsed event data has empty Indexed - ' + index);
|
||||
assert.ok((parsed[index] instanceof ethers.types.Indexed && parsed[index].hash == null), 'parsed event data has empty Indexed - ' + index);
|
||||
} else {
|
||||
assert.ok(equals(parsed[index], expected), 'parsed event data matches - ' + index);
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ function equals(name, actual, expected) {
|
||||
|
||||
if (typeof(actual) === 'object') {
|
||||
if (expected.indexed) {
|
||||
assert.ok(actual.type === 'indexed', 'index property has index - ' + name);
|
||||
assert.ok(actual instanceof ethers.types.Indexed, 'index property has index - ' + name);
|
||||
if (expected.hash) {
|
||||
assert.equal(actual.hash, expected.hash, 'index property with known hash matches - ' + name);
|
||||
}
|
||||
|
@ -41,7 +41,6 @@ function toBN(value) {
|
||||
function toBigNumber(bn) {
|
||||
return new _BigNumber(toHex(bn));
|
||||
}
|
||||
;
|
||||
var _BigNumber = /** @class */ (function () {
|
||||
function _BigNumber(value) {
|
||||
errors.checkNew(this, _BigNumber);
|
||||
|
@ -15,7 +15,6 @@ function computeHmac(algorithm, key, data) {
|
||||
if (!supportedAlgorithms[algorithm]) {
|
||||
errors.throwError('unsupported algorithm ' + algorithm, errors.UNSUPPORTED_OPERATION, { operation: 'hmac', algorithm: algorithm });
|
||||
}
|
||||
//return arrayify(_hmac(_hash[algorithm], arrayify(key)).update(arrayify(data)).digest());
|
||||
return bytes_1.arrayify(crypto_1.createHmac(algorithm, new Buffer(bytes_1.arrayify(key))).update(new Buffer(bytes_1.arrayify(data))).digest());
|
||||
}
|
||||
exports.computeHmac = computeHmac;
|
||||
|
@ -13,6 +13,14 @@ var bytes_1 = require("./bytes");
|
||||
var keccak256_1 = require("./keccak256");
|
||||
var RLP = __importStar(require("./rlp"));
|
||||
var errors = __importStar(require("./errors"));
|
||||
/* !!!!!!!!!!!!!!!!!!!!!!!! IMPORTANT !!!!!!!!!!!!!!!!!!!!!!!
|
||||
*
|
||||
* Due to a weird ordering-issue with browserify, there is an
|
||||
* import for secp256k1 at the bottom of the file; it must be
|
||||
* required AFTER the parse and serialize exports have been
|
||||
* defined.
|
||||
*
|
||||
*/
|
||||
function handleAddress(value) {
|
||||
if (value === '0x') {
|
||||
return null;
|
||||
|
39
utils/types.js
Normal file
39
utils/types.js
Normal file
@ -0,0 +1,39 @@
|
||||
"use strict";
|
||||
///////////////////////////////
|
||||
// Bytes
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
;
|
||||
;
|
||||
;
|
||||
///////////////////////////////
|
||||
// Interface
|
||||
var Indexed = /** @class */ (function () {
|
||||
function Indexed() {
|
||||
}
|
||||
return Indexed;
|
||||
}());
|
||||
exports.Indexed = Indexed;
|
||||
/**
|
||||
* Provider
|
||||
*
|
||||
* Note: We use an abstract class so we can use instanceof to determine if an
|
||||
* object is a Provider.
|
||||
*/
|
||||
var MinimalProvider = /** @class */ (function () {
|
||||
function MinimalProvider() {
|
||||
}
|
||||
return MinimalProvider;
|
||||
}());
|
||||
exports.MinimalProvider = MinimalProvider;
|
||||
/**
|
||||
* Signer
|
||||
*
|
||||
* Note: We use an abstract class so we can use instanceof to determine if an
|
||||
* object is a Signer.
|
||||
*/
|
||||
var Signer = /** @class */ (function () {
|
||||
function Signer() {
|
||||
}
|
||||
return Signer;
|
||||
}());
|
||||
exports.Signer = Signer;
|
@ -99,6 +99,9 @@ function parseUnits(value, unitType) {
|
||||
}
|
||||
// Remove commas
|
||||
var value = value.replace(/,/g, '');
|
||||
if (unitInfo.decimals === 0) {
|
||||
return bignumber_1.bigNumberify(value);
|
||||
}
|
||||
// Is it negative?
|
||||
var negative = (value.substring(0, 1) === '-');
|
||||
if (negative) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
@ -8,8 +8,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var xmlhttprequest_1 = require("xmlhttprequest");
|
||||
var utf8_1 = require("./utf8");
|
||||
var base64_1 = require("./base64");
|
||||
var utf8_1 = require("./utf8");
|
||||
var errors = __importStar(require("./errors"));
|
||||
function fetchJson(connection, json, processFunc) {
|
||||
var headers = [];
|
||||
|
@ -13,14 +13,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var aes_js_1 = __importDefault(require("aes-js"));
|
||||
var scrypt_js_1 = __importDefault(require("scrypt-js"));
|
||||
var uuid_1 = __importDefault(require("uuid"));
|
||||
var signing_key_1 = require("./signing-key");
|
||||
var HDNode = __importStar(require("./hdnode"));
|
||||
var address_1 = require("../utils/address");
|
||||
var bytes_1 = require("../utils/bytes");
|
||||
var pbkdf2_1 = require("../utils/pbkdf2");
|
||||
var keccak256_1 = require("../utils/keccak256");
|
||||
var utf8_1 = require("../utils/utf8");
|
||||
var random_bytes_1 = require("../utils/random-bytes");
|
||||
var signing_key_1 = require("./signing-key");
|
||||
var HDNode = __importStar(require("./hdnode"));
|
||||
function looseArrayify(hexString) {
|
||||
if (typeof (hexString) === 'string' && hexString.substring(0, 2) !== '0x') {
|
||||
hexString = '0x' + hexString;
|
||||
@ -193,6 +193,9 @@ function decrypt(json, password, progressCallback) {
|
||||
reject(new Error('unsupported key-derivation derived-key length'));
|
||||
return;
|
||||
}
|
||||
if (progressCallback) {
|
||||
progressCallback(0);
|
||||
}
|
||||
scrypt_js_1.default(passwordBytes, salt, N, r, p, 64, function (error, progress, key) {
|
||||
if (error) {
|
||||
error.progress = progress;
|
||||
@ -339,6 +342,9 @@ function encrypt(privateKey, password, options, progressCallback) {
|
||||
}
|
||||
}
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (progressCallback) {
|
||||
progressCallback(0);
|
||||
}
|
||||
// We take 64 bytes:
|
||||
// - 32 bytes As normal for the Web3 secret storage (derivedKey, macPrefix)
|
||||
// - 32 bytes AES key to encrypt mnemonic with (required here to be Ethers Wallet)
|
||||
|
5
wallet/types.js
Normal file
5
wallet/types.js
Normal file
@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var secret_storage_1 = require("./secret-storage");
|
||||
exports.ProgressCallback = secret_storage_1.ProgressCallback;
|
||||
exports.EncryptOptions = secret_storage_1.EncryptOptions;
|
@ -27,13 +27,9 @@ var properties_1 = require("../utils/properties");
|
||||
var random_bytes_1 = require("../utils/random-bytes");
|
||||
var secp256k1_1 = require("../utils/secp256k1");
|
||||
var transaction_1 = require("../utils/transaction");
|
||||
var types_1 = require("../utils/types");
|
||||
exports.Signer = types_1.Signer;
|
||||
var errors = __importStar(require("../utils/errors"));
|
||||
var Signer = /** @class */ (function () {
|
||||
function Signer() {
|
||||
}
|
||||
return Signer;
|
||||
}());
|
||||
exports.Signer = Signer;
|
||||
var Wallet = /** @class */ (function (_super) {
|
||||
__extends(Wallet, _super);
|
||||
function Wallet(privateKey, provider) {
|
||||
@ -168,7 +164,13 @@ var Wallet = /** @class */ (function (_super) {
|
||||
Wallet.fromEncryptedJson = function (json, password, progressCallback) {
|
||||
if (secretStorage.isCrowdsaleWallet(json)) {
|
||||
try {
|
||||
if (progressCallback) {
|
||||
progressCallback(0);
|
||||
}
|
||||
var privateKey = secretStorage.decryptCrowdsale(json, password);
|
||||
if (progressCallback) {
|
||||
progressCallback(1);
|
||||
}
|
||||
return Promise.resolve(new Wallet(privateKey));
|
||||
}
|
||||
catch (error) {
|
||||
@ -217,5 +219,5 @@ var Wallet = /** @class */ (function (_super) {
|
||||
});
|
||||
};
|
||||
return Wallet;
|
||||
}(Signer));
|
||||
}(types_1.Signer));
|
||||
exports.Wallet = Wallet;
|
||||
|
Loading…
Reference in New Issue
Block a user