Drop PendingChange field (#331)

* Drop pending_change

* Fixes

* Polish

* Fallback to psbt string
This commit is contained in:
Pietralberto Mazza
2024-09-26 14:56:20 +02:00
committed by GitHub
parent 2be78b0115
commit b15c0868b2
23 changed files with 522 additions and 454 deletions

View File

@@ -80,6 +80,11 @@ type ExplorerUtxo struct {
} `json:"status"`
}
type SpentStatus struct {
Spent bool `json:"spent"`
SpentBy string `json:"txid,omitempty"`
}
func (e ExplorerUtxo) ToUtxo(delay uint) Utxo {
return newUtxo(e, delay)
}
@@ -88,6 +93,7 @@ type Explorer interface {
GetTxHex(txid string) (string, error)
Broadcast(txHex string) (string, error)
GetTxs(addr string) ([]ExplorerTx, error)
GetTxOutspends(tx string) ([]SpentStatus, error)
GetUtxos(addr string) ([]ExplorerUtxo, error)
GetBalance(addr string) (uint64, error)
GetRedeemedVtxosBalance(
@@ -215,6 +221,28 @@ func (e *explorerSvc) GetTxs(addr string) ([]ExplorerTx, error) {
return payload, nil
}
func (e *explorerSvc) GetTxOutspends(txid string) ([]SpentStatus, error) {
resp, err := http.Get(fmt.Sprintf("%s/tx/%s/outspends", e.baseUrl, txid))
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("failed to get txs: %s", string(body))
}
spentStatuses := make([]SpentStatus, 0)
if err := json.Unmarshal(body, &spentStatuses); err != nil {
return nil, err
}
return spentStatuses, nil
}
func (e *explorerSvc) GetUtxos(addr string) ([]ExplorerUtxo, error) {
resp, err := http.Get(fmt.Sprintf("%s/address/%s/utxo", e.baseUrl, addr))
if err != nil {