def replace_outputs(tx, hash160): """Replace unsigned outputs in tx.""" if not is_hex(hash160) and len(hash160.replace('0x', '')) == 40: raise ValueError('hash160 must be 40 hex digits.') out_script = Script.from_human('OP_DUP OP_HASH160 %s OP_EQUALVERIFY OP_CHECKSIG' % hash160) unsigned_outputs = get_unsigned_outputs(tx) if not unsigned_outputs: return tx new_tx = Transaction.from_tx(tx) for o in unsigned_outputs: new_tx.vout[o].scriptPubKey = out_script return new_tx