Merge pull request #143 from lightninglabs/unspent-only

btc: filter address outputs, only return unspent
This commit is contained in:
Oliver Gugger 2024-06-28 08:11:11 -06:00 committed by GitHub
commit 34945205ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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) {