wrappers.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.ContractEventPayload = exports.ContractUnknownEventPayload = exports.ContractTransactionResponse = exports.ContractTransactionReceipt = exports.UndecodedEventLog = exports.EventLog = void 0;
  4. // import from provider.ts instead of index.ts to prevent circular dep
  5. // from EtherscanProvider
  6. const provider_js_1 = require("../providers/provider.js");
  7. const index_js_1 = require("../utils/index.js");
  8. /**
  9. * An **EventLog** contains additional properties parsed from the [[Log]].
  10. */
  11. class EventLog extends provider_js_1.Log {
  12. /**
  13. * The Contract Interface.
  14. */
  15. interface;
  16. /**
  17. * The matching event.
  18. */
  19. fragment;
  20. /**
  21. * The parsed arguments passed to the event by ``emit``.
  22. */
  23. args;
  24. /**
  25. * @_ignore:
  26. */
  27. constructor(log, iface, fragment) {
  28. super(log, log.provider);
  29. const args = iface.decodeEventLog(fragment, log.data, log.topics);
  30. (0, index_js_1.defineProperties)(this, { args, fragment, interface: iface });
  31. }
  32. /**
  33. * The name of the event.
  34. */
  35. get eventName() { return this.fragment.name; }
  36. /**
  37. * The signature of the event.
  38. */
  39. get eventSignature() { return this.fragment.format(); }
  40. }
  41. exports.EventLog = EventLog;
  42. /**
  43. * An **EventLog** contains additional properties parsed from the [[Log]].
  44. */
  45. class UndecodedEventLog extends provider_js_1.Log {
  46. /**
  47. * The error encounted when trying to decode the log.
  48. */
  49. error;
  50. /**
  51. * @_ignore:
  52. */
  53. constructor(log, error) {
  54. super(log, log.provider);
  55. (0, index_js_1.defineProperties)(this, { error });
  56. }
  57. }
  58. exports.UndecodedEventLog = UndecodedEventLog;
  59. /**
  60. * A **ContractTransactionReceipt** includes the parsed logs from a
  61. * [[TransactionReceipt]].
  62. */
  63. class ContractTransactionReceipt extends provider_js_1.TransactionReceipt {
  64. #iface;
  65. /**
  66. * @_ignore:
  67. */
  68. constructor(iface, provider, tx) {
  69. super(tx, provider);
  70. this.#iface = iface;
  71. }
  72. /**
  73. * The parsed logs for any [[Log]] which has a matching event in the
  74. * Contract ABI.
  75. */
  76. get logs() {
  77. return super.logs.map((log) => {
  78. const fragment = log.topics.length ? this.#iface.getEvent(log.topics[0]) : null;
  79. if (fragment) {
  80. try {
  81. return new EventLog(log, this.#iface, fragment);
  82. }
  83. catch (error) {
  84. return new UndecodedEventLog(log, error);
  85. }
  86. }
  87. return log;
  88. });
  89. }
  90. }
  91. exports.ContractTransactionReceipt = ContractTransactionReceipt;
  92. /**
  93. * A **ContractTransactionResponse** will return a
  94. * [[ContractTransactionReceipt]] when waited on.
  95. */
  96. class ContractTransactionResponse extends provider_js_1.TransactionResponse {
  97. #iface;
  98. /**
  99. * @_ignore:
  100. */
  101. constructor(iface, provider, tx) {
  102. super(tx, provider);
  103. this.#iface = iface;
  104. }
  105. /**
  106. * Resolves once this transaction has been mined and has
  107. * %%confirms%% blocks including it (default: ``1``) with an
  108. * optional %%timeout%%.
  109. *
  110. * This can resolve to ``null`` only if %%confirms%% is ``0``
  111. * and the transaction has not been mined, otherwise this will
  112. * wait until enough confirmations have completed.
  113. */
  114. async wait(confirms, timeout) {
  115. const receipt = await super.wait(confirms, timeout);
  116. if (receipt == null) {
  117. return null;
  118. }
  119. return new ContractTransactionReceipt(this.#iface, this.provider, receipt);
  120. }
  121. }
  122. exports.ContractTransactionResponse = ContractTransactionResponse;
  123. /**
  124. * A **ContractUnknownEventPayload** is included as the last parameter to
  125. * Contract Events when the event does not match any events in the ABI.
  126. */
  127. class ContractUnknownEventPayload extends index_js_1.EventPayload {
  128. /**
  129. * The log with no matching events.
  130. */
  131. log;
  132. /**
  133. * @_event:
  134. */
  135. constructor(contract, listener, filter, log) {
  136. super(contract, listener, filter);
  137. (0, index_js_1.defineProperties)(this, { log });
  138. }
  139. /**
  140. * Resolves to the block the event occured in.
  141. */
  142. async getBlock() {
  143. return await this.log.getBlock();
  144. }
  145. /**
  146. * Resolves to the transaction the event occured in.
  147. */
  148. async getTransaction() {
  149. return await this.log.getTransaction();
  150. }
  151. /**
  152. * Resolves to the transaction receipt the event occured in.
  153. */
  154. async getTransactionReceipt() {
  155. return await this.log.getTransactionReceipt();
  156. }
  157. }
  158. exports.ContractUnknownEventPayload = ContractUnknownEventPayload;
  159. /**
  160. * A **ContractEventPayload** is included as the last parameter to
  161. * Contract Events when the event is known.
  162. */
  163. class ContractEventPayload extends ContractUnknownEventPayload {
  164. /**
  165. * @_ignore:
  166. */
  167. constructor(contract, listener, filter, fragment, _log) {
  168. super(contract, listener, filter, new EventLog(_log, contract.interface, fragment));
  169. const args = contract.interface.decodeEventLog(fragment, this.log.data, this.log.topics);
  170. (0, index_js_1.defineProperties)(this, { args, fragment });
  171. }
  172. /**
  173. * The event name.
  174. */
  175. get eventName() {
  176. return this.fragment.name;
  177. }
  178. /**
  179. * The event signature.
  180. */
  181. get eventSignature() {
  182. return this.fragment.format();
  183. }
  184. }
  185. exports.ContractEventPayload = ContractEventPayload;
  186. //# sourceMappingURL=wrappers.js.map