Beispiel #1
0
def reconstruct_composed_tx_spec(model, tx):
    if isinstance(tx, str):
        tx = deserialize(tx)
    if not isinstance(tx, Tx):
        raise Exception('Tx is neiether string nor pycoin.tx.Tx!')

    pycoin_tx = tx

    composed_tx_spec = txspec.ComposedTxSpec(None)

    for py_txin in pycoin_tx.txs_in:
        # lookup the previous hash and generate the utxo
        in_txhash, in_outindex = py_txin.previous_hash, py_txin.previous_index
        in_txhash = in_txhash[::-1].encode('hex')

        composed_tx_spec.add_txin(
            txspec.ComposedTxSpec.TxIn(in_txhash, in_outindex))
        # in_tx = ccc.blockchain_state.get_tx(in_txhash)
        # value = in_tx.outputs[in_outindex].value
        # raw_address = script_to_raw_address(py_txin.script)
        # address = ccc.raw_to_address(raw_address)

    for py_txout in pycoin_tx.txs_out:
        script = py_txout.script
        raw_address = script_to_raw_address(script)
        if raw_address:
            address = model.ccc.raw_to_address(raw_address)
        else:
            address = None
        composed_tx_spec.add_txout(
            txspec.ComposedTxSpec.TxOut(py_txout.coin_value, address))

    return composed_tx_spec
Beispiel #2
0
def reconstruct_composed_tx_spec(model, tx):
    if isinstance(tx, str):
        tx = deserialize(tx)
    if not isinstance(tx, Tx):
        raise Exception("tx is neiether string nor pycoin.tx.Tx")

    pycoin_tx = tx

    txins, txouts = [], []

    for py_txin in pycoin_tx.txs_in:
        # lookup the previous hash and generate the utxo
        in_txhash, in_outindex = py_txin.previous_hash, py_txin.previous_index
        in_txhash = in_txhash[::-1].encode("hex")

        txins.append(txspec.ComposedTxSpec.TxIn(in_txhash, in_outindex))
        # in_tx = ccc.blockchain_state.get_tx(in_txhash)
        # value = in_tx.outputs[in_outindex].value
        # raw_address = script_to_raw_address(py_txin.script)
        # address = ccc.raw_to_address(raw_address)

    for py_txout in pycoin_tx.txs_out:
        script = py_txout.script
        raw_address = script_to_raw_address(script)
        if raw_address:
            address = model.ccc.raw_to_address(raw_address)
        else:
            address = None
        txouts.append(txspec.ComposedTxSpec.TxOut(py_txout.coin_value, address))
    return txspec.ComposedTxSpec(txins, txouts)
Beispiel #3
0
 def test_script_to_raw_address(self):
     self.assertEqual(script_to_raw_address(""), None)
Beispiel #4
0
 def test_script_to_raw_address(self):
     self.assertEqual(script_to_raw_address(''), None)