/
client.go
36 lines (30 loc) · 888 Bytes
/
client.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
package txpool
import (
"io"
"log"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/wire"
"github.com/skytree-lab/go-fundamental/chain/btc/btcapi"
)
type TxpoolClient struct {
baseURL string
}
func NewClient(netParams *chaincfg.Params) *TxpoolClient {
baseURL := ""
if netParams.Net == wire.MainNet {
baseURL = "https://mempool.space/api"
} else if netParams.Net == wire.TestNet3 {
baseURL = "https://mempool.space/testnet/api"
} else if netParams.Net == chaincfg.SigNetParams.Net {
baseURL = "https://mempool.space/signet/api"
} else {
log.Fatal("mempool don't support other netParams")
}
return &TxpoolClient{
baseURL: baseURL,
}
}
func (c *TxpoolClient) request(method, subPath string, requestBody io.Reader) ([]byte, error) {
return btcapi.Request(method, c.baseURL, subPath, requestBody)
}
var _ btcapi.BTCAPIClient = (*TxpoolClient)(nil)