-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
mempool.go
51 lines (46 loc) · 1.33 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
47
48
49
50
51
package whatsonchain
import (
"context"
"encoding/json"
"fmt"
"net/http"
)
// GetMempoolInfo this endpoint retrieves various info about the node's mempool for the selected network
//
// For more information: https://developers.whatsonchain.com/#get-mempool-info
func (c *Client) GetMempoolInfo(ctx context.Context) (info *MempoolInfo, err error) {
var resp string
// https://api.whatsonchain.com/v1/bsv/<network>/mempool/info
if resp, err = c.request(
ctx,
fmt.Sprintf("%s%s/mempool/info", apiEndpoint, c.Network()),
http.MethodGet, nil,
); err != nil {
return
}
if len(resp) == 0 {
return nil, ErrMempoolInfoNotFound
}
err = json.Unmarshal([]byte(resp), &info)
return
}
// GetMempoolTransactions this endpoint will retrieve a list of transaction ids from the node's mempool
// for the selected network
//
// For more information: https://developers.whatsonchain.com/#get-mempool-transactions
func (c *Client) GetMempoolTransactions(ctx context.Context) (transactions []string, err error) {
var resp string
// https://api.whatsonchain.com/v1/bsv/<network>/mempool/raw
if resp, err = c.request(
ctx,
fmt.Sprintf("%s%s/mempool/raw", apiEndpoint, c.Network()),
http.MethodGet, nil,
); err != nil {
return
}
if len(resp) == 0 {
return nil, ErrMempoolInfoNotFound
}
err = json.Unmarshal([]byte(resp), &transactions)
return
}