// deno-fmt-ignore-file // deno-lint-ignore-file // This code was bundled using `deno bundle` and it's not recommended to edit it manually new TextEncoder().encode("0123456789abcdef"); function errInvalidByte(__byte) { return new TypeError(`Invalid byte '${String.fromCharCode(__byte)}'`); } function errLength() { return new RangeError("Odd length hex string"); } function fromHexChar(__byte) { if (48 <= __byte && __byte <= 57) return __byte - 48; if (97 <= __byte && __byte <= 102) return __byte - 97 + 10; if (65 <= __byte && __byte <= 70) return __byte - 65 + 10; throw errInvalidByte(__byte); } function decode(src) { const dst = new Uint8Array(src.length / 2); for(let i = 0; i < dst.length; i++){ const a = fromHexChar(src[i * 2]); const b = fromHexChar(src[i * 2 + 1]); dst[i] = a << 4 | b; } if (src.length % 2 == 1) { fromHexChar(src[dst.length * 2]); throw errLength(); } return dst; } const TEXT_ENCODER = new TextEncoder(); const TEXT_DECODER = new TextDecoder(); function isReadableAscii(raw) { return raw.split("").every((__char)=>{ const charCode = __char.charCodeAt(0); return 0x20 <= charCode && charCode <= 0x7e; }); } function hexToText(hexString) { const hexBytes = TEXT_ENCODER.encode(hexString); const utfBytes = decode(hexBytes); return TEXT_DECODER.decode(utfBytes); } function plutusMapToPlainJson(source) { return source.reduce((all, item)=>{ const key = hexToText(item.k.bytes); const maybeText = hexToText(item.v.bytes); all[key] = isReadableAscii(maybeText) ? maybeText : item.v.bytes; return all; }, {}); } function parseDatum(raw) { try { const [metaField, versionField, _] = raw.plutus_data.fields; return { metadata: plutusMapToPlainJson(metaField.map), version: versionField.int }; } catch (err) { console.error(err); return null; } } function extractRefNFT(output, allDatums) { const asset = output.assets?.find((a)=>a.asset.startsWith("000")); if (!asset) return null; const datum = output.inline_datum || allDatums?.find((d)=>d.datum_hash == output.datum_hash); if (!datum) return null; return { label: asset.asset, policy: asset.policy, ...parseDatum(datum) }; } function processTx(tx) { return tx.outputs?.map((output)=>extractRefNFT(output, tx.plutus_data)).filter((x)=>!!x).map((x)=>({ ...x, txHash: tx.hash })); } function mapEvent(record) { if (!record.transaction) { return; } return processTx(record.transaction); } export { mapEvent as mapEvent };