MCPcopy Create free account
hub / github.com/CashScript/cashscript / decodeStackItem

Function decodeStackItem

packages/cashscript/src/debugging.ts:292–305  ·  view source on GitHub ↗
(element: StackItem, stack: Uint8Array[])

Source from the content-addressed store, hash-verified

290};
291
292const decodeStackItem = (element: StackItem, stack: Uint8Array[]): string | bigint | boolean => {
293 // Reversed since stack is in reverse order
294 const stackItem = [...stack].reverse()[element.stackIndex];
295
296 if (!stackItem) {
297 throw Error(`Stack item at index ${element.stackIndex} not found at instruction pointer ${element.ip}`);
298 }
299
300 if (element.type === PrimitiveType.BOOL) return decodeBool(stackItem);
301 if (element.type === PrimitiveType.INT) return decodeInt(stackItem);
302 if (element.type === PrimitiveType.STRING) return decodeString(stackItem);
303
304 return `0x${binToHex(stackItem)}`;
305};
306
307const failedFinalVerify = (evaluationResult: string | true): evaluationResult is string => {
308 // true indicates a successful evaluation (so no failed final verify)

Callers 1

decodeLogDataEntryFunction · 0.85

Calls 3

decodeBoolFunction · 0.90
decodeIntFunction · 0.90
decodeStringFunction · 0.90

Tested by

no test coverage detected