@@ -742,18 +742,20 @@ def fundbalancedchannel(self, remote_node, total_capacity, announce=True):
742742
743743 # Make sure the fundchannel is confirmed.
744744 num_tx = len (self .bitcoin .rpc .getrawmempool ())
745- tx = self .rpc .fundchannel (remote_node .info ['id' ], chan_capacity , feerate = 'slow' , minconf = 0 , announce = announce , push_msat = Millisatoshi (chan_capacity * 500 ))[ 'tx' ]
745+ res = self .rpc .fundchannel (remote_node .info ['id' ], chan_capacity , feerate = 'slow' , minconf = 0 , announce = announce , push_msat = Millisatoshi (chan_capacity * 500 ))
746746 wait_for (lambda : len (self .bitcoin .rpc .getrawmempool ()) == num_tx + 1 )
747- self .bitcoin .generate_block (1 )
747+ blockid = self .bitcoin .generate_block (1 )[ 0 ]
748748
749749 # Generate the scid.
750- # NOTE This assumes only the coinbase and the fundchannel is
751- # confirmed in the block.
752- outnum = get_tx_p2wsh_outnum (self .bitcoin , tx , total_capacity )
750+ outnum = get_tx_p2wsh_outnum (self .bitcoin , res ['tx' ], total_capacity )
753751 if outnum is None :
754- raise ValueError ("no outnum found. capacity {} tx {}" .format (total_capacity , tx ))
752+ raise ValueError ("no outnum found. capacity {} tx {}" .format (total_capacity , res ['tx' ]))
753+
754+ for i , txid in enumerate (self .bitcoin .rpc .getblock (blockid )['tx' ]):
755+ if txid == res ['txid' ]:
756+ txnum = i
755757
756- return '{}x1x{} ' .format (self .bitcoin .rpc .getblockcount (), outnum )
758+ return '{}x{}x{} ' .format (self .bitcoin .rpc .getblockcount (), txnum , outnum )
757759
758760 def getactivechannels (self ):
759761 return [c for c in self .rpc .listchannels ()['channels' ] if c ['active' ]]
@@ -855,11 +857,15 @@ def has_funds_on_addr(addr):
855857 announce = announce_channel ,
856858 ** kwargs )
857859 wait_for (lambda : res ['txid' ] in self .bitcoin .rpc .getrawmempool ())
858- self .bitcoin .generate_block (1 )
860+ blockid = self .bitcoin .generate_block (1 )[0 ]
861+
862+ for i , txid in enumerate (self .bitcoin .rpc .getblock (blockid )['tx' ]):
863+ if txid == res ['txid' ]:
864+ txnum = i
859865
860- # Hacky way to find our output.
861- scid = "{}x1x{}" . format ( self . bitcoin . rpc . getblockcount () ,
862- get_tx_p2wsh_outnum (self .bitcoin , res ['tx' ], amount ))
866+ scid = "{}x{}x{}" . format ( self . bitcoin . rpc . getblockcount (),
867+ txnum ,
868+ get_tx_p2wsh_outnum (self .bitcoin , res ['tx' ], amount ))
863869
864870 if wait_for_active :
865871 self .wait_channel_active (scid )
0 commit comments