def cltv_lock_to_height(node, tx, to_address, amount, height=(- 1)):
    'Modify the scriptPubKey to add an OP_CHECKLOCKTIMEVERIFY, and make\n    a transaction that spends it.\n\n    This transforms the output script to anyone can spend (OP_TRUE) if the\n    lock time condition is valid.\n\n    Default height is -1 which leads CLTV to fail\n\n    TODO: test more ways that transactions using CLTV could be invalid (eg\n    locktime requirements fail, sequence time requirements fail, etc).\n    '
    height_op = OP_1NEGATE
    if (height > 0):
        tx.vin[0].nSequence = 0
        tx.nLockTime = height
        height_op = CScriptNum(height)
    tx.vout[0].scriptPubKey = CScript([height_op, OP_CHECKLOCKTIMEVERIFY, OP_DROP, OP_TRUE])
    pad_tx(tx)
    fundtx_raw = node.signrawtransactionwithwallet(ToHex(tx))['hex']
    fundtx = FromHex(CTransaction(), fundtx_raw)
    fundtx.rehash()
    from_txid = fundtx.hash
    inputs = [{'txid': fundtx.hash, 'vout': 0}]
    output = {to_address: amount}
    spendtx_raw = node.createrawtransaction(inputs, output)
    spendtx = FromHex(CTransaction(), spendtx_raw)
    pad_tx(spendtx)
    return (fundtx, spendtx)
Modify the scriptPubKey to add an OP_CHECKLOCKTIMEVERIFY, and make
a transaction that spends it.

This transforms the output script to anyone can spend (OP_TRUE) if the
lock time condition is valid.

Default height is -1 which leads CLTV to fail

TODO: test more ways that transactions using CLTV could be invalid (eg
locktime requirements fail, sequence time requirements fail, etc).
def cltv_lock_to_height(node, tx, to_address, amount, height=(- 1)):
    'Modify the scriptPubKey to add an OP_CHECKLOCKTIMEVERIFY, and make\n    a transaction that spends it.\n\n    This transforms the output script to anyone can spend (OP_TRUE) if the\n    lock time condition is valid.\n\n    Default height is -1 which leads CLTV to fail\n\n    TODO: test more ways that transactions using CLTV could be invalid (eg\n    locktime requirements fail, sequence time requirements fail, etc).\n    '
    height_op = OP_1NEGATE
    if (height > 0):
        tx.vin[0].nSequence = 0
        tx.nLockTime = height
        height_op = CScriptNum(height)
    tx.vout[0].scriptPubKey = CScript([height_op, OP_CHECKLOCKTIMEVERIFY, OP_DROP, OP_TRUE])
    pad_tx(tx)
    fundtx_raw = node.signrawtransactionwithwallet(ToHex(tx))['hex']
    fundtx = FromHex(CTransaction(), fundtx_raw)
    fundtx.rehash()
    from_txid = fundtx.hash
    inputs = [{'txid': fundtx.hash, 'vout': 0}]
    output = {to_address: amount}
    spendtx_raw = node.createrawtransaction(inputs, output)
    spendtx = FromHex(CTransaction(), spendtx_raw)
    pad_tx(spendtx)
    return (fundtx, spendtx)