-
Notifications
You must be signed in to change notification settings - Fork 0
/
mempool.go
46 lines (39 loc) · 1.02 KB
/
mempool.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
package btcapi
import (
"encoding/json"
"fmt"
"strconv"
)
const MempoolRoute string = "/mempool"
type Fees struct {
NextBlock int `json:"nextBlock"`
ThirtyMinutes int `json:"30min"`
SixtyMinutes int `json:"60min"`
OneDay int `json:"1day"`
}
// MempoolCount returns the number of transactions in the mempool.
func (c Config) MempoolCount() (count int, err error) {
url := c.ExplorerURL + api + MempoolRoute + "/count"
body, err := getAPI(url)
if err != nil {
return count, err
}
count, err = strconv.Atoi(string(body))
if err != nil {
return count, fmt.Errorf("unable to parse returned body: %w", err)
}
return count, nil
}
// Fees returns the recommended fees to get included within pre-set deadlines.
func (c Config) Fees() (fees Fees, err error) {
url := c.ExplorerURL + api + MempoolRoute + "/fees"
body, err := getAPI(url)
if err != nil {
return fees, err
}
err = json.Unmarshal(body, &fees)
if err != nil {
return fees, fmt.Errorf("unable to parse returned body: %w", err)
}
return fees, nil
}