diff --git a/Ethereum/ethscriptions/package.json b/Ethereum/ethscriptions/package.json index b46780ea..d1e745be 100644 --- a/Ethereum/ethscriptions/package.json +++ b/Ethereum/ethscriptions/package.json @@ -24,14 +24,15 @@ "@subql/common": "latest", "@subql/types-ethereum": "latest", "@subql/validator": "latest", - "assert": "^2.0.0" + "assert": "^2.0.0", + "atob": "^2.1.2" }, "devDependencies": { "@subql/cli": "latest", - "@subql/types": "latest", - "@subql/testing": "latest", "@subql/node-ethereum": "latest", + "@subql/testing": "latest", + "@subql/types": "latest", "ethers": "^5.7.2", "typescript": "latest" } -} \ No newline at end of file +} diff --git a/Ethereum/ethscriptions/src/index.ts b/Ethereum/ethscriptions/src/index.ts index fb59776f..52373323 100644 --- a/Ethereum/ethscriptions/src/index.ts +++ b/Ethereum/ethscriptions/src/index.ts @@ -1,2 +1,4 @@ //Exports all handler functions +global.atob = require("atob"); + export * from "./mappings/mappingHandlers"; diff --git a/Ethereum/ethscriptions/src/mappings/mappingHandlers.ts b/Ethereum/ethscriptions/src/mappings/mappingHandlers.ts index 12d0d960..0f36d0de 100644 --- a/Ethereum/ethscriptions/src/mappings/mappingHandlers.ts +++ b/Ethereum/ethscriptions/src/mappings/mappingHandlers.ts @@ -21,6 +21,10 @@ export async function handleTransaction( if (tx.to) { //is unique or has rule=esip6 + if (!tx.input) { + return; + } + const decodedData = hexToUTF8(tx.input); //console.log(decodedData); if (isValidDataUri(decodedData)) { diff --git a/Ethereum/ethscriptions/src/mappings/utils.ts b/Ethereum/ethscriptions/src/mappings/utils.ts index 2f7ac7d2..911cff9c 100644 --- a/Ethereum/ethscriptions/src/mappings/utils.ts +++ b/Ethereum/ethscriptions/src/mappings/utils.ts @@ -1,23 +1,8 @@ -export function hexToUTF8(hexString: string) { - if (hexString.indexOf("0x") === 0) { - hexString = hexString.slice(2); - } - - const bytes = new Uint8Array(hexString.length / 2); - - for (let index = 0; index < bytes.length; index++) { - const start = index * 2; - const hexByte = hexString.slice(start, start + 2); - const byte = Number.parseInt(hexByte, 16); - if (Number.isNaN(byte) || byte < 0) - throw new Error( - `Invalid byte sequence ("${hexByte}" in "${hexString}").` - ); - bytes[index] = byte; - } +import { toUtf8String } from '@ethersproject/strings'; +import { hexlify } from '@ethersproject/bytes'; - let result = new TextDecoder().decode(bytes); - return result.replace(/\0/g, ""); +export function hexToUTF8(hexString: string): string { + return toUtf8String(hexlify(hexString)); } export function isValidDataUri(uri: string): boolean {