Skip to content
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

frontend: label change #2788

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

NicolaLS
Copy link
Contributor

@NicolaLS NicolaLS commented Jul 1, 2024

Label utxos that are to change addresses from our account (subaccounts
respectively) as change to give the user more information about the utxo
when selecting it in coin control.
requestly-isChange-for-all-tx-small png
requestly-isChange-for-all-tx

Copy link
Collaborator

@Beerosagos Beerosagos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Only one doubt about the first commit comment:

Possible false negative in case the user used another wallet and derived some change address behind the current change gap limit.

I think that in case the user received on a change address uncovered by our gap limit he will miss the whole utxo, not only the change badge. wdyt?

@@ -873,12 +874,19 @@ func (account *Account) SpendableOutputs() []*SpendableOutput {
panic(err)
}
for outPoint, txOut := range utxos {
isChange := false
for _, subacc := range account.subaccounts {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the same code as

for _, subacc := range account.subaccounts {
if subacc.changeAddresses.LookupByScriptHashHex(scriptHashHex) != nil {
return true
}
}

would be nice to move that to a method on Account, with a unit test, so it can be reused

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be better to make the AccountAddress change aware and then use getAddress instead of IsChange, here is how it could look like:
3b7fa12

I think it makes sense for AccounAdress to know whether it is change or not. Often times we'll want to get some address anyways, and even if we really only care for the IsChange value the overhead (looking at the receiveAdresses) does not matter at all since a hash map is used for the lookup (O(1)) I think this would make the code easier to understand.

Please lmk what you think @benma

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(added three commits after the initial backend commit, can squash them in case we want to do it like this)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please squash

@NicolaLS
Copy link
Contributor Author

NicolaLS commented Jul 4, 2024

LGTM! Only one doubt about the first commit comment:

Possible false negative in case the user used another wallet and derived some change address behind the current change gap limit.

I think that in case the user received on a change address uncovered by our gap limit he will miss the whole utxo, not only the change badge. wdyt?

Right, I don't know why I thought he would see the utxo. I'll amend the commit message, thanks.

@NicolaLS NicolaLS force-pushed the label-change branch 7 times, most recently from 23bf35a to 8da7d2c Compare July 8, 2024 14:49
Copy link
Collaborator

@thisconnect thisconnect left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

frontend LGTM

Copy link
Collaborator

@thisconnect thisconnect left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

frontend LGTM

@@ -873,12 +874,19 @@ func (account *Account) SpendableOutputs() []*SpendableOutput {
panic(err)
}
for outPoint, txOut := range utxos {
isChange := false
for _, subacc := range account.subaccounts {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please squash

@Beerosagos
Copy link
Collaborator

@NicolaLS is this ready for BE review or does it need other changes?

@NicolaLS
Copy link
Contributor Author

NicolaLS commented Aug 1, 2024

@NicolaLS is this ready for BE review or does it need other changes?

@Beerosagos It's ready, I added the IsChange method to the account and added a test (also fixed test package name). I still think something like this would be better rather than adding a method to account, but this could be a future PR/refactor too.

@@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package btc_test
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benma I guess there was a reason why this package was named btc_test, but I'm not sure which was it. Is it ok to move inside btc package?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benma could you take a look at this ? I can't imagine any reason why tests that test code from a certain package should be outside of that package (unit tests). but if there is/was a reason I can just undo the change in this PR.

I already addressed the other change requests from @Beerosagos

@@ -907,6 +902,17 @@ func (account *Account) VerifyExtendedPublicKey(signingConfigIndex int) (bool, e
return false, nil
}

// IsChange returns true if there is an address corresponding to the provided scriptHashHex in our
// accounts change address chain. It returns false if no addresss can be found.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: addresss

require.NoError(t, err)
require.NotEmpty(t, address)
require.Equal(t, base64.StdEncoding.EncodeToString([]byte("signature")), signature)

}

func TestIsChange(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice also to test for false positives: non-change addresses should not be mistakenly identified as change

Add a boolean field to the response of the utxos enpoint (the getUTXOS
handler) that tells us whether the utxo is to a change address of our
wallet or not. Also:
- Add IsChange method on btc.Account that returns a boolean. True if the
provided scriptHashHex is in our change address chain and false if not.
- Add a unit test for the IsChange method.
- Fix btc account and coin unit test package names.
Label utxos that are to change addresses from our account (subaccounts
respectively) as change to give the user more information about the utxo
when selecting it in coin control.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants