ethers.js/lib.commonjs/contract/wrappers.js

166 lines
4.9 KiB
JavaScript
Raw Permalink Normal View History

2022-09-05 16:57:11 -04:00
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
2022-11-09 02:57:02 -05:00
exports.ContractEventPayload = exports.ContractUnknownEventPayload = exports.ContractTransactionResponse = exports.ContractTransactionReceipt = exports.EventLog = void 0;
2022-12-03 17:01:29 -05:00
// import from provider.ts instead of index.ts to prevent circular dep
// from EtherscanProvider
const provider_js_1 = require("../providers/provider.js");
const index_js_1 = require("../utils/index.js");
2023-06-01 17:52:58 -04:00
/**
* An **EventLog** contains additional properties parsed from the [[Log]].
*/
2022-12-03 17:01:29 -05:00
class EventLog extends provider_js_1.Log {
2023-06-01 17:52:58 -04:00
/**
* The Contract Interface.
*/
2022-09-05 16:57:11 -04:00
interface;
2023-06-01 17:52:58 -04:00
/**
* The matching event.
*/
2022-09-05 16:57:11 -04:00
fragment;
2023-06-01 17:52:58 -04:00
/**
* The parsed arguments passed to the event by ``emit``.
*/
2022-09-05 16:57:11 -04:00
args;
2023-06-01 17:52:58 -04:00
/**
* @_ignore:
*/
2022-09-05 16:57:11 -04:00
constructor(log, iface, fragment) {
super(log, log.provider);
const args = iface.decodeEventLog(fragment, log.data, log.topics);
2022-12-03 17:01:29 -05:00
(0, index_js_1.defineProperties)(this, { args, fragment, interface: iface });
2022-09-05 16:57:11 -04:00
}
2023-06-01 17:52:58 -04:00
/**
* The name of the event.
*/
2022-09-05 16:57:11 -04:00
get eventName() { return this.fragment.name; }
2023-06-01 17:52:58 -04:00
/**
* The signature of the event.
*/
2022-09-05 16:57:11 -04:00
get eventSignature() { return this.fragment.format(); }
}
exports.EventLog = EventLog;
2023-06-01 17:52:58 -04:00
/**
* A **ContractTransactionReceipt** includes the parsed logs from a
* [[TransactionReceipt]].
*/
2022-12-03 17:01:29 -05:00
class ContractTransactionReceipt extends provider_js_1.TransactionReceipt {
2023-03-20 12:53:37 -04:00
#iface;
2023-06-01 17:52:58 -04:00
/**
* @_ignore:
*/
2022-09-05 16:57:11 -04:00
constructor(iface, provider, tx) {
super(tx, provider);
2023-03-20 12:53:37 -04:00
this.#iface = iface;
2022-09-05 16:57:11 -04:00
}
2023-06-01 17:52:58 -04:00
/**
* The parsed logs for any [[Log]] which has a matching event in the
* Contract ABI.
*/
2022-09-05 16:57:11 -04:00
get logs() {
return super.logs.map((log) => {
2023-03-20 12:53:37 -04:00
const fragment = log.topics.length ? this.#iface.getEvent(log.topics[0]) : null;
2022-09-05 16:57:11 -04:00
if (fragment) {
2023-03-20 12:53:37 -04:00
return new EventLog(log, this.#iface, fragment);
2022-09-05 16:57:11 -04:00
}
else {
return log;
}
});
}
}
exports.ContractTransactionReceipt = ContractTransactionReceipt;
2023-06-01 17:52:58 -04:00
/**
* A **ContractTransactionResponse** will return a
* [[ContractTransactionReceipt]] when waited on.
*/
2022-12-03 17:01:29 -05:00
class ContractTransactionResponse extends provider_js_1.TransactionResponse {
2023-03-20 12:53:37 -04:00
#iface;
2023-06-01 17:52:58 -04:00
/**
* @_ignore:
*/
2022-09-05 16:57:11 -04:00
constructor(iface, provider, tx) {
super(tx, provider);
2023-03-20 12:53:37 -04:00
this.#iface = iface;
2022-09-05 16:57:11 -04:00
}
2023-06-01 17:52:58 -04:00
/**
* Resolves once this transaction has been mined and has
* %%confirms%% blocks including it (default: ``1``) with an
* optional %%timeout%%.
*
* This can resolve to ``null`` only if %%confirms%% is ``0``
* and the transaction has not been mined, otherwise this will
* wait until enough confirmations have completed.
*/
2022-09-05 16:57:11 -04:00
async wait(confirms) {
2023-07-15 17:55:24 -04:00
const receipt = await super.wait(confirms);
2022-09-05 16:57:11 -04:00
if (receipt == null) {
return null;
}
2023-03-20 12:53:37 -04:00
return new ContractTransactionReceipt(this.#iface, this.provider, receipt);
2022-09-05 16:57:11 -04:00
}
}
exports.ContractTransactionResponse = ContractTransactionResponse;
2023-06-01 17:52:58 -04:00
/**
* A **ContractUnknownEventPayload** is included as the last parameter to
* Contract Events when the event does not match any events in the ABI.
*/
2022-12-03 17:01:29 -05:00
class ContractUnknownEventPayload extends index_js_1.EventPayload {
2023-06-01 17:52:58 -04:00
/**
* The log with no matching events.
*/
2022-09-05 16:57:11 -04:00
log;
2023-06-01 17:52:58 -04:00
/**
* @_event:
*/
2022-11-09 02:57:02 -05:00
constructor(contract, listener, filter, log) {
2022-09-05 16:57:11 -04:00
super(contract, listener, filter);
2022-12-03 17:01:29 -05:00
(0, index_js_1.defineProperties)(this, { log });
2022-09-05 16:57:11 -04:00
}
2023-06-01 17:52:58 -04:00
/**
* Resolves to the block the event occured in.
*/
2022-09-05 16:57:11 -04:00
async getBlock() {
return await this.log.getBlock();
}
2023-06-01 17:52:58 -04:00
/**
* Resolves to the transaction the event occured in.
*/
2022-09-05 16:57:11 -04:00
async getTransaction() {
return await this.log.getTransaction();
}
2023-06-01 17:52:58 -04:00
/**
* Resolves to the transaction receipt the event occured in.
*/
2022-09-05 16:57:11 -04:00
async getTransactionReceipt() {
return await this.log.getTransactionReceipt();
}
}
2022-11-09 02:57:02 -05:00
exports.ContractUnknownEventPayload = ContractUnknownEventPayload;
2023-06-01 17:52:58 -04:00
/**
* A **ContractEventPayload** is included as the last parameter to
* Contract Events when the event is known.
*/
2022-11-09 02:57:02 -05:00
class ContractEventPayload extends ContractUnknownEventPayload {
2023-06-01 17:52:58 -04:00
/**
* @_ignore:
*/
2022-11-09 02:57:02 -05:00
constructor(contract, listener, filter, fragment, _log) {
super(contract, listener, filter, new EventLog(_log, contract.interface, fragment));
const args = contract.interface.decodeEventLog(fragment, this.log.data, this.log.topics);
2022-12-03 17:01:29 -05:00
(0, index_js_1.defineProperties)(this, { args, fragment });
2022-11-09 02:57:02 -05:00
}
2023-06-01 17:52:58 -04:00
/**
* The event name.
*/
2022-11-09 02:57:02 -05:00
get eventName() {
return this.fragment.name;
}
2023-06-01 17:52:58 -04:00
/**
* The event signature.
*/
2022-11-09 02:57:02 -05:00
get eventSignature() {
return this.fragment.format();
}
}
2022-09-05 16:57:11 -04:00
exports.ContractEventPayload = ContractEventPayload;
//# sourceMappingURL=wrappers.js.map