Beispiel #1
0
def build_tx_from_skeleton(tx_skeleton,
                           txos_storage,
                           block_height,
                           historical=False,
                           non_context=False):
    '''
    By given tx_skeleton and txos_storage return transaction.
    If transaction is invalid or any input/output isn't available exception will be raised.
    Optionally, if `historical` is True we will check output_indexes both in mempool and spent outputs. 
  '''
    tx = Transaction(txos_storage=txos_storage)
    for _i in tx_skeleton.input_indexes:
        tx.inputs.append(txos_storage.confirmed[_i])
    for _o in tx_skeleton.output_indexes:
        if historical:
            try:
                tx.outputs.append(txos_storage.confirmed.find(_o))
            except:
                tx.outputs.append(txos_storage.mempool[_o])
        else:
            tx.outputs.append(txos_storage.mempool[_o])
    tx.additional_excesses = tx_skeleton.additional_excesses.copy()
    tx.combined_excesses = tx_skeleton.combined_excesses.copy()
    if historical or non_context:
        assert tx.non_context_verify(block_height=block_height)
    else:
        assert tx.verify(block_height=block_height)
    return tx
Beispiel #2
0
def build_tx_from_skeleton(tx_skeleton,
                           txos_storage,
                           excesses_storage,
                           block_height,
                           block_version,
                           rtx,
                           historical=False,
                           non_context=False):
    '''
    By given tx_skeleton and txos_storage return transaction.
    If transaction is invalid or any input/output isn't available exception will be raised.
    Optionally, if `historical` is True we will check output_indexes both in mempool and spent outputs. 
  '''
    tx = Transaction(txos_storage=txos_storage,
                     excesses_storage=excesses_storage)
    for _i in tx_skeleton.input_indexes:
        if historical or non_context:
            tx.inputs.append(txos_storage.confirmed.find(_i, rtx=rtx))
        else:
            tx.inputs.append(txos_storage.confirmed.get(_i, rtx=rtx))
    for _o in tx_skeleton.output_indexes:
        if historical or non_context:
            # About non_context: if we are on one branch and build block from another one
            # and this block contain output which is already commited on our branch (tx is
            # confirmed on both branches) we should get txo from confirmed storage
            try:
                tx.outputs.append(txos_storage.confirmed.find(_o, rtx=rtx))
            except:
                tx.outputs.append(txos_storage.mempool[_o])
        else:
            tx.outputs.append(txos_storage.mempool[_o])
    tx.additional_excesses = tx_skeleton.additional_excesses.copy()
    tx.updated_excesses = tx_skeleton.updated_excesses.copy()
    tx.mixer_offset = tx_skeleton.mixer_offset
    if historical or non_context:
        assert tx.non_context_verify(block_height=block_height)
    else:
        assert tx.verify(block_height=block_height,
                         block_version=block_version,
                         rtx=rtx)
    return tx