77 "time"
88
99 "github.com/btcsuite/btcd/btcutil"
10+ "github.com/btcsuite/btcd/wire"
1011 "github.com/lightninglabs/chantools/btc"
1112 "github.com/lightninglabs/chantools/dataformat"
1213 "github.com/lightninglabs/chantools/lnd"
@@ -211,16 +212,40 @@ func summarizeAncientChannelOutputs(apiURL, ancientFile string) error {
211212
212213 var (
213214 api = newExplorerAPI (apiURL )
215+ numSpents uint32
214216 numUnspents uint32
215217 unspentSats uint64
218+ spentSats uint64
216219 )
217- for _ , channel := range ancients {
220+ for idx , channel := range ancients {
221+ // The first entry is for unit tests.
222+ if idx == 0 {
223+ continue
224+ }
225+
226+ closeOutPoint , err := wire .NewOutPointFromString (channel .OP )
227+ if err != nil {
228+ return fmt .Errorf ("error parsing outpoint %s: %w" ,
229+ channel .OP , err )
230+ }
231+
218232 unspents , err := api .Unspent (channel .Addr )
219233 if err != nil {
220234 return fmt .Errorf ("error fetching unspents for %s: %w" ,
221235 channel .Addr , err )
222236 }
223237
238+ if len (unspents ) == 0 {
239+ tx , err := api .Transaction (closeOutPoint .Hash .String ())
240+ if err != nil {
241+ return fmt .Errorf ("error fetching transaction " +
242+ "%s: %w" , closeOutPoint .Hash , err )
243+ }
244+
245+ numSpents ++
246+ spentSats += tx .Vout [closeOutPoint .Index ].Value
247+ }
248+
224249 if len (unspents ) > 1 {
225250 log .Infof ("Address %s has multiple unspents" ,
226251 channel .Addr )
@@ -237,6 +262,8 @@ func summarizeAncientChannelOutputs(apiURL, ancientFile string) error {
237262
238263 log .Infof ("Found %d unspent outputs with %d sats" , numUnspents ,
239264 unspentSats )
265+ log .Infof ("%d outputs with %d sats have been spent" , numSpents ,
266+ spentSats )
240267
241268 return nil
242269}
0 commit comments