diff --git a/lib/data/Formatter/BlockNotification.ts b/lib/data/Formatter/BlockNotification.ts index 74507bf..21ca016 100644 --- a/lib/data/Formatter/BlockNotification.ts +++ b/lib/data/Formatter/BlockNotification.ts @@ -1,11 +1,13 @@ import BigNumber from "bignumber.js"; import { Converter } from "../index"; +import EventLog from "./EventLog"; export default class BlockNotification { readonly hash: string; readonly height: BigNumber; readonly indexes: BigNumber[][]; readonly events: BigNumber[][][]; + readonly logs: EventLog[][][]; constructor(data) { this.hash = data.hash; @@ -29,5 +31,17 @@ export default class BlockNotification { } } } + if (data.logs) { + this.logs = []; + for (let i = 0; i < data.logs.length; i++) { + this.logs[i] = []; + for (let j = 0; j < data.logs[i].length; j++) { + this.logs[i][j] = []; + for (let k = 0; k < data.logs[i][j].length; k++) { + this.logs[i][j][k] = data.logs[i][j][k]; + } + } + } + } } } diff --git a/lib/data/Formatter/EventLog.ts b/lib/data/Formatter/EventLog.ts new file mode 100644 index 0000000..03e5886 --- /dev/null +++ b/lib/data/Formatter/EventLog.ts @@ -0,0 +1,21 @@ +/* + * Copyright 2023 ICON Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default interface EventLog { + scoreAddress: string; + indexed: string[]; + data: string[]; +} diff --git a/lib/data/Formatter/EventNotification.ts b/lib/data/Formatter/EventNotification.ts index 9293618..fbd49fb 100644 --- a/lib/data/Formatter/EventNotification.ts +++ b/lib/data/Formatter/EventNotification.ts @@ -1,20 +1,26 @@ import BigNumber from "bignumber.js"; import { Converter } from "../index"; +import EventLog from "./EventLog"; export default class EventNotification { readonly hash: string; readonly height: BigNumber; readonly index: BigNumber; readonly events: BigNumber[]; + readonly logs: EventLog[]; constructor(data) { this.hash = data.hash; this.height = Converter.toBigNumber(data.height); this.index = Converter.toBigNumber(data.index); + this.events = []; + this.logs = []; if (data.events) { - this.events = []; - for (let i = 0; i < data.events; i++) + for (let i = 0; i < data.events.length; i++) this.events[i] = Converter.toBigNumber(data.events[i]); } + if (data.logs) { + for (let i = 0; i < data.logs.length; i++) this.logs[i] = data.logs[i]; + } } } diff --git a/lib/transport/monitor/BlockMonitorSpec.ts b/lib/transport/monitor/BlockMonitorSpec.ts index 6936593..678b3d1 100644 --- a/lib/transport/monitor/BlockMonitorSpec.ts +++ b/lib/transport/monitor/BlockMonitorSpec.ts @@ -22,10 +22,12 @@ import { Converter } from "../../data"; export default class BlockMonitorSpec implements MonitorSpec { readonly height: BigNumber; readonly eventFilters?: EventFilter[]; + readonly logs?: boolean; - constructor(height: BigNumber, eventFilters?: EventFilter[]) { + constructor(height: BigNumber, eventFilters?: EventFilter[], logs?: boolean) { this.height = height; this.eventFilters = eventFilters; + this.logs = logs; } getPath(): string { @@ -34,11 +36,13 @@ export default class BlockMonitorSpec implements MonitorSpec { getParam(): object { const height = Converter.toHex(this.height); + const params = { height }; + if (this.logs) params["logs"] = "0x1"; if (!this.eventFilters || this.eventFilters.length === 0) { - return { height }; + return params; } return { - height: height, + ...params, eventFilters: this.eventFilters.map((v) => v.toObject()), }; } diff --git a/quickstart/example/html/MonitorExample.html b/quickstart/example/html/MonitorExample.html index 14705ca..79ee4f4 100644 --- a/quickstart/example/html/MonitorExample.html +++ b/quickstart/example/html/MonitorExample.html @@ -15,6 +15,11 @@

1. monitor block

+

+

+
+
+

diff --git a/quickstart/example/js/MonitorExample.ts b/quickstart/example/js/MonitorExample.ts index 847e040..8a1596e 100644 --- a/quickstart/example/js/MonitorExample.ts +++ b/quickstart/example/js/MonitorExample.ts @@ -37,11 +37,17 @@ class MonitorExample { } async startMonitorBlock() { + const url = getInputValue('M01-url'); + const addr = getInputValue('M01-addr'); + const event = getInputValue('M01-event'); + const provider: HttpProvider = new HttpProvider(url); + this.iconService = new IconService(provider); const block = await this.iconService.getLastBlock().execute(); const height = block.height; - const spec = new BlockMonitorSpec(Converter.toBigNumber(height + 1)); + const eventFilter = new EventFilter(event, addr); + const spec = new BlockMonitorSpec(Converter.toBigNumber(height + 1), [eventFilter], true); const onevent = (data: BlockNotification) => { - document.getElementById("M01-3").innerHTML = `block height : ${data.height}, block hash : ${data.hash}`; + document.getElementById("M01-3").innerHTML = JSON.stringify(data); } const onerror = (error) => { console.log(error);