import { LibSdbInterface } from "../../../interface" ; import { LibSdbTypes } from "../../types" ; import { decode as decodeValue } from "./value" ; import { BN } from "bn.js" ; export async function decode ( position , offset , length , detail , _interface , address ) { let value = "" ; if ( position === null ) { value = "(storage location undefined)" ; } else { const content = await _interface . requestStorage ( address , position . toBuffer ( "be" , 32 ) ) ; let end = content . value . length - offset ; let start = end - length ; if ( start < 0 ) { start = 0 ; } if ( end < 0 ) { end = 0 ; } value = decodeValue ( detail , new BN ( content . value . slice ( start , end ) ) ) ; } return value ; }