def merge_txs(txs, spendables, payables):
    txs_in = []
    txs_out = []
    unspents = []
    for tx in txs:
        smaller = min(len(tx.txs_in), len(tx.txs_out))
        txs_in.extend(tx.txs_in[:smaller])
        txs_out.extend(tx.txs_out[:smaller])
        unspents.extend(tx.unspents[:smaller])
    for tx in txs:
        smaller = min(len(tx.txs_in), len(tx.txs_out))
        txs_in.extend(tx.txs_in[smaller:])
        txs_out.extend(tx.txs_out[smaller:])
        unspents.extend(tx.unspents[smaller:])
    for spendable in spendables:
        txs_in.append(spendable.tx_in())
        unspents.append(spendable)
    for (address, coin_value) in payables:
        script = standard_tx_out_script(address)
        txs_out.append(TxOut(coin_value, script))
    return (txs_in, txs_out, unspents)
def merge_txs(txs, spendables, payables):
    txs_in = []
    txs_out = []
    unspents = []
    for tx in txs:
        smaller = min(len(tx.txs_in), len(tx.txs_out))
        txs_in.extend(tx.txs_in[:smaller])
        txs_out.extend(tx.txs_out[:smaller])
        unspents.extend(tx.unspents[:smaller])
    for tx in txs:
        smaller = min(len(tx.txs_in), len(tx.txs_out))
        txs_in.extend(tx.txs_in[smaller:])
        txs_out.extend(tx.txs_out[smaller:])
        unspents.extend(tx.unspents[smaller:])
    for spendable in spendables:
        txs_in.append(spendable.tx_in())
        unspents.append(spendable)
    for (address, coin_value) in payables:
        script = standard_tx_out_script(address)
        txs_out.append(TxOut(coin_value, script))
    return (txs_in, txs_out, unspents)