Skip to content
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
8 changes: 4 additions & 4 deletions client/asset/bch/spv.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ func createSPVWallet(privPass []byte, seed []byte, bday time.Time, dbDir string,
return fmt.Errorf("CreateNewWallet error: %w", err)
}

errCloser := dex.NewErrorCloser(log)
defer errCloser.Done()
errCloser := dex.NewErrorCloser()
defer errCloser.Done(log)
errCloser.Add(loader.UnloadWallet)

if extIdx > 0 || intIdx > 0 {
Expand Down Expand Up @@ -186,8 +186,8 @@ func (w *bchSPVWallet) Start() (btc.SPVService, error) {
return nil, fmt.Errorf("couldn't load wallet: %w", err)
}

errCloser := dex.NewErrorCloser(w.log)
defer errCloser.Done()
errCloser := dex.NewErrorCloser()
defer errCloser.Done(w.log)
errCloser.Add(w.loader.UnloadWallet)

neutrinoDBPath := filepath.Join(w.dir, neutrinoDBName)
Expand Down
61 changes: 33 additions & 28 deletions client/asset/btc/btc.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ var (
walletBlockAllowance = time.Second * 10
conventionalConversionFactor = float64(dexbtc.UnitInfo.Conventional.ConversionFactor)

electrumOpts = []*asset.ConfigOption{
ElectrumConfigOpts = []*asset.ConfigOption{
{
Key: "rpcuser",
DisplayName: "JSON-RPC Username",
Expand All @@ -118,10 +118,9 @@ var (
DefaultValue: "127.0.0.1",
Comment thread
chappjc marked this conversation as resolved.
},
{
Key: "rpcport",
DisplayName: "JSON-RPC Port",
Description: "Electrum's 'rpcport' (if not set with address)",
DefaultValue: "6789",
Comment thread
chappjc marked this conversation as resolved.
Key: "rpcport",
DisplayName: "JSON-RPC Port",
Description: "Electrum's 'rpcport' (if not set with rpcbind)",
},
}

Expand Down Expand Up @@ -149,7 +148,7 @@ var (
Tab: "Electrum (external)",
Description: "Use an external Electrum Wallet",
// json: DefaultConfigPath: filepath.Join(btcutil.AppDataDir("electrum", false), "config"), // e.g. ~/.electrum/config
ConfigOpts: append(electrumOpts, CommonConfigOpts("BTC", true)...),
ConfigOpts: append(append(ElectrumConfigOpts, apiFallbackOpt(false)), CommonConfigOpts("BTC", false)...),
}

// WalletInfo defines some general information about a Bitcoin wallet.
Expand All @@ -166,6 +165,18 @@ var (
}
)

func apiFallbackOpt(defaultV bool) *asset.ConfigOption {
return &asset.ConfigOption{
Key: "apifeefallback",
DisplayName: "External fee rate estimates",
Description: "Allow fee rate estimation from a block explorer API. " +
"This is useful as a fallback for SPV wallets and RPC wallets " +
"that have recently been started.",
IsBoolean: true,
DefaultValue: defaultV,
}
}

// CommonConfigOpts are the common options that the Wallets recognize.
func CommonConfigOpts(symbol string /* upper-case */, withApiFallback bool) []*asset.ConfigOption {
opts := []*asset.ConfigOption{
Expand Down Expand Up @@ -209,14 +220,7 @@ func CommonConfigOpts(symbol string /* upper-case */, withApiFallback bool) []*a
}

if withApiFallback {
opts = append(opts, &asset.ConfigOption{
Key: "apifeefallback",
DisplayName: "External fee rate estimates",
Description: "Allow fee rate estimation from a block explorer API. " +
"This is useful as a fallback for SPV wallets and RPC wallets " +
"that have recently been started.",
IsBoolean: true,
})
opts = append(opts, apiFallbackOpt(true))
}
return opts
}
Expand Down Expand Up @@ -641,7 +645,7 @@ func (d *Driver) Exists(walletType, dataDir string, settings map[string]string,
}
dir := filepath.Join(dataDir, chainParams.Name, "spv")
// timeout and recoverWindow arguments borrowed from btcwallet directly.
loader := wallet.NewLoader(chainParams, dir, true, 60*time.Second, 250)
loader := wallet.NewLoader(chainParams, dir, true, dbTimeout, 250)
return loader.WalletExists()
}

Expand Down Expand Up @@ -974,7 +978,7 @@ func NewWallet(cfg *asset.WalletConfig, logger dex.Logger, net dex.Network) (ass

switch cfg.Type {
case walletTypeSPV:
return OpenSPVWallet(cloneCFG, newExtendedWallet)
return OpenSPVWallet(cloneCFG, openSPVWallet)
case walletTypeRPC, walletTypeLegacy:
rpcWallet, err := BTCCloneWallet(cloneCFG)
if err != nil {
Expand Down Expand Up @@ -1151,18 +1155,19 @@ func OpenSPVWallet(cfg *BTCCloneCFG, walletConstructor BTCWalletConstructor) (*E
}

spvw := &spvWallet{
chainParams: cfg.ChainParams,
cfg: walletCfg,
acctNum: defaultAcctNum,
acctName: defaultAcctName,
dir: filepath.Join(cfg.WalletCFG.DataDir, cfg.ChainParams.Name, "spv"),
txBlocks: make(map[chainhash.Hash]*hashEntry),
checkpoints: make(map[outPoint]*scanCheckpoint),
log: cfg.Logger.SubLogger("SPV"),
tipChan: make(chan *block, 8),
newBTCWallet: walletConstructor,
decodeAddr: btc.decodeAddr,
}
chainParams: cfg.ChainParams,
cfg: walletCfg,
acctNum: defaultAcctNum,
acctName: defaultAcctName,
dir: filepath.Join(cfg.WalletCFG.DataDir, cfg.ChainParams.Name, "spv"),
txBlocks: make(map[chainhash.Hash]*hashEntry),
checkpoints: make(map[outPoint]*scanCheckpoint),
log: cfg.Logger.SubLogger("SPV"),
tipChan: make(chan *block, 8),
decodeAddr: btc.decodeAddr,
}

spvw.wallet = walletConstructor(spvw.dir, spvw.cfg, spvw.chainParams, spvw.log)

btc.node = spvw

Expand Down
Loading