예제 #1
0
def get_next_tx_size(buffer: Union[memoryview, bytearray], offset: int) -> int:
    if not isinstance(buffer, memoryview):
        buffer = memoryview(buffer)
    _, txid_len = get_txid(buffer[offset:])
    off = txid_len + offset
    sig_length, size = ont_varint_to_int(buffer, off)
    off += size
    for _ in range(sig_length):
        invoke_length, size = ont_varint_to_int(buffer, off)
        off += size + invoke_length
        verify_length, size = ont_varint_to_int(buffer, off)
        off += size + verify_length
    return off - offset
예제 #2
0
 def parse_message(self):
     if not self._parsed:
         self._parsed = True
     off = ont_constants.ONT_HDR_COMMON_OFF
     self._version, = struct.unpack_from("<I", self.buf, off)
     off += ont_constants.ONT_INT_LEN
     self._consensus_payload = self._memoryview[off:]
     off += ont_constants.ONT_HASH_LEN + 2 * ont_constants.ONT_INT_LEN + ont_constants.ONT_SHORT_LEN
     self._consensus_data_full_len, size = ont_varint_to_int(self.buf, off)
     off += size
     self._consensus_payload_header = self._memoryview[:off]
     self._consensus_data = self._memoryview[off:off +
                                             self._consensus_data_full_len]
     self._consensus_data_str = bytearray(self._consensus_data).decode()
     self._consensus_data_json = json.loads(self._consensus_data_str)
     off += self._consensus_data_full_len
     self._owner_and_signature = self._memoryview[off:]
     self._consensus_data_type = self._consensus_data_json["type"]
     if self._consensus_data_type == ont_constants.BLOCK_PROPOSAL_CONSENSUS_MESSAGE_TYPE:
         encoded_payload = model_loader.load_model(
             ConsensusMsgPayload, self._consensus_data_json)
         self._consensus_data_len = encoded_payload.len
         self._decoded_payload = memoryview(
             base64.b64decode(encoded_payload.payload))
         self.parse_block_vbft_type()
예제 #3
0
 def parse_block_vbft_type(self):
     block_start_len, size = ont_varint_to_int(self._decoded_payload, 0)
     self._block_start_len_memoryview = self._decoded_payload[:size]
     off = size
     block_start = self._decoded_payload[off:off + block_start_len]
     self._block_start_txns = self.parse_block_core_type(block_start)
     self._empty_block_offset = off + block_start_len
     self._payload_tail = self._decoded_payload[self._empty_block_offset:]
예제 #4
0
    def parse_block_core_type(
            self, buf: Union[bytearray, memoryview]) -> List[memoryview]:
        if isinstance(buf, bytearray):
            buf = memoryview(buf)
        off = ont_constants.ONT_INT_LEN
        self._prev_block = OntObjectHash(buf, off, ont_constants.ONT_HASH_LEN)
        off += ont_constants.ONT_HASH_LEN * 3 + ont_constants.ONT_BLOCK_TIME_HEIGHT_CONS_DATA_LEN
        consensus_payload_length, size = ont_varint_to_int(buf, off)
        off += consensus_payload_length + size + ont_constants.ONT_BLOCK_NEXT_BOOKKEEPER_LEN
        self._header_offset = off
        hash_header = buf[:self._header_offset]
        self._hash_val = OntObjectHash(buf=crypto.double_sha256(hash_header),
                                       length=ont_constants.ONT_HASH_LEN)
        bookkeepers_length, size = ont_varint_to_int(buf, off)
        off += size
        for _ in range(bookkeepers_length):
            _, size = ont_varint_to_int(buf, off)
            off += size + ont_constants.ONT_BOOKKEEPER_LEN

        sig_data_length, size = ont_varint_to_int(buf, off)
        off += size
        for _ in range(sig_data_length):
            sig_length, size = ont_varint_to_int(buf, off)
            off += size + sig_length

        self._txn_count, = struct.unpack_from("<L", buf, off)
        off += ont_constants.ONT_INT_LEN
        self._tx_offset = off
        self._txn_header = buf[:off]
        txns = []
        start = self._tx_offset
        txn_count = self._txn_count
        assert isinstance(txn_count, int)
        for _ in range(txn_count):
            _, off = get_txid(buf[start:])
            sig_length, size = ont_varint_to_int(buf[start:], off)
            off += size
            for i in range(sig_length):
                invoke_length, size = ont_varint_to_int(buf[start:], off)
                off += size + invoke_length
                verify_length, size = ont_varint_to_int(buf[start:], off)
                off += size + verify_length
            txns.append(buf[start:start + off])
            start += off

        return txns