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

86 lines
3.1 KiB
JavaScript
Raw Normal View History

2022-09-05 23:57:11 +03:00
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
2022-11-09 10:57:02 +03:00
exports.ContractEventPayload = exports.ContractUnknownEventPayload = exports.ContractTransactionResponse = exports.ContractTransactionReceipt = exports.EventLog = void 0;
2022-12-04 01:01:29 +03: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");
class EventLog extends provider_js_1.Log {
2022-09-05 23:57:11 +03:00
interface;
fragment;
args;
constructor(log, iface, fragment) {
super(log, log.provider);
const args = iface.decodeEventLog(fragment, log.data, log.topics);
2022-12-04 01:01:29 +03:00
(0, index_js_1.defineProperties)(this, { args, fragment, interface: iface });
2022-09-05 23:57:11 +03:00
}
get eventName() { return this.fragment.name; }
get eventSignature() { return this.fragment.format(); }
}
exports.EventLog = EventLog;
2022-12-04 01:01:29 +03:00
class ContractTransactionReceipt extends provider_js_1.TransactionReceipt {
2022-09-05 23:57:11 +03:00
#interface;
constructor(iface, provider, tx) {
super(tx, provider);
this.#interface = iface;
}
get logs() {
return super.logs.map((log) => {
const fragment = log.topics.length ? this.#interface.getEvent(log.topics[0]) : null;
if (fragment) {
return new EventLog(log, this.#interface, fragment);
}
else {
return log;
}
});
}
}
exports.ContractTransactionReceipt = ContractTransactionReceipt;
2022-12-04 01:01:29 +03:00
class ContractTransactionResponse extends provider_js_1.TransactionResponse {
2022-09-05 23:57:11 +03:00
#interface;
constructor(iface, provider, tx) {
super(tx, provider);
this.#interface = iface;
}
async wait(confirms) {
const receipt = await super.wait();
if (receipt == null) {
return null;
}
return new ContractTransactionReceipt(this.#interface, this.provider, receipt);
}
}
exports.ContractTransactionResponse = ContractTransactionResponse;
2022-12-04 01:01:29 +03:00
class ContractUnknownEventPayload extends index_js_1.EventPayload {
2022-09-05 23:57:11 +03:00
log;
2022-11-09 10:57:02 +03:00
constructor(contract, listener, filter, log) {
2022-09-05 23:57:11 +03:00
super(contract, listener, filter);
2022-12-04 01:01:29 +03:00
(0, index_js_1.defineProperties)(this, { log });
2022-09-05 23:57:11 +03:00
}
async getBlock() {
return await this.log.getBlock();
}
async getTransaction() {
return await this.log.getTransaction();
}
async getTransactionReceipt() {
return await this.log.getTransactionReceipt();
}
}
2022-11-09 10:57:02 +03:00
exports.ContractUnknownEventPayload = ContractUnknownEventPayload;
class ContractEventPayload extends ContractUnknownEventPayload {
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-04 01:01:29 +03:00
(0, index_js_1.defineProperties)(this, { args, fragment });
2022-11-09 10:57:02 +03:00
}
get eventName() {
return this.fragment.name;
}
get eventSignature() {
return this.fragment.format();
}
}
2022-09-05 23:57:11 +03:00
exports.ContractEventPayload = ContractEventPayload;
//# sourceMappingURL=wrappers.js.map