Skip to content

Commit

Permalink
client/core: do not disable accounts with unspent bonds
Browse files Browse the repository at this point in the history
  • Loading branch information
chappjc committed Feb 24, 2023
1 parent d41b9a9 commit ac3591d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion client/core/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@ func (c *Core) AccountDisable(pw []byte, addr string) error {
return newError(unknownDEXErr, "error retrieving dex conn: %w", err)
}

// Check active orders.
// Check active orders or bonds.
if dc.hasActiveOrders() {
return fmt.Errorf("cannot disable account with active orders")
}
if dc.hasUnspentBond() {
return fmt.Errorf("cannot disable account with unspent bonds")
}

err = c.db.DisableAccount(dc.acct.host)
if err != nil {
Expand Down
10 changes: 8 additions & 2 deletions client/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -2775,11 +2775,17 @@ func (dc *dexConnection) bondTotal(assetID uint32) (total, active uint64) {
return dc.bondTotalInternal(assetID)
}

func (dc *dexConnection) hasUnspentBond(assetID uint32) bool {
func (dc *dexConnection) hasUnspentAssetBond(assetID uint32) bool {
total, _ := dc.bondTotal(assetID)
return total > 0
}

func (dc *dexConnection) hasUnspentBond() bool {
dc.acct.authMtx.RLock()
defer dc.acct.authMtx.RUnlock()
return len(dc.acct.bonds) > 0 || len(dc.acct.pendingBonds) > 0 || len(dc.acct.expiredBonds) > 0
}

// isActiveBondAsset indicates if a wallet (or it's parent if the asset is a
// token, or it's children if it's a base asset) is needed for bonding on any
// configured DEX. includeLive should be set to consider all existing unspent
Expand Down Expand Up @@ -2808,7 +2814,7 @@ func (c *Core) isActiveBondAsset(assetID uint32, includeLive bool) bool {
}
if includeLive {
for id := range assetIDs {
if dc.hasUnspentBond(id) {
if dc.hasUnspentAssetBond(id) {
return true
}
}
Expand Down

0 comments on commit ac3591d

Please sign in to comment.