decred.org/dcrdex@v1.0.3/dex/networks/btc/clone.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 btc 5 6 import ( 7 "github.com/btcsuite/btcd/btcutil" 8 "github.com/btcsuite/btcd/chaincfg" 9 "github.com/btcsuite/btcd/chaincfg/chainhash" 10 "github.com/btcsuite/btcd/wire" 11 ) 12 13 // AddressDecoder decodes a string address to a btcutil.Address. 14 type AddressDecoder func(addr string, net *chaincfg.Params) (btcutil.Address, error) 15 16 // AddressStringer converts the btcutil.Address into a string address. This may 17 // be different from using (btcutil.Address).String when there is a special 18 // encoding such as a BCH "Cash Address". 19 type AddressStringer func(btcutil.Address, *chaincfg.Params) (string, error) 20 21 // ReadCloneParams translates a CloneParams into a btcsuite chaincfg.Params. 22 func ReadCloneParams(cloneParams *CloneParams) *chaincfg.Params { 23 return &chaincfg.Params{ 24 Name: cloneParams.Name, 25 PubKeyHashAddrID: cloneParams.PubKeyHashAddrID, 26 ScriptHashAddrID: cloneParams.ScriptHashAddrID, 27 Bech32HRPSegwit: cloneParams.Bech32HRPSegwit, 28 CoinbaseMaturity: cloneParams.CoinbaseMaturity, 29 Net: wire.BitcoinNet(cloneParams.Net), 30 HDPrivateKeyID: cloneParams.HDPrivateKeyID, 31 HDPublicKeyID: cloneParams.HDPublicKeyID, 32 GenesisHash: cloneParams.GenesisHash, 33 } 34 } 35 36 // CloneParams are the parameters needed by BTC-clone-based Backend and 37 // ExchangeWallet implementations. Pass a *CloneParams to ReadCloneParams to 38 // create a *chaincfg.Params for server/asset/btc.NewBTCClone and 39 // client/asset/btc.BTCCloneWallet. 40 type CloneParams struct { 41 // Name defines a human-readable identifier for the network. e.g. "mainnet", 42 // "testnet4", or "regtest" 43 Name string 44 // PubKeyHashAddrID: Net ID byte for a pubkey-hash address 45 PubKeyHashAddrID byte 46 // ScriptHashAddrID: Net ID byte for a script-hash address 47 ScriptHashAddrID byte 48 // Bech32HRPSegwit: Human-readable part for Bech32 encoded segwit addresses, 49 // as defined in BIP 173. 50 Bech32HRPSegwit string 51 // CoinbaseMaturity: The number of confirmations before a transaction 52 // spending a coinbase input can be spent. 53 CoinbaseMaturity uint16 54 // Net is the network identifier, e.g. wire.BitcoinNet. 55 Net uint32 56 GenesisHash *chainhash.Hash 57 // HDPrivateKeyID and HDPublicKeyID are the BIP32 hierarchical deterministic 58 // extended key magic sequences. They are ONLY required if there is a need 59 // to derive addresses from an extended key, such as if the asset is being 60 // used by the server with the hdkeychain package to create fee addresses. 61 // These are not required by the client. 62 HDPrivateKeyID [4]byte 63 HDPublicKeyID [4]byte 64 }