-
Notifications
You must be signed in to change notification settings - Fork 0
/
asset.go
119 lines (104 loc) · 3.3 KB
/
asset.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
109
110
111
112
113
114
115
116
117
118
119
// This code is available on the terms of the project LICENSE.md file,
// also available online at https://blueoakcouncil.org/license/1.0.0.
package app
import (
"fmt"
"strings"
"time"
)
const (
UnsupportedScriptError = ErrorKind("unsupported script type")
defaultLockTimeTaker = 8 * time.Hour
defaultlockTimeMaker = 20 * time.Hour
)
var (
// These string variables are defined to enable setting custom locktime values
// that may be used instead of `DefaultLockTimeTaker` and `DefaultLockTimeMaker`
// IF running on a test network (testnet or regtest) AND both values are set to
// valid duration strings.
// Same values should be set when building server and client binaries.
testLockTimeTaker string
testLockTimeMaker string
testLockTime struct {
taker time.Duration
maker time.Duration
}
)
// Set test locktime values on init. Panics if invalid or 0-second duration
// strings are provided.
func init() {
if testLockTimeTaker == "" && testLockTimeMaker == "" {
testLockTime.taker, testLockTime.maker = defaultLockTimeTaker, defaultlockTimeMaker
return
}
testLockTime.taker, _ = time.ParseDuration(testLockTimeTaker)
if testLockTime.taker.Seconds() == 0 {
panic(fmt.Sprintf("invalid value for testLockTimeTaker: %q", testLockTimeTaker))
}
testLockTime.maker, _ = time.ParseDuration(testLockTimeMaker)
if testLockTime.maker.Seconds() == 0 {
panic(fmt.Sprintf("invalid value for testLockTimeMaker: %q", testLockTimeMaker))
}
}
// LockTimeTaker returns the taker locktime value that should be used by both
// client and server for the specified network. Mainnet uses a constant value
// while test networks support setting a custom value during build.
func LockTimeTaker(network Network) time.Duration {
if network == Mainnet {
return defaultLockTimeTaker
}
return testLockTime.taker
}
// LockTimeMaker returns the maker locktime value that should be used by both
// client and server for the specified network. Mainnet uses a constant value
// while test networks support setting a custom value during build.
func LockTimeMaker(network Network) time.Duration {
if network == Mainnet {
return defaultlockTimeMaker
}
return testLockTime.maker
}
// Network flags passed to asset backends to signify which network to use.
type Network uint8
const (
Mainnet Network = iota
Testnet
Regtest
)
// The DEX recognizes only three networks. Simnet is an alias of Regtest.
const Simnet = Regtest
// String returns the string representation of a Network.
func (n Network) String() string {
switch n {
case Mainnet:
return "mainnet"
case Testnet:
return "testnet"
case Simnet:
return "simnet"
}
return ""
}
// NetFromString returns the Network for the given network name.
func NetFromString(net string) (Network, error) {
switch strings.ToLower(net) {
case "mainnet":
return Mainnet, nil
case "testnet":
return Testnet, nil
case "regtest", "regnet", "simnet":
return Simnet, nil
}
return 255, fmt.Errorf("unknown network %s", net)
}
// Asset is the configurable asset variables.
type Asset struct {
ID uint32 `json:"id"`
Symbol string `json:"symbol"`
LotSize uint64 `json:"lotSize"`
RateStep uint64 `json:"rateStep"`
MaxFeeRate uint64 `json:"maxFeeRate"`
SwapSize uint64 `json:"swapSize"`
SwapSizeBase uint64 `json:"swapSizeBase"`
SwapConf uint32 `json:"swapConf"`
}