decred.org/dcrdex@v1.0.5/server/asset/ltc/ltc.go (about) 1 // This code is available on the terms of the project LICENSE.md file, 2 // also available online at https://blueoakcouncil.org/license/1.0.0. 3 4 package ltc 5 6 import ( 7 "fmt" 8 9 "decred.org/dcrdex/dex" 10 dexbtc "decred.org/dcrdex/dex/networks/btc" 11 dexltc "decred.org/dcrdex/dex/networks/ltc" 12 "decred.org/dcrdex/server/asset" 13 "decred.org/dcrdex/server/asset/btc" 14 "github.com/btcsuite/btcd/chaincfg" 15 ) 16 17 // Driver implements asset.Driver. 18 type Driver struct{} 19 20 // Setup creates the LTC backend. Start the backend with its Run method. 21 func (d *Driver) Setup(cfg *asset.BackendConfig) (asset.Backend, error) { 22 return NewBackend(cfg) 23 } 24 25 // DecodeCoinID creates a human-readable representation of a coin ID for 26 // Litecoin. 27 func (d *Driver) DecodeCoinID(coinID []byte) (string, error) { 28 // Litecoin and Bitcoin have the same tx hash and output format. 29 return (&btc.Driver{}).DecodeCoinID(coinID) 30 } 31 32 // UnitInfo returns the dex.UnitInfo for the asset. 33 func (d *Driver) UnitInfo() dex.UnitInfo { 34 return dexltc.UnitInfo 35 } 36 37 // Version returns the Backend implementation's version number. 38 func (d *Driver) Version() uint32 { 39 return version 40 } 41 42 // MinBondSize calculates the minimum bond size for a given fee rate that avoids 43 // dust outputs on the bond and refund txs, assuming the maxFeeRate doesn't 44 // change. 45 func (d *Driver) MinBondSize(maxFeeRate uint64) uint64 { 46 return dexbtc.MinBondSize(maxFeeRate, true) 47 } 48 49 // MinLotSize calculates the minimum bond size for a given fee rate that avoids 50 // dust outputs on the swap and refund txs, assuming the maxFeeRate doesn't 51 // change. 52 func (d *Driver) MinLotSize(maxFeeRate uint64) uint64 { 53 return dexbtc.MinLotSize(maxFeeRate, true) 54 } 55 56 // Name is the asset's name. 57 func (d *Driver) Name() string { 58 return "Litecoin" 59 } 60 61 func init() { 62 asset.Register(BipID, &Driver{}) 63 } 64 65 const ( 66 version = 1 67 BipID = 2 68 assetName = "ltc" 69 ) 70 71 // NewBackend generates the network parameters and creates a ltc backend as a 72 // btc clone using an asset/btc helper function. 73 func NewBackend(cfg *asset.BackendConfig) (asset.Backend, error) { 74 var params *chaincfg.Params 75 switch cfg.Net { 76 case dex.Mainnet: 77 params = dexltc.MainNetParams 78 case dex.Testnet: 79 params = dexltc.TestNet4Params 80 case dex.Regtest: 81 params = dexltc.RegressionNetParams 82 default: 83 return nil, fmt.Errorf("unknown network ID %v", cfg.Net) 84 } 85 86 // Designate the clone ports. These will be overwritten by any explicit 87 // settings in the configuration file. 88 ports := dexbtc.NetPorts{ 89 Mainnet: "9332", 90 Testnet: "19332", 91 Simnet: "19443", 92 } 93 94 configPath := cfg.ConfigPath 95 if configPath == "" { 96 configPath = dexbtc.SystemConfigPath("litecoin") 97 } 98 99 return btc.NewBTCClone(&btc.BackendCloneConfig{ 100 Name: assetName, 101 Segwit: true, 102 ConfigPath: configPath, 103 Logger: cfg.Logger, 104 Net: cfg.Net, 105 ChainParams: params, 106 Ports: ports, 107 BlockDeserializer: dexltc.DeserializeBlockBytes, 108 NoCompetitionFeeRate: 10, 109 // It looks like if you set it to 1, litecoind just returns data for 2 110 // anyway. 111 FeeConfs: 2, 112 MaxFeeBlocks: 20, 113 RelayAddr: cfg.RelayAddr, 114 }) 115 }