Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: check for an output to be unspent. #156

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion btc/explorer_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,31 @@ 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{
// 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{
Txid: tx.TXID,
Vin: voutIdx,
}
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
Loading