Beispiel #1
0
def alice_swap_tx(txid_to_spend, utxo_index, amount_to_send):
    txout_script = coinExchangeScript(alice_public_key_BTC, bob_public_key_BTC, hash_of_secret())
    txout = create_txout(amount_to_send, txout_script)

    txin_scriptPubKey = P2PKH_scriptPubKey(alice_address_BTC)
    txin = create_txin(txid_to_spend, utxo_index)
    txin_scriptSig = P2PKH_scriptSig(txin, txout, txin_scriptPubKey,
        alice_secret_key_BTC, alice_public_key_BTC)
    
    tx = create_signed_transaction(txin, txout, txin_scriptPubKey,
                              txin_scriptSig)
    print('Alice swap tx (BTC) created successfully!')
    return tx, txout_script
Beispiel #2
0
def split_coins(amount_to_send, txid_to_spend, utxo_index, n, network):
    txin_scriptPubKey = address.to_scriptPubKey()
    txin = create_txin(txid_to_spend, utxo_index)
    txout_scriptPubKey = address.to_scriptPubKey()
    txout = create_txout(amount_to_send / n, txout_scriptPubKey)
    tx = CMutableTransaction([txin], [txout] * n)
    sighash = SignatureHash(txin_scriptPubKey, tx, 0, SIGHASH_ALL)
    txin.scriptSig = CScript(
        [private_key.sign(sighash) + bytes([SIGHASH_ALL]), public_key])
    VerifyScript(txin.scriptSig, txin_scriptPubKey, tx, 0,
                 (SCRIPT_VERIFY_P2SH, ))
    response = broadcast_transaction(tx, network)
    print(response.status_code, response.reason)
    print(response.text)
Beispiel #3
0
def redeem_swap(amount_to_send, bob_swap_tx, txin_scriptPubKey):
    txout_script = P2PKH_scriptPubKey(alice_address_BCY)
    txout = create_txout(amount_to_send, txout_script)

    txin = create_txin(b2x(bob_swap_tx.GetTxid()), 0)
    tx = CMutableTransaction([txin], [txout])
    alice_signature_BCY = sign_BCY(tx, txin_scriptPubKey)
    txin_scriptSig = coinExchangeScriptSig1(alice_signature_BCY, alice_secret_x)
    txin.scriptSig = CScript(txin_scriptSig)
    VerifyScript(txin.scriptSig, CScript(txin_scriptPubKey),
                 tx, 0, (SCRIPT_VERIFY_P2SH,))

    print('Alice redeem from swap tx (BCY) created successfully!')
    return tx, alice_secret_x
Beispiel #4
0
def send_from_P2PKH_transaction(amount_to_send, txid_to_spend, utxo_index,
                                txout_scriptPubKey, sender_private_key,
                                network):

    sender_public_key = sender_private_key.pub
    sender_address = P2PKHBitcoinAddress.from_pubkey(sender_public_key)

    txout = create_txout(amount_to_send, txout_scriptPubKey)

    txin_scriptPubKey = P2PKH_scriptPubKey(sender_address)
    txin = create_txin(txid_to_spend, utxo_index)
    txin_scriptSig = P2PKH_scriptSig(txin, txout, txin_scriptPubKey,
                                     sender_private_key, sender_public_key)

    new_tx = create_signed_transaction(txin, txout, txin_scriptPubKey,
                                       txin_scriptSig)

    return broadcast_transaction(new_tx, network)
Beispiel #5
0
def return_coins_tx(amount_to_send, last_tx, lock_time, script):
    txin = create_txin(b2x(last_tx.GetTxid()), 0)
    txout = create_txout(amount_to_send, P2PKH_scriptPubKey(alice_address_BTC))
    tx = CMutableTransaction([txin], [txout], nLockTime=lock_time)
    return tx