1 | const callable = require('../util/callable');
|
2 | const EventCoder = require('./EventCoder');
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | class LogFilter {
|
8 | constructor({ address, topics }, event) {
|
9 | this.address = address;
|
10 | this.topics = topics;
|
11 | Reflect.defineProperty(this, 'event', { value: event });
|
12 | }
|
13 |
|
14 | async getLogs(options) {
|
15 | const logs = await this.event.conflux.getLogs({ ...options, address: this.address, topics: this.topics });
|
16 |
|
17 | logs.forEach(log => {
|
18 | log.params = this.event.decodeLog(log);
|
19 | });
|
20 |
|
21 | return logs;
|
22 | }
|
23 | }
|
24 |
|
25 | class ContractEvent extends EventCoder {
|
26 | constructor(fragment, contract, conflux) {
|
27 | super(fragment);
|
28 | this.contract = contract;
|
29 | this.conflux = conflux;
|
30 |
|
31 | return callable(this, this.call.bind(this));
|
32 | }
|
33 |
|
34 | call(...args) {
|
35 | const address = this.contract.address;
|
36 | const topics = [this.signature, ...this.encodeTopics(args)];
|
37 | return new LogFilter({ address, topics }, this);
|
38 | }
|
39 |
|
40 | decodeLog(log) {
|
41 | const namedTuple = super.decodeLog(log);
|
42 | return {
|
43 | name: this.name,
|
44 | fullName: this.fullName,
|
45 | type: this.type,
|
46 | signature: this.signature,
|
47 | array: [...namedTuple],
|
48 | object: namedTuple.toObject(),
|
49 | };
|
50 | }
|
51 | }
|
52 |
|
53 | module.exports = ContractEvent;
|
54 | module.exports.LogFilter = LogFilter;
|