UNPKG

@gorbchain-xyz/chaindecode

Version:

GorbchainSDK V1.3+ - Complete Solana development toolkit with advanced cryptography, messaging, and collaboration features. Build secure applications with blockchain, DeFi, and end-to-end encryption.

60 lines (59 loc) 3.35 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; // Fetch and decode a transaction by signature using the registry // This belongs in the SDK transaction utilities, not in the app import { PROGRAM_IDS } from '../utils/gorbchainConfig.js'; import { ensureFallbackDecoders } from '../utils/ensureFallbackDecoders.js'; import { fetchTransactionBySignature } from '../rpc/fetchTransactionBySignature.js'; export function getAndDecodeTransaction(_a) { return __awaiter(this, arguments, void 0, function* ({ signature, registry, connection }) { var _b, _c; const tx = yield fetchTransactionBySignature(connection, signature); if (!((_c = (_b = tx === null || tx === void 0 ? void 0 : tx.transaction) === null || _b === void 0 ? void 0 : _b.message) === null || _c === void 0 ? void 0 : _c.instructions)) { return { decoded: [], meta: null }; } const mapped = tx.transaction.message.instructions.map((ix, i) => { const programId = tx.transaction.message.accountKeys[ix.programIdIndex]; let type = 'raw'; if (programId === PROGRAM_IDS.token2022) type = 'token2022'; else if (programId === PROGRAM_IDS.ata) type = 'ata'; else if (programId === PROGRAM_IDS.metaplex) type = 'metaplex'; else type = `unknown${i}`; return Object.assign(Object.assign({}, ix), { type, programId }); }); ensureFallbackDecoders(mapped, registry); const decoded = mapped.map((ix) => { var _a, _b; try { // Convert instruction to the format expected by registry const instructionForRegistry = { programId: ix.programId, data: ix.data, accounts: ((_a = ix.accounts) !== null && _a !== void 0 ? _a : []).map((accountIndex) => { var _a; return (_a = tx.transaction.message.accountKeys[accountIndex]) !== null && _a !== void 0 ? _a : 'unknown'; }) }; return registry.decode(instructionForRegistry); } catch (e) { return { type: 'error', programId: ix.programId, data: { error: e instanceof Error ? e.message : String(e) }, accounts: ((_b = ix.accounts) !== null && _b !== void 0 ? _b : []).map((accountIndex) => { var _a; return (_a = tx.transaction.message.accountKeys[accountIndex]) !== null && _a !== void 0 ? _a : 'unknown'; }), raw: ix }; } }); return { decoded, meta: tx.meta }; }); }