-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
108 lines (87 loc) · 3.03 KB
/
init.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package block
import (
"github.com/weijun-sh/gethscan-server/log"
"github.com/weijun-sh/gethscan-server/tokens"
)
var (
cfgMinRelayFee int64 = 3000 // BTC才400
cfgMinRelayFeePerKb int64 = 10000
cfgMaxRelayFeePerKb int64 = 500000
cfgPlusFeePercentage uint64
cfgEstimateFeeBlocks = 6
cfgFromPublicKey string
cfgUtxoAggregateMinCount = 20
cfgUtxoAggregateMinValue = uint64(1000000)
cfgUtxoAggregateToAddress string
)
// Init init btc extra
func Init(btcExtra *tokens.BtcExtraConfig) {
if BridgeInstance == nil {
return
}
if btcExtra == nil {
log.Fatal("Block bridge must config 'BtcExtra'")
}
initFromPublicKey()
initRelayFee(btcExtra)
initAggregate(btcExtra)
}
func initFromPublicKey() {
if len(tokens.GetTokenPairsConfig()) != 1 {
log.Fatalf("Block bridge does not support multiple tokens")
}
pairCfg, exist := tokens.GetTokenPairsConfig()[PairID]
if !exist {
log.Fatalf("Block bridge must have pairID %v", PairID)
}
cfgFromPublicKey = pairCfg.SrcToken.DcrmPubkey
_, err := BridgeInstance.GetCompressedPublicKey(cfgFromPublicKey, true)
if err != nil {
log.Fatal("wrong block dcrm public key", "err", err)
}
}
func initRelayFee(btcExtra *tokens.BtcExtraConfig) {
if btcExtra.MinRelayFee > 0 {
cfgMinRelayFee = btcExtra.MinRelayFee
maxMinRelayFee, _ := newAmount(0.001)
minRelayFee := btcAmountType(cfgMinRelayFee)
if minRelayFee > maxMinRelayFee {
log.Fatal("BtcMinRelayFee is too large", "value", minRelayFee, "max", maxMinRelayFee)
}
}
if btcExtra.EstimateFeeBlocks > 0 {
cfgEstimateFeeBlocks = btcExtra.EstimateFeeBlocks
if cfgEstimateFeeBlocks > 25 {
log.Fatal("EstimateFeeBlocks is too large, must <= 25")
}
}
if btcExtra.PlusFeePercentage > 0 {
cfgPlusFeePercentage = btcExtra.PlusFeePercentage
if cfgPlusFeePercentage > 5000 {
log.Fatal("PlusFeePercentage is too large, must <= 5000")
}
}
if btcExtra.MaxRelayFeePerKb > 0 {
cfgMaxRelayFeePerKb = btcExtra.MaxRelayFeePerKb
}
if btcExtra.MinRelayFeePerKb > 0 {
cfgMinRelayFeePerKb = btcExtra.MinRelayFeePerKb
}
if cfgMinRelayFeePerKb > cfgMaxRelayFeePerKb {
log.Fatal("MinRelayFeePerKb is larger than MaxRelayFeePerKb", "min", cfgMinRelayFeePerKb, "max", cfgMaxRelayFeePerKb)
}
log.Info("Init Block extra", "MinRelayFee", cfgMinRelayFee, "MinRelayFeePerKb", cfgMinRelayFeePerKb, "MaxRelayFeePerKb", cfgMaxRelayFeePerKb, "PlusFeePercentage", cfgPlusFeePercentage)
}
func initAggregate(btcExtra *tokens.BtcExtraConfig) {
if btcExtra.UtxoAggregateMinCount > 0 {
cfgUtxoAggregateMinCount = btcExtra.UtxoAggregateMinCount
}
if btcExtra.UtxoAggregateMinValue > 0 {
cfgUtxoAggregateMinValue = btcExtra.UtxoAggregateMinValue
}
cfgUtxoAggregateToAddress = btcExtra.UtxoAggregateToAddress
if !BridgeInstance.IsValidAddress(cfgUtxoAggregateToAddress) {
log.Fatal("wrong utxo aggregate to address", "toAddress", cfgUtxoAggregateToAddress)
}
log.Info("Init Block extra", "UtxoAggregateMinCount", cfgUtxoAggregateMinCount, "UtxoAggregateMinValue", cfgUtxoAggregateMinValue, "UtxoAggregateToAddress", cfgUtxoAggregateToAddress)
}