Skip to content

Commit

Permalink
api: check for an output to be unspent.
Browse files Browse the repository at this point in the history
  • Loading branch information
ziggie1984 committed Aug 18, 2024
1 parent f062b53 commit 0bca88e
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions btc/explorer_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,28 @@ func (a *ExplorerAPI) Unspent(addr string) ([]*Vout, error) {
for _, tx := range txs {
for voutIdx, vout := range tx.Vout {
if vout.ScriptPubkeyAddr == addr {
vout.Outspend = &Outspend{
Txid: tx.TXID,
Vin: voutIdx,
// We need to also make sure that the tx is not
// already spent before including it as unspent.
//
// NOTE: Somehow LND sometimes contructs
// channels with the same keyfamily base hence
// the same pubkey. Needs to be investigated on
// the LND side.
outSpend := &Outspend{}
url := fmt.Sprintf(
"%s/tx/%s/outspend/%d", a.BaseURL,
tx.TXID, voutIdx,
)
err := fetchJSON(url, outSpend)
if err != nil {
return nil, err
}

if outSpend.Spent {
continue
}

vout.Outspend = outSpend
outputs = append(outputs, vout)
}
}
Expand Down

0 comments on commit 0bca88e

Please sign in to comment.