Generates wait examples
(l1, l2, bitcoind, executor)
| 1082 | |
| 1083 | |
| 1084 | def generate_wait_examples(l1, l2, bitcoind, executor): |
| 1085 | """Generates wait examples""" |
| 1086 | try: |
| 1087 | logger.info('Wait Start...') |
| 1088 | inv1 = l2.rpc.invoice(1000, 'inv1', 'inv1') |
| 1089 | inv2 = l2.rpc.invoice(2000, 'inv2', 'inv2') |
| 1090 | inv3 = l2.rpc.invoice(3000, 'inv3', 'inv3') |
| 1091 | inv4 = l2.rpc.invoice(4000, 'inv4', 'inv4') |
| 1092 | inv5 = l2.rpc.invoice(5000, 'inv5', 'inv5') |
| 1093 | # Wait invoice |
| 1094 | wi3 = executor.submit(l2.rpc.waitinvoice, 'inv3') |
| 1095 | time.sleep(1) |
| 1096 | l1.rpc.pay(inv2['bolt11']) |
| 1097 | time.sleep(1) |
| 1098 | wi2res = executor.submit(l2.rpc.waitinvoice, 'inv2').result(timeout=5) |
| 1099 | update_example(node=l2, method='waitinvoice', params={'label': 'inv2'}, response=wi2res) |
| 1100 | |
| 1101 | l1.rpc.pay(inv3['bolt11']) |
| 1102 | wi3res = wi3.result(timeout=5) |
| 1103 | update_example(node=l2, method='waitinvoice', params=['inv3'], response=wi3res) |
| 1104 | |
| 1105 | # Wait any invoice |
| 1106 | wai = executor.submit(l2.rpc.waitanyinvoice) |
| 1107 | time.sleep(1) |
| 1108 | l1.rpc.pay(inv5['bolt11']) |
| 1109 | l1.rpc.pay(inv4['bolt11']) |
| 1110 | waires = wai.result(timeout=5) |
| 1111 | update_example(node=l2, method='waitanyinvoice', params={}, response=waires) |
| 1112 | pay_index = waires['pay_index'] |
| 1113 | wai_pay_index_res = executor.submit(l2.rpc.waitanyinvoice, pay_index, 0).result(timeout=5) |
| 1114 | update_example(node=l2, method='waitanyinvoice', params={'lastpay_index': pay_index, 'timeout': 0}, response=wai_pay_index_res) |
| 1115 | |
| 1116 | # Wait with subsystem examples |
| 1117 | update_example(node=l2, method='wait', params={'subsystem': 'invoices', 'indexname': 'created', 'nextvalue': 0}) |
| 1118 | |
| 1119 | wspres_l1 = l1.rpc.wait(subsystem='sendpays', indexname='created', nextvalue=0) |
| 1120 | nextvalue = int(wspres_l1['created']) + 1 |
| 1121 | wsp_created_l1 = executor.submit(l1.rpc.call, 'wait', {'subsystem': 'sendpays', 'indexname': 'created', 'nextvalue': nextvalue}) |
| 1122 | wsp_updated_l1 = executor.submit(l1.rpc.call, 'wait', {'subsystem': 'sendpays', 'indexname': 'updated', 'nextvalue': nextvalue}) |
| 1123 | time.sleep(1) |
| 1124 | routestep = { |
| 1125 | 'amount_msat': 1000, |
| 1126 | 'id': l2.info['id'], |
| 1127 | 'delay': 5, |
| 1128 | 'channel': first_scid(l1, l2) |
| 1129 | } |
| 1130 | l1.rpc.sendpay([routestep], inv1['payment_hash'], payment_secret=inv1['payment_secret']) |
| 1131 | wspc_res = wsp_created_l1.result(5) |
| 1132 | wspu_res = wsp_updated_l1.result(5) |
| 1133 | update_example(node=l1, method='wait', params={'subsystem': 'sendpays', 'indexname': 'created', 'nextvalue': nextvalue}, response=wspc_res) |
| 1134 | update_example(node=l1, method='wait', params=['sendpays', 'updated', nextvalue], response=wspu_res) |
| 1135 | |
| 1136 | # Wait blockheight |
| 1137 | curr_blockheight = l2.rpc.getinfo()['blockheight'] |
| 1138 | if curr_blockheight < 130: |
| 1139 | bitcoind.generate_block(130 - curr_blockheight) |
| 1140 | sync_blockheight(bitcoind, [l2]) |
| 1141 | update_example(node=l2, method='waitblockheight', params={'blockheight': 126}, description=[f'This will return immediately since the current blockheight exceeds the requested waitblockheight.']) |