forked from libsv/go-bt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfees.go
92 lines (80 loc) · 2.18 KB
/
fees.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package bt
import (
"errors"
)
const (
// FeeTypeStandard is the fee type for standard tx parts
FeeTypeStandard = "standard"
// FeeTypeData is the fee type for data tx parts
FeeTypeData = "data"
)
// FeeUnit displays the amount of Satoshis needed
// for a specific amount of Bytes in a transaction
// see https://github.com/bitcoin-sv-specs/brfc-misc/tree/master/feespec
type FeeUnit struct {
Satoshis int `json:"satoshis"` // Fee in satoshis of the amount of Bytes
Bytes int `json:"bytes"` // Number of bytes that the Fee covers
}
// Fee displays the MiningFee as well as the RelayFee for a specific
// FeeType, for example 'standard' or 'data'
// see https://github.com/bitcoin-sv-specs/brfc-misc/tree/master/feespec
type Fee struct {
FeeType string `json:"feeType"` // standard || data
MiningFee FeeUnit `json:"miningFee"`
RelayFee FeeUnit `json:"relayFee"` // Fee for retaining Tx in secondary mempool
}
// DefaultStandardFee returns the default
// standard fees offered by most miners.
func DefaultStandardFee() *Fee {
return &Fee{
FeeType: FeeTypeStandard,
MiningFee: FeeUnit{
Satoshis: 5,
Bytes: 10,
},
RelayFee: FeeUnit{
Satoshis: 5,
Bytes: 10,
},
}
}
// DefaultDataFee returns the default
// data fees offered by most miners.
func DefaultDataFee() *Fee {
return &Fee{
FeeType: FeeTypeData,
MiningFee: FeeUnit{
Satoshis: 25,
Bytes: 100,
},
RelayFee: FeeUnit{
Satoshis: 25,
Bytes: 100,
},
}
}
// DefaultFees returns an array of the default
// standard and data fees offered by most miners.
func DefaultFees() (f []*Fee) {
f = append(f, DefaultStandardFee())
f = append(f, DefaultDataFee())
return
}
// GetStandardFee returns the standard fee in the fees array supplied.
func GetStandardFee(fees []*Fee) (*Fee, error) {
for _, f := range fees {
if f.FeeType == FeeTypeStandard {
return f, nil
}
}
return nil, errors.New("no " + FeeTypeStandard + " fee supplied")
}
// GetDataFee returns the data fee in the fees array supplied.
func GetDataFee(fees []*Fee) (*Fee, error) {
for _, f := range fees {
if f.FeeType == FeeTypeData {
return f, nil
}
}
return nil, errors.New("no " + FeeTypeData + " fee supplied")
}