Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
buck54321 authored and ukane-philemon committed Oct 11, 2024
1 parent c9bf340 commit 0eca856
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
14 changes: 8 additions & 6 deletions client/core/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (c *Core) disconnectDEX(dc *dexConnection) {

// ToggleAccountStatus is used to disable or enable an account by given host and
// application password.
func (c *Core) ToggleAccountStatus(pw []byte, addr string, disable bool) error {
func (c *Core) ToggleAccountStatus(pw []byte, host string, disable bool) error {
// Validate password.
crypter, err := c.encryptionKey(pw)
if err != nil {
Expand All @@ -57,7 +57,7 @@ func (c *Core) ToggleAccountStatus(pw []byte, addr string, disable bool) error {

// Get dex connection by host. All exchange servers (enabled or not) are loaded as
// dexConnections but disabled servers are not connected.
dc, _, err := c.dex(addr)
dc, _, err := c.dex(host)
if err != nil {
return newError(unknownDEXErr, "error retrieving dex conn: %w", err)
}
Expand All @@ -77,7 +77,7 @@ func (c *Core) ToggleAccountStatus(pw []byte, addr string, disable bool) error {
}
}

err = c.db.ToggleAccountStatus(addr, disable)
err = c.db.ToggleAccountStatus(host, disable)
if err != nil {
return newError(accountStatusUpdateErr, "error updating account status: %w", err)
}
Expand All @@ -86,12 +86,14 @@ func (c *Core) ToggleAccountStatus(pw []byte, addr string, disable bool) error {
dc.acct.toggleAccountStatus(true)
c.stopDEXConnection(dc)
} else {
acctInfo, err := c.db.Account(addr)
acctInfo, err := c.db.Account(host)
if err != nil {
return err
}

c.connectAccount(acctInfo)
dc, connected := c.connectAccount(acctInfo)
if !connected {
return fmt.Errorf("failed to connected re-enabled account: %w", err)
}
c.initializeDEXConnection(dc, crypter)
}

Expand Down
14 changes: 5 additions & 9 deletions client/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -5145,10 +5145,6 @@ func (c *Core) initializeDEXConnection(dc *dexConnection, crypter encrypt.Crypte
return // don't attempt authDEX for view-only conn
}

if initialized, _ := dc.acct.status(); !initialized {
return // dex account is not yet initialized, so we can't unlock it.
}

// Unlock before checking auth and continuing, because if the user
// logged out and didn't shut down, the account is still authed, but
// locked, and needs unlocked.
Expand Down Expand Up @@ -7134,7 +7130,7 @@ func (c *Core) initialize() error {
wg.Add(1)
go func(acct *db.AccountInfo) {
defer wg.Done()
if c.connectAccount(acct) {
if _, connected := c.connectAccount(acct); connected {
atomic.AddUint32(&liveConns, 1)
}
}(acct)
Expand Down Expand Up @@ -7190,7 +7186,7 @@ func (c *Core) initialize() error {
// the conns map even if the connection attempt failed (connected == false), and
// the connect retry / keepalive loop is active. The intial connection attempt
// or keepalive loop will not run if acct is disabled.
func (c *Core) connectAccount(acct *db.AccountInfo) (connected bool) {
func (c *Core) connectAccount(acct *db.AccountInfo) (dc *dexConnection, connected bool) {
host, err := addrHost(acct.Host)
if err != nil {
c.log.Errorf("skipping loading of %s due to address parse error: %v", host, err)
Expand All @@ -7199,15 +7195,15 @@ func (c *Core) connectAccount(acct *db.AccountInfo) (connected bool) {

if c.cfg.TheOneHost != "" && c.cfg.TheOneHost != host {
c.log.Infof("Running with --onehost = %q.", c.cfg.TheOneHost)
return false
return
}

var connectFlag connectDEXFlag
if acct.ViewOnly() {
connectFlag |= connectDEXFlagViewOnly
}

dc, err := c.newDEXConnection(acct, connectFlag)
dc, err = c.newDEXConnection(acct, connectFlag)
if err != nil {
c.log.Errorf("Unable to prepare DEX %s: %v", host, err)
return
Expand All @@ -7220,7 +7216,7 @@ func (c *Core) connectAccount(acct *db.AccountInfo) (connected bool) {

// Connected or not, the dexConnection goes in the conns map now.
c.addDexConnection(dc)
return err == nil
return dc, err == nil
}

func (c *Core) dbOrders(host string) ([]*db.MetaOrder, error) {
Expand Down

0 comments on commit 0eca856

Please sign in to comment.