-
Notifications
You must be signed in to change notification settings - Fork 0
/
gettx.go
48 lines (39 loc) · 784 Bytes
/
gettx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"encoding/json"
"net/http"
)
type UTXOResponse struct {
Amount *int64 `json:"amount"`
Script *string `json:"script"`
}
type TxResponse struct {
TXID string `json:"txid"`
Vout []TxVout `json:"vout"`
Vin []TxIn `json:"vin"`
}
type TxIn struct {
TXID string `json:"txid"`
}
type TxVout struct {
ScriptPubKey string `json:"scriptPubKey"`
Value int64 `json:"value"`
}
func getTransaction(txid string) (tx TxResponse, err error) {
// then try explorers
for _, endpoint := range esploras {
w, errW := http.Get(endpoint + "/tx/" + txid)
if errW != nil {
err = errW
continue
}
defer w.Body.Close()
errW = json.NewDecoder(w.Body).Decode(&tx)
if errW != nil {
err = errW
continue
}
return tx, nil
}
return
}