@@ -120,6 +120,24 @@ func summarizeAncientChannels(apiURL string,
120120
121121 api := newExplorerAPI (apiURL )
122122
123+ results , err := ancientChannelCandidates (api , channels )
124+ if err != nil {
125+ return fmt .Errorf ("error finding ancient channels: %w" , err )
126+ }
127+
128+ summaryBytes , err := json .MarshalIndent (results , "" , " " )
129+ if err != nil {
130+ return err
131+ }
132+ fileName := fmt .Sprintf ("results/summary-ancient-%s.json" ,
133+ time .Now ().Format ("2006-01-02-15-04-05" ))
134+ log .Infof ("Writing result to %s" , fileName )
135+ return os .WriteFile (fileName , summaryBytes , 0644 )
136+ }
137+
138+ func ancientChannelCandidates (api * btc.ExplorerAPI ,
139+ channels []* dataformat.SummaryEntry ) ([]* ancientChannel , error ) {
140+
123141 var results []* ancientChannel
124142 for _ , target := range channels {
125143 if target .ClosingTX == nil {
@@ -155,8 +173,9 @@ func summarizeAncientChannels(apiURL string,
155173
156174 addr , err := lnd .ParseAddress (closeTx .ToRemoteAddr , chainParams )
157175 if err != nil {
158- return fmt .Errorf ("error parsing address %s of %s: %w" ,
159- closeTx .ToRemoteAddr , closeTx .TXID , err )
176+ return nil , fmt .Errorf ("error parsing address %s of " +
177+ "%s: %w" , closeTx .ToRemoteAddr , closeTx .TXID ,
178+ err )
160179 }
161180
162181 if _ , ok := addr .(* btcutil.AddressWitnessPubKeyHash ); ! ok {
@@ -167,8 +186,8 @@ func summarizeAncientChannels(apiURL string,
167186
168187 tx , err := api .Transaction (closeTx .TXID )
169188 if err != nil {
170- return fmt .Errorf ("error fetching transaction %s: %w" ,
171- closeTx .TXID , err )
189+ return nil , fmt .Errorf ("error fetching transaction " +
190+ "%s: %w" , closeTx .TXID , err )
172191 }
173192
174193 for idx , txOut := range tx .Vout {
@@ -182,19 +201,13 @@ func summarizeAncientChannels(apiURL string,
182201 idx ),
183202 Addr : closeTx .ToRemoteAddr ,
184203 CP : target .LocalUnrevokedCommitPoint ,
204+ Node : target .RemotePubkey ,
185205 })
186206 }
187207 }
188208 }
189209
190- summaryBytes , err := json .MarshalIndent (results , "" , " " )
191- if err != nil {
192- return err
193- }
194- fileName := fmt .Sprintf ("results/summary-ancient-%s.json" ,
195- time .Now ().Format ("2006-01-02-15-04-05" ))
196- log .Infof ("Writing result to %s" , fileName )
197- return os .WriteFile (fileName , summaryBytes , 0644 )
210+ return results , nil
198211}
199212
200213func summarizeAncientChannelOutputs (apiURL , ancientFile string ) error {
0 commit comments