decred.org/dcrdex@v1.0.5/client/asset/dash/dash.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 dash 5 6 import ( 7 "fmt" 8 "strconv" 9 10 "decred.org/dcrdex/client/asset" 11 "decred.org/dcrdex/client/asset/btc" 12 "decred.org/dcrdex/dex" 13 dexbtc "decred.org/dcrdex/dex/networks/btc" 14 dexdash "decred.org/dcrdex/dex/networks/dash" 15 16 "github.com/btcsuite/btcd/chaincfg" 17 ) 18 19 const ( 20 version = 0 21 BipID = 5 22 minNetworkVersion = 200101 // Dash v20.1.1 23 walletTypeRPC = "dashdRPC" 24 defaultRedeemConfTarget = 2 25 ) 26 27 var ( 28 configOpts = append(btc.RPCConfigOpts("Dash", "9998"), []*asset.ConfigOption{ 29 { 30 Key: "fallbackfee", 31 DisplayName: "Fallback fee rate", 32 Description: "Dash's 'fallbackfee' rate. Units: DASH/kB", 33 DefaultValue: strconv.FormatFloat(dexdash.DefaultFee*1000/1e8, 'f', -1, 64), 34 }, 35 { 36 Key: "feeratelimit", 37 DisplayName: "Highest acceptable fee rate", 38 Description: "This is the highest network fee rate you are willing to " + 39 "pay on swap transactions. If feeratelimit is lower than a market's " + 40 "maxfeerate, you will not be able to trade on that market with this " + 41 "wallet. Units: DASH/kB", 42 DefaultValue: strconv.FormatFloat(dexdash.DefaultFeeRateLimit*1000/1e8, 'f', -1, 64), 43 }, 44 { 45 Key: "redeemconftarget", 46 DisplayName: "Redeem confirmation target", 47 Description: "The target number of blocks for the redeem transaction " + 48 "to be mined. Used to set the transaction's fee rate. " + 49 "(default: 2 blocks)", 50 DefaultValue: strconv.FormatUint(defaultRedeemConfTarget, 10), 51 }, 52 { 53 Key: "txsplit", 54 DisplayName: "Pre-split funding inputs", 55 Description: "When placing an order, create a \"split\" transaction to fund the order without locking more of the wallet balance than " + 56 "necessary. Otherwise, excess funds may be reserved to fund the order until the first swap contract is broadcast " + 57 "during match settlement, or the order is canceled. This an extra transaction for which network mining fees are paid. " + 58 "Used only for standing-type orders, e.g. limit orders without immediate time-in-force.", 59 IsBoolean: true, 60 DefaultValue: "true", 61 }, 62 }...) 63 64 // WalletInfo defines some general information about a Dash wallet. 65 WalletInfo = &asset.WalletInfo{ 66 Name: "Dash", 67 SupportedVersions: []uint32{version}, 68 UnitInfo: dexdash.UnitInfo, 69 AvailableWallets: []*asset.WalletDefinition{ 70 { 71 Type: walletTypeRPC, 72 Tab: "Dash Core (external)", 73 Description: "Connect to dashd", 74 DefaultConfigPath: dexbtc.SystemConfigPath("dash"), 75 ConfigOpts: configOpts, 76 }, 77 }, 78 } 79 ) 80 81 func init() { 82 asset.Register(BipID, &Driver{}) 83 } 84 85 // Driver implements asset.Driver. 86 type Driver struct{} 87 88 // Open creates the Dash exchange wallet. Start the wallet with its Run method. 89 func (d *Driver) Open(cfg *asset.WalletConfig, logger dex.Logger, network dex.Network) (asset.Wallet, error) { 90 return newWallet(cfg, logger, network) 91 } 92 93 // DecodeCoinID creates a human-readable representation of a coin ID for Dash 94 func (d *Driver) DecodeCoinID(coinID []byte) (string, error) { 95 // Dash and Bitcoin have the same tx hash and output format. 96 return (&btc.Driver{}).DecodeCoinID(coinID) 97 } 98 99 // Info returns basic information about the wallet and asset. 100 func (d *Driver) Info() *asset.WalletInfo { 101 return WalletInfo 102 } 103 104 // MinLotSize calculates the minimum bond size for a given fee rate that avoids 105 // dust outputs on the swap and refund txs, assuming the maxFeeRate doesn't 106 // change. 107 func (d *Driver) MinLotSize(maxFeeRate uint64) uint64 { 108 return dexbtc.MinLotSize(maxFeeRate, false) 109 } 110 111 // newWallet constructs a new client wallet for Dash based on the WalletDefinition.Type 112 func newWallet(cfg *asset.WalletConfig, logger dex.Logger, network dex.Network) (asset.Wallet, error) { 113 var params *chaincfg.Params 114 switch network { 115 case dex.Mainnet: 116 params = dexdash.MainNetParams 117 case dex.Testnet: 118 params = dexdash.TestNetParams 119 case dex.Regtest: 120 params = dexdash.RegressionNetParams 121 default: 122 return nil, fmt.Errorf("unknown network ID %v", network) 123 } 124 125 // Designate the clone ports. 126 ports := dexbtc.NetPorts{ 127 Mainnet: "9998", 128 Testnet: "19998", 129 Simnet: "19898", 130 } 131 132 cloneCFG := &btc.BTCCloneCFG{ 133 WalletCFG: cfg, 134 MinNetworkVersion: minNetworkVersion, 135 WalletInfo: WalletInfo, 136 Symbol: "dash", 137 Logger: logger, 138 Network: network, 139 ChainParams: params, 140 Ports: ports, 141 DefaultFallbackFee: dexdash.DefaultFee, 142 DefaultFeeRateLimit: dexdash.DefaultFeeRateLimit, 143 LegacyBalance: false, 144 Segwit: false, 145 // Dash v19.1.0 has a breaking change from the true/false 'allowhighfees' 146 // to 'maxfeerate' in DASH/kB, the same as btc. 147 LegacyRawFeeLimit: false, 148 InitTxSize: dexbtc.InitTxSize, 149 InitTxSizeBase: dexbtc.InitTxSizeBase, 150 PrivKeyFunc: nil, 151 AddressDecoder: nil, 152 AddressStringer: nil, 153 BlockDeserializer: nil, 154 ArglessChangeAddrRPC: true, // getrawchangeaddress has No address-type arg 155 NonSegwitSigner: nil, 156 FeeEstimator: nil, // estimatesmartfee + getblockstats 157 ExternalFeeEstimator: nil, 158 OmitAddressType: true, // getnewaddress has No address-type arg 159 LegacySignTxRPC: false, // Has signrawtransactionwithwallet RPC 160 BooleanGetBlockRPC: false, // Use 0/1 for verbose param 161 LegacyValidateAddressRPC: false, // getaddressinfo 162 SingularWallet: false, // wallet can have "" as a path but also a name like "gamma" 163 UnlockSpends: false, 164 ConstantDustLimit: 0, 165 AssetID: BipID, 166 } 167 168 return btc.BTCCloneWallet(cloneCFG) 169 }