def getBlockHeight(txBinary):
    binunpack = BinaryUnpacker(txBinary)
    binunpack.advance(VERSION_LENGTH)
    txInCount = binunpack.get(VAR_INT)
    binunpack.advance(TX_OUT_HASH_LENGTH + TX_OUT_INDEX_LENGTH)
    sigScriptLength = binunpack.get(VAR_INT)
    binunpack.advance(1)
    height = binary_to_int(binunpack.get(BINARY_CHUNK, 3))
    return height
def getBlockHeight(txBinary):
   binunpack = BinaryUnpacker(txBinary)
   binunpack.advance(VERSION_LENGTH)
   txInCount = binunpack.get(VAR_INT)
   binunpack.advance(TX_OUT_HASH_LENGTH + TX_OUT_INDEX_LENGTH)
   sigScriptLength = binunpack.get(VAR_INT)
   binunpack.advance(1)
   height = binary_to_int(binunpack.get(BINARY_CHUNK, 3))
   return height
Beispiel #3
0
def getNextBlockHash(f):
   fileOffset = f.tell()
   f.seek(MAGIC_NUMBER_LENGTH, 1)
   blkSize = binary_to_int(f.read(BLOCK_SIZE_LENGTH), LITTLEENDIAN)
   result = None
   if blkSize > 0:
      blkString = f.read(blkSize)
      blkHdrBinary = blkString[:HEADER_LENGTH]
      result = sha256(sha256(blkHdrBinary))
   else:
      f.seek(0,2)
   return result
def getNextBlock(f):
    fileOffset = f.tell()
    f.seek(MAGIC_NUMBER_LENGTH, 1)
    blkSize = binary_to_int(f.read(BLOCK_SIZE_LENGTH), LITTLEENDIAN)
    result = None
    if blkSize > 0:
        binunpack = BinaryUnpacker(f.read(blkSize))
        blkHdrBinary = binunpack.get(BINARY_CHUNK, HEADER_LENGTH)
        txCount = binunpack.get(VAR_INT)
        txBinary = binunpack.get(BINARY_CHUNK, binunpack.getRemainingSize())
        blockHeight = getBlockHeight(txBinary)
        result = [sha256(sha256(blkHdrBinary)), blockHeight, fileOffset]
    else:
        f.seek(0, 2)
    return result
def getNextBlock(f):
   fileOffset = f.tell()
   f.seek(MAGIC_NUMBER_LENGTH, 1)
   blkSize = binary_to_int(f.read(BLOCK_SIZE_LENGTH), LITTLEENDIAN)
   result = None
   if blkSize > 0:
      binunpack = BinaryUnpacker(f.read(blkSize))
      blkHdrBinary = binunpack.get(BINARY_CHUNK, HEADER_LENGTH)
      txCount = binunpack.get(VAR_INT)
      txBinary = binunpack.get(BINARY_CHUNK, binunpack.getRemainingSize())
      blockHeight = getBlockHeight(txBinary)
      result = [sha256(sha256(blkHdrBinary)), blockHeight, fileOffset]
   else:
      f.seek(0,2)
   return result