decred.org/dcrdex@v1.0.5/server/asset/doge/doge.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 doge 5 6 import ( 7 "fmt" 8 9 "decred.org/dcrdex/dex" 10 dexbtc "decred.org/dcrdex/dex/networks/btc" 11 dexdoge "decred.org/dcrdex/dex/networks/doge" 12 "decred.org/dcrdex/server/asset" 13 "decred.org/dcrdex/server/asset/btc" 14 "github.com/btcsuite/btcd/chaincfg" 15 ) 16 17 const dustLimit = 1_000_000 // sats => 0.01 DOGE, the "soft" limit (DEFAULT_DUST_LIMIT) 18 19 var maxFeeBlocks = 16 20 21 // Driver implements asset.Driver. 22 type Driver struct{} 23 24 // Setup creates the LTC backend. Start the backend with its Run method. 25 func (d *Driver) Setup(cfg *asset.BackendConfig) (asset.Backend, error) { 26 return NewBackend(cfg) 27 } 28 29 // DecodeCoinID creates a human-readable representation of a coin ID for 30 // Litecoin. 31 func (d *Driver) DecodeCoinID(coinID []byte) (string, error) { 32 // Litecoin and Bitcoin have the same tx hash and output format. 33 return (&btc.Driver{}).DecodeCoinID(coinID) 34 } 35 36 // Version returns the Backend implementation's version number. 37 func (d *Driver) Version() uint32 { 38 return version 39 } 40 41 // UnitInfo returns the dex.UnitInfo for the asset. 42 func (d *Driver) UnitInfo() dex.UnitInfo { 43 return dexdoge.UnitInfo 44 } 45 46 // MinBondSize calculates the minimum bond size for a given fee rate that avoids 47 // dust outputs on the bond and refund txs, assuming the maxFeeRate doesn't 48 // change. 49 func (d *Driver) MinBondSize(maxFeeRate uint64) uint64 { 50 return dustLimit + dexbtc.RefundBondTxSize(false)*maxFeeRate 51 } 52 53 // MinLotSize calculates the minimum bond size for a given fee rate that avoids 54 // dust outputs on the swap and refund txs, assuming the maxFeeRate doesn't 55 // change. 56 func (d *Driver) MinLotSize(maxFeeRate uint64) uint64 { 57 return dustLimit + dexbtc.RedeemSwapTxSize(false)*maxFeeRate 58 } 59 60 // Name is the asset's name. 61 func (d *Driver) Name() string { 62 return "Dogecoin" 63 } 64 65 func init() { 66 asset.Register(BipID, &Driver{}) 67 } 68 69 const ( 70 version = 0 71 BipID = 3 72 assetName = "doge" 73 feeConfs = 8 74 ) 75 76 // NewBackend generates the network parameters and creates a ltc backend as a 77 // btc clone using an asset/btc helper function. 78 func NewBackend(cfg *asset.BackendConfig) (asset.Backend, error) { 79 var params *chaincfg.Params 80 switch cfg.Net { 81 case dex.Mainnet: 82 params = dexdoge.MainNetParams 83 case dex.Testnet: 84 params = dexdoge.TestNet4Params 85 case dex.Regtest: 86 params = dexdoge.RegressionNetParams 87 default: 88 return nil, fmt.Errorf("unknown network ID %v", cfg.Net) 89 } 90 91 // Designate the clone ports. These will be overwritten by any explicit 92 // settings in the configuration file. 93 ports := dexbtc.NetPorts{ 94 Mainnet: "22555", 95 Testnet: "44555", 96 Simnet: "18332", 97 } 98 99 configPath := cfg.ConfigPath 100 if configPath == "" { 101 configPath = dexbtc.SystemConfigPath("dogecoin") 102 } 103 104 return btc.NewBTCClone(&btc.BackendCloneConfig{ 105 Name: assetName, 106 // Segwit may be enabled in v1.21. 107 // If so, it may work differently than Bitcoin. 108 // https://github.com/dogecoin/dogecoin/discussions/2264 109 // Looks like Segwit will be false for a little while longer. Should 110 // think about how to transition once activated. 111 Segwit: false, 112 ConfigPath: configPath, 113 Logger: cfg.Logger, 114 Net: cfg.Net, 115 ChainParams: params, 116 Ports: ports, 117 DumbFeeEstimates: true, // dogecoind actually has estimatesmartfee, but it is marked deprecated 118 FeeConfs: feeConfs, 119 ManualMedianFee: true, 120 NoCompetitionFeeRate: dexdoge.DefaultFee, 121 MaxFeeBlocks: maxFeeBlocks, 122 BooleanGetBlockRPC: true, 123 BlockDeserializer: dexdoge.DeserializeBlock, 124 RelayAddr: cfg.RelayAddr, 125 }) 126 }