-
Notifications
You must be signed in to change notification settings - Fork 84
/
ltc.go
82 lines (69 loc) · 2.15 KB
/
ltc.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
// 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 ltc
import (
"fmt"
"decred.org/dcrdex/dex"
dexbtc "decred.org/dcrdex/dex/networks/btc"
dexltc "decred.org/dcrdex/dex/networks/ltc"
"decred.org/dcrdex/server/asset"
"decred.org/dcrdex/server/asset/btc"
"github.com/btcsuite/btcd/chaincfg"
)
// Driver implements asset.Driver.
type Driver struct{}
// Setup creates the LTC backend. Start the backend with its Run method.
func (d *Driver) Setup(configPath string, logger dex.Logger, network dex.Network) (asset.Backend, error) {
return NewBackend(configPath, logger, network)
}
// DecodeCoinID creates a human-readable representation of a coin ID for
// Litecoin.
func (d *Driver) DecodeCoinID(coinID []byte) (string, error) {
// Litecoin and Bitcoin have the same tx hash and output format.
return (&btc.Driver{}).DecodeCoinID(coinID)
}
// Version returns the Backend implementation's version number.
func (d *Driver) Version() uint32 {
return version
}
func init() {
asset.Register(assetName, &Driver{})
}
const (
version = 0
assetName = "ltc"
)
// NewBackend generates the network parameters and creates a ltc backend as a
// btc clone using an asset/btc helper function.
func NewBackend(configPath string, logger dex.Logger, network dex.Network) (asset.Backend, error) {
var params *chaincfg.Params
switch network {
case dex.Mainnet:
params = dexltc.MainNetParams
case dex.Testnet:
params = dexltc.TestNet4Params
case dex.Regtest:
params = dexltc.RegressionNetParams
default:
return nil, fmt.Errorf("unknown network ID %v", network)
}
// Designate the clone ports. These will be overwritten by any explicit
// settings in the configuration file.
ports := dexbtc.NetPorts{
Mainnet: "9332",
Testnet: "19332",
Simnet: "19443",
}
if configPath == "" {
configPath = dexbtc.SystemConfigPath("litecoin")
}
return btc.NewBTCClone(&btc.BackendCloneConfig{
Name: assetName,
Segwit: false, // TODO: Change to true.
ConfigPath: configPath,
Logger: logger,
Net: network,
ChainParams: params,
Ports: ports,
})
}