import { LibSdbTypes } from "../../types" ; import { decode as decodeValue } from "./value" ; import { BN } from "bn.js" ; export function decode ( stackPosition , memoryOffset , detail , stack , memory ) { let v = "" ; if ( stackPosition !== null && stack . length > stackPosition ) { const memoryLocation = stack [ stackPosition ] . toNumber ( ) + memoryOffset ; if ( memoryLocation === undefined ) { return "(invalid memory location)" ; } const memorySlice = memory . slice ( memoryLocation , memoryLocation + 32 ) ; const element = Array . from ( memorySlice , function ( byte ) { if ( byte === null ) { return "" ; } else { return ( "0" + ( byte ) . toString ( 16 ) ) . slice ( - 2 ) ; } } ) . join ( "" ) ; if ( element ) { v = decodeValue ( detail , new BN ( element , 16 ) ) ; } } return v ; }