forked from checksum0/go-electrum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
misc.go
64 lines (50 loc) · 1.81 KB
/
misc.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
52
53
54
55
56
57
58
59
60
61
62
63
64
package electrum
import "context"
type basicResp struct {
Result string `json:"result"`
}
// GetFeeResp represents the response to GetFee().
type GetFeeResp struct {
Result float32 `json:"result"`
}
// GetFee returns the estimated transaction fee per kilobytes for a transaction
// to be confirmed within a target number of blocks.
// https://electrumx.readthedocs.io/en/latest/protocol-methods.html#blockchain-estimatefee
func (s *Client) GetFee(ctx context.Context, target uint32) (float32, error) {
var resp GetFeeResp
err := s.request(ctx, "blockchain.estimatefee", []interface{}{target}, &resp)
if err != nil {
return -1, err
}
return resp.Result, err
}
// GetRelayFee returns the minimum fee a transaction must pay to be accepted into the
// remote server memory pool.
// https://electrumx.readthedocs.io/en/latest/protocol-methods.html#blockchain-relayfee
func (s *Client) GetRelayFee(ctx context.Context) (float32, error) {
var resp GetFeeResp
err := s.request(ctx, "blockchain.relayfee", []interface{}{}, &resp)
if err != nil {
return -1, err
}
return resp.Result, err
}
// GetFeeHistogramResp represents the response to GetFee().
type getFeeHistogramResp struct {
Result [][2]uint64 `json:"result"`
}
// GetFeeHistogram returns a histogram of the fee rates paid by transactions in the
// memory pool, weighted by transacation size.
// https://electrumx.readthedocs.io/en/latest/protocol-methods.html#mempool-get-fee-histogram
func (s *Client) GetFeeHistogram(ctx context.Context) (map[uint32]uint64, error) {
var resp getFeeHistogramResp
err := s.request(ctx, "mempool.get_fee_histogram", []interface{}{}, &resp)
if err != nil {
return nil, err
}
feeMap := make(map[uint32]uint64)
for i := 0; i < len(resp.Result); i++ {
feeMap[uint32(resp.Result[i][0])] = resp.Result[i][1]
}
return feeMap, err
}