-
Notifications
You must be signed in to change notification settings - Fork 105
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
bonds: UI updates and import/export #2200
Merged
+555
−403
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6c8ee4b
client/{db,webserver}: bonds import/export with account
chappjc 538c12f
client: Add BondsFeeBuffer for reg funding info
chappjc 1cc2347
client/core: postbond automatically unlocks the wallet
chappjc 16dadb7
client/core: only warn about server bond support when bonding
chappjc cda67d5
ui: reword registration forms for bonds
chappjc 0df3ef3
ui: hide bond strength form until it has utility
chappjc 431c711
npm audit fix: CVE-2023-28154 (webpack 5.76)
chappjc 08185ca
deps: golang.org/x repos for net CVE
chappjc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -345,11 +345,22 @@ func (c *Core) rotateBonds(ctx context.Context) { | |
refundCoin, err := wallet.RefundBond(ctx, bond.Version, bond.CoinID, bond.Data, bond.Amount, priv) | ||
priv.Zero() | ||
bondAlreadySpent = errors.Is(err, asset.CoinNotFoundError) // or never mined! | ||
if err != nil && !bondAlreadySpent { | ||
c.log.Errorf("Failed to generate bond refund tx: %v", err) | ||
continue | ||
if err != nil { | ||
if errors.Is(err, asset.ErrIncorrectBondKey) { // imported account and app seed is different | ||
c.log.Warnf("Private key to spend bond %v is not available. Broadcasting backup refund tx.", bondIDStr) | ||
refundCoinID, err := wallet.SendTransaction(bond.RefundTx) | ||
if err != nil { | ||
c.log.Errorf("Failed to broadcast bond refund txn %x: %v", bond.RefundTx, err) | ||
continue | ||
} | ||
refundCoinStr, _ = asset.DecodeCoinID(bond.AssetID, refundCoinID) | ||
} else if !bondAlreadySpent { | ||
c.log.Errorf("Failed to generate bond refund tx: %v", err) | ||
continue | ||
} | ||
} else { | ||
refundCoinStr, refundVal = refundCoin.String(), refundCoin.Value() | ||
} | ||
refundCoinStr, refundVal = refundCoin.String(), refundCoin.Value() | ||
} | ||
// RefundBond increases reserves when it spends the bond, adding to | ||
// the wallet's balance (available or immature). | ||
|
@@ -396,7 +407,9 @@ func (c *Core) rotateBonds(ctx context.Context) { | |
|
||
bondAsset := bondAssets[bondAssetID] | ||
if bondAsset == nil { | ||
c.log.Warnf("Bond asset %d not supported by DEX %v", bondAssetID, dc.acct.host) | ||
if targetTier > 0 { | ||
c.log.Warnf("Bond asset %d not supported by DEX %v", bondAssetID, dc.acct.host) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this only happen if the dex stopped supporting a bond asset they previously used to support? |
||
} | ||
continue | ||
} | ||
|
||
|
@@ -935,6 +948,22 @@ func (c *Core) UpdateBondOptions(form *BondOptionsForm) error { | |
return err | ||
} | ||
|
||
// BondsFeeBuffer suggests how much extra may be required for the transaction | ||
// fees part of bond reserves when bond rotation is enabled. This may be used to | ||
// inform the consumer how much extra (beyond double the bond amount) is | ||
// required to facilitate uninterrupted maintenance of a target trading tier. | ||
func (c *Core) BondsFeeBuffer(assetID uint32) (uint64, error) { | ||
wallet, err := c.connectedWallet(assetID) | ||
if err != nil { | ||
return 0, err | ||
} | ||
bonder, ok := wallet.Wallet.(asset.Bonder) | ||
if !ok { | ||
return 0, errors.New("wallet does not support bonds") | ||
} | ||
return bonder.BondsFeeBuffer(), nil | ||
} | ||
|
||
// PostBond begins the process of posting a new bond for a new or existing DEX | ||
// account. On return, the bond transaction will have been broadcast, and when | ||
// the required number of confirmations is reached, Core will submit the bond | ||
|
@@ -973,11 +1002,6 @@ func (c *Core) PostBond(form *PostBondForm) (*PostBondResult, error) { | |
if _, ok := wallet.Wallet.(asset.Bonder); !ok { // will fail in MakeBondTx, but assert early | ||
return nil, fmt.Errorf("wallet %v is not an asset.Bonder", bondAssetSymbol) | ||
} | ||
_, err = wallet.refreshUnlock() | ||
if err != nil { | ||
// TODO: Unlock with form.AppPass? | ||
return nil, fmt.Errorf("bond asset wallet %v is locked", unbip(bondAssetID)) | ||
} | ||
if !wallet.synchronized() { // otherwise we might double spend if the wallet keys were used elsewhere | ||
return nil, fmt.Errorf("wallet %v is not synchronized", unbip(bondAssetID)) | ||
} | ||
|
@@ -996,6 +1020,14 @@ func (c *Core) PostBond(form *PostBondForm) (*PostBondResult, error) { | |
return nil, newError(addressParseErr, "error parsing address: %v", err) | ||
} | ||
|
||
// Get ready to generate the bond txn. | ||
if !wallet.unlocked() { | ||
err = wallet.Unlock(crypter) | ||
if err != nil { | ||
return nil, newError(walletAuthErr, "failed to unlock %s wallet: %v", unbip(wallet.AssetID), err) | ||
} | ||
} | ||
|
||
var success, acctExists bool | ||
|
||
// When creating an account or registering a view-only account, the default | ||
|
@@ -1129,14 +1161,6 @@ func (c *Core) PostBond(form *PostBondForm) (*PostBondResult, error) { | |
dc.acct.authMtx.Unlock() | ||
} | ||
|
||
// Get ready to generate the bond txn. | ||
if !wallet.unlocked() { | ||
err = wallet.Unlock(crypter) | ||
if err != nil { | ||
return nil, newError(walletAuthErr, "failed to unlock %s wallet: %v", unbip(wallet.AssetID), err) | ||
} | ||
} | ||
|
||
// Make a bond transaction for the account ID generated from our public key. | ||
bondCoin, err := c.makeAndPostBond(dc, acctExists, wallet, form.Bond, lockTime, bondAsset) | ||
if err != nil { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the more sophisticated technique to roughly 1) add the bond to appropriate map, 2) update tier, and 3) call
monitorBondConfs
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add or update. Probably other error prone stuff.