From 99d09823aa371048b059a0737cb5e74f35d12ad5 Mon Sep 17 00:00:00 2001 From: Inwon Kim Date: Tue, 29 Aug 2023 14:59:47 +0900 Subject: [PATCH 1/5] Fix EventNotification * add logs * fix events assignment --- lib/data/Formatter/EventNotification.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/data/Formatter/EventNotification.ts b/lib/data/Formatter/EventNotification.ts index 9293618..bb8b1e5 100644 --- a/lib/data/Formatter/EventNotification.ts +++ b/lib/data/Formatter/EventNotification.ts @@ -6,15 +6,20 @@ export default class EventNotification { readonly height: BigNumber; readonly index: BigNumber; readonly events: BigNumber[]; + readonly logs: object[]; 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]; + } } } From 5ea0a9ac9b19d5f4af62c579d772c3323ae319a9 Mon Sep 17 00:00:00 2001 From: Inwon Kim Date: Tue, 29 Aug 2023 15:56:58 +0900 Subject: [PATCH 2/5] Define EventLog interface --- lib/data/Formatter/EventLog.ts | 21 +++++++++++++++++++++ lib/data/Formatter/EventNotification.ts | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 lib/data/Formatter/EventLog.ts 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 bb8b1e5..fbd49fb 100644 --- a/lib/data/Formatter/EventNotification.ts +++ b/lib/data/Formatter/EventNotification.ts @@ -1,12 +1,13 @@ 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: object[]; + readonly logs: EventLog[]; constructor(data) { this.hash = data.hash; From 1637e4da87dfbc4954af634cd1d4c9fb8b590b75 Mon Sep 17 00:00:00 2001 From: Inwon Kim Date: Tue, 29 Aug 2023 15:57:33 +0900 Subject: [PATCH 3/5] Add logs to BlockNotification.ts --- lib/data/Formatter/BlockNotification.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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]; + } + } + } + } } } From f49bd87276ce493da33ebb4905819cc7d5595edc Mon Sep 17 00:00:00 2001 From: Inwon Kim Date: Tue, 29 Aug 2023 16:56:02 +0900 Subject: [PATCH 4/5] Add logs to BlockMonitorSpec --- lib/transport/monitor/BlockMonitorSpec.ts | 10 +++++++--- quickstart/example/js/MonitorExample.ts | 5 +++-- 2 files changed, 10 insertions(+), 5 deletions(-) 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/js/MonitorExample.ts b/quickstart/example/js/MonitorExample.ts index 847e040..22834c9 100644 --- a/quickstart/example/js/MonitorExample.ts +++ b/quickstart/example/js/MonitorExample.ts @@ -39,9 +39,10 @@ class MonitorExample { async startMonitorBlock() { const block = await this.iconService.getLastBlock().execute(); const height = block.height; - const spec = new BlockMonitorSpec(Converter.toBigNumber(height + 1)); + const spec = new BlockMonitorSpec(Converter.toBigNumber(height + 1), + [new EventFilter("ICXIssued(int,int,int,int)", "cx0000000000000000000000000000000000000000")], 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); From 747e13168190b0a1391dd34eb1ca979d3a502180 Mon Sep 17 00:00:00 2001 From: Inwon Kim Date: Tue, 29 Aug 2023 17:20:05 +0900 Subject: [PATCH 5/5] Modify MonitorExample * input monitor params from user --- quickstart/example/html/MonitorExample.html | 5 +++++ quickstart/example/js/MonitorExample.ts | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) 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 22834c9..8a1596e 100644 --- a/quickstart/example/js/MonitorExample.ts +++ b/quickstart/example/js/MonitorExample.ts @@ -37,10 +37,15 @@ 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), - [new EventFilter("ICXIssued(int,int,int,int)", "cx0000000000000000000000000000000000000000")], true); + 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 = JSON.stringify(data); }