Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: bitcoin spv #1230

Merged
merged 22 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions client/asset/bch/bch.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,16 @@ const (
// structure.
defaultFee = 100
minNetworkVersion = 221100
walletTypeRPC = "bitcoindRPC"
walletTypeLegacy = ""
)

var (
netPorts = dexbtc.NetPorts{
Mainnet: "8332",
Testnet: "18332",
Simnet: "18443",
}
Comment on lines +41 to +45
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a biggie, but doesn't this increase the scope and lifetime of this variable, compared to when it was just local to a function?

fallbackFeeKey = "fallbackfee"
configOpts = []*asset.ConfigOption{
{
Expand Down Expand Up @@ -85,9 +92,14 @@ var (
Name: "Bitcoin Cash",
Version: version,
// Same as bitcoin. That's dumb.
DefaultConfigPath: dexbtc.SystemConfigPath("bitcoin"),
ConfigOpts: configOpts,
UnitInfo: dexbch.UnitInfo,
UnitInfo: dexbch.UnitInfo,
AvailableWallets: []*asset.WalletDefinition{{
Type: walletTypeRPC,
Tab: "External",
Description: "Connect to bitcoind",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also uses a bitcoind binary? Maybe a comment if so, quite surprising and confusing. I also noticed above that walletTypeRPC = "bitcoindRPC".

DefaultConfigPath: dexbtc.SystemConfigPath("bitcoin"), // Same as bitcoin. That's dumb.
ConfigOpts: configOpts,
}},
}
)

Expand All @@ -98,15 +110,14 @@ func init() {
// Driver implements asset.Driver.
type Driver struct{}

// Open opens the BCH exchange wallet. Start the wallet with its Run method.
// Check that Driver implements asset.Driver.
var _ asset.Driver = (*Driver)(nil)

// Open creates the BCH exchange wallet. Start the wallet with its Run method.
func (d *Driver) Open(cfg *asset.WalletConfig, logger dex.Logger, network dex.Network) (asset.Wallet, error) {
return NewWallet(cfg, logger, network)
}

func (d *Driver) Create(params *asset.CreateWalletParams) error {
return fmt.Errorf("no creatable wallet types")
}

// DecodeCoinID creates a human-readable representation of a coin ID for
// Bitcoin Cash.
func (d *Driver) DecodeCoinID(coinID []byte) (string, error) {
Expand All @@ -120,9 +131,7 @@ func (d *Driver) Info() *asset.WalletInfo {
}

// NewWallet is the exported constructor by which the DEX will import the
// exchange wallet. The wallet will shut down when the provided context is
// canceled. The configPath can be an empty string, in which case the standard
// system location of the daemon config file is assumed.
// exchange wallet.
func NewWallet(cfg *asset.WalletConfig, logger dex.Logger, network dex.Network) (asset.Wallet, error) {
var params *chaincfg.Params
switch network {
Expand All @@ -139,11 +148,6 @@ func NewWallet(cfg *asset.WalletConfig, logger dex.Logger, network dex.Network)
// Designate the clone ports. These will be overwritten by any explicit
// settings in the configuration file. Bitcoin Cash uses the same default
// ports as Bitcoin.
ports := dexbtc.NetPorts{
Mainnet: "8332",
Testnet: "18332",
Simnet: "18443",
}
cloneCFG := &btc.BTCCloneCFG{
WalletCFG: cfg,
MinNetworkVersion: minNetworkVersion,
Expand All @@ -152,7 +156,7 @@ func NewWallet(cfg *asset.WalletConfig, logger dex.Logger, network dex.Network)
Logger: logger,
Network: network,
ChainParams: params,
Ports: ports,
Ports: netPorts,
DefaultFallbackFee: defaultFee,
Segwit: false,
LegacyBalance: true,
Expand Down
8 changes: 5 additions & 3 deletions client/asset/bch/regnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
dexbtc "decred.org/dcrdex/dex/networks/btc"
)

const alphaAddress = "bchreg:qqnm4z2tftyyeu3kvzzepmlp9mj3g6fvxgft570vll"

var (
tLotSize uint64 = 1e6
tRateStep uint64 = 10
Expand All @@ -40,5 +38,9 @@ var (
)

func TestWallet(t *testing.T) {
livetest.Run(t, NewWallet, alphaAddress, tLotSize, tBCH, false)
livetest.Run(t, &livetest.Config{
NewWallet: NewWallet,
LotSize: tLotSize,
Asset: tBCH,
})
}
Loading