-
Notifications
You must be signed in to change notification settings - Fork 122
[WIP] swap: enable UTXO selection. #4140
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -349,6 +349,11 @@ export type TTxInput = { | |||||||||||||||||
| } | ||||||||||||||||||
| ); | ||||||||||||||||||
|
|
||||||||||||||||||
| export type TSelectedUTXO = { | ||||||||||||||||||
| outPoint: string; | ||||||||||||||||||
| address: string; | ||||||||||||||||||
| }; | ||||||||||||||||||
|
Comment on lines
+352
to
+355
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. Make Line 354 requires 💡 Suggested fix export type TSelectedUTXO = {
outPoint: string;
- address: string;
+ address?: string;
};📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
|
|
||||||||||||||||||
| export type TTxProposalErrorCode = | ||||||||||||||||||
| | 'accountNotSynced' | ||||||||||||||||||
| | 'feeTooLow' | ||||||||||||||||||
|
|
@@ -361,6 +366,7 @@ export type TTxProposalResult = { | |||||||||||||||||
| amount: TAmountWithConversions; | ||||||||||||||||||
| fee: TAmountWithConversions; | ||||||||||||||||||
| recipientDisplayAddress: string; | ||||||||||||||||||
| selectedUTXOs?: TSelectedUTXO[]; | ||||||||||||||||||
| success: true; | ||||||||||||||||||
| total: TAmountWithConversions; | ||||||||||||||||||
| } | { | ||||||||||||||||||
|
|
@@ -437,6 +443,21 @@ export const getUTXOs = (code: AccountCode): Promise<TUTXO[]> => { | |||||||||||||||||
| return apiGet(`account/${code}/utxos`); | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| type TUTXOsAmount = { | ||||||||||||||||||
| success: true; | ||||||||||||||||||
| amount: TAmountWithConversions; | ||||||||||||||||||
| } | { | ||||||||||||||||||
| success: false; | ||||||||||||||||||
| errorMessage: string; | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| export const getUTXOsAmount = ( | ||||||||||||||||||
| code: AccountCode, | ||||||||||||||||||
| selectedUTXOs: string[], | ||||||||||||||||||
| ): Promise<TUTXOsAmount> => { | ||||||||||||||||||
| return apiPost(`account/${code}/utxos/amount`, { selectedUTXOS: selectedUTXOs }); | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| type TSecureOutput = { | ||||||||||||||||||
| hasSecureOutput: boolean; | ||||||||||||||||||
| optional: boolean; | ||||||||||||||||||
|
|
||||||||||||||||||
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.
🧹 Nitpick | 🔵 Trivial | ⚡ Quick win
Add a non-spendable outpoint test case for
SelectedUTXOsAmount.This test currently validates only the success path; the method’s key guard (selected outpoint not spendable) is untested.
Suggested test addition
func TestSelectedUTXOsAmount(t *testing.T) { account := testAccount(t) selectedOutPoint := *wire.NewOutPoint(&chainhash.Hash{}, 1) amount, err := account.SelectedUTXOsAmount(map[wire.OutPoint]struct{}{ selectedOutPoint: {}, }) require.NoError(t, err) require.Equal(t, coin.NewAmountFromInt64(1000000), amount) + + _, err = account.SelectedUTXOsAmount(map[wire.OutPoint]struct{}{ + *wire.NewOutPoint(&chainhash.Hash{}, 999): {}, + }) + require.ErrorContains(t, err, "is not spendable") }📝 Committable suggestion
🤖 Prompt for AI Agents