Ejemplo n.º 1
0
    def parse_from_binary(self, input_data):
        offset = 32
        self.previous_tx_hash = format_hash(input_data[:offset])
        self.index = decode_uint32(input_data[offset:offset + 4])
        offset += 4
        self.txin_script_length, varint_size = decode_varint(
            input_data[offset:])

        offset += varint_size
        script = Script().parse_from_binary(
            input_data[offset:offset + self.txin_script_length])

        operations = list(script)
        parts = []
        for operation in operations:
            if isinstance(operation, bytes):
                parts.append(b2a_hex(operation).decode("ascii"))
            else:
                parts.append(str(operation))
        self.script_sig = " ".join(parts)

        offset += self.txin_script_length

        self.sequence_no = decode_uint32(input_data[offset:offset + 4])
        offset += 4
        self.size = offset
        return self
Ejemplo n.º 2
0
    def parse_from_binary(self, tx_data):
        offset = 4
        self.version_no = decode_uint32(tx_data[:offset])
        self.in_counter, varint_size = decode_varint(tx_data[offset:])
        offset += varint_size

        for i in range(self.in_counter):
            the_input = Input().parse_from_binary(tx_data[offset:])
            self.inputs.append(the_input)
            offset += the_input.size

        self.out_counter, varint_size = decode_varint(tx_data[offset:])
        offset += varint_size

        for i in range(self.out_counter):
            the_output = Output().parse_from_binary(tx_data[offset:])
            self.outputs.append(the_output)
            offset += the_output.size

        self.lock_time = decode_uint32(tx_data[offset:offset+4])
        self.size = offset + 4

        return self
Ejemplo n.º 3
0
    def parse_from_binary(self, block_data, top=5):
        block_header_size = 80
        offset = block_header_size
        self.block_header = BlockHeader().parse_from_binary(
            block_data[:offset])

        self.tx_counter, varint_size = decode_varint(block_data[offset:])
        offset += varint_size

        if (top >= self.tx_counter):
            top = self.tx_counter

        for i in range(top):
            tx = Transaction().parse_from_binary(block_data[offset:])
            self.txs.append(tx)
            offset += tx.size

        return self
Ejemplo n.º 4
0
    def parse_from_binary(self, output_data):
        offset = 8
        self.value = decode_uint64(output_data[:offset])
        self.txout_script_length, varint_size = decode_varint(output_data[8:])
        offset += varint_size
        script = Script().parse_from_binary(output_data[offset:offset+self.txout_script_length])
        operations = list(script)
        parts = []
        for operation in operations:
            if isinstance(operation, bytes):
                parts.append(b2a_hex(operation).decode("ascii"))
            else:
                parts.append(str(operation))

        self.script_pubkey = " ".join(parts)

        offset += self.txout_script_length
        self.size = offset
        return self