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

Add get_budget implementation #726

Merged
merged 5 commits into from
Oct 28, 2024
Merged

Conversation

jklein24
Copy link
Contributor

@jklein24 jklein24 commented Oct 7, 2024

Closes #703

frontend/src/types.ts Outdated Show resolved Hide resolved
nip47/permissions/permissions.go Outdated Show resolved Hide resolved
@@ -22,6 +22,7 @@ const (
const (
PAY_INVOICE_SCOPE = "pay_invoice" // also covers pay_keysend and multi_* payment methods
GET_BALANCE_SCOPE = "get_balance"
GET_BUDGET_SCOPE = "get_budget"
Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering if we should not have a scope for this one - instead it chould always be callable. Is there any benefit of having a scope? (also, an extra scope requires including an extra checkbox in the UI that the user has to understand when configuring permissions)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed having it always be callable makes sense. Is there another method which has that behavior right now that I could copy? If not, I'll just dig a bit deeper to make that work.

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 an always granted scope with some tests for this. That way, if there are other "always allowed" methods, they can just be added there.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the get_info method also bypasses the check here: https://github.com/getAlby/hub/blob/master/nip47/event_handler.go#L272

We need to come up with a better solution, but for now to see if it works you could try adding an && nip47Request.Method != models.GET_BUDGET_METHOD

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh cool, should I just add get_info to my new ALWAYS_GRANTED scope instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure about the ALWAYS_GRANTED scope. This seems to have some side effects (for example, the new scope is now returned and the frontend does not know how to display it)
image

Also the scope is now included in only new apps in the database (there is a new app_permissions row for always_granted), but only new ones. The older app connections will not have it.

image

And it seems a bit hacky to even call HasPermission explicitly with the always_granted scope which actually just always returns true anyway.

I know my original suggestion is not the best, but on the plus side it's isolated to a single line of code and simply skips the permission check for that request method.

@bumi @im-adithya any thoughts on this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, thanks for catching the UI issue, I hadn't noticed that! FWIW, my intent here was actually to not store this scope in the DB or show it in the UI at all. Instead, I was hoping to just have it be implicitly granted to all requests. I'll try to make that the case now, but can definitely switch to a specific GET_BUDGET_SCOPE if you prefer. I just think it's a bit weird to show that in the UI in general.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adjusted to avoid always_granted in the db and UI. Let me know if you'd still prefer an explicit budget scope though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks! I also don't think we should have a GET_BUDGET_SCOPE. I was just wondering if a single line check like I suggested would be simpler than having this ALWAYS_GRANTED scope, and in the end we just bypass the logic anyway.


maxAmount := appPermission.MaxAmountSat
if maxAmount == 0 {
publishResponse(&models.Response{
Copy link
Contributor

Choose a reason for hiding this comment

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

We actually did not catch this in your proposal. I am not sure an empty result makes sense. Maybe the connection should not support this method and return an error instead if the app tries to call this method when a budget is not set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm that's a good alternative too. Maybe we should discuss on the NIP PR. There are some tradeoffs to think through for sure.

@rolznz rolznz requested review from bumi and im-adithya October 7, 2024 07:16
@rolznz
Copy link
Contributor

rolznz commented Oct 7, 2024

@jklein24 thanks for the PR. Awesome!

jklein24 and others added 2 commits October 11, 2024 12:06
- replace always granted scope with always granted method list
- return nil for budget renews at for "never" budget renewal
- add extra tests
@rolznz
Copy link
Contributor

rolznz commented Oct 19, 2024

@jklein24 I have added some changes in a feedback PR here jklein24#1

I've tested the flow, and everything looks good to me. Please let me know if you have any concerns with the changes!

@rolznz
Copy link
Contributor

rolznz commented Oct 19, 2024

JS SDK implementation: getAlby/js-sdk#264

@rolznz rolznz modified the milestone: v1.11.0 Oct 19, 2024
@jklein24
Copy link
Contributor Author

@jklein24 I have added some changes in a feedback PR here jklein24#1

I've tested the flow, and everything looks good to me. Please let me know if you have any concerns with the changes!

LGTM, thanks!

Copy link
Contributor

@rolznz rolznz left a comment

Choose a reason for hiding this comment

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

tACK

Copy link
Member

@im-adithya im-adithya left a comment

Choose a reason for hiding this comment

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

tACK

@rolznz rolznz merged commit 430c9fe into getAlby:master Oct 28, 2024
4 of 8 checks passed
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.

Implement get_budget NWC method
3 participants