Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stwiname committed Dec 21, 2023
1 parent 599f430 commit f51dc25
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 23 deletions.
9 changes: 5 additions & 4 deletions Ethereum/ethscriptions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
2 changes: 2 additions & 0 deletions Ethereum/ethscriptions/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
//Exports all handler functions
global.atob = require("atob");

export * from "./mappings/mappingHandlers";
4 changes: 4 additions & 0 deletions Ethereum/ethscriptions/src/mappings/mappingHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
23 changes: 4 additions & 19 deletions Ethereum/ethscriptions/src/mappings/utils.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit f51dc25

Please sign in to comment.