def bob_swap_tx(txid_to_spend, utxo_index, amount_to_send, hash_of_secret): txout_script = coinExchangeScript(bob_public_key_BCY, alice_public_key_BCY, hash_of_secret) txout = create_txout(amount_to_send, txout_script) txin_scriptPubKey = P2PKH_scriptPubKey(bob_address_BCY) txin = create_txin(txid_to_spend, utxo_index) txin_scriptSig = P2PKH_scriptSig(txin, txout, txin_scriptPubKey, bob_secret_key_BCY, bob_public_key_BCY) tx = create_signed_transaction(txin, txout, txin_scriptPubKey, txin_scriptSig) print('Bob swap tx (BCY) created successfully!') return tx, txout_script
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
def send_from_multisig_transaction(amount_to_send, txid_to_spend, utxo_index, txin_scriptPubKey, txout_scriptPubKey): txout = create_txout(amount_to_send, txout_scriptPubKey) txin = create_txin(txid_to_spend, utxo_index) txin_scriptSig = multisig_scriptSig(txin, txout, txin_scriptPubKey) new_tx = create_signed_transaction(txin, txout, txin_scriptPubKey, txin_scriptSig) return broadcast_transaction(new_tx) if __name__ == '__main__': ###################################################################### # TODO: set these parameters correctly amount_to_send = None txid_to_spend = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' utxo_index = None ###################################################################### txin_scriptPubKey = ex3a_txout_scriptPubKey txout_scriptPubKey = P2PKH_scriptPubKey(faucet_address) response = send_from_multisig_transaction(amount_to_send, txid_to_spend, utxo_index, txin_scriptPubKey, txout_scriptPubKey) print(response.status_code, response.reason) print(response.text)
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