decred.org/dcrdex@v1.0.5/server/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  
     9  	"decred.org/dcrdex/dex"
    10  	dexbtc "decred.org/dcrdex/dex/networks/btc"
    11  	dexdash "decred.org/dcrdex/dex/networks/dash"
    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 Dash 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 Dash.
    26  func (d *Driver) DecodeCoinID(coinID []byte) (string, error) {
    27  	// Dash and Bitcoin have the same tx hash and output format.
    28  	return (&btc.Driver{}).DecodeCoinID(coinID)
    29  }
    30  
    31  // Version returns the Backend implementation's version number.
    32  func (d *Driver) Version() uint32 {
    33  	return version
    34  }
    35  
    36  // UnitInfo returns the dex.UnitInfo for the asset.
    37  func (d *Driver) UnitInfo() dex.UnitInfo {
    38  	return dexdash.UnitInfo
    39  }
    40  
    41  // Name is the asset's name.
    42  func (d *Driver) Name() string {
    43  	return "Dash"
    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 dexbtc.MinBondSize(maxFeeRate, false)
    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 dexbtc.MinLotSize(maxFeeRate, false)
    58  }
    59  
    60  func init() {
    61  	asset.Register(BipID, &Driver{})
    62  }
    63  
    64  const (
    65  	version   = 0
    66  	BipID     = 5
    67  	assetName = "dash"
    68  )
    69  
    70  // NewBackend generates the network parameters and creates a dash backend as a
    71  // btc clone using an asset/btc helper function.
    72  func NewBackend(cfg *asset.BackendConfig) (asset.Backend, error) {
    73  	var params *chaincfg.Params
    74  	switch cfg.Net {
    75  	case dex.Mainnet:
    76  		params = dexdash.MainNetParams
    77  	case dex.Testnet:
    78  		params = dexdash.TestNetParams
    79  	case dex.Regtest:
    80  		params = dexdash.RegressionNetParams
    81  	default:
    82  		return nil, fmt.Errorf("unknown network ID %v", cfg.Net)
    83  	}
    84  
    85  	// Designate the clone ports.
    86  	ports := dexbtc.NetPorts{
    87  		Mainnet: "9998",
    88  		Testnet: "19998",
    89  		Simnet:  "19898",
    90  	}
    91  
    92  	configPath := cfg.ConfigPath
    93  	if configPath == "" {
    94  		configPath = dexbtc.SystemConfigPath("dash")
    95  	}
    96  
    97  	return btc.NewBTCClone(&btc.BackendCloneConfig{
    98  		Name:        assetName,
    99  		Segwit:      false,
   100  		ConfigPath:  configPath,
   101  		Logger:      cfg.Logger,
   102  		Net:         cfg.Net,
   103  		ChainParams: params,
   104  		Ports:       ports,
   105  		// getblockstats exists
   106  		// estimatesmartfee exists but no estimatefee
   107  		NoCompetitionFeeRate: 1,
   108  		// masternode finalization Dash InstantSend 2 blocks
   109  		FeeConfs:     2,
   110  		MaxFeeBlocks: 16,
   111  		RelayAddr:    cfg.RelayAddr,
   112  	})
   113  }