Updated dist files.
This commit is contained in:
parent
f4e247fc92
commit
7b5ce86c5b
15
contract.d.ts
vendored
15
contract.d.ts
vendored
@ -1,5 +1,6 @@
|
|||||||
import { BigNumber } from './utils/bignumber';
|
import { BigNumber } from './utils/bignumber';
|
||||||
import { Indexed, Interface } from './utils/interface';
|
import { Indexed, Interface } from './utils/interface';
|
||||||
|
import { UnsignedTransaction } from './utils/transaction';
|
||||||
import { Provider } from './providers/abstract-provider';
|
import { Provider } from './providers/abstract-provider';
|
||||||
import { Signer } from './abstract-signer';
|
import { Signer } from './abstract-signer';
|
||||||
import { Arrayish } from './utils/bytes';
|
import { Arrayish } from './utils/bytes';
|
||||||
@ -49,7 +50,6 @@ export declare class Contract {
|
|||||||
fallback(overrides?: TransactionRequest): Promise<TransactionResponse>;
|
fallback(overrides?: TransactionRequest): Promise<TransactionResponse>;
|
||||||
connect(signerOrProvider: Signer | Provider | string): Contract;
|
connect(signerOrProvider: Signer | Provider | string): Contract;
|
||||||
attach(addressOrName: string): Contract;
|
attach(addressOrName: string): Contract;
|
||||||
deploy(bytecode: string, ...args: Array<any>): Promise<Contract>;
|
|
||||||
static isIndexed(value: any): value is Indexed;
|
static isIndexed(value: any): value is Indexed;
|
||||||
private _events;
|
private _events;
|
||||||
private _getEventFilter;
|
private _getEventFilter;
|
||||||
@ -63,4 +63,17 @@ export declare class Contract {
|
|||||||
removeAllListeners(eventName: EventFilter | string): Contract;
|
removeAllListeners(eventName: EventFilter | string): Contract;
|
||||||
removeListener(eventName: any, listener: Listener): Contract;
|
removeListener(eventName: any, listener: Listener): Contract;
|
||||||
}
|
}
|
||||||
|
export declare class ContractFactory {
|
||||||
|
readonly interface: Interface;
|
||||||
|
readonly bytecode: string;
|
||||||
|
readonly signer: Signer;
|
||||||
|
constructor(contractInterface: Array<string | ParamType> | string | Interface, bytecode: Arrayish | string | {
|
||||||
|
object: string;
|
||||||
|
}, signer?: Signer);
|
||||||
|
getDeployTransaction(...args: Array<any>): UnsignedTransaction;
|
||||||
|
deploy(...args: Array<any>): Promise<Contract>;
|
||||||
|
attach(address: string): Contract;
|
||||||
|
connect(signer: Signer): ContractFactory;
|
||||||
|
static fromSolidity(compilerOutput: any, signer?: Signer): ContractFactory;
|
||||||
|
}
|
||||||
export {};
|
export {};
|
||||||
|
160
contract.js
160
contract.js
@ -258,12 +258,6 @@ var Contract = /** @class */ (function () {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// Not connected to an on-chain instance, so do not connect functions and events
|
|
||||||
if (!addressOrName) {
|
|
||||||
properties_1.defineReadOnly(this, 'address', null);
|
|
||||||
properties_1.defineReadOnly(this, 'addressPromise', Promise.resolve(null));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this._events = [];
|
this._events = [];
|
||||||
properties_1.defineReadOnly(this, 'address', addressOrName);
|
properties_1.defineReadOnly(this, 'address', addressOrName);
|
||||||
if (this.provider) {
|
if (this.provider) {
|
||||||
@ -282,6 +276,7 @@ var Contract = /** @class */ (function () {
|
|||||||
properties_1.defineReadOnly(this, 'addressPromise', Promise.resolve(address_1.getAddress(addressOrName)));
|
properties_1.defineReadOnly(this, 'addressPromise', Promise.resolve(address_1.getAddress(addressOrName)));
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
// Without a provider, we cannot use ENS names
|
||||||
errors.throwError('provider is required to use non-address contract address', errors.INVALID_ARGUMENT, { argument: 'addressOrName', value: addressOrName });
|
errors.throwError('provider is required to use non-address contract address', errors.INVALID_ARGUMENT, { argument: 'addressOrName', value: addressOrName });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -362,52 +357,6 @@ var Contract = /** @class */ (function () {
|
|||||||
Contract.prototype.attach = function (addressOrName) {
|
Contract.prototype.attach = function (addressOrName) {
|
||||||
return new Contract(addressOrName, this.interface, this.signer || this.provider);
|
return new Contract(addressOrName, this.interface, this.signer || this.provider);
|
||||||
};
|
};
|
||||||
// Deploy the contract with the bytecode, resolving to the deployed address.
|
|
||||||
// Use contract.deployTransaction.wait() to wait until the contract has
|
|
||||||
// been mined.
|
|
||||||
Contract.prototype.deploy = function (bytecode) {
|
|
||||||
var _this = this;
|
|
||||||
var args = [];
|
|
||||||
for (var _i = 1; _i < arguments.length; _i++) {
|
|
||||||
args[_i - 1] = arguments[_i];
|
|
||||||
}
|
|
||||||
if (this.signer == null) {
|
|
||||||
throw new Error('missing signer'); // @TODO: errors.throwError
|
|
||||||
}
|
|
||||||
// A lot of common tools do not prefix bytecode with a 0x
|
|
||||||
if (typeof (bytecode) === 'string' && bytecode.match(/^[0-9a-f]*$/i) && (bytecode.length % 2) == 0) {
|
|
||||||
bytecode = '0x' + bytecode;
|
|
||||||
}
|
|
||||||
if (!bytes_1.isHexString(bytecode)) {
|
|
||||||
errors.throwError('bytecode must be a valid hex string', errors.INVALID_ARGUMENT, { arg: 'bytecode', value: bytecode });
|
|
||||||
}
|
|
||||||
if ((bytecode.length % 2) !== 0) {
|
|
||||||
errors.throwError('bytecode must be valid data (even length)', errors.INVALID_ARGUMENT, { arg: 'bytecode', value: bytecode });
|
|
||||||
}
|
|
||||||
var tx = {};
|
|
||||||
if (args.length === this.interface.deployFunction.inputs.length + 1) {
|
|
||||||
tx = properties_1.shallowCopy(args.pop());
|
|
||||||
for (var key in tx) {
|
|
||||||
if (!allowedTransactionKeys[key]) {
|
|
||||||
throw new Error('unknown transaction override ' + key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
['data', 'from', 'to'].forEach(function (key) {
|
|
||||||
if (tx[key] == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
errors.throwError('cannot override ' + key, errors.UNSUPPORTED_OPERATION, { operation: key });
|
|
||||||
});
|
|
||||||
tx.data = this.interface.deployFunction.encode(bytecode, args);
|
|
||||||
errors.checkArgumentCount(args.length, this.interface.deployFunction.inputs.length, 'in Contract constructor');
|
|
||||||
// @TODO: overrides of args.length = this.interface.deployFunction.inputs.length + 1
|
|
||||||
return this.signer.sendTransaction(tx).then(function (tx) {
|
|
||||||
var contract = new Contract(address_1.getContractAddress(tx), _this.interface, _this.signer || _this.provider);
|
|
||||||
properties_1.defineReadOnly(contract, 'deployTransaction', tx);
|
|
||||||
return contract;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
Contract.isIndexed = function (value) {
|
Contract.isIndexed = function (value) {
|
||||||
return interface_1.Interface.isIndexed(value);
|
return interface_1.Interface.isIndexed(value);
|
||||||
};
|
};
|
||||||
@ -589,3 +538,110 @@ var Contract = /** @class */ (function () {
|
|||||||
return Contract;
|
return Contract;
|
||||||
}());
|
}());
|
||||||
exports.Contract = Contract;
|
exports.Contract = Contract;
|
||||||
|
var ContractFactory = /** @class */ (function () {
|
||||||
|
function ContractFactory(contractInterface, bytecode, signer) {
|
||||||
|
var bytecodeHex = null;
|
||||||
|
// Allow the bytecode object from the Solidity compiler
|
||||||
|
if (typeof (bytecode) === 'string') {
|
||||||
|
bytecodeHex = bytecode;
|
||||||
|
}
|
||||||
|
else if (bytes_1.isArrayish(bytecode)) {
|
||||||
|
bytecodeHex = bytes_1.hexlify(bytecode);
|
||||||
|
}
|
||||||
|
else if (typeof (bytecode.object) === 'string') {
|
||||||
|
bytecodeHex = bytecode.object;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
errors.throwError('bytecode must be a valid hex string', errors.INVALID_ARGUMENT, { arg: 'bytecode', value: bytecode });
|
||||||
|
}
|
||||||
|
// Make sure it is 0x prefixed
|
||||||
|
if (bytecodeHex.substring(0, 2) !== '0x') {
|
||||||
|
bytecodeHex = '0x' + bytecodeHex;
|
||||||
|
}
|
||||||
|
if (!bytes_1.isHexString(bytecodeHex)) {
|
||||||
|
errors.throwError('bytecode must be a valid hex string', errors.INVALID_ARGUMENT, { arg: 'bytecode', value: bytecode });
|
||||||
|
}
|
||||||
|
if ((bytecodeHex.length % 2) !== 0) {
|
||||||
|
errors.throwError('bytecode must be valid data (even length)', errors.INVALID_ARGUMENT, { arg: 'bytecode', value: bytecode });
|
||||||
|
}
|
||||||
|
properties_1.defineReadOnly(this, 'bytecode', bytecodeHex);
|
||||||
|
if (interface_1.Interface.isInterface(contractInterface)) {
|
||||||
|
properties_1.defineReadOnly(this, 'interface', contractInterface);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
properties_1.defineReadOnly(this, 'interface', new interface_1.Interface(contractInterface));
|
||||||
|
}
|
||||||
|
if (signer && !abstract_signer_1.Signer.isSigner(signer)) {
|
||||||
|
errors.throwError('invalid signer', errors.INVALID_ARGUMENT, { arg: 'signer', value: null });
|
||||||
|
}
|
||||||
|
properties_1.defineReadOnly(this, 'signer', signer || null);
|
||||||
|
}
|
||||||
|
ContractFactory.prototype.getDeployTransaction = function () {
|
||||||
|
var args = [];
|
||||||
|
for (var _i = 0; _i < arguments.length; _i++) {
|
||||||
|
args[_i] = arguments[_i];
|
||||||
|
}
|
||||||
|
var tx = {};
|
||||||
|
// If we have 1 additional argument, we allow transaction overrides
|
||||||
|
if (args.length === this.interface.deployFunction.inputs.length + 1) {
|
||||||
|
tx = properties_1.shallowCopy(args.pop());
|
||||||
|
for (var key in tx) {
|
||||||
|
if (!allowedTransactionKeys[key]) {
|
||||||
|
throw new Error('unknown transaction override ' + key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Do not allow these to be overridden in a deployment transaction
|
||||||
|
['data', 'from', 'to'].forEach(function (key) {
|
||||||
|
if (tx[key] == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
errors.throwError('cannot override ' + key, errors.UNSUPPORTED_OPERATION, { operation: key });
|
||||||
|
});
|
||||||
|
// Make sure the call matches the constructor signature
|
||||||
|
errors.checkArgumentCount(args.length, this.interface.deployFunction.inputs.length, 'in Contract constructor');
|
||||||
|
// Set the data to the bytecode + the encoded constructor arguments
|
||||||
|
tx.data = this.interface.deployFunction.encode(this.bytecode, args);
|
||||||
|
return tx;
|
||||||
|
};
|
||||||
|
ContractFactory.prototype.deploy = function () {
|
||||||
|
var _this = this;
|
||||||
|
var args = [];
|
||||||
|
for (var _i = 0; _i < arguments.length; _i++) {
|
||||||
|
args[_i] = arguments[_i];
|
||||||
|
}
|
||||||
|
// Get the deployment transaction (with optional overrides)
|
||||||
|
var tx = this.getDeployTransaction.apply(this, args);
|
||||||
|
// Send the deployment transaction
|
||||||
|
return this.signer.sendTransaction(tx).then(function (tx) {
|
||||||
|
var contract = new Contract(address_1.getContractAddress(tx), _this.interface, _this.signer);
|
||||||
|
properties_1.defineReadOnly(contract, 'deployTransaction', tx);
|
||||||
|
return contract;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
ContractFactory.prototype.attach = function (address) {
|
||||||
|
return new Contract(address, this.interface, this.signer);
|
||||||
|
};
|
||||||
|
ContractFactory.prototype.connect = function (signer) {
|
||||||
|
return new ContractFactory(this.interface, this.bytecode, signer);
|
||||||
|
};
|
||||||
|
ContractFactory.fromSolidity = function (compilerOutput, signer) {
|
||||||
|
if (compilerOutput == null) {
|
||||||
|
errors.throwError('missing compiler output', errors.MISSING_ARGUMENT, { argument: 'compilerOutput' });
|
||||||
|
}
|
||||||
|
if (typeof (compilerOutput) === 'string') {
|
||||||
|
compilerOutput = JSON.parse(compilerOutput);
|
||||||
|
}
|
||||||
|
var abi = compilerOutput.abi;
|
||||||
|
var bytecode = null;
|
||||||
|
if (compilerOutput.bytecode) {
|
||||||
|
bytecode = compilerOutput.bytecode;
|
||||||
|
}
|
||||||
|
else if (compilerOutput.evm && compilerOutput.evm.bytecode) {
|
||||||
|
bytecode = compilerOutput.evm.bytecode;
|
||||||
|
}
|
||||||
|
return new ContractFactory(abi, bytecode, signer);
|
||||||
|
};
|
||||||
|
return ContractFactory;
|
||||||
|
}());
|
||||||
|
exports.ContractFactory = ContractFactory;
|
||||||
|
225
dist/ethers.js
vendored
225
dist/ethers.js
vendored
@ -306,12 +306,6 @@ var Contract = /** @class */ (function () {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// Not connected to an on-chain instance, so do not connect functions and events
|
|
||||||
if (!addressOrName) {
|
|
||||||
properties_1.defineReadOnly(this, 'address', null);
|
|
||||||
properties_1.defineReadOnly(this, 'addressPromise', Promise.resolve(null));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this._events = [];
|
this._events = [];
|
||||||
properties_1.defineReadOnly(this, 'address', addressOrName);
|
properties_1.defineReadOnly(this, 'address', addressOrName);
|
||||||
if (this.provider) {
|
if (this.provider) {
|
||||||
@ -330,6 +324,7 @@ var Contract = /** @class */ (function () {
|
|||||||
properties_1.defineReadOnly(this, 'addressPromise', Promise.resolve(address_1.getAddress(addressOrName)));
|
properties_1.defineReadOnly(this, 'addressPromise', Promise.resolve(address_1.getAddress(addressOrName)));
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
// Without a provider, we cannot use ENS names
|
||||||
errors.throwError('provider is required to use non-address contract address', errors.INVALID_ARGUMENT, { argument: 'addressOrName', value: addressOrName });
|
errors.throwError('provider is required to use non-address contract address', errors.INVALID_ARGUMENT, { argument: 'addressOrName', value: addressOrName });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -410,52 +405,6 @@ var Contract = /** @class */ (function () {
|
|||||||
Contract.prototype.attach = function (addressOrName) {
|
Contract.prototype.attach = function (addressOrName) {
|
||||||
return new Contract(addressOrName, this.interface, this.signer || this.provider);
|
return new Contract(addressOrName, this.interface, this.signer || this.provider);
|
||||||
};
|
};
|
||||||
// Deploy the contract with the bytecode, resolving to the deployed address.
|
|
||||||
// Use contract.deployTransaction.wait() to wait until the contract has
|
|
||||||
// been mined.
|
|
||||||
Contract.prototype.deploy = function (bytecode) {
|
|
||||||
var _this = this;
|
|
||||||
var args = [];
|
|
||||||
for (var _i = 1; _i < arguments.length; _i++) {
|
|
||||||
args[_i - 1] = arguments[_i];
|
|
||||||
}
|
|
||||||
if (this.signer == null) {
|
|
||||||
throw new Error('missing signer'); // @TODO: errors.throwError
|
|
||||||
}
|
|
||||||
// A lot of common tools do not prefix bytecode with a 0x
|
|
||||||
if (typeof (bytecode) === 'string' && bytecode.match(/^[0-9a-f]*$/i) && (bytecode.length % 2) == 0) {
|
|
||||||
bytecode = '0x' + bytecode;
|
|
||||||
}
|
|
||||||
if (!bytes_1.isHexString(bytecode)) {
|
|
||||||
errors.throwError('bytecode must be a valid hex string', errors.INVALID_ARGUMENT, { arg: 'bytecode', value: bytecode });
|
|
||||||
}
|
|
||||||
if ((bytecode.length % 2) !== 0) {
|
|
||||||
errors.throwError('bytecode must be valid data (even length)', errors.INVALID_ARGUMENT, { arg: 'bytecode', value: bytecode });
|
|
||||||
}
|
|
||||||
var tx = {};
|
|
||||||
if (args.length === this.interface.deployFunction.inputs.length + 1) {
|
|
||||||
tx = properties_1.shallowCopy(args.pop());
|
|
||||||
for (var key in tx) {
|
|
||||||
if (!allowedTransactionKeys[key]) {
|
|
||||||
throw new Error('unknown transaction override ' + key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
['data', 'from', 'to'].forEach(function (key) {
|
|
||||||
if (tx[key] == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
errors.throwError('cannot override ' + key, errors.UNSUPPORTED_OPERATION, { operation: key });
|
|
||||||
});
|
|
||||||
tx.data = this.interface.deployFunction.encode(bytecode, args);
|
|
||||||
errors.checkArgumentCount(args.length, this.interface.deployFunction.inputs.length, 'in Contract constructor');
|
|
||||||
// @TODO: overrides of args.length = this.interface.deployFunction.inputs.length + 1
|
|
||||||
return this.signer.sendTransaction(tx).then(function (tx) {
|
|
||||||
var contract = new Contract(address_1.getContractAddress(tx), _this.interface, _this.signer || _this.provider);
|
|
||||||
properties_1.defineReadOnly(contract, 'deployTransaction', tx);
|
|
||||||
return contract;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
Contract.isIndexed = function (value) {
|
Contract.isIndexed = function (value) {
|
||||||
return interface_1.Interface.isIndexed(value);
|
return interface_1.Interface.isIndexed(value);
|
||||||
};
|
};
|
||||||
@ -637,6 +586,113 @@ var Contract = /** @class */ (function () {
|
|||||||
return Contract;
|
return Contract;
|
||||||
}());
|
}());
|
||||||
exports.Contract = Contract;
|
exports.Contract = Contract;
|
||||||
|
var ContractFactory = /** @class */ (function () {
|
||||||
|
function ContractFactory(contractInterface, bytecode, signer) {
|
||||||
|
var bytecodeHex = null;
|
||||||
|
// Allow the bytecode object from the Solidity compiler
|
||||||
|
if (typeof (bytecode) === 'string') {
|
||||||
|
bytecodeHex = bytecode;
|
||||||
|
}
|
||||||
|
else if (bytes_1.isArrayish(bytecode)) {
|
||||||
|
bytecodeHex = bytes_1.hexlify(bytecode);
|
||||||
|
}
|
||||||
|
else if (typeof (bytecode.object) === 'string') {
|
||||||
|
bytecodeHex = bytecode.object;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
errors.throwError('bytecode must be a valid hex string', errors.INVALID_ARGUMENT, { arg: 'bytecode', value: bytecode });
|
||||||
|
}
|
||||||
|
// Make sure it is 0x prefixed
|
||||||
|
if (bytecodeHex.substring(0, 2) !== '0x') {
|
||||||
|
bytecodeHex = '0x' + bytecodeHex;
|
||||||
|
}
|
||||||
|
if (!bytes_1.isHexString(bytecodeHex)) {
|
||||||
|
errors.throwError('bytecode must be a valid hex string', errors.INVALID_ARGUMENT, { arg: 'bytecode', value: bytecode });
|
||||||
|
}
|
||||||
|
if ((bytecodeHex.length % 2) !== 0) {
|
||||||
|
errors.throwError('bytecode must be valid data (even length)', errors.INVALID_ARGUMENT, { arg: 'bytecode', value: bytecode });
|
||||||
|
}
|
||||||
|
properties_1.defineReadOnly(this, 'bytecode', bytecodeHex);
|
||||||
|
if (interface_1.Interface.isInterface(contractInterface)) {
|
||||||
|
properties_1.defineReadOnly(this, 'interface', contractInterface);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
properties_1.defineReadOnly(this, 'interface', new interface_1.Interface(contractInterface));
|
||||||
|
}
|
||||||
|
if (signer && !abstract_signer_1.Signer.isSigner(signer)) {
|
||||||
|
errors.throwError('invalid signer', errors.INVALID_ARGUMENT, { arg: 'signer', value: null });
|
||||||
|
}
|
||||||
|
properties_1.defineReadOnly(this, 'signer', signer || null);
|
||||||
|
}
|
||||||
|
ContractFactory.prototype.getDeployTransaction = function () {
|
||||||
|
var args = [];
|
||||||
|
for (var _i = 0; _i < arguments.length; _i++) {
|
||||||
|
args[_i] = arguments[_i];
|
||||||
|
}
|
||||||
|
var tx = {};
|
||||||
|
// If we have 1 additional argument, we allow transaction overrides
|
||||||
|
if (args.length === this.interface.deployFunction.inputs.length + 1) {
|
||||||
|
tx = properties_1.shallowCopy(args.pop());
|
||||||
|
for (var key in tx) {
|
||||||
|
if (!allowedTransactionKeys[key]) {
|
||||||
|
throw new Error('unknown transaction override ' + key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Do not allow these to be overridden in a deployment transaction
|
||||||
|
['data', 'from', 'to'].forEach(function (key) {
|
||||||
|
if (tx[key] == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
errors.throwError('cannot override ' + key, errors.UNSUPPORTED_OPERATION, { operation: key });
|
||||||
|
});
|
||||||
|
// Make sure the call matches the constructor signature
|
||||||
|
errors.checkArgumentCount(args.length, this.interface.deployFunction.inputs.length, 'in Contract constructor');
|
||||||
|
// Set the data to the bytecode + the encoded constructor arguments
|
||||||
|
tx.data = this.interface.deployFunction.encode(this.bytecode, args);
|
||||||
|
return tx;
|
||||||
|
};
|
||||||
|
ContractFactory.prototype.deploy = function () {
|
||||||
|
var _this = this;
|
||||||
|
var args = [];
|
||||||
|
for (var _i = 0; _i < arguments.length; _i++) {
|
||||||
|
args[_i] = arguments[_i];
|
||||||
|
}
|
||||||
|
// Get the deployment transaction (with optional overrides)
|
||||||
|
var tx = this.getDeployTransaction.apply(this, args);
|
||||||
|
// Send the deployment transaction
|
||||||
|
return this.signer.sendTransaction(tx).then(function (tx) {
|
||||||
|
var contract = new Contract(address_1.getContractAddress(tx), _this.interface, _this.signer);
|
||||||
|
properties_1.defineReadOnly(contract, 'deployTransaction', tx);
|
||||||
|
return contract;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
ContractFactory.prototype.attach = function (address) {
|
||||||
|
return new Contract(address, this.interface, this.signer);
|
||||||
|
};
|
||||||
|
ContractFactory.prototype.connect = function (signer) {
|
||||||
|
return new ContractFactory(this.interface, this.bytecode, signer);
|
||||||
|
};
|
||||||
|
ContractFactory.fromSolidity = function (compilerOutput, signer) {
|
||||||
|
if (compilerOutput == null) {
|
||||||
|
errors.throwError('missing compiler output', errors.MISSING_ARGUMENT, { argument: 'compilerOutput' });
|
||||||
|
}
|
||||||
|
if (typeof (compilerOutput) === 'string') {
|
||||||
|
compilerOutput = JSON.parse(compilerOutput);
|
||||||
|
}
|
||||||
|
var abi = compilerOutput.abi;
|
||||||
|
var bytecode = null;
|
||||||
|
if (compilerOutput.bytecode) {
|
||||||
|
bytecode = compilerOutput.bytecode;
|
||||||
|
}
|
||||||
|
else if (compilerOutput.evm && compilerOutput.evm.bytecode) {
|
||||||
|
bytecode = compilerOutput.evm.bytecode;
|
||||||
|
}
|
||||||
|
return new ContractFactory(abi, bytecode, signer);
|
||||||
|
};
|
||||||
|
return ContractFactory;
|
||||||
|
}());
|
||||||
|
exports.ContractFactory = ContractFactory;
|
||||||
|
|
||||||
},{"./abstract-signer":2,"./constants":3,"./errors":5,"./providers/abstract-provider":49,"./utils/abi-coder":58,"./utils/address":59,"./utils/bignumber":61,"./utils/bytes":62,"./utils/interface":67,"./utils/properties":72}],5:[function(require,module,exports){
|
},{"./abstract-signer":2,"./constants":3,"./errors":5,"./providers/abstract-provider":49,"./utils/abi-coder":58,"./utils/address":59,"./utils/bignumber":61,"./utils/bytes":62,"./utils/interface":67,"./utils/properties":72}],5:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
@ -760,6 +816,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
var contract_1 = require("./contract");
|
var contract_1 = require("./contract");
|
||||||
exports.Contract = contract_1.Contract;
|
exports.Contract = contract_1.Contract;
|
||||||
|
exports.ContractFactory = contract_1.ContractFactory;
|
||||||
exports.VoidSigner = contract_1.VoidSigner;
|
exports.VoidSigner = contract_1.VoidSigner;
|
||||||
var abstract_signer_1 = require("./abstract-signer");
|
var abstract_signer_1 = require("./abstract-signer");
|
||||||
exports.Signer = abstract_signer_1.Signer;
|
exports.Signer = abstract_signer_1.Signer;
|
||||||
@ -13709,6 +13766,7 @@ exports.parseBytes32String = utf8_1.parseBytes32String;
|
|||||||
exports.toUtf8Bytes = utf8_1.toUtf8Bytes;
|
exports.toUtf8Bytes = utf8_1.toUtf8Bytes;
|
||||||
exports.toUtf8String = utf8_1.toUtf8String;
|
exports.toUtf8String = utf8_1.toUtf8String;
|
||||||
var units_1 = require("./units");
|
var units_1 = require("./units");
|
||||||
|
exports.commify = units_1.commify;
|
||||||
exports.formatEther = units_1.formatEther;
|
exports.formatEther = units_1.formatEther;
|
||||||
exports.parseEther = units_1.parseEther;
|
exports.parseEther = units_1.parseEther;
|
||||||
exports.formatUnits = units_1.formatUnits;
|
exports.formatUnits = units_1.formatUnits;
|
||||||
@ -15472,21 +15530,51 @@ function getUnitInfo(name) {
|
|||||||
}
|
}
|
||||||
// Make sure we got something
|
// Make sure we got something
|
||||||
if (!info) {
|
if (!info) {
|
||||||
errors.throwError('invalid unitType', errors.INVALID_ARGUMENT, { arg: 'name', value: name });
|
errors.throwError('invalid unitType', errors.INVALID_ARGUMENT, { argument: 'name', value: name });
|
||||||
}
|
}
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
function formatUnits(value, unitType, options) {
|
// Some environments have issues with RegEx that contain back-tracking, so we cannot
|
||||||
/*
|
// use them.
|
||||||
if (typeof(unitType) === 'object' && !options) {
|
function commify(value) {
|
||||||
options = unitType;
|
var comps = String(value).split('.');
|
||||||
unitType = undefined;
|
if (comps.length > 2 || !comps[0].match(/^-?[0-9]*$/) || (comps[1] && !comps[1].match(/^[0-9]*$/)) || value === '.' || value === '-.') {
|
||||||
|
errors.throwError('invalid value', errors.INVALID_ARGUMENT, { argument: 'value', value: value });
|
||||||
}
|
}
|
||||||
if (unitType == null) { unitType = 18; }
|
// Make sure we have at least one whole digit (0 if none)
|
||||||
*/
|
var whole = comps[0];
|
||||||
if (!options) {
|
var negative = '';
|
||||||
options = {};
|
if (whole.substring(0, 1) === '-') {
|
||||||
|
negative = '-';
|
||||||
|
whole = whole.substring(1);
|
||||||
}
|
}
|
||||||
|
// Make sure we have at least 1 whole digit with no leading zeros
|
||||||
|
while (whole.substring(0, 1) === '0') {
|
||||||
|
whole = whole.substring(1);
|
||||||
|
}
|
||||||
|
if (whole === '') {
|
||||||
|
whole = '0';
|
||||||
|
}
|
||||||
|
var suffix = '';
|
||||||
|
if (comps.length === 2) {
|
||||||
|
suffix = '.' + (comps[1] || '0');
|
||||||
|
}
|
||||||
|
var formatted = [];
|
||||||
|
while (whole.length) {
|
||||||
|
if (whole.length <= 3) {
|
||||||
|
formatted.unshift(whole);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var index = whole.length - 3;
|
||||||
|
formatted.unshift(whole.substring(index));
|
||||||
|
whole = whole.substring(0, index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return negative + formatted.join(',') + suffix;
|
||||||
|
}
|
||||||
|
exports.commify = commify;
|
||||||
|
function formatUnits(value, unitType) {
|
||||||
var unitInfo = getUnitInfo(unitType);
|
var unitInfo = getUnitInfo(unitType);
|
||||||
// Make sure wei is a big number (convert as necessary)
|
// Make sure wei is a big number (convert as necessary)
|
||||||
value = bignumber_1.bigNumberify(value);
|
value = bignumber_1.bigNumberify(value);
|
||||||
@ -15498,14 +15586,9 @@ function formatUnits(value, unitType, options) {
|
|||||||
while (fraction.length < unitInfo.decimals) {
|
while (fraction.length < unitInfo.decimals) {
|
||||||
fraction = '0' + fraction;
|
fraction = '0' + fraction;
|
||||||
}
|
}
|
||||||
// Strip off trailing zeros (but keep one if would otherwise be bare decimal point)
|
// Strip training 0
|
||||||
if (!options.pad) {
|
|
||||||
fraction = fraction.match(/^([0-9]*[1-9]|0)(0*)/)[1];
|
fraction = fraction.match(/^([0-9]*[1-9]|0)(0*)/)[1];
|
||||||
}
|
|
||||||
var whole = value.div(unitInfo.tenPower).toString();
|
var whole = value.div(unitInfo.tenPower).toString();
|
||||||
if (options.commify) {
|
|
||||||
whole = whole.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
||||||
}
|
|
||||||
value = whole + '.' + fraction;
|
value = whole + '.' + fraction;
|
||||||
if (negative) {
|
if (negative) {
|
||||||
value = '-' + value;
|
value = '-' + value;
|
||||||
@ -15521,8 +15604,6 @@ function parseUnits(value, unitType) {
|
|||||||
if (typeof (value) !== 'string' || !value.match(/^-?[0-9.,]+$/)) {
|
if (typeof (value) !== 'string' || !value.match(/^-?[0-9.,]+$/)) {
|
||||||
errors.throwError('invalid decimal value', errors.INVALID_ARGUMENT, { arg: 'value', value: value });
|
errors.throwError('invalid decimal value', errors.INVALID_ARGUMENT, { arg: 'value', value: value });
|
||||||
}
|
}
|
||||||
// Remove commas
|
|
||||||
var value = value.replace(/,/g, '');
|
|
||||||
if (unitInfo.decimals === 0) {
|
if (unitInfo.decimals === 0) {
|
||||||
return bignumber_1.bigNumberify(value);
|
return bignumber_1.bigNumberify(value);
|
||||||
}
|
}
|
||||||
@ -15563,8 +15644,8 @@ function parseUnits(value, unitType) {
|
|||||||
return wei;
|
return wei;
|
||||||
}
|
}
|
||||||
exports.parseUnits = parseUnits;
|
exports.parseUnits = parseUnits;
|
||||||
function formatEther(wei, options) {
|
function formatEther(wei) {
|
||||||
return formatUnits(wei, 18, options);
|
return formatUnits(wei, 18);
|
||||||
}
|
}
|
||||||
exports.formatEther = formatEther;
|
exports.formatEther = formatEther;
|
||||||
function parseEther(ether) {
|
function parseEther(ether) {
|
||||||
|
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
90
dist/ethers.types.txt
vendored
90
dist/ethers.types.txt
vendored
@ -7,7 +7,7 @@ declare module 'ethers' {
|
|||||||
}
|
}
|
||||||
|
|
||||||
declare module 'ethers/ethers' {
|
declare module 'ethers/ethers' {
|
||||||
import { Contract, VoidSigner } from 'ethers/contract';
|
import { Contract, ContractFactory, VoidSigner } from 'ethers/contract';
|
||||||
import { Signer } from 'ethers/abstract-signer';
|
import { Signer } from 'ethers/abstract-signer';
|
||||||
import { Wallet } from 'ethers/wallet';
|
import { Wallet } from 'ethers/wallet';
|
||||||
import * as constants from 'ethers/constants';
|
import * as constants from 'ethers/constants';
|
||||||
@ -19,12 +19,13 @@ declare module 'ethers/ethers' {
|
|||||||
import { version } from 'ethers/_version';
|
import { version } from 'ethers/_version';
|
||||||
import { ContractFunction, Event, EventFilter } from 'ethers/contract';
|
import { ContractFunction, Event, EventFilter } from 'ethers/contract';
|
||||||
function getDefaultProvider(network?: utils.Network | string): providers.BaseProvider;
|
function getDefaultProvider(network?: utils.Network | string): providers.BaseProvider;
|
||||||
export { Signer, Wallet, VoidSigner, getDefaultProvider, providers, Contract, constants, errors, utils, wordlists, platform, version, ContractFunction, Event, EventFilter };
|
export { Signer, Wallet, VoidSigner, getDefaultProvider, providers, Contract, ContractFactory, constants, errors, utils, wordlists, platform, version, ContractFunction, Event, EventFilter };
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module 'ethers/contract' {
|
declare module 'ethers/contract' {
|
||||||
import { BigNumber } from 'ethers/utils/bignumber';
|
import { BigNumber } from 'ethers/utils/bignumber';
|
||||||
import { Indexed, Interface } from 'ethers/utils/interface';
|
import { Indexed, Interface } from 'ethers/utils/interface';
|
||||||
|
import { UnsignedTransaction } from 'ethers/utils/transaction';
|
||||||
import { Provider } from 'ethers/providers/abstract-provider';
|
import { Provider } from 'ethers/providers/abstract-provider';
|
||||||
import { Signer } from 'ethers/abstract-signer';
|
import { Signer } from 'ethers/abstract-signer';
|
||||||
import { Arrayish } from 'ethers/utils/bytes';
|
import { Arrayish } from 'ethers/utils/bytes';
|
||||||
@ -73,7 +74,6 @@ declare module 'ethers/contract' {
|
|||||||
fallback(overrides?: TransactionRequest): Promise<TransactionResponse>;
|
fallback(overrides?: TransactionRequest): Promise<TransactionResponse>;
|
||||||
connect(signerOrProvider: Signer | Provider | string): Contract;
|
connect(signerOrProvider: Signer | Provider | string): Contract;
|
||||||
attach(addressOrName: string): Contract;
|
attach(addressOrName: string): Contract;
|
||||||
deploy(bytecode: string, ...args: Array<any>): Promise<Contract>;
|
|
||||||
static isIndexed(value: any): value is Indexed;
|
static isIndexed(value: any): value is Indexed;
|
||||||
on(event: EventFilter | string, listener: Listener): Contract;
|
on(event: EventFilter | string, listener: Listener): Contract;
|
||||||
once(event: EventFilter | string, listener: Listener): Contract;
|
once(event: EventFilter | string, listener: Listener): Contract;
|
||||||
@ -84,6 +84,19 @@ declare module 'ethers/contract' {
|
|||||||
removeAllListeners(eventName: EventFilter | string): Contract;
|
removeAllListeners(eventName: EventFilter | string): Contract;
|
||||||
removeListener(eventName: any, listener: Listener): Contract;
|
removeListener(eventName: any, listener: Listener): Contract;
|
||||||
}
|
}
|
||||||
|
export class ContractFactory {
|
||||||
|
readonly interface: Interface;
|
||||||
|
readonly bytecode: string;
|
||||||
|
readonly signer: Signer;
|
||||||
|
constructor(contractInterface: Array<string | ParamType> | string | Interface, bytecode: Arrayish | string | {
|
||||||
|
object: string;
|
||||||
|
}, signer?: Signer);
|
||||||
|
getDeployTransaction(...args: Array<any>): UnsignedTransaction;
|
||||||
|
deploy(...args: Array<any>): Promise<Contract>;
|
||||||
|
attach(address: string): Contract;
|
||||||
|
connect(signer: Signer): ContractFactory;
|
||||||
|
static fromSolidity(compilerOutput: any, signer?: Signer): ContractFactory;
|
||||||
|
}
|
||||||
export {};
|
export {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,7 +219,7 @@ declare module 'ethers/utils' {
|
|||||||
import { SigningKey } from 'ethers/utils/signing-key';
|
import { SigningKey } from 'ethers/utils/signing-key';
|
||||||
import { parse as parseTransaction, serialize as serializeTransaction } from 'ethers/utils/transaction';
|
import { parse as parseTransaction, serialize as serializeTransaction } from 'ethers/utils/transaction';
|
||||||
import { formatBytes32String, parseBytes32String, toUtf8Bytes, toUtf8String } from 'ethers/utils/utf8';
|
import { formatBytes32String, parseBytes32String, toUtf8Bytes, toUtf8String } from 'ethers/utils/utf8';
|
||||||
import { formatEther, parseEther, formatUnits, parseUnits } from 'ethers/utils/units';
|
import { commify, formatEther, parseEther, formatUnits, parseUnits } from 'ethers/utils/units';
|
||||||
import { fetchJson } from 'ethers/utils/web';
|
import { fetchJson } from 'ethers/utils/web';
|
||||||
import { SupportedAlgorithms } from 'ethers/utils/hmac';
|
import { SupportedAlgorithms } from 'ethers/utils/hmac';
|
||||||
import { UnicodeNormalizationForm } from 'ethers/utils/utf8';
|
import { UnicodeNormalizationForm } from 'ethers/utils/utf8';
|
||||||
@ -219,7 +232,7 @@ declare module 'ethers/utils' {
|
|||||||
import { ConnectionInfo, OnceBlockable, PollOptions } from 'ethers/utils/web';
|
import { ConnectionInfo, OnceBlockable, PollOptions } from 'ethers/utils/web';
|
||||||
import { EncryptOptions, ProgressCallback } from 'ethers/utils/secret-storage';
|
import { EncryptOptions, ProgressCallback } from 'ethers/utils/secret-storage';
|
||||||
import { Wordlist } from 'ethers/utils/wordlist';
|
import { Wordlist } from 'ethers/utils/wordlist';
|
||||||
export { AbiCoder, defaultAbiCoder, formatSignature, formatParamType, parseSignature, parseParamType, RLP, fetchJson, getNetwork, deepCopy, defineReadOnly, resolveProperties, shallowCopy, arrayify, concat, padZeros, stripZeros, HDNode, SigningKey, Interface, base64, BigNumber, bigNumberify, hexlify, hexStripZeros, hexZeroPad, hexDataLength, hexDataSlice, toUtf8Bytes, toUtf8String, formatBytes32String, parseBytes32String, hashMessage, namehash, id, getAddress, getIcapAddress, getContractAddress, formatEther, parseEther, formatUnits, parseUnits, 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, 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, };
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module 'ethers/wordlists' {
|
declare module 'ethers/wordlists' {
|
||||||
@ -387,6 +400,37 @@ declare module 'ethers/utils/interface' {
|
|||||||
export {};
|
export {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare module 'ethers/utils/transaction' {
|
||||||
|
import { BigNumber } from 'ethers/utils/bignumber';
|
||||||
|
import { Arrayish, Signature } from 'ethers/utils/bytes';
|
||||||
|
import { BigNumberish } from 'ethers/utils/bignumber';
|
||||||
|
export type UnsignedTransaction = {
|
||||||
|
to?: string;
|
||||||
|
nonce?: number;
|
||||||
|
gasLimit?: BigNumberish;
|
||||||
|
gasPrice?: BigNumberish;
|
||||||
|
data?: Arrayish;
|
||||||
|
value?: BigNumberish;
|
||||||
|
chainId?: number;
|
||||||
|
};
|
||||||
|
export interface Transaction {
|
||||||
|
hash?: string;
|
||||||
|
to?: string;
|
||||||
|
from?: string;
|
||||||
|
nonce: number;
|
||||||
|
gasLimit: BigNumber;
|
||||||
|
gasPrice: BigNumber;
|
||||||
|
data: string;
|
||||||
|
value: BigNumber;
|
||||||
|
chainId: number;
|
||||||
|
r?: string;
|
||||||
|
s?: string;
|
||||||
|
v?: number;
|
||||||
|
}
|
||||||
|
export function serialize(transaction: UnsignedTransaction, signature?: Arrayish | Signature): string;
|
||||||
|
export function parse(rawTransaction: Arrayish): Transaction;
|
||||||
|
}
|
||||||
|
|
||||||
declare module 'ethers/providers/abstract-provider' {
|
declare module 'ethers/providers/abstract-provider' {
|
||||||
import { BigNumber } from 'ethers/utils/bignumber';
|
import { BigNumber } from 'ethers/utils/bignumber';
|
||||||
import { Arrayish } from 'ethers/utils/bytes';
|
import { Arrayish } from 'ethers/utils/bytes';
|
||||||
@ -904,37 +948,6 @@ declare module 'ethers/utils/secp256k1' {
|
|||||||
export function verifyMessage(message: Arrayish | string, signature: Signature | string): string;
|
export function verifyMessage(message: Arrayish | string, signature: Signature | string): string;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module 'ethers/utils/transaction' {
|
|
||||||
import { BigNumber } from 'ethers/utils/bignumber';
|
|
||||||
import { Arrayish, Signature } from 'ethers/utils/bytes';
|
|
||||||
import { BigNumberish } from 'ethers/utils/bignumber';
|
|
||||||
export type UnsignedTransaction = {
|
|
||||||
to?: string;
|
|
||||||
nonce?: number;
|
|
||||||
gasLimit?: BigNumberish;
|
|
||||||
gasPrice?: BigNumberish;
|
|
||||||
data?: Arrayish;
|
|
||||||
value?: BigNumberish;
|
|
||||||
chainId?: number;
|
|
||||||
};
|
|
||||||
export interface Transaction {
|
|
||||||
hash?: string;
|
|
||||||
to?: string;
|
|
||||||
from?: string;
|
|
||||||
nonce: number;
|
|
||||||
gasLimit: BigNumber;
|
|
||||||
gasPrice: BigNumber;
|
|
||||||
data: string;
|
|
||||||
value: BigNumber;
|
|
||||||
chainId: number;
|
|
||||||
r?: string;
|
|
||||||
s?: string;
|
|
||||||
v?: number;
|
|
||||||
}
|
|
||||||
export function serialize(transaction: UnsignedTransaction, signature?: Arrayish | Signature): string;
|
|
||||||
export function parse(rawTransaction: Arrayish): Transaction;
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module 'ethers/utils/utf8' {
|
declare module 'ethers/utils/utf8' {
|
||||||
import { Arrayish } from 'ethers/utils/bytes';
|
import { Arrayish } from 'ethers/utils/bytes';
|
||||||
export enum UnicodeNormalizationForm {
|
export enum UnicodeNormalizationForm {
|
||||||
@ -953,9 +966,10 @@ declare module 'ethers/utils/utf8' {
|
|||||||
declare module 'ethers/utils/units' {
|
declare module 'ethers/utils/units' {
|
||||||
import { BigNumber } from 'ethers/utils/bignumber';
|
import { BigNumber } from 'ethers/utils/bignumber';
|
||||||
import { BigNumberish } from 'ethers/utils/bignumber';
|
import { BigNumberish } from 'ethers/utils/bignumber';
|
||||||
export function formatUnits(value: BigNumberish, unitType?: string | number, options?: any): string;
|
export function commify(value: string | number): string;
|
||||||
|
export function formatUnits(value: BigNumberish, unitType?: string | number): string;
|
||||||
export function parseUnits(value: string, unitType?: string | number): BigNumber;
|
export function parseUnits(value: string, unitType?: string | number): BigNumber;
|
||||||
export function formatEther(wei: BigNumberish, options?: any): string;
|
export function formatEther(wei: BigNumberish): string;
|
||||||
export function parseEther(ether: string): BigNumber;
|
export function parseEther(ether: string): BigNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
ethers.d.ts
vendored
4
ethers.d.ts
vendored
@ -1,4 +1,4 @@
|
|||||||
import { Contract, VoidSigner } from './contract';
|
import { Contract, ContractFactory, VoidSigner } from './contract';
|
||||||
import { Signer } from './abstract-signer';
|
import { Signer } from './abstract-signer';
|
||||||
import { Wallet } from './wallet';
|
import { Wallet } from './wallet';
|
||||||
import * as constants from './constants';
|
import * as constants from './constants';
|
||||||
@ -10,4 +10,4 @@ import { platform } from './utils/shims';
|
|||||||
import { version } from './_version';
|
import { version } from './_version';
|
||||||
import { ContractFunction, Event, EventFilter } from './contract';
|
import { ContractFunction, Event, EventFilter } from './contract';
|
||||||
declare function getDefaultProvider(network?: utils.Network | string): providers.BaseProvider;
|
declare function getDefaultProvider(network?: utils.Network | string): providers.BaseProvider;
|
||||||
export { Signer, Wallet, VoidSigner, getDefaultProvider, providers, Contract, constants, errors, utils, wordlists, platform, version, ContractFunction, Event, EventFilter };
|
export { Signer, Wallet, VoidSigner, getDefaultProvider, providers, Contract, ContractFactory, constants, errors, utils, wordlists, platform, version, ContractFunction, Event, EventFilter };
|
||||||
|
@ -9,6 +9,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
var contract_1 = require("./contract");
|
var contract_1 = require("./contract");
|
||||||
exports.Contract = contract_1.Contract;
|
exports.Contract = contract_1.Contract;
|
||||||
|
exports.ContractFactory = contract_1.ContractFactory;
|
||||||
exports.VoidSigner = contract_1.VoidSigner;
|
exports.VoidSigner = contract_1.VoidSigner;
|
||||||
var abstract_signer_1 = require("./abstract-signer");
|
var abstract_signer_1 = require("./abstract-signer");
|
||||||
exports.Signer = abstract_signer_1.Signer;
|
exports.Signer = abstract_signer_1.Signer;
|
||||||
|
4
utils/index.d.ts
vendored
4
utils/index.d.ts
vendored
@ -18,7 +18,7 @@ import { computeAddress, computePublicKey, recoverAddress, recoverPublicKey, ver
|
|||||||
import { SigningKey } from './signing-key';
|
import { SigningKey } from './signing-key';
|
||||||
import { parse as parseTransaction, serialize as serializeTransaction } from './transaction';
|
import { parse as parseTransaction, serialize as serializeTransaction } from './transaction';
|
||||||
import { formatBytes32String, parseBytes32String, toUtf8Bytes, toUtf8String } from './utf8';
|
import { formatBytes32String, parseBytes32String, toUtf8Bytes, toUtf8String } from './utf8';
|
||||||
import { formatEther, parseEther, formatUnits, parseUnits } from './units';
|
import { commify, formatEther, parseEther, formatUnits, parseUnits } from './units';
|
||||||
import { fetchJson } from './web';
|
import { fetchJson } from './web';
|
||||||
import { SupportedAlgorithms } from './hmac';
|
import { SupportedAlgorithms } from './hmac';
|
||||||
import { UnicodeNormalizationForm } from './utf8';
|
import { UnicodeNormalizationForm } from './utf8';
|
||||||
@ -31,4 +31,4 @@ import { Transaction, UnsignedTransaction } from './transaction';
|
|||||||
import { ConnectionInfo, OnceBlockable, PollOptions } from './web';
|
import { ConnectionInfo, OnceBlockable, PollOptions } from './web';
|
||||||
import { EncryptOptions, ProgressCallback } from './secret-storage';
|
import { EncryptOptions, ProgressCallback } from './secret-storage';
|
||||||
import { Wordlist } from './wordlist';
|
import { Wordlist } from './wordlist';
|
||||||
export { AbiCoder, defaultAbiCoder, formatSignature, formatParamType, parseSignature, parseParamType, RLP, fetchJson, getNetwork, deepCopy, defineReadOnly, resolveProperties, shallowCopy, arrayify, concat, padZeros, stripZeros, HDNode, SigningKey, Interface, base64, BigNumber, bigNumberify, hexlify, hexStripZeros, hexZeroPad, hexDataLength, hexDataSlice, toUtf8Bytes, toUtf8String, formatBytes32String, parseBytes32String, hashMessage, namehash, id, getAddress, getIcapAddress, getContractAddress, formatEther, parseEther, formatUnits, parseUnits, 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, 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, };
|
||||||
|
@ -81,6 +81,7 @@ exports.parseBytes32String = utf8_1.parseBytes32String;
|
|||||||
exports.toUtf8Bytes = utf8_1.toUtf8Bytes;
|
exports.toUtf8Bytes = utf8_1.toUtf8Bytes;
|
||||||
exports.toUtf8String = utf8_1.toUtf8String;
|
exports.toUtf8String = utf8_1.toUtf8String;
|
||||||
var units_1 = require("./units");
|
var units_1 = require("./units");
|
||||||
|
exports.commify = units_1.commify;
|
||||||
exports.formatEther = units_1.formatEther;
|
exports.formatEther = units_1.formatEther;
|
||||||
exports.parseEther = units_1.parseEther;
|
exports.parseEther = units_1.parseEther;
|
||||||
exports.formatUnits = units_1.formatUnits;
|
exports.formatUnits = units_1.formatUnits;
|
||||||
|
5
utils/units.d.ts
vendored
5
utils/units.d.ts
vendored
@ -1,6 +1,7 @@
|
|||||||
import { BigNumber } from './bignumber';
|
import { BigNumber } from './bignumber';
|
||||||
import { BigNumberish } from './bignumber';
|
import { BigNumberish } from './bignumber';
|
||||||
export declare function formatUnits(value: BigNumberish, unitType?: string | number, options?: any): string;
|
export declare function commify(value: string | number): string;
|
||||||
|
export declare function formatUnits(value: BigNumberish, unitType?: string | number): string;
|
||||||
export declare function parseUnits(value: string, unitType?: string | number): BigNumber;
|
export declare function parseUnits(value: string, unitType?: string | number): BigNumber;
|
||||||
export declare function formatEther(wei: BigNumberish, options?: any): string;
|
export declare function formatEther(wei: BigNumberish): string;
|
||||||
export declare function parseEther(ether: string): BigNumber;
|
export declare function parseEther(ether: string): BigNumber;
|
||||||
|
@ -49,21 +49,51 @@ function getUnitInfo(name) {
|
|||||||
}
|
}
|
||||||
// Make sure we got something
|
// Make sure we got something
|
||||||
if (!info) {
|
if (!info) {
|
||||||
errors.throwError('invalid unitType', errors.INVALID_ARGUMENT, { arg: 'name', value: name });
|
errors.throwError('invalid unitType', errors.INVALID_ARGUMENT, { argument: 'name', value: name });
|
||||||
}
|
}
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
function formatUnits(value, unitType, options) {
|
// Some environments have issues with RegEx that contain back-tracking, so we cannot
|
||||||
/*
|
// use them.
|
||||||
if (typeof(unitType) === 'object' && !options) {
|
function commify(value) {
|
||||||
options = unitType;
|
var comps = String(value).split('.');
|
||||||
unitType = undefined;
|
if (comps.length > 2 || !comps[0].match(/^-?[0-9]*$/) || (comps[1] && !comps[1].match(/^[0-9]*$/)) || value === '.' || value === '-.') {
|
||||||
|
errors.throwError('invalid value', errors.INVALID_ARGUMENT, { argument: 'value', value: value });
|
||||||
}
|
}
|
||||||
if (unitType == null) { unitType = 18; }
|
// Make sure we have at least one whole digit (0 if none)
|
||||||
*/
|
var whole = comps[0];
|
||||||
if (!options) {
|
var negative = '';
|
||||||
options = {};
|
if (whole.substring(0, 1) === '-') {
|
||||||
|
negative = '-';
|
||||||
|
whole = whole.substring(1);
|
||||||
}
|
}
|
||||||
|
// Make sure we have at least 1 whole digit with no leading zeros
|
||||||
|
while (whole.substring(0, 1) === '0') {
|
||||||
|
whole = whole.substring(1);
|
||||||
|
}
|
||||||
|
if (whole === '') {
|
||||||
|
whole = '0';
|
||||||
|
}
|
||||||
|
var suffix = '';
|
||||||
|
if (comps.length === 2) {
|
||||||
|
suffix = '.' + (comps[1] || '0');
|
||||||
|
}
|
||||||
|
var formatted = [];
|
||||||
|
while (whole.length) {
|
||||||
|
if (whole.length <= 3) {
|
||||||
|
formatted.unshift(whole);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var index = whole.length - 3;
|
||||||
|
formatted.unshift(whole.substring(index));
|
||||||
|
whole = whole.substring(0, index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return negative + formatted.join(',') + suffix;
|
||||||
|
}
|
||||||
|
exports.commify = commify;
|
||||||
|
function formatUnits(value, unitType) {
|
||||||
var unitInfo = getUnitInfo(unitType);
|
var unitInfo = getUnitInfo(unitType);
|
||||||
// Make sure wei is a big number (convert as necessary)
|
// Make sure wei is a big number (convert as necessary)
|
||||||
value = bignumber_1.bigNumberify(value);
|
value = bignumber_1.bigNumberify(value);
|
||||||
@ -75,14 +105,9 @@ function formatUnits(value, unitType, options) {
|
|||||||
while (fraction.length < unitInfo.decimals) {
|
while (fraction.length < unitInfo.decimals) {
|
||||||
fraction = '0' + fraction;
|
fraction = '0' + fraction;
|
||||||
}
|
}
|
||||||
// Strip off trailing zeros (but keep one if would otherwise be bare decimal point)
|
// Strip training 0
|
||||||
if (!options.pad) {
|
|
||||||
fraction = fraction.match(/^([0-9]*[1-9]|0)(0*)/)[1];
|
fraction = fraction.match(/^([0-9]*[1-9]|0)(0*)/)[1];
|
||||||
}
|
|
||||||
var whole = value.div(unitInfo.tenPower).toString();
|
var whole = value.div(unitInfo.tenPower).toString();
|
||||||
if (options.commify) {
|
|
||||||
whole = whole.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
||||||
}
|
|
||||||
value = whole + '.' + fraction;
|
value = whole + '.' + fraction;
|
||||||
if (negative) {
|
if (negative) {
|
||||||
value = '-' + value;
|
value = '-' + value;
|
||||||
@ -98,8 +123,6 @@ function parseUnits(value, unitType) {
|
|||||||
if (typeof (value) !== 'string' || !value.match(/^-?[0-9.,]+$/)) {
|
if (typeof (value) !== 'string' || !value.match(/^-?[0-9.,]+$/)) {
|
||||||
errors.throwError('invalid decimal value', errors.INVALID_ARGUMENT, { arg: 'value', value: value });
|
errors.throwError('invalid decimal value', errors.INVALID_ARGUMENT, { arg: 'value', value: value });
|
||||||
}
|
}
|
||||||
// Remove commas
|
|
||||||
var value = value.replace(/,/g, '');
|
|
||||||
if (unitInfo.decimals === 0) {
|
if (unitInfo.decimals === 0) {
|
||||||
return bignumber_1.bigNumberify(value);
|
return bignumber_1.bigNumberify(value);
|
||||||
}
|
}
|
||||||
@ -140,8 +163,8 @@ function parseUnits(value, unitType) {
|
|||||||
return wei;
|
return wei;
|
||||||
}
|
}
|
||||||
exports.parseUnits = parseUnits;
|
exports.parseUnits = parseUnits;
|
||||||
function formatEther(wei, options) {
|
function formatEther(wei) {
|
||||||
return formatUnits(wei, 18, options);
|
return formatUnits(wei, 18);
|
||||||
}
|
}
|
||||||
exports.formatEther = formatEther;
|
exports.formatEther = formatEther;
|
||||||
function parseEther(ether) {
|
function parseEther(ether) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user