diff --git a/contrib/pyln-testing/pyln/testing/utils.py b/contrib/pyln-testing/pyln/testing/utils.py index 728db5fcd..4e259e5c4 100644 --- a/contrib/pyln-testing/pyln/testing/utils.py +++ b/contrib/pyln-testing/pyln/testing/utils.py @@ -1205,6 +1205,26 @@ class LightningNode(object): self.daemon.wait_for_log('peer_out WIRE_UPDATE_FEE') assert(self.rpc.feerates('perkw')['perkw']['opening'] == rate) + def wait_for_onchaind_tx(self, *args): + """Wait for onchaind to ask lightningd to create one or more txs. Each arg is a pair of typename, resolvename. Returns tuples of the rawtx, txid and number of blocks delay for each pair. + """ + # Could happen in any order. + needle = self.daemon.logsearch_start + ret = () + for i in range(0, len(args), 2): + self.daemon.logsearch_start = needle + r = self.daemon.wait_for_log('Telling lightningd about {} to resolve {}' + .format(args[i], args[i + 1])) + blocks = int(re.search(r'\(([-0-9]*) more blocks\)', r).group(1)) + + # The next 'Broadcast for onchaind' will be the tx. + # Now grab the corresponding broadcast lightningd did, to get actual tx: + r = self.daemon.wait_for_log('Broadcast for onchaind tx') + rawtx = re.search(r'.* tx ([0-9a-fA-F]*)', r).group(1) + txid = self.bitcoin.rpc.decoderawtransaction(rawtx, True)['txid'] + ret = ret + ((rawtx, txid, blocks),) + return ret + def wait_for_onchaind_broadcast(self, name, resolve=None): """Wait for onchaind to drop tx name to resolve (if any)""" if resolve: