def test_unsigned_legacy_tx(self): outpoint = simple.outpoint( tx_id=helpers.P2PKH['human']['ins'][0]['hash'], index=helpers.P2PKH['human']['ins'][0]['index']) tx_in = simple.unsigned_input( outpoint=outpoint, sequence=helpers.P2PKH['human']['ins'][0]['sequence']) tx_out = simple.output(helpers.P2PKH['human']['outs'][0]['value'], helpers.P2PKH['human']['outs'][0]['addr']) tx_return_output = txn.make_op_return_output( helpers.P2PKH['human']['outs'][1]['memo']) tx = simple.unsigned_legacy_tx(tx_ins=[tx_in], tx_outs=[tx_out, tx_return_output]) self.assertEqual(tx, helpers.P2PKH['ser']['tx']['unsigned'])
def make_btc_shutdown_txns(auction_tx_id: str, idxs: List[int], add_funds_tx_id: str, add_funds_idx: int, add_funds_value: int, control_addr: str, control_addr_keypair: Tuple[str, str], change_addr: str, eth_addr: str, fee: int = 7700) -> List[str]: ''' Shuts down an auction by winning them with the owner keypair Args: tx_id: the split tx for the auction set idxs: the unpurchased indexes add_funds_tx_id: a prevout tx id to fund these transactions add_funds_idx: the prevout index add_funds_value: the prevout value control_addr: the input prevout's controlling address control_addr_keypair: the priv/pub keypair as a tuple of hex change_addr: where to send leftover funds eth_addr: where to deliver auction proceeds fee: the tx fee to pay ''' prev = (add_funds_tx_id, add_funds_idx) val = add_funds_value shutdown_txns = [] pubkeyhash = rutils.hash160(bytes.fromhex(control_addr_keypair[1])) prevout_script = b'\x19\x76\xa9\x14' + pubkeyhash + b'\x88\xac' for i in range(len(idxs)): tx_ins = [ simple.unsigned_input(simple.outpoint(auction_tx_id, idxs[i])), simple.unsigned_input(simple.outpoint(*prev)) ] out_val = val + 550 - fee addr = control_addr if i < len(idxs) - 1 else change_addr tx_outs = [ simple.output(out_val, addr), tx.make_op_return_output(bytes.fromhex(eth_addr[2:])) ] shutdown_tx = simple.unsigned_witness_tx(tx_ins, tx_outs) tx_witnesses = [] sighash_bytes = shutdown_tx.sighash_all( index=0, script=prevout_script, prevout_value=rutils.i2le_padded(550, 8), anyone_can_pay=False) sig = utils.sign_hash(sighash_bytes, control_addr_keypair[0]) sig = '{}{}'.format(sig, '01') # Build the witness wit = tx.make_witness( [bytes.fromhex(sig), bytes.fromhex(control_addr_keypair[1])]) tx_witnesses.append(wit) sighash_bytes_2 = shutdown_tx.sighash_all( index=1, script=prevout_script, prevout_value=rutils.i2le_padded(val, 8), anyone_can_pay=False) sig_2 = utils.sign_hash(sighash_bytes_2, control_addr_keypair[0]) sig_2 = '{}{}'.format(sig_2, '01') # Build the witness wit_2 = tx.make_witness( [bytes.fromhex(sig_2), bytes.fromhex(control_addr_keypair[1])]) tx_witnesses.append(wit_2) prev = (shutdown_tx.tx_id.hex(), 0) val = out_val shutdown_txns.append(shutdown_tx.copy(tx_witnesses=tx_witnesses).hex()) return shutdown_txns