UNPKG

@bithomp/xrpl-api

Version:

A Bithomp JavaScript/TypeScript library for interacting with the XRP Ledger

43 lines (42 loc) 1.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseHooksExecutions = parseHooksExecutions; function parseHooksExecutions(tx) { return new HooksExecutions(tx).call(); } class HooksExecutions { constructor(tx) { this.tx = tx; this.executions = []; } call() { const hookExecutions = this.tx.meta.HookExecutions; if (!hookExecutions) { return undefined; } for (const execution of hookExecutions) { if (execution.HookExecution) { this.executions.push(this.parseHookExecution(execution.HookExecution)); } } if (this.executions.length === 0) { return undefined; } return this.executions; } parseHookExecution(hookExecution) { let hookReturnString = Buffer.from(hookExecution.HookReturnString, "hex"); hookReturnString = hookReturnString.subarray(0, hookReturnString.indexOf(0x00)); return { account: hookExecution.HookAccount, emitCount: hookExecution.HookEmitCount, executionIndex: hookExecution.HookExecutionIndex, hash: hookExecution.HookHash, instructionCount: hookExecution.HookInstructionCount, result: hookExecution.HookResult, returnCode: hookExecution.HookReturnCode, returnString: hookReturnString.toString("utf-8"), stateChangeCount: hookExecution.HookStateChangeCount, }; } }