From 2c48b81aed47038b0ea05cefafaa6b3a18f3f80d Mon Sep 17 00:00:00 2001 From: KillariDev Date: Wed, 31 Jul 2024 17:22:43 +0300 Subject: [PATCH] when ens name is in bytes, decode is to string --- app/ts/simulation/logHandlers.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/app/ts/simulation/logHandlers.ts b/app/ts/simulation/logHandlers.ts index ff54975e..7648b3d4 100644 --- a/app/ts/simulation/logHandlers.ts +++ b/app/ts/simulation/logHandlers.ts @@ -285,12 +285,27 @@ export function handleEnsExpiryExtended(eventLog: ParsedEvent) { } } +function decodeENSName(encodedName: Uint8Array): string { + let i = 0 + let decodedName = '' + while (i < encodedName.length) { + const length = encodedName[i] + if (length === 0 || length === undefined) break + i++ + let label = new TextDecoder().decode(encodedName.slice(i, i + length)) + decodedName += label + '.' + i += length + } + if (decodedName.endsWith('.')) decodedName = decodedName.slice(0, -1) + return decodedName +} + // event NameWrapped(bytes32 indexed node, bytes name, address owner, uint32 fuses, uint64 expiry) export function handleNameWrapped(eventLog: ParsedEvent) { - if (eventLog.args[0]?.typeValue.type !== 'fixedBytes' || eventLog.args[1]?.typeValue.type !== 'string' || eventLog.args[2]?.typeValue.type !== 'address' || eventLog.args[3]?.typeValue.type !== 'unsignedInteger' || eventLog.args[4]?.typeValue.type !== 'unsignedInteger') throw new Error('Malformed ENS ExpiryExtended Event') + if (eventLog.args[0]?.typeValue.type !== 'fixedBytes' || eventLog.args[1]?.typeValue.type !== 'bytes' || eventLog.args[2]?.typeValue.type !== 'address' || eventLog.args[3]?.typeValue.type !== 'unsignedInteger' || eventLog.args[4]?.typeValue.type !== 'unsignedInteger') throw new Error('Malformed ENS ExpiryExtended Event') return { node: EthereumBytes32.parse(dataStringWith0xStart(eventLog.args[0].typeValue.value)), - name: eventLog.args[1].typeValue.value, + name: decodeENSName(eventLog.args[1].typeValue.value), owner: eventLog.args[2].typeValue.value, fuses: extractENSFuses(eventLog.args[3]?.typeValue.value), expires: eventLog.args[4].typeValue.value,