Skip to content

Commit

Permalink
btc: filter address outputs, only return unspent
Browse files Browse the repository at this point in the history
  • Loading branch information
guggero committed Jun 26, 2024
1 parent d173f8c commit 83aa752
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion btc/explorer_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,26 @@ func (a *ExplorerAPI) Unspent(addr string) ([]*Vout, error) {
}
}

return outputs, nil
// Now filter those that are really unspent, because above we get all
// outputs that are sent to the address.
var unspent []*Vout
for idx, vout := range outputs {
url := fmt.Sprintf(
"%s/tx/%s/outspend/%d", a.BaseURL, vout.Outspend.Txid,
idx,
)
outspend := Outspend{}
err := fetchJSON(url, &outspend)
if err != nil {
return nil, err
}

if !outspend.Spent {
unspent = append(unspent, vout)
}
}

return unspent, nil
}

func (a *ExplorerAPI) Address(outpoint string) (string, error) {
Expand Down

0 comments on commit 83aa752

Please sign in to comment.