Esempio n. 1
0
    def from_raw(txoutputraw,cursor=0,has_segwit=False):
        """
        Imports a TxOutput from a Transaction's hexadecimal data

        Attributes
        ----------
        txinputraw : string (hex)
            The hexadecimal raw string of the Transaction
        cursor : int
            The cursor of which the algorithm will start to read the data
        has_segwit : boolean
            Is the Tx Output segwit or not
        """
        txoutputraw = to_bytes(txoutputraw)

        # read the amount of the TxOutput
        value = int.from_bytes(txoutputraw[cursor:cursor + 8][::-1], 'big')
        cursor += 8

        # read the size (bytes length) of the integer representing the size of the locking
        # Script's raw data and the size of the locking Script's raw data
        lock_script_size, size = vi_to_int(txoutputraw[cursor:cursor + 9])
        cursor += size
        lock_script = txoutputraw[cursor:cursor + lock_script_size]
        cursor += lock_script_size
        return TxOutput(amount=value,
                        script_pubkey=Script.from_raw(lock_script, has_segwit=has_segwit)),cursor
Esempio n. 2
0
    def from_raw(txinputraw, cursor=0, has_segwit=False):
        """
        Imports a TxInput from a Transaction's hexadecimal data

        Attributes
        ----------
        txinputraw : string (hex)
            The hexadecimal raw string of the Transaction
        cursor : int
            The cursor of which the algorithm will start to read the data
        has_segwit : boolean
            Is the Tx Input segwit or not
        """
        txinputraw = to_bytes(txinputraw)

        # read the 32 bytes of TxInput ID
        inp_hash = txinputraw[cursor:cursor + 32][::-1]

        if not len(inp_hash):
            raise Exception("Input transaction hash not found. Probably malformed raw transaction")
        output_n = txinputraw[cursor + 32:cursor + 36][::-1]
        cursor += 36

        # read the size (bytes length) of the integer representing the size of the Script's raw
        # data and the size of the Script's raw data
        unlocking_script_size, size = vi_to_int(txinputraw[cursor:cursor + 9])
        cursor += size
        unlocking_script = txinputraw[cursor:cursor + unlocking_script_size]
        cursor += unlocking_script_size
        sequence_number = txinputraw[cursor:cursor + 4]
        cursor += 4
        return TxInput(txid = inp_hash.hex(),
                       txout_index=int(output_n.hex(), 16),
                       script_sig=Script.from_raw(unlocking_script,has_segwit=has_segwit), sequence=sequence_number),cursor