Skip to content

Commit

Permalink
client/asset: add FundsMixer wallet trait and implement for dcr (#2478)
Browse files Browse the repository at this point in the history
* client/asset: add FundsMixer wallet trait and implement for dcr
  • Loading branch information
itswisdomagain authored Nov 17, 2023
1 parent b6c4c3e commit aeaeea5
Show file tree
Hide file tree
Showing 12 changed files with 784 additions and 161 deletions.
40 changes: 33 additions & 7 deletions client/asset/dcr/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ var (
)

type walletConfig struct {
PrimaryAccount string `ini:"account"`
UnmixedAccount string `ini:"unmixedaccount"`
TradingAccount string `ini:"tradingaccount"`
UseSplitTx bool `ini:"txsplit"`
FallbackFeeRate float64 `ini:"fallbackfee"`
FeeRateLimit float64 `ini:"feeratelimit"`
Expand All @@ -43,10 +40,13 @@ type walletConfig struct {
}

type rpcConfig struct {
RPCUser string `ini:"username"`
RPCPass string `ini:"password"`
RPCListen string `ini:"rpclisten"`
RPCCert string `ini:"rpccert"`
PrimaryAccount string `ini:"account"`
UnmixedAccount string `ini:"unmixedaccount"`
TradingAccount string `ini:"tradingaccount"`
RPCUser string `ini:"username"`
RPCPass string `ini:"password"`
RPCListen string `ini:"rpclisten"`
RPCCert string `ini:"rpccert"`
}

func loadRPCConfig(settings map[string]string, network dex.Network) (*rpcConfig, *chaincfg.Params, error) {
Expand All @@ -55,6 +55,7 @@ func loadRPCConfig(settings map[string]string, network dex.Network) (*rpcConfig,
if err != nil {
return nil, nil, err
}

var defaultServer string
switch network {
case dex.Simnet:
Expand All @@ -74,6 +75,31 @@ func loadRPCConfig(settings map[string]string, network dex.Network) (*rpcConfig,
} else {
cfg.RPCCert = dex.CleanAndExpandPath(cfg.RPCCert)
}

if cfg.PrimaryAccount == "" {
cfg.PrimaryAccount = defaultAcctName
}

// Both UnmixedAccount and TradingAccount must be provided if primary
// account is a mixed account. Providing one but not the other is bad
// configuration. If set, the account names will be validated on Connect.
if (cfg.UnmixedAccount == "") != (cfg.TradingAccount == "") {
return nil, nil, fmt.Errorf("'Change Account Name' and 'Temporary Trading Account' MUST "+
"be set to treat %[1]q as a mixed account. If %[1]q is not a mixed account, values "+
"should NOT be set for 'Change Account Name' and 'Temporary Trading Account'",
cfg.PrimaryAccount)
}
if cfg.UnmixedAccount != "" {
switch {
case cfg.PrimaryAccount == cfg.UnmixedAccount:
return nil, nil, fmt.Errorf("Primary Account should not be the same as Change Account")
case cfg.PrimaryAccount == cfg.TradingAccount:
return nil, nil, fmt.Errorf("Primary Account should not be the same as Temporary Trading Account")
case cfg.TradingAccount == cfg.UnmixedAccount:
return nil, nil, fmt.Errorf("Temporary Trading Account should not be the same as Change Account")
}
}

return cfg, chainParams, nil
}

Expand Down
Loading

0 comments on commit aeaeea5

Please sign in to comment.