alby-hub/api/api.go

1172 lines
34 KiB
Go
Raw Normal View History

2024-05-30 00:06:06 +07:00
package api
import (
"context"
"encoding/json"
"errors"
"flag"
2024-05-30 00:06:06 +07:00
"fmt"
"io"
"net/http"
"net/url"
"slices"
"sync"
2024-05-30 00:06:06 +07:00
"time"
"github.com/sirupsen/logrus"
feat: add buzzpay internal app (#580) * feat: add uncle jim internal app * fix: wrong number in instructions * chore: simplify alby jim internal app copy * Feat: app metadata (#570) * chore: wg.Add() before go (#559) * chore: code cleanup (#558) * Update README.md Add command to make the install script executable in the instructions. * feat: add migration card in wallet screen (#555) * feat: add migration card in wallet screen * chore: transfer funds if channel exists * chore: typo * chore: improve copy * chore: add transfer funds button * fix: remove duplicate icon --------- Co-authored-by: Roland Bewick <roland.bewick@gmail.com> * chore: run extra workflows on PR (#563) * chore: run extra workflows on PR * fix: pull request workflows * build(deps): bump github.com/nbd-wtf/go-nostr from 0.34.5 to 0.34.10 (#551) Bumps [github.com/nbd-wtf/go-nostr](https://github.com/nbd-wtf/go-nostr) from 0.34.5 to 0.34.10. - [Commits](https://github.com/nbd-wtf/go-nostr/compare/v0.34.5...v0.34.10) --- updated-dependencies: - dependency-name: github.com/nbd-wtf/go-nostr dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump gopkg.in/DataDog/dd-trace-go.v1 from 1.66.0 to 1.67.0 (#552) Bumps gopkg.in/DataDog/dd-trace-go.v1 from 1.66.0 to 1.67.0. --- updated-dependencies: - dependency-name: gopkg.in/DataDog/dd-trace-go.v1 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix: do not render 0 on withdraw onchain funds page when reserve balance is 0 (#549) * chore: update fly default kill timeout to ensure app gracefully shuts down (#547) * feat: app metadata * fix(wails): parse max length in log output endpoint (#568) * fix: alby account image and name on transaction list * fix: vertically center transaction item content * fix: use slashed zero on wallet balance * chore: align app image with app name in transaction list * fix: ensure auth with correct user if refresh token expires (#572) * fix: do not allow editing name of Alby Account connection * fix: change "Create Wallet" to "Create Subaccount" * fix: subaccount copy * chore: update friends and family app icon * fix: update app store images (#574) * fix: update app store images * chore: update paper scissors hodl and zapplanner icons * chore: update lume and habla news icons * chore: resize and compress zapplanner and rps logos --------- Co-authored-by: Roland Bewick <roland.bewick@gmail.com> * feat: add new auto channel flow that works with existing channels (#556) * feat: add new auto channel flow that works with existing channels * chore: remove "first" from auto channel copy * feat: new transaction list item design --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Matjaž Lipuš <matjazl@gmail.com> Co-authored-by: BtcPins <pardus79@gmail.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> Co-authored-by: Adithya Vardhan <imadithyavardhan@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * feat: add buzzpay internal app * chore: remove connection secret from metadata * fix: make buzzpay isolated * chore: update buzzpay app UI and instructions * chore: extract app creation into shared method * fix: isolated app permission display * chore: update copy --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Matjaž Lipuš <matjazl@gmail.com> Co-authored-by: BtcPins <pardus79@gmail.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> Co-authored-by: Adithya Vardhan <imadithyavardhan@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-09-03 21:31:28 +07:00
"gorm.io/datatypes"
2024-05-30 00:06:06 +07:00
"gorm.io/gorm"
2024-07-05 20:32:40 +07:00
"github.com/getAlby/hub/alby"
"github.com/getAlby/hub/apps"
2024-07-05 20:32:40 +07:00
"github.com/getAlby/hub/config"
Feat: dynamic budgets (#226) * feat: add transactions table * feat: add transactions service with makeinvoice method * feat: use internal transactions WIP * feat: check unsettled transactions * feat: use transactions service in nip47 package WIP * feat: use transactions service in NIP-47 handlers * fix: transaction list colors * fix: tests * chore: remove old payments table * fix: return budget usage as sats * feat: use internal transactions table for keysend payments * feat: consume nwc_payment_received event in transaction service (WIP) * feat: update existing transaction from nwc_payment_received event in transactions service * feat: update existing transaction from nwc_payment_sent event in transactions service * feat: handle async payment failed events in transactions service * fix: tests * feat: correctly implement NIP-47 NOT_FOUND error code * feat: intercept self payments * feat: isolated balance and visibility * feat: validate keysend payment does not exceed app internal balance * feat: budget check in transactions service, correctly pass payment errors to NIP-47 response also reduce query duplication * fix: order transactions when looking up transaction * feat: add fee reserves to unsettled outgoing transactions * chore: rename app permissions max amount field * chore: rename transaction amount values to be clearly millisats * chore: merge balance type and visibility into isolated property on apps table * chore: move duplicated permission check from nip-47 controllers to handler * fix: app name in transaction list * Feat: permissions revamp v2 (#273) * feat: revamp permissions component * chore: changes * chore: changes * chore: add view mode for show app screen * chore: further changes * feat: new illustration for linking account (#254) * feat: new illustration for linking account * fix: update paths * fix: icon props (#256) * fix: use date from frontend * chore: add expiryselect component * chore: further changes * chore: further changes * chore: add date-fns for date picker * chore: further changes * chore: further changes * fix: add central LDK gossip node to help gossip new public channels (#262) * fix: make dialog responsive (#258) * chore: further changes * typo * chore: spacing issues * chore: use scopes from capabilities * chore: change scope type descriptions * chore: styling fixes * chore: fix typings * chore: budget renewal component * fix: LDK mark channel as inactive and show error if counterparty forwarding info missing (#267) fix: mark channel as inactive and show error if counterparty forwarding info missing * chore: remove unnecessary dark classes (#255) * fix: links to open first channel in sidebar and onboarding checklist (#268) * feat: improve migrate node UI (#269) * fix: migrate node copy (#270) * fix: stop nostr when app is shutdown and use context to stop lnclient (#271) * fix: permissions revamp WIP * feat: basic isolated apps UI * fix: new app connection, edit app connection, deep linking --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> * fix: make transactions table ID autoincrement * fix: do not send unrelated notifications to isolated apps * fix: nip-47 notifications not receiving updated transaction state * fix: migrate existing tables to have autoincrementing primary keys (#274) * fix: migrate existing tables to have autoincrementing primary keys * fix: recreate request and response event tables after apps * fix: remove null from request_events app_id * fix: do not crash when reloading app created page * chore: update pragma commands, add busy_timeout * fix: remove unnecessary migration of user_configs table * chore: update comment on autoincrement migration * feat: sqlite database config improvements * fix: autoincrement migration to delete unlinked app permissions * chore: update tests for dynamic budgets (WIP) * fix: get balance tests * chore: add extra event handler tests * chore: add extra event handler test * chore: add extra multi_pay_invoice tests * chore: transactions service tests (WIP) * chore: add transactions service payment tests * chore: add tests for self payments * fix: notifications tests * chore: add notifications tests for transactions service * chore: add fee reserve tests for transactions service * chore: add list transactions tests * chore: add keysend tests for transactions service * feat: subscribe for payments and invoices (#281) * fix: db transaction should be passed as pointer * feat(lnd): subscribe for payments and invoices * chore: rearrange check for settled * chore: remove TODO * chore: retry on error and add select * chore: publish payment failed event * chore: use json logging * feat: add lnd notification types * chore: remove sleep * fix: incorrect key on transaction list items * fix: test * fix: disable isolated app type on non-supported backends --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com>
2024-07-19 23:30:22 +07:00
"github.com/getAlby/hub/constants"
2024-07-05 20:32:40 +07:00
"github.com/getAlby/hub/db"
Feat: dynamic budgets (#226) * feat: add transactions table * feat: add transactions service with makeinvoice method * feat: use internal transactions WIP * feat: check unsettled transactions * feat: use transactions service in nip47 package WIP * feat: use transactions service in NIP-47 handlers * fix: transaction list colors * fix: tests * chore: remove old payments table * fix: return budget usage as sats * feat: use internal transactions table for keysend payments * feat: consume nwc_payment_received event in transaction service (WIP) * feat: update existing transaction from nwc_payment_received event in transactions service * feat: update existing transaction from nwc_payment_sent event in transactions service * feat: handle async payment failed events in transactions service * fix: tests * feat: correctly implement NIP-47 NOT_FOUND error code * feat: intercept self payments * feat: isolated balance and visibility * feat: validate keysend payment does not exceed app internal balance * feat: budget check in transactions service, correctly pass payment errors to NIP-47 response also reduce query duplication * fix: order transactions when looking up transaction * feat: add fee reserves to unsettled outgoing transactions * chore: rename app permissions max amount field * chore: rename transaction amount values to be clearly millisats * chore: merge balance type and visibility into isolated property on apps table * chore: move duplicated permission check from nip-47 controllers to handler * fix: app name in transaction list * Feat: permissions revamp v2 (#273) * feat: revamp permissions component * chore: changes * chore: changes * chore: add view mode for show app screen * chore: further changes * feat: new illustration for linking account (#254) * feat: new illustration for linking account * fix: update paths * fix: icon props (#256) * fix: use date from frontend * chore: add expiryselect component * chore: further changes * chore: further changes * chore: add date-fns for date picker * chore: further changes * chore: further changes * fix: add central LDK gossip node to help gossip new public channels (#262) * fix: make dialog responsive (#258) * chore: further changes * typo * chore: spacing issues * chore: use scopes from capabilities * chore: change scope type descriptions * chore: styling fixes * chore: fix typings * chore: budget renewal component * fix: LDK mark channel as inactive and show error if counterparty forwarding info missing (#267) fix: mark channel as inactive and show error if counterparty forwarding info missing * chore: remove unnecessary dark classes (#255) * fix: links to open first channel in sidebar and onboarding checklist (#268) * feat: improve migrate node UI (#269) * fix: migrate node copy (#270) * fix: stop nostr when app is shutdown and use context to stop lnclient (#271) * fix: permissions revamp WIP * feat: basic isolated apps UI * fix: new app connection, edit app connection, deep linking --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> * fix: make transactions table ID autoincrement * fix: do not send unrelated notifications to isolated apps * fix: nip-47 notifications not receiving updated transaction state * fix: migrate existing tables to have autoincrementing primary keys (#274) * fix: migrate existing tables to have autoincrementing primary keys * fix: recreate request and response event tables after apps * fix: remove null from request_events app_id * fix: do not crash when reloading app created page * chore: update pragma commands, add busy_timeout * fix: remove unnecessary migration of user_configs table * chore: update comment on autoincrement migration * feat: sqlite database config improvements * fix: autoincrement migration to delete unlinked app permissions * chore: update tests for dynamic budgets (WIP) * fix: get balance tests * chore: add extra event handler tests * chore: add extra event handler test * chore: add extra multi_pay_invoice tests * chore: transactions service tests (WIP) * chore: add transactions service payment tests * chore: add tests for self payments * fix: notifications tests * chore: add notifications tests for transactions service * chore: add fee reserve tests for transactions service * chore: add list transactions tests * chore: add keysend tests for transactions service * feat: subscribe for payments and invoices (#281) * fix: db transaction should be passed as pointer * feat(lnd): subscribe for payments and invoices * chore: rearrange check for settled * chore: remove TODO * chore: retry on error and add select * chore: publish payment failed event * chore: use json logging * feat: add lnd notification types * chore: remove sleep * fix: incorrect key on transaction list items * fix: test * fix: disable isolated app type on non-supported backends --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com>
2024-07-19 23:30:22 +07:00
"github.com/getAlby/hub/db/queries"
2024-07-05 20:32:40 +07:00
"github.com/getAlby/hub/events"
"github.com/getAlby/hub/lnclient"
"github.com/getAlby/hub/logger"
permissions "github.com/getAlby/hub/nip47/permissions"
"github.com/getAlby/hub/service"
"github.com/getAlby/hub/service/keys"
"github.com/getAlby/hub/utils"
"github.com/getAlby/hub/version"
2024-05-30 00:06:06 +07:00
)
type api struct {
db *gorm.DB
appsSvc apps.AppsService
cfg config.Config
svc service.Service
permissionsSvc permissions.PermissionsService
keys keys.Keys
albyOAuthSvc alby.AlbyOAuthService
startupError error
startupErrorTime time.Time
2024-05-30 00:06:06 +07:00
}
2024-06-29 22:29:55 +07:00
func NewAPI(svc service.Service, gormDB *gorm.DB, config config.Config, keys keys.Keys, albyOAuthSvc alby.AlbyOAuthService, eventPublisher events.EventPublisher) *api {
2024-05-30 00:06:06 +07:00
return &api{
2024-06-17 19:42:09 +07:00
db: gormDB,
feat: app child key derived from wallet master key (#736) * feat(appwalletKey): add GetBIP32ChildKey * feat: fix interface * feat: adding subscription WiP * feat: handle nostr subscriptions for lifecycle of apps * Delete .idea/.gitignore * Delete .idea/hub.iml * Delete .idea/modules.xml * Delete .idea/vcs.xml * fix: remove unnecessary * fix: missing handling legacy app * fix: review fixes * fix: use app.ID for key calculation instead of passing in event * fix: add TODO * fix: remove unnecessary check * fix: improve err handling and remove check * chore: store master nostr key to avoid deriving each time * chore: rename app nostr_pubkey to app_pubkey, extract app consumers into separate files * chore: finish renaming * fix: update app wallet pubkey on app creation * fix: not NULL check * fix: fix HandleEvent * fix: error handling * fix: error handling * fix: move StartSubscription to start.go * fix: remove duplicated error check * fix: make tests use AppsService for creating apps * chore: remove unused code * chore: minor event handler improvements - fix error code response when failing to update request event - fix log content when failing to decrypt request event - move logging of app to correct place * fix: add event_handler tests for legacy app * chore: add comment about legacy apps in deleteAppConsumer * fix: remove unused app from tests * fix: error handling in startAppWalletSubscription * fix: only create event info and nostr subscription for master key if there are legacy apps * fix: add legacy tests * fix: move fetching of Nip47 event info to deleteAppConsumer * fix: fixed arguments * fix: use require instead of assert * fix: adapt GetAppWalletKey to use DeriveKey with path 1' * fix: for backends that don't use a mnemonic, create appKey from nostrSecretKey * fix: cleanup eventPublisher Subscribers when relay reconnects * fix: bip32.FirstHardenedChild + appID * fix: remove unused env vars * fix: generate new mnemonic if empty * fix: add tests.CreateTestServiceWithMnemonic to fix TestEncryptedBackup * fix: handle both relay and main ctx Done * chore: add keys tests * chore: add extra assertions to keys test * chore: log when legacy app subscription is created * chore: remove unnecessary break * chore: add log when relay is successfully connected * fix: only auto-start node if it has been started before --------- Co-authored-by: Roland Bewick <roland.bewick@gmail.com>
2024-11-07 13:06:01 +01:00
appsSvc: apps.NewAppsService(gormDB, eventPublisher, keys),
2024-06-17 19:42:09 +07:00
cfg: config,
svc: svc,
2024-06-29 22:29:55 +07:00
permissionsSvc: permissions.NewPermissionsService(gormDB, eventPublisher),
2024-06-17 19:42:09 +07:00
keys: keys,
albyOAuthSvc: albyOAuthSvc,
2024-05-30 00:06:06 +07:00
}
}
func (api *api) CreateApp(createAppRequest *CreateAppRequest) (*CreateAppResponse, error) {
backendType, _ := api.cfg.Get("LNBackendType", "")
if createAppRequest.Isolated &&
backendType != "LDK" &&
backendType != "LND" {
return nil, fmt.Errorf(
"sub-wallets are currently not supported on your node backend. Try LDK or LND")
}
2024-05-30 00:06:06 +07:00
expiresAt, err := api.parseExpiresAt(createAppRequest.ExpiresAt)
if err != nil {
return nil, fmt.Errorf("invalid expiresAt: %v", err)
}
if len(createAppRequest.Scopes) == 0 {
return nil, fmt.Errorf("won't create an app without scopes")
2024-05-30 00:06:06 +07:00
}
for _, scope := range createAppRequest.Scopes {
if !slices.Contains(permissions.AllScopes(), scope) {
return nil, fmt.Errorf("did not recognize requested scope: %s", scope)
2024-06-17 19:42:09 +07:00
}
}
app, pairingSecretKey, err := api.appsSvc.CreateApp(
Feat: dynamic budgets (#226) * feat: add transactions table * feat: add transactions service with makeinvoice method * feat: use internal transactions WIP * feat: check unsettled transactions * feat: use transactions service in nip47 package WIP * feat: use transactions service in NIP-47 handlers * fix: transaction list colors * fix: tests * chore: remove old payments table * fix: return budget usage as sats * feat: use internal transactions table for keysend payments * feat: consume nwc_payment_received event in transaction service (WIP) * feat: update existing transaction from nwc_payment_received event in transactions service * feat: update existing transaction from nwc_payment_sent event in transactions service * feat: handle async payment failed events in transactions service * fix: tests * feat: correctly implement NIP-47 NOT_FOUND error code * feat: intercept self payments * feat: isolated balance and visibility * feat: validate keysend payment does not exceed app internal balance * feat: budget check in transactions service, correctly pass payment errors to NIP-47 response also reduce query duplication * fix: order transactions when looking up transaction * feat: add fee reserves to unsettled outgoing transactions * chore: rename app permissions max amount field * chore: rename transaction amount values to be clearly millisats * chore: merge balance type and visibility into isolated property on apps table * chore: move duplicated permission check from nip-47 controllers to handler * fix: app name in transaction list * Feat: permissions revamp v2 (#273) * feat: revamp permissions component * chore: changes * chore: changes * chore: add view mode for show app screen * chore: further changes * feat: new illustration for linking account (#254) * feat: new illustration for linking account * fix: update paths * fix: icon props (#256) * fix: use date from frontend * chore: add expiryselect component * chore: further changes * chore: further changes * chore: add date-fns for date picker * chore: further changes * chore: further changes * fix: add central LDK gossip node to help gossip new public channels (#262) * fix: make dialog responsive (#258) * chore: further changes * typo * chore: spacing issues * chore: use scopes from capabilities * chore: change scope type descriptions * chore: styling fixes * chore: fix typings * chore: budget renewal component * fix: LDK mark channel as inactive and show error if counterparty forwarding info missing (#267) fix: mark channel as inactive and show error if counterparty forwarding info missing * chore: remove unnecessary dark classes (#255) * fix: links to open first channel in sidebar and onboarding checklist (#268) * feat: improve migrate node UI (#269) * fix: migrate node copy (#270) * fix: stop nostr when app is shutdown and use context to stop lnclient (#271) * fix: permissions revamp WIP * feat: basic isolated apps UI * fix: new app connection, edit app connection, deep linking --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> * fix: make transactions table ID autoincrement * fix: do not send unrelated notifications to isolated apps * fix: nip-47 notifications not receiving updated transaction state * fix: migrate existing tables to have autoincrementing primary keys (#274) * fix: migrate existing tables to have autoincrementing primary keys * fix: recreate request and response event tables after apps * fix: remove null from request_events app_id * fix: do not crash when reloading app created page * chore: update pragma commands, add busy_timeout * fix: remove unnecessary migration of user_configs table * chore: update comment on autoincrement migration * feat: sqlite database config improvements * fix: autoincrement migration to delete unlinked app permissions * chore: update tests for dynamic budgets (WIP) * fix: get balance tests * chore: add extra event handler tests * chore: add extra event handler test * chore: add extra multi_pay_invoice tests * chore: transactions service tests (WIP) * chore: add transactions service payment tests * chore: add tests for self payments * fix: notifications tests * chore: add notifications tests for transactions service * chore: add fee reserve tests for transactions service * chore: add list transactions tests * chore: add keysend tests for transactions service * feat: subscribe for payments and invoices (#281) * fix: db transaction should be passed as pointer * feat(lnd): subscribe for payments and invoices * chore: rearrange check for settled * chore: remove TODO * chore: retry on error and add select * chore: publish payment failed event * chore: use json logging * feat: add lnd notification types * chore: remove sleep * fix: incorrect key on transaction list items * fix: test * fix: disable isolated app type on non-supported backends --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com>
2024-07-19 23:30:22 +07:00
createAppRequest.Name,
createAppRequest.Pubkey,
createAppRequest.MaxAmountSat,
createAppRequest.BudgetRenewal,
expiresAt,
createAppRequest.Scopes,
feat: add uncle jim internal app (#557) * feat: add uncle jim internal app * fix: wrong number in instructions * chore: simplify alby jim internal app copy * Feat: app metadata (#570) * chore: wg.Add() before go (#559) * chore: code cleanup (#558) * Update README.md Add command to make the install script executable in the instructions. * feat: add migration card in wallet screen (#555) * feat: add migration card in wallet screen * chore: transfer funds if channel exists * chore: typo * chore: improve copy * chore: add transfer funds button * fix: remove duplicate icon --------- Co-authored-by: Roland Bewick <roland.bewick@gmail.com> * chore: run extra workflows on PR (#563) * chore: run extra workflows on PR * fix: pull request workflows * build(deps): bump github.com/nbd-wtf/go-nostr from 0.34.5 to 0.34.10 (#551) Bumps [github.com/nbd-wtf/go-nostr](https://github.com/nbd-wtf/go-nostr) from 0.34.5 to 0.34.10. - [Commits](https://github.com/nbd-wtf/go-nostr/compare/v0.34.5...v0.34.10) --- updated-dependencies: - dependency-name: github.com/nbd-wtf/go-nostr dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump gopkg.in/DataDog/dd-trace-go.v1 from 1.66.0 to 1.67.0 (#552) Bumps gopkg.in/DataDog/dd-trace-go.v1 from 1.66.0 to 1.67.0. --- updated-dependencies: - dependency-name: gopkg.in/DataDog/dd-trace-go.v1 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix: do not render 0 on withdraw onchain funds page when reserve balance is 0 (#549) * chore: update fly default kill timeout to ensure app gracefully shuts down (#547) * feat: app metadata * fix(wails): parse max length in log output endpoint (#568) * fix: alby account image and name on transaction list * fix: vertically center transaction item content * fix: use slashed zero on wallet balance * chore: align app image with app name in transaction list * fix: ensure auth with correct user if refresh token expires (#572) * fix: do not allow editing name of Alby Account connection * fix: change "Create Wallet" to "Create Subaccount" * fix: subaccount copy * chore: update friends and family app icon * fix: update app store images (#574) * fix: update app store images * chore: update paper scissors hodl and zapplanner icons * chore: update lume and habla news icons * chore: resize and compress zapplanner and rps logos --------- Co-authored-by: Roland Bewick <roland.bewick@gmail.com> * feat: add new auto channel flow that works with existing channels (#556) * feat: add new auto channel flow that works with existing channels * chore: remove "first" from auto channel copy * feat: new transaction list item design --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Matjaž Lipuš <matjazl@gmail.com> Co-authored-by: BtcPins <pardus79@gmail.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> Co-authored-by: Adithya Vardhan <imadithyavardhan@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix: copy * fix: less detailed icon for uncle jim app * fix: shorten app description --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Matjaž Lipuš <matjazl@gmail.com> Co-authored-by: BtcPins <pardus79@gmail.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> Co-authored-by: Adithya Vardhan <imadithyavardhan@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: René Aaron <rene@twentyuno.net> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com>
2024-09-02 17:40:34 +07:00
createAppRequest.Isolated,
feat: app child key derived from wallet master key (#736) * feat(appwalletKey): add GetBIP32ChildKey * feat: fix interface * feat: adding subscription WiP * feat: handle nostr subscriptions for lifecycle of apps * Delete .idea/.gitignore * Delete .idea/hub.iml * Delete .idea/modules.xml * Delete .idea/vcs.xml * fix: remove unnecessary * fix: missing handling legacy app * fix: review fixes * fix: use app.ID for key calculation instead of passing in event * fix: add TODO * fix: remove unnecessary check * fix: improve err handling and remove check * chore: store master nostr key to avoid deriving each time * chore: rename app nostr_pubkey to app_pubkey, extract app consumers into separate files * chore: finish renaming * fix: update app wallet pubkey on app creation * fix: not NULL check * fix: fix HandleEvent * fix: error handling * fix: error handling * fix: move StartSubscription to start.go * fix: remove duplicated error check * fix: make tests use AppsService for creating apps * chore: remove unused code * chore: minor event handler improvements - fix error code response when failing to update request event - fix log content when failing to decrypt request event - move logging of app to correct place * fix: add event_handler tests for legacy app * chore: add comment about legacy apps in deleteAppConsumer * fix: remove unused app from tests * fix: error handling in startAppWalletSubscription * fix: only create event info and nostr subscription for master key if there are legacy apps * fix: add legacy tests * fix: move fetching of Nip47 event info to deleteAppConsumer * fix: fixed arguments * fix: use require instead of assert * fix: adapt GetAppWalletKey to use DeriveKey with path 1' * fix: for backends that don't use a mnemonic, create appKey from nostrSecretKey * fix: cleanup eventPublisher Subscribers when relay reconnects * fix: bip32.FirstHardenedChild + appID * fix: remove unused env vars * fix: generate new mnemonic if empty * fix: add tests.CreateTestServiceWithMnemonic to fix TestEncryptedBackup * fix: handle both relay and main ctx Done * chore: add keys tests * chore: add extra assertions to keys test * chore: log when legacy app subscription is created * chore: remove unnecessary break * chore: add log when relay is successfully connected * fix: only auto-start node if it has been started before --------- Co-authored-by: Roland Bewick <roland.bewick@gmail.com>
2024-11-07 13:06:01 +01:00
createAppRequest.Metadata,
)
2024-05-30 00:06:06 +07:00
if err != nil {
return nil, err
}
2024-06-17 19:42:09 +07:00
relayUrl := api.cfg.GetRelayUrl()
2024-05-30 00:06:06 +07:00
responseBody := &CreateAppResponse{}
responseBody.Id = app.ID
2024-05-30 00:06:06 +07:00
responseBody.Name = createAppRequest.Name
feat: app child key derived from wallet master key (#736) * feat(appwalletKey): add GetBIP32ChildKey * feat: fix interface * feat: adding subscription WiP * feat: handle nostr subscriptions for lifecycle of apps * Delete .idea/.gitignore * Delete .idea/hub.iml * Delete .idea/modules.xml * Delete .idea/vcs.xml * fix: remove unnecessary * fix: missing handling legacy app * fix: review fixes * fix: use app.ID for key calculation instead of passing in event * fix: add TODO * fix: remove unnecessary check * fix: improve err handling and remove check * chore: store master nostr key to avoid deriving each time * chore: rename app nostr_pubkey to app_pubkey, extract app consumers into separate files * chore: finish renaming * fix: update app wallet pubkey on app creation * fix: not NULL check * fix: fix HandleEvent * fix: error handling * fix: error handling * fix: move StartSubscription to start.go * fix: remove duplicated error check * fix: make tests use AppsService for creating apps * chore: remove unused code * chore: minor event handler improvements - fix error code response when failing to update request event - fix log content when failing to decrypt request event - move logging of app to correct place * fix: add event_handler tests for legacy app * chore: add comment about legacy apps in deleteAppConsumer * fix: remove unused app from tests * fix: error handling in startAppWalletSubscription * fix: only create event info and nostr subscription for master key if there are legacy apps * fix: add legacy tests * fix: move fetching of Nip47 event info to deleteAppConsumer * fix: fixed arguments * fix: use require instead of assert * fix: adapt GetAppWalletKey to use DeriveKey with path 1' * fix: for backends that don't use a mnemonic, create appKey from nostrSecretKey * fix: cleanup eventPublisher Subscribers when relay reconnects * fix: bip32.FirstHardenedChild + appID * fix: remove unused env vars * fix: generate new mnemonic if empty * fix: add tests.CreateTestServiceWithMnemonic to fix TestEncryptedBackup * fix: handle both relay and main ctx Done * chore: add keys tests * chore: add extra assertions to keys test * chore: log when legacy app subscription is created * chore: remove unnecessary break * chore: add log when relay is successfully connected * fix: only auto-start node if it has been started before --------- Co-authored-by: Roland Bewick <roland.bewick@gmail.com>
2024-11-07 13:06:01 +01:00
responseBody.Pubkey = app.AppPubkey
2024-05-30 00:06:06 +07:00
responseBody.PairingSecret = pairingSecretKey
lightningAddress, err := api.albyOAuthSvc.GetLightningAddress()
if err != nil {
return nil, err
}
2024-05-30 00:06:06 +07:00
if createAppRequest.ReturnTo != "" {
returnToUrl, err := url.Parse(createAppRequest.ReturnTo)
if err == nil {
query := returnToUrl.Query()
query.Add("relay", relayUrl)
feat: app child key derived from wallet master key (#736) * feat(appwalletKey): add GetBIP32ChildKey * feat: fix interface * feat: adding subscription WiP * feat: handle nostr subscriptions for lifecycle of apps * Delete .idea/.gitignore * Delete .idea/hub.iml * Delete .idea/modules.xml * Delete .idea/vcs.xml * fix: remove unnecessary * fix: missing handling legacy app * fix: review fixes * fix: use app.ID for key calculation instead of passing in event * fix: add TODO * fix: remove unnecessary check * fix: improve err handling and remove check * chore: store master nostr key to avoid deriving each time * chore: rename app nostr_pubkey to app_pubkey, extract app consumers into separate files * chore: finish renaming * fix: update app wallet pubkey on app creation * fix: not NULL check * fix: fix HandleEvent * fix: error handling * fix: error handling * fix: move StartSubscription to start.go * fix: remove duplicated error check * fix: make tests use AppsService for creating apps * chore: remove unused code * chore: minor event handler improvements - fix error code response when failing to update request event - fix log content when failing to decrypt request event - move logging of app to correct place * fix: add event_handler tests for legacy app * chore: add comment about legacy apps in deleteAppConsumer * fix: remove unused app from tests * fix: error handling in startAppWalletSubscription * fix: only create event info and nostr subscription for master key if there are legacy apps * fix: add legacy tests * fix: move fetching of Nip47 event info to deleteAppConsumer * fix: fixed arguments * fix: use require instead of assert * fix: adapt GetAppWalletKey to use DeriveKey with path 1' * fix: for backends that don't use a mnemonic, create appKey from nostrSecretKey * fix: cleanup eventPublisher Subscribers when relay reconnects * fix: bip32.FirstHardenedChild + appID * fix: remove unused env vars * fix: generate new mnemonic if empty * fix: add tests.CreateTestServiceWithMnemonic to fix TestEncryptedBackup * fix: handle both relay and main ctx Done * chore: add keys tests * chore: add extra assertions to keys test * chore: log when legacy app subscription is created * chore: remove unnecessary break * chore: add log when relay is successfully connected * fix: only auto-start node if it has been started before --------- Co-authored-by: Roland Bewick <roland.bewick@gmail.com>
2024-11-07 13:06:01 +01:00
query.Add("pubkey", *app.WalletPubkey)
if lightningAddress != "" && !app.Isolated {
query.Add("lud16", lightningAddress)
}
2024-05-30 00:06:06 +07:00
returnToUrl.RawQuery = query.Encode()
responseBody.ReturnTo = returnToUrl.String()
}
}
var lud16 string
if lightningAddress != "" && !app.Isolated {
lud16 = fmt.Sprintf("&lud16=%s", lightningAddress)
}
feat: app child key derived from wallet master key (#736) * feat(appwalletKey): add GetBIP32ChildKey * feat: fix interface * feat: adding subscription WiP * feat: handle nostr subscriptions for lifecycle of apps * Delete .idea/.gitignore * Delete .idea/hub.iml * Delete .idea/modules.xml * Delete .idea/vcs.xml * fix: remove unnecessary * fix: missing handling legacy app * fix: review fixes * fix: use app.ID for key calculation instead of passing in event * fix: add TODO * fix: remove unnecessary check * fix: improve err handling and remove check * chore: store master nostr key to avoid deriving each time * chore: rename app nostr_pubkey to app_pubkey, extract app consumers into separate files * chore: finish renaming * fix: update app wallet pubkey on app creation * fix: not NULL check * fix: fix HandleEvent * fix: error handling * fix: error handling * fix: move StartSubscription to start.go * fix: remove duplicated error check * fix: make tests use AppsService for creating apps * chore: remove unused code * chore: minor event handler improvements - fix error code response when failing to update request event - fix log content when failing to decrypt request event - move logging of app to correct place * fix: add event_handler tests for legacy app * chore: add comment about legacy apps in deleteAppConsumer * fix: remove unused app from tests * fix: error handling in startAppWalletSubscription * fix: only create event info and nostr subscription for master key if there are legacy apps * fix: add legacy tests * fix: move fetching of Nip47 event info to deleteAppConsumer * fix: fixed arguments * fix: use require instead of assert * fix: adapt GetAppWalletKey to use DeriveKey with path 1' * fix: for backends that don't use a mnemonic, create appKey from nostrSecretKey * fix: cleanup eventPublisher Subscribers when relay reconnects * fix: bip32.FirstHardenedChild + appID * fix: remove unused env vars * fix: generate new mnemonic if empty * fix: add tests.CreateTestServiceWithMnemonic to fix TestEncryptedBackup * fix: handle both relay and main ctx Done * chore: add keys tests * chore: add extra assertions to keys test * chore: log when legacy app subscription is created * chore: remove unnecessary break * chore: add log when relay is successfully connected * fix: only auto-start node if it has been started before --------- Co-authored-by: Roland Bewick <roland.bewick@gmail.com>
2024-11-07 13:06:01 +01:00
responseBody.PairingUri = fmt.Sprintf("nostr+walletconnect://%s?relay=%s&secret=%s%s", *app.WalletPubkey, relayUrl, pairingSecretKey, lud16)
2024-05-30 00:06:06 +07:00
return responseBody, nil
}
func (api *api) UpdateApp(userApp *db.App, updateAppRequest *UpdateAppRequest) error {
name := updateAppRequest.Name
if name == "" {
return fmt.Errorf("won't update an app to have no name")
}
Feat: dynamic budgets (#226) * feat: add transactions table * feat: add transactions service with makeinvoice method * feat: use internal transactions WIP * feat: check unsettled transactions * feat: use transactions service in nip47 package WIP * feat: use transactions service in NIP-47 handlers * fix: transaction list colors * fix: tests * chore: remove old payments table * fix: return budget usage as sats * feat: use internal transactions table for keysend payments * feat: consume nwc_payment_received event in transaction service (WIP) * feat: update existing transaction from nwc_payment_received event in transactions service * feat: update existing transaction from nwc_payment_sent event in transactions service * feat: handle async payment failed events in transactions service * fix: tests * feat: correctly implement NIP-47 NOT_FOUND error code * feat: intercept self payments * feat: isolated balance and visibility * feat: validate keysend payment does not exceed app internal balance * feat: budget check in transactions service, correctly pass payment errors to NIP-47 response also reduce query duplication * fix: order transactions when looking up transaction * feat: add fee reserves to unsettled outgoing transactions * chore: rename app permissions max amount field * chore: rename transaction amount values to be clearly millisats * chore: merge balance type and visibility into isolated property on apps table * chore: move duplicated permission check from nip-47 controllers to handler * fix: app name in transaction list * Feat: permissions revamp v2 (#273) * feat: revamp permissions component * chore: changes * chore: changes * chore: add view mode for show app screen * chore: further changes * feat: new illustration for linking account (#254) * feat: new illustration for linking account * fix: update paths * fix: icon props (#256) * fix: use date from frontend * chore: add expiryselect component * chore: further changes * chore: further changes * chore: add date-fns for date picker * chore: further changes * chore: further changes * fix: add central LDK gossip node to help gossip new public channels (#262) * fix: make dialog responsive (#258) * chore: further changes * typo * chore: spacing issues * chore: use scopes from capabilities * chore: change scope type descriptions * chore: styling fixes * chore: fix typings * chore: budget renewal component * fix: LDK mark channel as inactive and show error if counterparty forwarding info missing (#267) fix: mark channel as inactive and show error if counterparty forwarding info missing * chore: remove unnecessary dark classes (#255) * fix: links to open first channel in sidebar and onboarding checklist (#268) * feat: improve migrate node UI (#269) * fix: migrate node copy (#270) * fix: stop nostr when app is shutdown and use context to stop lnclient (#271) * fix: permissions revamp WIP * feat: basic isolated apps UI * fix: new app connection, edit app connection, deep linking --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> * fix: make transactions table ID autoincrement * fix: do not send unrelated notifications to isolated apps * fix: nip-47 notifications not receiving updated transaction state * fix: migrate existing tables to have autoincrementing primary keys (#274) * fix: migrate existing tables to have autoincrementing primary keys * fix: recreate request and response event tables after apps * fix: remove null from request_events app_id * fix: do not crash when reloading app created page * chore: update pragma commands, add busy_timeout * fix: remove unnecessary migration of user_configs table * chore: update comment on autoincrement migration * feat: sqlite database config improvements * fix: autoincrement migration to delete unlinked app permissions * chore: update tests for dynamic budgets (WIP) * fix: get balance tests * chore: add extra event handler tests * chore: add extra event handler test * chore: add extra multi_pay_invoice tests * chore: transactions service tests (WIP) * chore: add transactions service payment tests * chore: add tests for self payments * fix: notifications tests * chore: add notifications tests for transactions service * chore: add fee reserve tests for transactions service * chore: add list transactions tests * chore: add keysend tests for transactions service * feat: subscribe for payments and invoices (#281) * fix: db transaction should be passed as pointer * feat(lnd): subscribe for payments and invoices * chore: rearrange check for settled * chore: remove TODO * chore: retry on error and add select * chore: publish payment failed event * chore: use json logging * feat: add lnd notification types * chore: remove sleep * fix: incorrect key on transaction list items * fix: test * fix: disable isolated app type on non-supported backends --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com>
2024-07-19 23:30:22 +07:00
maxAmount := updateAppRequest.MaxAmountSat
2024-05-30 00:06:06 +07:00
budgetRenewal := updateAppRequest.BudgetRenewal
if len(updateAppRequest.Scopes) == 0 {
2024-05-30 00:06:06 +07:00
return fmt.Errorf("won't update an app to have no request methods")
}
newScopes := updateAppRequest.Scopes
2024-05-30 00:06:06 +07:00
expiresAt, err := api.parseExpiresAt(updateAppRequest.ExpiresAt)
if err != nil {
return fmt.Errorf("invalid expiresAt: %v", err)
}
err = api.db.Transaction(func(tx *gorm.DB) error {
// Update app name if it is not the same
if name != userApp.Name {
err := tx.Model(&db.App{}).Where("id", userApp.ID).Update("name", name).Error
if err != nil {
return err
}
}
// Update app isolation if it is not the same
if updateAppRequest.Isolated != userApp.Isolated {
err := tx.Model(&db.App{}).Where("id", userApp.ID).Update("isolated", updateAppRequest.Isolated).Error
if err != nil {
return err
}
}
// Update the app metadata
feat: add buzzpay internal app (#580) * feat: add uncle jim internal app * fix: wrong number in instructions * chore: simplify alby jim internal app copy * Feat: app metadata (#570) * chore: wg.Add() before go (#559) * chore: code cleanup (#558) * Update README.md Add command to make the install script executable in the instructions. * feat: add migration card in wallet screen (#555) * feat: add migration card in wallet screen * chore: transfer funds if channel exists * chore: typo * chore: improve copy * chore: add transfer funds button * fix: remove duplicate icon --------- Co-authored-by: Roland Bewick <roland.bewick@gmail.com> * chore: run extra workflows on PR (#563) * chore: run extra workflows on PR * fix: pull request workflows * build(deps): bump github.com/nbd-wtf/go-nostr from 0.34.5 to 0.34.10 (#551) Bumps [github.com/nbd-wtf/go-nostr](https://github.com/nbd-wtf/go-nostr) from 0.34.5 to 0.34.10. - [Commits](https://github.com/nbd-wtf/go-nostr/compare/v0.34.5...v0.34.10) --- updated-dependencies: - dependency-name: github.com/nbd-wtf/go-nostr dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump gopkg.in/DataDog/dd-trace-go.v1 from 1.66.0 to 1.67.0 (#552) Bumps gopkg.in/DataDog/dd-trace-go.v1 from 1.66.0 to 1.67.0. --- updated-dependencies: - dependency-name: gopkg.in/DataDog/dd-trace-go.v1 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix: do not render 0 on withdraw onchain funds page when reserve balance is 0 (#549) * chore: update fly default kill timeout to ensure app gracefully shuts down (#547) * feat: app metadata * fix(wails): parse max length in log output endpoint (#568) * fix: alby account image and name on transaction list * fix: vertically center transaction item content * fix: use slashed zero on wallet balance * chore: align app image with app name in transaction list * fix: ensure auth with correct user if refresh token expires (#572) * fix: do not allow editing name of Alby Account connection * fix: change "Create Wallet" to "Create Subaccount" * fix: subaccount copy * chore: update friends and family app icon * fix: update app store images (#574) * fix: update app store images * chore: update paper scissors hodl and zapplanner icons * chore: update lume and habla news icons * chore: resize and compress zapplanner and rps logos --------- Co-authored-by: Roland Bewick <roland.bewick@gmail.com> * feat: add new auto channel flow that works with existing channels (#556) * feat: add new auto channel flow that works with existing channels * chore: remove "first" from auto channel copy * feat: new transaction list item design --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Matjaž Lipuš <matjazl@gmail.com> Co-authored-by: BtcPins <pardus79@gmail.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> Co-authored-by: Adithya Vardhan <imadithyavardhan@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * feat: add buzzpay internal app * chore: remove connection secret from metadata * fix: make buzzpay isolated * chore: update buzzpay app UI and instructions * chore: extract app creation into shared method * fix: isolated app permission display * chore: update copy --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Matjaž Lipuš <matjazl@gmail.com> Co-authored-by: BtcPins <pardus79@gmail.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> Co-authored-by: Adithya Vardhan <imadithyavardhan@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-09-03 21:31:28 +07:00
if updateAppRequest.Metadata != nil {
var metadataBytes []byte
var err error
metadataBytes, err = json.Marshal(updateAppRequest.Metadata)
if err != nil {
logger.Logger.WithError(err).Error("Failed to serialize metadata")
return err
}
err = tx.Model(&db.App{}).Where("id", userApp.ID).Update("metadata", datatypes.JSON(metadataBytes)).Error
if err != nil {
return err
}
}
2024-05-30 00:06:06 +07:00
// Update existing permissions with new budget and expiry
err = tx.Model(&db.AppPermission{}).Where("app_id", userApp.ID).Updates(map[string]interface{}{
2024-05-30 00:06:06 +07:00
"ExpiresAt": expiresAt,
Feat: dynamic budgets (#226) * feat: add transactions table * feat: add transactions service with makeinvoice method * feat: use internal transactions WIP * feat: check unsettled transactions * feat: use transactions service in nip47 package WIP * feat: use transactions service in NIP-47 handlers * fix: transaction list colors * fix: tests * chore: remove old payments table * fix: return budget usage as sats * feat: use internal transactions table for keysend payments * feat: consume nwc_payment_received event in transaction service (WIP) * feat: update existing transaction from nwc_payment_received event in transactions service * feat: update existing transaction from nwc_payment_sent event in transactions service * feat: handle async payment failed events in transactions service * fix: tests * feat: correctly implement NIP-47 NOT_FOUND error code * feat: intercept self payments * feat: isolated balance and visibility * feat: validate keysend payment does not exceed app internal balance * feat: budget check in transactions service, correctly pass payment errors to NIP-47 response also reduce query duplication * fix: order transactions when looking up transaction * feat: add fee reserves to unsettled outgoing transactions * chore: rename app permissions max amount field * chore: rename transaction amount values to be clearly millisats * chore: merge balance type and visibility into isolated property on apps table * chore: move duplicated permission check from nip-47 controllers to handler * fix: app name in transaction list * Feat: permissions revamp v2 (#273) * feat: revamp permissions component * chore: changes * chore: changes * chore: add view mode for show app screen * chore: further changes * feat: new illustration for linking account (#254) * feat: new illustration for linking account * fix: update paths * fix: icon props (#256) * fix: use date from frontend * chore: add expiryselect component * chore: further changes * chore: further changes * chore: add date-fns for date picker * chore: further changes * chore: further changes * fix: add central LDK gossip node to help gossip new public channels (#262) * fix: make dialog responsive (#258) * chore: further changes * typo * chore: spacing issues * chore: use scopes from capabilities * chore: change scope type descriptions * chore: styling fixes * chore: fix typings * chore: budget renewal component * fix: LDK mark channel as inactive and show error if counterparty forwarding info missing (#267) fix: mark channel as inactive and show error if counterparty forwarding info missing * chore: remove unnecessary dark classes (#255) * fix: links to open first channel in sidebar and onboarding checklist (#268) * feat: improve migrate node UI (#269) * fix: migrate node copy (#270) * fix: stop nostr when app is shutdown and use context to stop lnclient (#271) * fix: permissions revamp WIP * feat: basic isolated apps UI * fix: new app connection, edit app connection, deep linking --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> * fix: make transactions table ID autoincrement * fix: do not send unrelated notifications to isolated apps * fix: nip-47 notifications not receiving updated transaction state * fix: migrate existing tables to have autoincrementing primary keys (#274) * fix: migrate existing tables to have autoincrementing primary keys * fix: recreate request and response event tables after apps * fix: remove null from request_events app_id * fix: do not crash when reloading app created page * chore: update pragma commands, add busy_timeout * fix: remove unnecessary migration of user_configs table * chore: update comment on autoincrement migration * feat: sqlite database config improvements * fix: autoincrement migration to delete unlinked app permissions * chore: update tests for dynamic budgets (WIP) * fix: get balance tests * chore: add extra event handler tests * chore: add extra event handler test * chore: add extra multi_pay_invoice tests * chore: transactions service tests (WIP) * chore: add transactions service payment tests * chore: add tests for self payments * fix: notifications tests * chore: add notifications tests for transactions service * chore: add fee reserve tests for transactions service * chore: add list transactions tests * chore: add keysend tests for transactions service * feat: subscribe for payments and invoices (#281) * fix: db transaction should be passed as pointer * feat(lnd): subscribe for payments and invoices * chore: rearrange check for settled * chore: remove TODO * chore: retry on error and add select * chore: publish payment failed event * chore: use json logging * feat: add lnd notification types * chore: remove sleep * fix: incorrect key on transaction list items * fix: test * fix: disable isolated app type on non-supported backends --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com>
2024-07-19 23:30:22 +07:00
"MaxAmountSat": maxAmount,
2024-05-30 00:06:06 +07:00
"BudgetRenewal": budgetRenewal,
}).Error
if err != nil {
return err
}
var existingPermissions []db.AppPermission
if err := tx.Where("app_id = ?", userApp.ID).Find(&existingPermissions).Error; err != nil {
return err
}
existingScopeMap := make(map[string]bool)
2024-05-30 00:06:06 +07:00
for _, perm := range existingPermissions {
existingScopeMap[perm.Scope] = true
2024-05-30 00:06:06 +07:00
}
// Add new permissions
for _, method := range newScopes {
if !existingScopeMap[method] {
2024-05-30 00:06:06 +07:00
perm := db.AppPermission{
App: *userApp,
Scope: method,
2024-05-30 00:06:06 +07:00
ExpiresAt: expiresAt,
Feat: dynamic budgets (#226) * feat: add transactions table * feat: add transactions service with makeinvoice method * feat: use internal transactions WIP * feat: check unsettled transactions * feat: use transactions service in nip47 package WIP * feat: use transactions service in NIP-47 handlers * fix: transaction list colors * fix: tests * chore: remove old payments table * fix: return budget usage as sats * feat: use internal transactions table for keysend payments * feat: consume nwc_payment_received event in transaction service (WIP) * feat: update existing transaction from nwc_payment_received event in transactions service * feat: update existing transaction from nwc_payment_sent event in transactions service * feat: handle async payment failed events in transactions service * fix: tests * feat: correctly implement NIP-47 NOT_FOUND error code * feat: intercept self payments * feat: isolated balance and visibility * feat: validate keysend payment does not exceed app internal balance * feat: budget check in transactions service, correctly pass payment errors to NIP-47 response also reduce query duplication * fix: order transactions when looking up transaction * feat: add fee reserves to unsettled outgoing transactions * chore: rename app permissions max amount field * chore: rename transaction amount values to be clearly millisats * chore: merge balance type and visibility into isolated property on apps table * chore: move duplicated permission check from nip-47 controllers to handler * fix: app name in transaction list * Feat: permissions revamp v2 (#273) * feat: revamp permissions component * chore: changes * chore: changes * chore: add view mode for show app screen * chore: further changes * feat: new illustration for linking account (#254) * feat: new illustration for linking account * fix: update paths * fix: icon props (#256) * fix: use date from frontend * chore: add expiryselect component * chore: further changes * chore: further changes * chore: add date-fns for date picker * chore: further changes * chore: further changes * fix: add central LDK gossip node to help gossip new public channels (#262) * fix: make dialog responsive (#258) * chore: further changes * typo * chore: spacing issues * chore: use scopes from capabilities * chore: change scope type descriptions * chore: styling fixes * chore: fix typings * chore: budget renewal component * fix: LDK mark channel as inactive and show error if counterparty forwarding info missing (#267) fix: mark channel as inactive and show error if counterparty forwarding info missing * chore: remove unnecessary dark classes (#255) * fix: links to open first channel in sidebar and onboarding checklist (#268) * feat: improve migrate node UI (#269) * fix: migrate node copy (#270) * fix: stop nostr when app is shutdown and use context to stop lnclient (#271) * fix: permissions revamp WIP * feat: basic isolated apps UI * fix: new app connection, edit app connection, deep linking --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> * fix: make transactions table ID autoincrement * fix: do not send unrelated notifications to isolated apps * fix: nip-47 notifications not receiving updated transaction state * fix: migrate existing tables to have autoincrementing primary keys (#274) * fix: migrate existing tables to have autoincrementing primary keys * fix: recreate request and response event tables after apps * fix: remove null from request_events app_id * fix: do not crash when reloading app created page * chore: update pragma commands, add busy_timeout * fix: remove unnecessary migration of user_configs table * chore: update comment on autoincrement migration * feat: sqlite database config improvements * fix: autoincrement migration to delete unlinked app permissions * chore: update tests for dynamic budgets (WIP) * fix: get balance tests * chore: add extra event handler tests * chore: add extra event handler test * chore: add extra multi_pay_invoice tests * chore: transactions service tests (WIP) * chore: add transactions service payment tests * chore: add tests for self payments * fix: notifications tests * chore: add notifications tests for transactions service * chore: add fee reserve tests for transactions service * chore: add list transactions tests * chore: add keysend tests for transactions service * feat: subscribe for payments and invoices (#281) * fix: db transaction should be passed as pointer * feat(lnd): subscribe for payments and invoices * chore: rearrange check for settled * chore: remove TODO * chore: retry on error and add select * chore: publish payment failed event * chore: use json logging * feat: add lnd notification types * chore: remove sleep * fix: incorrect key on transaction list items * fix: test * fix: disable isolated app type on non-supported backends --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com>
2024-07-19 23:30:22 +07:00
MaxAmountSat: int(maxAmount),
2024-05-30 00:06:06 +07:00
BudgetRenewal: budgetRenewal,
}
if err := tx.Create(&perm).Error; err != nil {
return err
}
}
delete(existingScopeMap, method)
2024-05-30 00:06:06 +07:00
}
// Remove old permissions
for method := range existingScopeMap {
if err := tx.Where("app_id = ? AND scope = ?", userApp.ID, method).Delete(&db.AppPermission{}).Error; err != nil {
2024-05-30 00:06:06 +07:00
return err
}
}
api.svc.GetEventPublisher().Publish(&events.Event{
Event: "nwc_app_updated",
Properties: map[string]interface{}{
"name": name,
"id": userApp.ID,
},
})
2024-05-30 00:06:06 +07:00
// commit transaction
return nil
})
return err
}
func (api *api) DeleteApp(userApp *db.App) error {
feat: app child key derived from wallet master key (#736) * feat(appwalletKey): add GetBIP32ChildKey * feat: fix interface * feat: adding subscription WiP * feat: handle nostr subscriptions for lifecycle of apps * Delete .idea/.gitignore * Delete .idea/hub.iml * Delete .idea/modules.xml * Delete .idea/vcs.xml * fix: remove unnecessary * fix: missing handling legacy app * fix: review fixes * fix: use app.ID for key calculation instead of passing in event * fix: add TODO * fix: remove unnecessary check * fix: improve err handling and remove check * chore: store master nostr key to avoid deriving each time * chore: rename app nostr_pubkey to app_pubkey, extract app consumers into separate files * chore: finish renaming * fix: update app wallet pubkey on app creation * fix: not NULL check * fix: fix HandleEvent * fix: error handling * fix: error handling * fix: move StartSubscription to start.go * fix: remove duplicated error check * fix: make tests use AppsService for creating apps * chore: remove unused code * chore: minor event handler improvements - fix error code response when failing to update request event - fix log content when failing to decrypt request event - move logging of app to correct place * fix: add event_handler tests for legacy app * chore: add comment about legacy apps in deleteAppConsumer * fix: remove unused app from tests * fix: error handling in startAppWalletSubscription * fix: only create event info and nostr subscription for master key if there are legacy apps * fix: add legacy tests * fix: move fetching of Nip47 event info to deleteAppConsumer * fix: fixed arguments * fix: use require instead of assert * fix: adapt GetAppWalletKey to use DeriveKey with path 1' * fix: for backends that don't use a mnemonic, create appKey from nostrSecretKey * fix: cleanup eventPublisher Subscribers when relay reconnects * fix: bip32.FirstHardenedChild + appID * fix: remove unused env vars * fix: generate new mnemonic if empty * fix: add tests.CreateTestServiceWithMnemonic to fix TestEncryptedBackup * fix: handle both relay and main ctx Done * chore: add keys tests * chore: add extra assertions to keys test * chore: log when legacy app subscription is created * chore: remove unnecessary break * chore: add log when relay is successfully connected * fix: only auto-start node if it has been started before --------- Co-authored-by: Roland Bewick <roland.bewick@gmail.com>
2024-11-07 13:06:01 +01:00
return api.appsSvc.DeleteApp(userApp)
2024-05-30 00:06:06 +07:00
}
Feat: dynamic budgets (#226) * feat: add transactions table * feat: add transactions service with makeinvoice method * feat: use internal transactions WIP * feat: check unsettled transactions * feat: use transactions service in nip47 package WIP * feat: use transactions service in NIP-47 handlers * fix: transaction list colors * fix: tests * chore: remove old payments table * fix: return budget usage as sats * feat: use internal transactions table for keysend payments * feat: consume nwc_payment_received event in transaction service (WIP) * feat: update existing transaction from nwc_payment_received event in transactions service * feat: update existing transaction from nwc_payment_sent event in transactions service * feat: handle async payment failed events in transactions service * fix: tests * feat: correctly implement NIP-47 NOT_FOUND error code * feat: intercept self payments * feat: isolated balance and visibility * feat: validate keysend payment does not exceed app internal balance * feat: budget check in transactions service, correctly pass payment errors to NIP-47 response also reduce query duplication * fix: order transactions when looking up transaction * feat: add fee reserves to unsettled outgoing transactions * chore: rename app permissions max amount field * chore: rename transaction amount values to be clearly millisats * chore: merge balance type and visibility into isolated property on apps table * chore: move duplicated permission check from nip-47 controllers to handler * fix: app name in transaction list * Feat: permissions revamp v2 (#273) * feat: revamp permissions component * chore: changes * chore: changes * chore: add view mode for show app screen * chore: further changes * feat: new illustration for linking account (#254) * feat: new illustration for linking account * fix: update paths * fix: icon props (#256) * fix: use date from frontend * chore: add expiryselect component * chore: further changes * chore: further changes * chore: add date-fns for date picker * chore: further changes * chore: further changes * fix: add central LDK gossip node to help gossip new public channels (#262) * fix: make dialog responsive (#258) * chore: further changes * typo * chore: spacing issues * chore: use scopes from capabilities * chore: change scope type descriptions * chore: styling fixes * chore: fix typings * chore: budget renewal component * fix: LDK mark channel as inactive and show error if counterparty forwarding info missing (#267) fix: mark channel as inactive and show error if counterparty forwarding info missing * chore: remove unnecessary dark classes (#255) * fix: links to open first channel in sidebar and onboarding checklist (#268) * feat: improve migrate node UI (#269) * fix: migrate node copy (#270) * fix: stop nostr when app is shutdown and use context to stop lnclient (#271) * fix: permissions revamp WIP * feat: basic isolated apps UI * fix: new app connection, edit app connection, deep linking --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> * fix: make transactions table ID autoincrement * fix: do not send unrelated notifications to isolated apps * fix: nip-47 notifications not receiving updated transaction state * fix: migrate existing tables to have autoincrementing primary keys (#274) * fix: migrate existing tables to have autoincrementing primary keys * fix: recreate request and response event tables after apps * fix: remove null from request_events app_id * fix: do not crash when reloading app created page * chore: update pragma commands, add busy_timeout * fix: remove unnecessary migration of user_configs table * chore: update comment on autoincrement migration * feat: sqlite database config improvements * fix: autoincrement migration to delete unlinked app permissions * chore: update tests for dynamic budgets (WIP) * fix: get balance tests * chore: add extra event handler tests * chore: add extra event handler test * chore: add extra multi_pay_invoice tests * chore: transactions service tests (WIP) * chore: add transactions service payment tests * chore: add tests for self payments * fix: notifications tests * chore: add notifications tests for transactions service * chore: add fee reserve tests for transactions service * chore: add list transactions tests * chore: add keysend tests for transactions service * feat: subscribe for payments and invoices (#281) * fix: db transaction should be passed as pointer * feat(lnd): subscribe for payments and invoices * chore: rearrange check for settled * chore: remove TODO * chore: retry on error and add select * chore: publish payment failed event * chore: use json logging * feat: add lnd notification types * chore: remove sleep * fix: incorrect key on transaction list items * fix: test * fix: disable isolated app type on non-supported backends --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com>
2024-07-19 23:30:22 +07:00
func (api *api) GetApp(dbApp *db.App) *App {
2024-05-30 00:06:06 +07:00
var lastEvent db.RequestEvent
Feat: dynamic budgets (#226) * feat: add transactions table * feat: add transactions service with makeinvoice method * feat: use internal transactions WIP * feat: check unsettled transactions * feat: use transactions service in nip47 package WIP * feat: use transactions service in NIP-47 handlers * fix: transaction list colors * fix: tests * chore: remove old payments table * fix: return budget usage as sats * feat: use internal transactions table for keysend payments * feat: consume nwc_payment_received event in transaction service (WIP) * feat: update existing transaction from nwc_payment_received event in transactions service * feat: update existing transaction from nwc_payment_sent event in transactions service * feat: handle async payment failed events in transactions service * fix: tests * feat: correctly implement NIP-47 NOT_FOUND error code * feat: intercept self payments * feat: isolated balance and visibility * feat: validate keysend payment does not exceed app internal balance * feat: budget check in transactions service, correctly pass payment errors to NIP-47 response also reduce query duplication * fix: order transactions when looking up transaction * feat: add fee reserves to unsettled outgoing transactions * chore: rename app permissions max amount field * chore: rename transaction amount values to be clearly millisats * chore: merge balance type and visibility into isolated property on apps table * chore: move duplicated permission check from nip-47 controllers to handler * fix: app name in transaction list * Feat: permissions revamp v2 (#273) * feat: revamp permissions component * chore: changes * chore: changes * chore: add view mode for show app screen * chore: further changes * feat: new illustration for linking account (#254) * feat: new illustration for linking account * fix: update paths * fix: icon props (#256) * fix: use date from frontend * chore: add expiryselect component * chore: further changes * chore: further changes * chore: add date-fns for date picker * chore: further changes * chore: further changes * fix: add central LDK gossip node to help gossip new public channels (#262) * fix: make dialog responsive (#258) * chore: further changes * typo * chore: spacing issues * chore: use scopes from capabilities * chore: change scope type descriptions * chore: styling fixes * chore: fix typings * chore: budget renewal component * fix: LDK mark channel as inactive and show error if counterparty forwarding info missing (#267) fix: mark channel as inactive and show error if counterparty forwarding info missing * chore: remove unnecessary dark classes (#255) * fix: links to open first channel in sidebar and onboarding checklist (#268) * feat: improve migrate node UI (#269) * fix: migrate node copy (#270) * fix: stop nostr when app is shutdown and use context to stop lnclient (#271) * fix: permissions revamp WIP * feat: basic isolated apps UI * fix: new app connection, edit app connection, deep linking --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> * fix: make transactions table ID autoincrement * fix: do not send unrelated notifications to isolated apps * fix: nip-47 notifications not receiving updated transaction state * fix: migrate existing tables to have autoincrementing primary keys (#274) * fix: migrate existing tables to have autoincrementing primary keys * fix: recreate request and response event tables after apps * fix: remove null from request_events app_id * fix: do not crash when reloading app created page * chore: update pragma commands, add busy_timeout * fix: remove unnecessary migration of user_configs table * chore: update comment on autoincrement migration * feat: sqlite database config improvements * fix: autoincrement migration to delete unlinked app permissions * chore: update tests for dynamic budgets (WIP) * fix: get balance tests * chore: add extra event handler tests * chore: add extra event handler test * chore: add extra multi_pay_invoice tests * chore: transactions service tests (WIP) * chore: add transactions service payment tests * chore: add tests for self payments * fix: notifications tests * chore: add notifications tests for transactions service * chore: add fee reserve tests for transactions service * chore: add list transactions tests * chore: add keysend tests for transactions service * feat: subscribe for payments and invoices (#281) * fix: db transaction should be passed as pointer * feat(lnd): subscribe for payments and invoices * chore: rearrange check for settled * chore: remove TODO * chore: retry on error and add select * chore: publish payment failed event * chore: use json logging * feat: add lnd notification types * chore: remove sleep * fix: incorrect key on transaction list items * fix: test * fix: disable isolated app type on non-supported backends --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com>
2024-07-19 23:30:22 +07:00
lastEventResult := api.db.Where("app_id = ?", dbApp.ID).Order("id desc").Limit(1).Find(&lastEvent)
2024-05-30 00:06:06 +07:00
paySpecificPermission := db.AppPermission{}
appPermissions := []db.AppPermission{}
var expiresAt *time.Time
Feat: dynamic budgets (#226) * feat: add transactions table * feat: add transactions service with makeinvoice method * feat: use internal transactions WIP * feat: check unsettled transactions * feat: use transactions service in nip47 package WIP * feat: use transactions service in NIP-47 handlers * fix: transaction list colors * fix: tests * chore: remove old payments table * fix: return budget usage as sats * feat: use internal transactions table for keysend payments * feat: consume nwc_payment_received event in transaction service (WIP) * feat: update existing transaction from nwc_payment_received event in transactions service * feat: update existing transaction from nwc_payment_sent event in transactions service * feat: handle async payment failed events in transactions service * fix: tests * feat: correctly implement NIP-47 NOT_FOUND error code * feat: intercept self payments * feat: isolated balance and visibility * feat: validate keysend payment does not exceed app internal balance * feat: budget check in transactions service, correctly pass payment errors to NIP-47 response also reduce query duplication * fix: order transactions when looking up transaction * feat: add fee reserves to unsettled outgoing transactions * chore: rename app permissions max amount field * chore: rename transaction amount values to be clearly millisats * chore: merge balance type and visibility into isolated property on apps table * chore: move duplicated permission check from nip-47 controllers to handler * fix: app name in transaction list * Feat: permissions revamp v2 (#273) * feat: revamp permissions component * chore: changes * chore: changes * chore: add view mode for show app screen * chore: further changes * feat: new illustration for linking account (#254) * feat: new illustration for linking account * fix: update paths * fix: icon props (#256) * fix: use date from frontend * chore: add expiryselect component * chore: further changes * chore: further changes * chore: add date-fns for date picker * chore: further changes * chore: further changes * fix: add central LDK gossip node to help gossip new public channels (#262) * fix: make dialog responsive (#258) * chore: further changes * typo * chore: spacing issues * chore: use scopes from capabilities * chore: change scope type descriptions * chore: styling fixes * chore: fix typings * chore: budget renewal component * fix: LDK mark channel as inactive and show error if counterparty forwarding info missing (#267) fix: mark channel as inactive and show error if counterparty forwarding info missing * chore: remove unnecessary dark classes (#255) * fix: links to open first channel in sidebar and onboarding checklist (#268) * feat: improve migrate node UI (#269) * fix: migrate node copy (#270) * fix: stop nostr when app is shutdown and use context to stop lnclient (#271) * fix: permissions revamp WIP * feat: basic isolated apps UI * fix: new app connection, edit app connection, deep linking --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> * fix: make transactions table ID autoincrement * fix: do not send unrelated notifications to isolated apps * fix: nip-47 notifications not receiving updated transaction state * fix: migrate existing tables to have autoincrementing primary keys (#274) * fix: migrate existing tables to have autoincrementing primary keys * fix: recreate request and response event tables after apps * fix: remove null from request_events app_id * fix: do not crash when reloading app created page * chore: update pragma commands, add busy_timeout * fix: remove unnecessary migration of user_configs table * chore: update comment on autoincrement migration * feat: sqlite database config improvements * fix: autoincrement migration to delete unlinked app permissions * chore: update tests for dynamic budgets (WIP) * fix: get balance tests * chore: add extra event handler tests * chore: add extra event handler test * chore: add extra multi_pay_invoice tests * chore: transactions service tests (WIP) * chore: add transactions service payment tests * chore: add tests for self payments * fix: notifications tests * chore: add notifications tests for transactions service * chore: add fee reserve tests for transactions service * chore: add list transactions tests * chore: add keysend tests for transactions service * feat: subscribe for payments and invoices (#281) * fix: db transaction should be passed as pointer * feat(lnd): subscribe for payments and invoices * chore: rearrange check for settled * chore: remove TODO * chore: retry on error and add select * chore: publish payment failed event * chore: use json logging * feat: add lnd notification types * chore: remove sleep * fix: incorrect key on transaction list items * fix: test * fix: disable isolated app type on non-supported backends --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com>
2024-07-19 23:30:22 +07:00
api.db.Where("app_id = ?", dbApp.ID).Find(&appPermissions)
2024-05-30 00:06:06 +07:00
requestMethods := []string{}
for _, appPerm := range appPermissions {
expiresAt = appPerm.ExpiresAt
Feat: dynamic budgets (#226) * feat: add transactions table * feat: add transactions service with makeinvoice method * feat: use internal transactions WIP * feat: check unsettled transactions * feat: use transactions service in nip47 package WIP * feat: use transactions service in NIP-47 handlers * fix: transaction list colors * fix: tests * chore: remove old payments table * fix: return budget usage as sats * feat: use internal transactions table for keysend payments * feat: consume nwc_payment_received event in transaction service (WIP) * feat: update existing transaction from nwc_payment_received event in transactions service * feat: update existing transaction from nwc_payment_sent event in transactions service * feat: handle async payment failed events in transactions service * fix: tests * feat: correctly implement NIP-47 NOT_FOUND error code * feat: intercept self payments * feat: isolated balance and visibility * feat: validate keysend payment does not exceed app internal balance * feat: budget check in transactions service, correctly pass payment errors to NIP-47 response also reduce query duplication * fix: order transactions when looking up transaction * feat: add fee reserves to unsettled outgoing transactions * chore: rename app permissions max amount field * chore: rename transaction amount values to be clearly millisats * chore: merge balance type and visibility into isolated property on apps table * chore: move duplicated permission check from nip-47 controllers to handler * fix: app name in transaction list * Feat: permissions revamp v2 (#273) * feat: revamp permissions component * chore: changes * chore: changes * chore: add view mode for show app screen * chore: further changes * feat: new illustration for linking account (#254) * feat: new illustration for linking account * fix: update paths * fix: icon props (#256) * fix: use date from frontend * chore: add expiryselect component * chore: further changes * chore: further changes * chore: add date-fns for date picker * chore: further changes * chore: further changes * fix: add central LDK gossip node to help gossip new public channels (#262) * fix: make dialog responsive (#258) * chore: further changes * typo * chore: spacing issues * chore: use scopes from capabilities * chore: change scope type descriptions * chore: styling fixes * chore: fix typings * chore: budget renewal component * fix: LDK mark channel as inactive and show error if counterparty forwarding info missing (#267) fix: mark channel as inactive and show error if counterparty forwarding info missing * chore: remove unnecessary dark classes (#255) * fix: links to open first channel in sidebar and onboarding checklist (#268) * feat: improve migrate node UI (#269) * fix: migrate node copy (#270) * fix: stop nostr when app is shutdown and use context to stop lnclient (#271) * fix: permissions revamp WIP * feat: basic isolated apps UI * fix: new app connection, edit app connection, deep linking --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> * fix: make transactions table ID autoincrement * fix: do not send unrelated notifications to isolated apps * fix: nip-47 notifications not receiving updated transaction state * fix: migrate existing tables to have autoincrementing primary keys (#274) * fix: migrate existing tables to have autoincrementing primary keys * fix: recreate request and response event tables after apps * fix: remove null from request_events app_id * fix: do not crash when reloading app created page * chore: update pragma commands, add busy_timeout * fix: remove unnecessary migration of user_configs table * chore: update comment on autoincrement migration * feat: sqlite database config improvements * fix: autoincrement migration to delete unlinked app permissions * chore: update tests for dynamic budgets (WIP) * fix: get balance tests * chore: add extra event handler tests * chore: add extra event handler test * chore: add extra multi_pay_invoice tests * chore: transactions service tests (WIP) * chore: add transactions service payment tests * chore: add tests for self payments * fix: notifications tests * chore: add notifications tests for transactions service * chore: add fee reserve tests for transactions service * chore: add list transactions tests * chore: add keysend tests for transactions service * feat: subscribe for payments and invoices (#281) * fix: db transaction should be passed as pointer * feat(lnd): subscribe for payments and invoices * chore: rearrange check for settled * chore: remove TODO * chore: retry on error and add select * chore: publish payment failed event * chore: use json logging * feat: add lnd notification types * chore: remove sleep * fix: incorrect key on transaction list items * fix: test * fix: disable isolated app type on non-supported backends --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com>
2024-07-19 23:30:22 +07:00
if appPerm.Scope == constants.PAY_INVOICE_SCOPE {
// find the pay_invoice-specific permissions
2024-05-30 00:06:06 +07:00
paySpecificPermission = appPerm
}
requestMethods = append(requestMethods, appPerm.Scope)
2024-05-30 00:06:06 +07:00
}
// renewsIn := ""
2024-06-17 19:42:09 +07:00
budgetUsage := uint64(0)
Feat: dynamic budgets (#226) * feat: add transactions table * feat: add transactions service with makeinvoice method * feat: use internal transactions WIP * feat: check unsettled transactions * feat: use transactions service in nip47 package WIP * feat: use transactions service in NIP-47 handlers * fix: transaction list colors * fix: tests * chore: remove old payments table * fix: return budget usage as sats * feat: use internal transactions table for keysend payments * feat: consume nwc_payment_received event in transaction service (WIP) * feat: update existing transaction from nwc_payment_received event in transactions service * feat: update existing transaction from nwc_payment_sent event in transactions service * feat: handle async payment failed events in transactions service * fix: tests * feat: correctly implement NIP-47 NOT_FOUND error code * feat: intercept self payments * feat: isolated balance and visibility * feat: validate keysend payment does not exceed app internal balance * feat: budget check in transactions service, correctly pass payment errors to NIP-47 response also reduce query duplication * fix: order transactions when looking up transaction * feat: add fee reserves to unsettled outgoing transactions * chore: rename app permissions max amount field * chore: rename transaction amount values to be clearly millisats * chore: merge balance type and visibility into isolated property on apps table * chore: move duplicated permission check from nip-47 controllers to handler * fix: app name in transaction list * Feat: permissions revamp v2 (#273) * feat: revamp permissions component * chore: changes * chore: changes * chore: add view mode for show app screen * chore: further changes * feat: new illustration for linking account (#254) * feat: new illustration for linking account * fix: update paths * fix: icon props (#256) * fix: use date from frontend * chore: add expiryselect component * chore: further changes * chore: further changes * chore: add date-fns for date picker * chore: further changes * chore: further changes * fix: add central LDK gossip node to help gossip new public channels (#262) * fix: make dialog responsive (#258) * chore: further changes * typo * chore: spacing issues * chore: use scopes from capabilities * chore: change scope type descriptions * chore: styling fixes * chore: fix typings * chore: budget renewal component * fix: LDK mark channel as inactive and show error if counterparty forwarding info missing (#267) fix: mark channel as inactive and show error if counterparty forwarding info missing * chore: remove unnecessary dark classes (#255) * fix: links to open first channel in sidebar and onboarding checklist (#268) * feat: improve migrate node UI (#269) * fix: migrate node copy (#270) * fix: stop nostr when app is shutdown and use context to stop lnclient (#271) * fix: permissions revamp WIP * feat: basic isolated apps UI * fix: new app connection, edit app connection, deep linking --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> * fix: make transactions table ID autoincrement * fix: do not send unrelated notifications to isolated apps * fix: nip-47 notifications not receiving updated transaction state * fix: migrate existing tables to have autoincrementing primary keys (#274) * fix: migrate existing tables to have autoincrementing primary keys * fix: recreate request and response event tables after apps * fix: remove null from request_events app_id * fix: do not crash when reloading app created page * chore: update pragma commands, add busy_timeout * fix: remove unnecessary migration of user_configs table * chore: update comment on autoincrement migration * feat: sqlite database config improvements * fix: autoincrement migration to delete unlinked app permissions * chore: update tests for dynamic budgets (WIP) * fix: get balance tests * chore: add extra event handler tests * chore: add extra event handler test * chore: add extra multi_pay_invoice tests * chore: transactions service tests (WIP) * chore: add transactions service payment tests * chore: add tests for self payments * fix: notifications tests * chore: add notifications tests for transactions service * chore: add fee reserve tests for transactions service * chore: add list transactions tests * chore: add keysend tests for transactions service * feat: subscribe for payments and invoices (#281) * fix: db transaction should be passed as pointer * feat(lnd): subscribe for payments and invoices * chore: rearrange check for settled * chore: remove TODO * chore: retry on error and add select * chore: publish payment failed event * chore: use json logging * feat: add lnd notification types * chore: remove sleep * fix: incorrect key on transaction list items * fix: test * fix: disable isolated app type on non-supported backends --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com>
2024-07-19 23:30:22 +07:00
maxAmount := uint64(paySpecificPermission.MaxAmountSat)
budgetUsage = queries.GetBudgetUsageSat(api.db, &paySpecificPermission)
2024-05-30 00:06:06 +07:00
feat: add uncle jim internal app (#557) * feat: add uncle jim internal app * fix: wrong number in instructions * chore: simplify alby jim internal app copy * Feat: app metadata (#570) * chore: wg.Add() before go (#559) * chore: code cleanup (#558) * Update README.md Add command to make the install script executable in the instructions. * feat: add migration card in wallet screen (#555) * feat: add migration card in wallet screen * chore: transfer funds if channel exists * chore: typo * chore: improve copy * chore: add transfer funds button * fix: remove duplicate icon --------- Co-authored-by: Roland Bewick <roland.bewick@gmail.com> * chore: run extra workflows on PR (#563) * chore: run extra workflows on PR * fix: pull request workflows * build(deps): bump github.com/nbd-wtf/go-nostr from 0.34.5 to 0.34.10 (#551) Bumps [github.com/nbd-wtf/go-nostr](https://github.com/nbd-wtf/go-nostr) from 0.34.5 to 0.34.10. - [Commits](https://github.com/nbd-wtf/go-nostr/compare/v0.34.5...v0.34.10) --- updated-dependencies: - dependency-name: github.com/nbd-wtf/go-nostr dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump gopkg.in/DataDog/dd-trace-go.v1 from 1.66.0 to 1.67.0 (#552) Bumps gopkg.in/DataDog/dd-trace-go.v1 from 1.66.0 to 1.67.0. --- updated-dependencies: - dependency-name: gopkg.in/DataDog/dd-trace-go.v1 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix: do not render 0 on withdraw onchain funds page when reserve balance is 0 (#549) * chore: update fly default kill timeout to ensure app gracefully shuts down (#547) * feat: app metadata * fix(wails): parse max length in log output endpoint (#568) * fix: alby account image and name on transaction list * fix: vertically center transaction item content * fix: use slashed zero on wallet balance * chore: align app image with app name in transaction list * fix: ensure auth with correct user if refresh token expires (#572) * fix: do not allow editing name of Alby Account connection * fix: change "Create Wallet" to "Create Subaccount" * fix: subaccount copy * chore: update friends and family app icon * fix: update app store images (#574) * fix: update app store images * chore: update paper scissors hodl and zapplanner icons * chore: update lume and habla news icons * chore: resize and compress zapplanner and rps logos --------- Co-authored-by: Roland Bewick <roland.bewick@gmail.com> * feat: add new auto channel flow that works with existing channels (#556) * feat: add new auto channel flow that works with existing channels * chore: remove "first" from auto channel copy * feat: new transaction list item design --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Matjaž Lipuš <matjazl@gmail.com> Co-authored-by: BtcPins <pardus79@gmail.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> Co-authored-by: Adithya Vardhan <imadithyavardhan@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix: copy * fix: less detailed icon for uncle jim app * fix: shorten app description --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Matjaž Lipuš <matjazl@gmail.com> Co-authored-by: BtcPins <pardus79@gmail.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> Co-authored-by: Adithya Vardhan <imadithyavardhan@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: René Aaron <rene@twentyuno.net> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com>
2024-09-02 17:40:34 +07:00
var metadata Metadata
if dbApp.Metadata != nil {
jsonErr := json.Unmarshal(dbApp.Metadata, &metadata)
if jsonErr != nil {
logger.Logger.WithError(jsonErr).WithFields(logrus.Fields{
"app_id": dbApp.ID,
}).Error("Failed to deserialize app metadata")
}
}
2024-05-30 00:06:06 +07:00
response := App{
Feat: dynamic budgets (#226) * feat: add transactions table * feat: add transactions service with makeinvoice method * feat: use internal transactions WIP * feat: check unsettled transactions * feat: use transactions service in nip47 package WIP * feat: use transactions service in NIP-47 handlers * fix: transaction list colors * fix: tests * chore: remove old payments table * fix: return budget usage as sats * feat: use internal transactions table for keysend payments * feat: consume nwc_payment_received event in transaction service (WIP) * feat: update existing transaction from nwc_payment_received event in transactions service * feat: update existing transaction from nwc_payment_sent event in transactions service * feat: handle async payment failed events in transactions service * fix: tests * feat: correctly implement NIP-47 NOT_FOUND error code * feat: intercept self payments * feat: isolated balance and visibility * feat: validate keysend payment does not exceed app internal balance * feat: budget check in transactions service, correctly pass payment errors to NIP-47 response also reduce query duplication * fix: order transactions when looking up transaction * feat: add fee reserves to unsettled outgoing transactions * chore: rename app permissions max amount field * chore: rename transaction amount values to be clearly millisats * chore: merge balance type and visibility into isolated property on apps table * chore: move duplicated permission check from nip-47 controllers to handler * fix: app name in transaction list * Feat: permissions revamp v2 (#273) * feat: revamp permissions component * chore: changes * chore: changes * chore: add view mode for show app screen * chore: further changes * feat: new illustration for linking account (#254) * feat: new illustration for linking account * fix: update paths * fix: icon props (#256) * fix: use date from frontend * chore: add expiryselect component * chore: further changes * chore: further changes * chore: add date-fns for date picker * chore: further changes * chore: further changes * fix: add central LDK gossip node to help gossip new public channels (#262) * fix: make dialog responsive (#258) * chore: further changes * typo * chore: spacing issues * chore: use scopes from capabilities * chore: change scope type descriptions * chore: styling fixes * chore: fix typings * chore: budget renewal component * fix: LDK mark channel as inactive and show error if counterparty forwarding info missing (#267) fix: mark channel as inactive and show error if counterparty forwarding info missing * chore: remove unnecessary dark classes (#255) * fix: links to open first channel in sidebar and onboarding checklist (#268) * feat: improve migrate node UI (#269) * fix: migrate node copy (#270) * fix: stop nostr when app is shutdown and use context to stop lnclient (#271) * fix: permissions revamp WIP * feat: basic isolated apps UI * fix: new app connection, edit app connection, deep linking --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> * fix: make transactions table ID autoincrement * fix: do not send unrelated notifications to isolated apps * fix: nip-47 notifications not receiving updated transaction state * fix: migrate existing tables to have autoincrementing primary keys (#274) * fix: migrate existing tables to have autoincrementing primary keys * fix: recreate request and response event tables after apps * fix: remove null from request_events app_id * fix: do not crash when reloading app created page * chore: update pragma commands, add busy_timeout * fix: remove unnecessary migration of user_configs table * chore: update comment on autoincrement migration * feat: sqlite database config improvements * fix: autoincrement migration to delete unlinked app permissions * chore: update tests for dynamic budgets (WIP) * fix: get balance tests * chore: add extra event handler tests * chore: add extra event handler test * chore: add extra multi_pay_invoice tests * chore: transactions service tests (WIP) * chore: add transactions service payment tests * chore: add tests for self payments * fix: notifications tests * chore: add notifications tests for transactions service * chore: add fee reserve tests for transactions service * chore: add list transactions tests * chore: add keysend tests for transactions service * feat: subscribe for payments and invoices (#281) * fix: db transaction should be passed as pointer * feat(lnd): subscribe for payments and invoices * chore: rearrange check for settled * chore: remove TODO * chore: retry on error and add select * chore: publish payment failed event * chore: use json logging * feat: add lnd notification types * chore: remove sleep * fix: incorrect key on transaction list items * fix: test * fix: disable isolated app type on non-supported backends --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com>
2024-07-19 23:30:22 +07:00
ID: dbApp.ID,
Name: dbApp.Name,
Description: dbApp.Description,
CreatedAt: dbApp.CreatedAt,
UpdatedAt: dbApp.UpdatedAt,
feat: app child key derived from wallet master key (#736) * feat(appwalletKey): add GetBIP32ChildKey * feat: fix interface * feat: adding subscription WiP * feat: handle nostr subscriptions for lifecycle of apps * Delete .idea/.gitignore * Delete .idea/hub.iml * Delete .idea/modules.xml * Delete .idea/vcs.xml * fix: remove unnecessary * fix: missing handling legacy app * fix: review fixes * fix: use app.ID for key calculation instead of passing in event * fix: add TODO * fix: remove unnecessary check * fix: improve err handling and remove check * chore: store master nostr key to avoid deriving each time * chore: rename app nostr_pubkey to app_pubkey, extract app consumers into separate files * chore: finish renaming * fix: update app wallet pubkey on app creation * fix: not NULL check * fix: fix HandleEvent * fix: error handling * fix: error handling * fix: move StartSubscription to start.go * fix: remove duplicated error check * fix: make tests use AppsService for creating apps * chore: remove unused code * chore: minor event handler improvements - fix error code response when failing to update request event - fix log content when failing to decrypt request event - move logging of app to correct place * fix: add event_handler tests for legacy app * chore: add comment about legacy apps in deleteAppConsumer * fix: remove unused app from tests * fix: error handling in startAppWalletSubscription * fix: only create event info and nostr subscription for master key if there are legacy apps * fix: add legacy tests * fix: move fetching of Nip47 event info to deleteAppConsumer * fix: fixed arguments * fix: use require instead of assert * fix: adapt GetAppWalletKey to use DeriveKey with path 1' * fix: for backends that don't use a mnemonic, create appKey from nostrSecretKey * fix: cleanup eventPublisher Subscribers when relay reconnects * fix: bip32.FirstHardenedChild + appID * fix: remove unused env vars * fix: generate new mnemonic if empty * fix: add tests.CreateTestServiceWithMnemonic to fix TestEncryptedBackup * fix: handle both relay and main ctx Done * chore: add keys tests * chore: add extra assertions to keys test * chore: log when legacy app subscription is created * chore: remove unnecessary break * chore: add log when relay is successfully connected * fix: only auto-start node if it has been started before --------- Co-authored-by: Roland Bewick <roland.bewick@gmail.com>
2024-11-07 13:06:01 +01:00
AppPubkey: dbApp.AppPubkey,
ExpiresAt: expiresAt,
Feat: dynamic budgets (#226) * feat: add transactions table * feat: add transactions service with makeinvoice method * feat: use internal transactions WIP * feat: check unsettled transactions * feat: use transactions service in nip47 package WIP * feat: use transactions service in NIP-47 handlers * fix: transaction list colors * fix: tests * chore: remove old payments table * fix: return budget usage as sats * feat: use internal transactions table for keysend payments * feat: consume nwc_payment_received event in transaction service (WIP) * feat: update existing transaction from nwc_payment_received event in transactions service * feat: update existing transaction from nwc_payment_sent event in transactions service * feat: handle async payment failed events in transactions service * fix: tests * feat: correctly implement NIP-47 NOT_FOUND error code * feat: intercept self payments * feat: isolated balance and visibility * feat: validate keysend payment does not exceed app internal balance * feat: budget check in transactions service, correctly pass payment errors to NIP-47 response also reduce query duplication * fix: order transactions when looking up transaction * feat: add fee reserves to unsettled outgoing transactions * chore: rename app permissions max amount field * chore: rename transaction amount values to be clearly millisats * chore: merge balance type and visibility into isolated property on apps table * chore: move duplicated permission check from nip-47 controllers to handler * fix: app name in transaction list * Feat: permissions revamp v2 (#273) * feat: revamp permissions component * chore: changes * chore: changes * chore: add view mode for show app screen * chore: further changes * feat: new illustration for linking account (#254) * feat: new illustration for linking account * fix: update paths * fix: icon props (#256) * fix: use date from frontend * chore: add expiryselect component * chore: further changes * chore: further changes * chore: add date-fns for date picker * chore: further changes * chore: further changes * fix: add central LDK gossip node to help gossip new public channels (#262) * fix: make dialog responsive (#258) * chore: further changes * typo * chore: spacing issues * chore: use scopes from capabilities * chore: change scope type descriptions * chore: styling fixes * chore: fix typings * chore: budget renewal component * fix: LDK mark channel as inactive and show error if counterparty forwarding info missing (#267) fix: mark channel as inactive and show error if counterparty forwarding info missing * chore: remove unnecessary dark classes (#255) * fix: links to open first channel in sidebar and onboarding checklist (#268) * feat: improve migrate node UI (#269) * fix: migrate node copy (#270) * fix: stop nostr when app is shutdown and use context to stop lnclient (#271) * fix: permissions revamp WIP * feat: basic isolated apps UI * fix: new app connection, edit app connection, deep linking --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> * fix: make transactions table ID autoincrement * fix: do not send unrelated notifications to isolated apps * fix: nip-47 notifications not receiving updated transaction state * fix: migrate existing tables to have autoincrementing primary keys (#274) * fix: migrate existing tables to have autoincrementing primary keys * fix: recreate request and response event tables after apps * fix: remove null from request_events app_id * fix: do not crash when reloading app created page * chore: update pragma commands, add busy_timeout * fix: remove unnecessary migration of user_configs table * chore: update comment on autoincrement migration * feat: sqlite database config improvements * fix: autoincrement migration to delete unlinked app permissions * chore: update tests for dynamic budgets (WIP) * fix: get balance tests * chore: add extra event handler tests * chore: add extra event handler test * chore: add extra multi_pay_invoice tests * chore: transactions service tests (WIP) * chore: add transactions service payment tests * chore: add tests for self payments * fix: notifications tests * chore: add notifications tests for transactions service * chore: add fee reserve tests for transactions service * chore: add list transactions tests * chore: add keysend tests for transactions service * feat: subscribe for payments and invoices (#281) * fix: db transaction should be passed as pointer * feat(lnd): subscribe for payments and invoices * chore: rearrange check for settled * chore: remove TODO * chore: retry on error and add select * chore: publish payment failed event * chore: use json logging * feat: add lnd notification types * chore: remove sleep * fix: incorrect key on transaction list items * fix: test * fix: disable isolated app type on non-supported backends --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com>
2024-07-19 23:30:22 +07:00
MaxAmountSat: maxAmount,
Scopes: requestMethods,
BudgetUsage: budgetUsage,
BudgetRenewal: paySpecificPermission.BudgetRenewal,
Feat: dynamic budgets (#226) * feat: add transactions table * feat: add transactions service with makeinvoice method * feat: use internal transactions WIP * feat: check unsettled transactions * feat: use transactions service in nip47 package WIP * feat: use transactions service in NIP-47 handlers * fix: transaction list colors * fix: tests * chore: remove old payments table * fix: return budget usage as sats * feat: use internal transactions table for keysend payments * feat: consume nwc_payment_received event in transaction service (WIP) * feat: update existing transaction from nwc_payment_received event in transactions service * feat: update existing transaction from nwc_payment_sent event in transactions service * feat: handle async payment failed events in transactions service * fix: tests * feat: correctly implement NIP-47 NOT_FOUND error code * feat: intercept self payments * feat: isolated balance and visibility * feat: validate keysend payment does not exceed app internal balance * feat: budget check in transactions service, correctly pass payment errors to NIP-47 response also reduce query duplication * fix: order transactions when looking up transaction * feat: add fee reserves to unsettled outgoing transactions * chore: rename app permissions max amount field * chore: rename transaction amount values to be clearly millisats * chore: merge balance type and visibility into isolated property on apps table * chore: move duplicated permission check from nip-47 controllers to handler * fix: app name in transaction list * Feat: permissions revamp v2 (#273) * feat: revamp permissions component * chore: changes * chore: changes * chore: add view mode for show app screen * chore: further changes * feat: new illustration for linking account (#254) * feat: new illustration for linking account * fix: update paths * fix: icon props (#256) * fix: use date from frontend * chore: add expiryselect component * chore: further changes * chore: further changes * chore: add date-fns for date picker * chore: further changes * chore: further changes * fix: add central LDK gossip node to help gossip new public channels (#262) * fix: make dialog responsive (#258) * chore: further changes * typo * chore: spacing issues * chore: use scopes from capabilities * chore: change scope type descriptions * chore: styling fixes * chore: fix typings * chore: budget renewal component * fix: LDK mark channel as inactive and show error if counterparty forwarding info missing (#267) fix: mark channel as inactive and show error if counterparty forwarding info missing * chore: remove unnecessary dark classes (#255) * fix: links to open first channel in sidebar and onboarding checklist (#268) * feat: improve migrate node UI (#269) * fix: migrate node copy (#270) * fix: stop nostr when app is shutdown and use context to stop lnclient (#271) * fix: permissions revamp WIP * feat: basic isolated apps UI * fix: new app connection, edit app connection, deep linking --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> * fix: make transactions table ID autoincrement * fix: do not send unrelated notifications to isolated apps * fix: nip-47 notifications not receiving updated transaction state * fix: migrate existing tables to have autoincrementing primary keys (#274) * fix: migrate existing tables to have autoincrementing primary keys * fix: recreate request and response event tables after apps * fix: remove null from request_events app_id * fix: do not crash when reloading app created page * chore: update pragma commands, add busy_timeout * fix: remove unnecessary migration of user_configs table * chore: update comment on autoincrement migration * feat: sqlite database config improvements * fix: autoincrement migration to delete unlinked app permissions * chore: update tests for dynamic budgets (WIP) * fix: get balance tests * chore: add extra event handler tests * chore: add extra event handler test * chore: add extra multi_pay_invoice tests * chore: transactions service tests (WIP) * chore: add transactions service payment tests * chore: add tests for self payments * fix: notifications tests * chore: add notifications tests for transactions service * chore: add fee reserve tests for transactions service * chore: add list transactions tests * chore: add keysend tests for transactions service * feat: subscribe for payments and invoices (#281) * fix: db transaction should be passed as pointer * feat(lnd): subscribe for payments and invoices * chore: rearrange check for settled * chore: remove TODO * chore: retry on error and add select * chore: publish payment failed event * chore: use json logging * feat: add lnd notification types * chore: remove sleep * fix: incorrect key on transaction list items * fix: test * fix: disable isolated app type on non-supported backends --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com>
2024-07-19 23:30:22 +07:00
Isolated: dbApp.Isolated,
feat: add uncle jim internal app (#557) * feat: add uncle jim internal app * fix: wrong number in instructions * chore: simplify alby jim internal app copy * Feat: app metadata (#570) * chore: wg.Add() before go (#559) * chore: code cleanup (#558) * Update README.md Add command to make the install script executable in the instructions. * feat: add migration card in wallet screen (#555) * feat: add migration card in wallet screen * chore: transfer funds if channel exists * chore: typo * chore: improve copy * chore: add transfer funds button * fix: remove duplicate icon --------- Co-authored-by: Roland Bewick <roland.bewick@gmail.com> * chore: run extra workflows on PR (#563) * chore: run extra workflows on PR * fix: pull request workflows * build(deps): bump github.com/nbd-wtf/go-nostr from 0.34.5 to 0.34.10 (#551) Bumps [github.com/nbd-wtf/go-nostr](https://github.com/nbd-wtf/go-nostr) from 0.34.5 to 0.34.10. - [Commits](https://github.com/nbd-wtf/go-nostr/compare/v0.34.5...v0.34.10) --- updated-dependencies: - dependency-name: github.com/nbd-wtf/go-nostr dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump gopkg.in/DataDog/dd-trace-go.v1 from 1.66.0 to 1.67.0 (#552) Bumps gopkg.in/DataDog/dd-trace-go.v1 from 1.66.0 to 1.67.0. --- updated-dependencies: - dependency-name: gopkg.in/DataDog/dd-trace-go.v1 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix: do not render 0 on withdraw onchain funds page when reserve balance is 0 (#549) * chore: update fly default kill timeout to ensure app gracefully shuts down (#547) * feat: app metadata * fix(wails): parse max length in log output endpoint (#568) * fix: alby account image and name on transaction list * fix: vertically center transaction item content * fix: use slashed zero on wallet balance * chore: align app image with app name in transaction list * fix: ensure auth with correct user if refresh token expires (#572) * fix: do not allow editing name of Alby Account connection * fix: change "Create Wallet" to "Create Subaccount" * fix: subaccount copy * chore: update friends and family app icon * fix: update app store images (#574) * fix: update app store images * chore: update paper scissors hodl and zapplanner icons * chore: update lume and habla news icons * chore: resize and compress zapplanner and rps logos --------- Co-authored-by: Roland Bewick <roland.bewick@gmail.com> * feat: add new auto channel flow that works with existing channels (#556) * feat: add new auto channel flow that works with existing channels * chore: remove "first" from auto channel copy * feat: new transaction list item design --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Matjaž Lipuš <matjazl@gmail.com> Co-authored-by: BtcPins <pardus79@gmail.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> Co-authored-by: Adithya Vardhan <imadithyavardhan@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix: copy * fix: less detailed icon for uncle jim app * fix: shorten app description --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Matjaž Lipuš <matjazl@gmail.com> Co-authored-by: BtcPins <pardus79@gmail.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> Co-authored-by: Adithya Vardhan <imadithyavardhan@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: René Aaron <rene@twentyuno.net> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com>
2024-09-02 17:40:34 +07:00
Metadata: metadata,
Feat: dynamic budgets (#226) * feat: add transactions table * feat: add transactions service with makeinvoice method * feat: use internal transactions WIP * feat: check unsettled transactions * feat: use transactions service in nip47 package WIP * feat: use transactions service in NIP-47 handlers * fix: transaction list colors * fix: tests * chore: remove old payments table * fix: return budget usage as sats * feat: use internal transactions table for keysend payments * feat: consume nwc_payment_received event in transaction service (WIP) * feat: update existing transaction from nwc_payment_received event in transactions service * feat: update existing transaction from nwc_payment_sent event in transactions service * feat: handle async payment failed events in transactions service * fix: tests * feat: correctly implement NIP-47 NOT_FOUND error code * feat: intercept self payments * feat: isolated balance and visibility * feat: validate keysend payment does not exceed app internal balance * feat: budget check in transactions service, correctly pass payment errors to NIP-47 response also reduce query duplication * fix: order transactions when looking up transaction * feat: add fee reserves to unsettled outgoing transactions * chore: rename app permissions max amount field * chore: rename transaction amount values to be clearly millisats * chore: merge balance type and visibility into isolated property on apps table * chore: move duplicated permission check from nip-47 controllers to handler * fix: app name in transaction list * Feat: permissions revamp v2 (#273) * feat: revamp permissions component * chore: changes * chore: changes * chore: add view mode for show app screen * chore: further changes * feat: new illustration for linking account (#254) * feat: new illustration for linking account * fix: update paths * fix: icon props (#256) * fix: use date from frontend * chore: add expiryselect component * chore: further changes * chore: further changes * chore: add date-fns for date picker * chore: further changes * chore: further changes * fix: add central LDK gossip node to help gossip new public channels (#262) * fix: make dialog responsive (#258) * chore: further changes * typo * chore: spacing issues * chore: use scopes from capabilities * chore: change scope type descriptions * chore: styling fixes * chore: fix typings * chore: budget renewal component * fix: LDK mark channel as inactive and show error if counterparty forwarding info missing (#267) fix: mark channel as inactive and show error if counterparty forwarding info missing * chore: remove unnecessary dark classes (#255) * fix: links to open first channel in sidebar and onboarding checklist (#268) * feat: improve migrate node UI (#269) * fix: migrate node copy (#270) * fix: stop nostr when app is shutdown and use context to stop lnclient (#271) * fix: permissions revamp WIP * feat: basic isolated apps UI * fix: new app connection, edit app connection, deep linking --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> * fix: make transactions table ID autoincrement * fix: do not send unrelated notifications to isolated apps * fix: nip-47 notifications not receiving updated transaction state * fix: migrate existing tables to have autoincrementing primary keys (#274) * fix: migrate existing tables to have autoincrementing primary keys * fix: recreate request and response event tables after apps * fix: remove null from request_events app_id * fix: do not crash when reloading app created page * chore: update pragma commands, add busy_timeout * fix: remove unnecessary migration of user_configs table * chore: update comment on autoincrement migration * feat: sqlite database config improvements * fix: autoincrement migration to delete unlinked app permissions * chore: update tests for dynamic budgets (WIP) * fix: get balance tests * chore: add extra event handler tests * chore: add extra event handler test * chore: add extra multi_pay_invoice tests * chore: transactions service tests (WIP) * chore: add transactions service payment tests * chore: add tests for self payments * fix: notifications tests * chore: add notifications tests for transactions service * chore: add fee reserve tests for transactions service * chore: add list transactions tests * chore: add keysend tests for transactions service * feat: subscribe for payments and invoices (#281) * fix: db transaction should be passed as pointer * feat(lnd): subscribe for payments and invoices * chore: rearrange check for settled * chore: remove TODO * chore: retry on error and add select * chore: publish payment failed event * chore: use json logging * feat: add lnd notification types * chore: remove sleep * fix: incorrect key on transaction list items * fix: test * fix: disable isolated app type on non-supported backends --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com>
2024-07-19 23:30:22 +07:00
}
if dbApp.Isolated {
response.Balance = queries.GetIsolatedBalance(api.db, dbApp.ID)
2024-05-30 00:06:06 +07:00
}
if lastEventResult.RowsAffected > 0 {
response.LastEventAt = &lastEvent.CreatedAt
}
return &response
}
func (api *api) ListApps() ([]App, error) {
// TODO: join dbApps and permissions
dbApps := []db.App{}
err := api.db.Find(&dbApps).Error
if err != nil {
logger.Logger.WithError(err).Error("Failed to list apps")
return nil, err
}
2024-05-30 00:06:06 +07:00
appPermissions := []db.AppPermission{}
err = api.db.Find(&appPermissions).Error
if err != nil {
logger.Logger.WithError(err).Error("Failed to list app permissions")
return nil, err
}
2024-05-30 00:06:06 +07:00
permissionsMap := make(map[uint][]db.AppPermission)
for _, perm := range appPermissions {
2024-05-30 00:06:06 +07:00
permissionsMap[perm.AppId] = append(permissionsMap[perm.AppId], perm)
}
apiApps := []App{}
Feat: dynamic budgets (#226) * feat: add transactions table * feat: add transactions service with makeinvoice method * feat: use internal transactions WIP * feat: check unsettled transactions * feat: use transactions service in nip47 package WIP * feat: use transactions service in NIP-47 handlers * fix: transaction list colors * fix: tests * chore: remove old payments table * fix: return budget usage as sats * feat: use internal transactions table for keysend payments * feat: consume nwc_payment_received event in transaction service (WIP) * feat: update existing transaction from nwc_payment_received event in transactions service * feat: update existing transaction from nwc_payment_sent event in transactions service * feat: handle async payment failed events in transactions service * fix: tests * feat: correctly implement NIP-47 NOT_FOUND error code * feat: intercept self payments * feat: isolated balance and visibility * feat: validate keysend payment does not exceed app internal balance * feat: budget check in transactions service, correctly pass payment errors to NIP-47 response also reduce query duplication * fix: order transactions when looking up transaction * feat: add fee reserves to unsettled outgoing transactions * chore: rename app permissions max amount field * chore: rename transaction amount values to be clearly millisats * chore: merge balance type and visibility into isolated property on apps table * chore: move duplicated permission check from nip-47 controllers to handler * fix: app name in transaction list * Feat: permissions revamp v2 (#273) * feat: revamp permissions component * chore: changes * chore: changes * chore: add view mode for show app screen * chore: further changes * feat: new illustration for linking account (#254) * feat: new illustration for linking account * fix: update paths * fix: icon props (#256) * fix: use date from frontend * chore: add expiryselect component * chore: further changes * chore: further changes * chore: add date-fns for date picker * chore: further changes * chore: further changes * fix: add central LDK gossip node to help gossip new public channels (#262) * fix: make dialog responsive (#258) * chore: further changes * typo * chore: spacing issues * chore: use scopes from capabilities * chore: change scope type descriptions * chore: styling fixes * chore: fix typings * chore: budget renewal component * fix: LDK mark channel as inactive and show error if counterparty forwarding info missing (#267) fix: mark channel as inactive and show error if counterparty forwarding info missing * chore: remove unnecessary dark classes (#255) * fix: links to open first channel in sidebar and onboarding checklist (#268) * feat: improve migrate node UI (#269) * fix: migrate node copy (#270) * fix: stop nostr when app is shutdown and use context to stop lnclient (#271) * fix: permissions revamp WIP * feat: basic isolated apps UI * fix: new app connection, edit app connection, deep linking --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> * fix: make transactions table ID autoincrement * fix: do not send unrelated notifications to isolated apps * fix: nip-47 notifications not receiving updated transaction state * fix: migrate existing tables to have autoincrementing primary keys (#274) * fix: migrate existing tables to have autoincrementing primary keys * fix: recreate request and response event tables after apps * fix: remove null from request_events app_id * fix: do not crash when reloading app created page * chore: update pragma commands, add busy_timeout * fix: remove unnecessary migration of user_configs table * chore: update comment on autoincrement migration * feat: sqlite database config improvements * fix: autoincrement migration to delete unlinked app permissions * chore: update tests for dynamic budgets (WIP) * fix: get balance tests * chore: add extra event handler tests * chore: add extra event handler test * chore: add extra multi_pay_invoice tests * chore: transactions service tests (WIP) * chore: add transactions service payment tests * chore: add tests for self payments * fix: notifications tests * chore: add notifications tests for transactions service * chore: add fee reserve tests for transactions service * chore: add list transactions tests * chore: add keysend tests for transactions service * feat: subscribe for payments and invoices (#281) * fix: db transaction should be passed as pointer * feat(lnd): subscribe for payments and invoices * chore: rearrange check for settled * chore: remove TODO * chore: retry on error and add select * chore: publish payment failed event * chore: use json logging * feat: add lnd notification types * chore: remove sleep * fix: incorrect key on transaction list items * fix: test * fix: disable isolated app type on non-supported backends --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com>
2024-07-19 23:30:22 +07:00
for _, dbApp := range dbApps {
2024-05-30 00:06:06 +07:00
apiApp := App{
Feat: dynamic budgets (#226) * feat: add transactions table * feat: add transactions service with makeinvoice method * feat: use internal transactions WIP * feat: check unsettled transactions * feat: use transactions service in nip47 package WIP * feat: use transactions service in NIP-47 handlers * fix: transaction list colors * fix: tests * chore: remove old payments table * fix: return budget usage as sats * feat: use internal transactions table for keysend payments * feat: consume nwc_payment_received event in transaction service (WIP) * feat: update existing transaction from nwc_payment_received event in transactions service * feat: update existing transaction from nwc_payment_sent event in transactions service * feat: handle async payment failed events in transactions service * fix: tests * feat: correctly implement NIP-47 NOT_FOUND error code * feat: intercept self payments * feat: isolated balance and visibility * feat: validate keysend payment does not exceed app internal balance * feat: budget check in transactions service, correctly pass payment errors to NIP-47 response also reduce query duplication * fix: order transactions when looking up transaction * feat: add fee reserves to unsettled outgoing transactions * chore: rename app permissions max amount field * chore: rename transaction amount values to be clearly millisats * chore: merge balance type and visibility into isolated property on apps table * chore: move duplicated permission check from nip-47 controllers to handler * fix: app name in transaction list * Feat: permissions revamp v2 (#273) * feat: revamp permissions component * chore: changes * chore: changes * chore: add view mode for show app screen * chore: further changes * feat: new illustration for linking account (#254) * feat: new illustration for linking account * fix: update paths * fix: icon props (#256) * fix: use date from frontend * chore: add expiryselect component * chore: further changes * chore: further changes * chore: add date-fns for date picker * chore: further changes * chore: further changes * fix: add central LDK gossip node to help gossip new public channels (#262) * fix: make dialog responsive (#258) * chore: further changes * typo * chore: spacing issues * chore: use scopes from capabilities * chore: change scope type descriptions * chore: styling fixes * chore: fix typings * chore: budget renewal component * fix: LDK mark channel as inactive and show error if counterparty forwarding info missing (#267) fix: mark channel as inactive and show error if counterparty forwarding info missing * chore: remove unnecessary dark classes (#255) * fix: links to open first channel in sidebar and onboarding checklist (#268) * feat: improve migrate node UI (#269) * fix: migrate node copy (#270) * fix: stop nostr when app is shutdown and use context to stop lnclient (#271) * fix: permissions revamp WIP * feat: basic isolated apps UI * fix: new app connection, edit app connection, deep linking --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> * fix: make transactions table ID autoincrement * fix: do not send unrelated notifications to isolated apps * fix: nip-47 notifications not receiving updated transaction state * fix: migrate existing tables to have autoincrementing primary keys (#274) * fix: migrate existing tables to have autoincrementing primary keys * fix: recreate request and response event tables after apps * fix: remove null from request_events app_id * fix: do not crash when reloading app created page * chore: update pragma commands, add busy_timeout * fix: remove unnecessary migration of user_configs table * chore: update comment on autoincrement migration * feat: sqlite database config improvements * fix: autoincrement migration to delete unlinked app permissions * chore: update tests for dynamic budgets (WIP) * fix: get balance tests * chore: add extra event handler tests * chore: add extra event handler test * chore: add extra multi_pay_invoice tests * chore: transactions service tests (WIP) * chore: add transactions service payment tests * chore: add tests for self payments * fix: notifications tests * chore: add notifications tests for transactions service * chore: add fee reserve tests for transactions service * chore: add list transactions tests * chore: add keysend tests for transactions service * feat: subscribe for payments and invoices (#281) * fix: db transaction should be passed as pointer * feat(lnd): subscribe for payments and invoices * chore: rearrange check for settled * chore: remove TODO * chore: retry on error and add select * chore: publish payment failed event * chore: use json logging * feat: add lnd notification types * chore: remove sleep * fix: incorrect key on transaction list items * fix: test * fix: disable isolated app type on non-supported backends --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com>
2024-07-19 23:30:22 +07:00
ID: dbApp.ID,
Name: dbApp.Name,
Description: dbApp.Description,
CreatedAt: dbApp.CreatedAt,
UpdatedAt: dbApp.UpdatedAt,
feat: app child key derived from wallet master key (#736) * feat(appwalletKey): add GetBIP32ChildKey * feat: fix interface * feat: adding subscription WiP * feat: handle nostr subscriptions for lifecycle of apps * Delete .idea/.gitignore * Delete .idea/hub.iml * Delete .idea/modules.xml * Delete .idea/vcs.xml * fix: remove unnecessary * fix: missing handling legacy app * fix: review fixes * fix: use app.ID for key calculation instead of passing in event * fix: add TODO * fix: remove unnecessary check * fix: improve err handling and remove check * chore: store master nostr key to avoid deriving each time * chore: rename app nostr_pubkey to app_pubkey, extract app consumers into separate files * chore: finish renaming * fix: update app wallet pubkey on app creation * fix: not NULL check * fix: fix HandleEvent * fix: error handling * fix: error handling * fix: move StartSubscription to start.go * fix: remove duplicated error check * fix: make tests use AppsService for creating apps * chore: remove unused code * chore: minor event handler improvements - fix error code response when failing to update request event - fix log content when failing to decrypt request event - move logging of app to correct place * fix: add event_handler tests for legacy app * chore: add comment about legacy apps in deleteAppConsumer * fix: remove unused app from tests * fix: error handling in startAppWalletSubscription * fix: only create event info and nostr subscription for master key if there are legacy apps * fix: add legacy tests * fix: move fetching of Nip47 event info to deleteAppConsumer * fix: fixed arguments * fix: use require instead of assert * fix: adapt GetAppWalletKey to use DeriveKey with path 1' * fix: for backends that don't use a mnemonic, create appKey from nostrSecretKey * fix: cleanup eventPublisher Subscribers when relay reconnects * fix: bip32.FirstHardenedChild + appID * fix: remove unused env vars * fix: generate new mnemonic if empty * fix: add tests.CreateTestServiceWithMnemonic to fix TestEncryptedBackup * fix: handle both relay and main ctx Done * chore: add keys tests * chore: add extra assertions to keys test * chore: log when legacy app subscription is created * chore: remove unnecessary break * chore: add log when relay is successfully connected * fix: only auto-start node if it has been started before --------- Co-authored-by: Roland Bewick <roland.bewick@gmail.com>
2024-11-07 13:06:01 +01:00
AppPubkey: dbApp.AppPubkey,
Feat: dynamic budgets (#226) * feat: add transactions table * feat: add transactions service with makeinvoice method * feat: use internal transactions WIP * feat: check unsettled transactions * feat: use transactions service in nip47 package WIP * feat: use transactions service in NIP-47 handlers * fix: transaction list colors * fix: tests * chore: remove old payments table * fix: return budget usage as sats * feat: use internal transactions table for keysend payments * feat: consume nwc_payment_received event in transaction service (WIP) * feat: update existing transaction from nwc_payment_received event in transactions service * feat: update existing transaction from nwc_payment_sent event in transactions service * feat: handle async payment failed events in transactions service * fix: tests * feat: correctly implement NIP-47 NOT_FOUND error code * feat: intercept self payments * feat: isolated balance and visibility * feat: validate keysend payment does not exceed app internal balance * feat: budget check in transactions service, correctly pass payment errors to NIP-47 response also reduce query duplication * fix: order transactions when looking up transaction * feat: add fee reserves to unsettled outgoing transactions * chore: rename app permissions max amount field * chore: rename transaction amount values to be clearly millisats * chore: merge balance type and visibility into isolated property on apps table * chore: move duplicated permission check from nip-47 controllers to handler * fix: app name in transaction list * Feat: permissions revamp v2 (#273) * feat: revamp permissions component * chore: changes * chore: changes * chore: add view mode for show app screen * chore: further changes * feat: new illustration for linking account (#254) * feat: new illustration for linking account * fix: update paths * fix: icon props (#256) * fix: use date from frontend * chore: add expiryselect component * chore: further changes * chore: further changes * chore: add date-fns for date picker * chore: further changes * chore: further changes * fix: add central LDK gossip node to help gossip new public channels (#262) * fix: make dialog responsive (#258) * chore: further changes * typo * chore: spacing issues * chore: use scopes from capabilities * chore: change scope type descriptions * chore: styling fixes * chore: fix typings * chore: budget renewal component * fix: LDK mark channel as inactive and show error if counterparty forwarding info missing (#267) fix: mark channel as inactive and show error if counterparty forwarding info missing * chore: remove unnecessary dark classes (#255) * fix: links to open first channel in sidebar and onboarding checklist (#268) * feat: improve migrate node UI (#269) * fix: migrate node copy (#270) * fix: stop nostr when app is shutdown and use context to stop lnclient (#271) * fix: permissions revamp WIP * feat: basic isolated apps UI * fix: new app connection, edit app connection, deep linking --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> * fix: make transactions table ID autoincrement * fix: do not send unrelated notifications to isolated apps * fix: nip-47 notifications not receiving updated transaction state * fix: migrate existing tables to have autoincrementing primary keys (#274) * fix: migrate existing tables to have autoincrementing primary keys * fix: recreate request and response event tables after apps * fix: remove null from request_events app_id * fix: do not crash when reloading app created page * chore: update pragma commands, add busy_timeout * fix: remove unnecessary migration of user_configs table * chore: update comment on autoincrement migration * feat: sqlite database config improvements * fix: autoincrement migration to delete unlinked app permissions * chore: update tests for dynamic budgets (WIP) * fix: get balance tests * chore: add extra event handler tests * chore: add extra event handler test * chore: add extra multi_pay_invoice tests * chore: transactions service tests (WIP) * chore: add transactions service payment tests * chore: add tests for self payments * fix: notifications tests * chore: add notifications tests for transactions service * chore: add fee reserve tests for transactions service * chore: add list transactions tests * chore: add keysend tests for transactions service * feat: subscribe for payments and invoices (#281) * fix: db transaction should be passed as pointer * feat(lnd): subscribe for payments and invoices * chore: rearrange check for settled * chore: remove TODO * chore: retry on error and add select * chore: publish payment failed event * chore: use json logging * feat: add lnd notification types * chore: remove sleep * fix: incorrect key on transaction list items * fix: test * fix: disable isolated app type on non-supported backends --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com>
2024-07-19 23:30:22 +07:00
Isolated: dbApp.Isolated,
}
if dbApp.Isolated {
apiApp.Balance = queries.GetIsolatedBalance(api.db, dbApp.ID)
2024-05-30 00:06:06 +07:00
}
Feat: dynamic budgets (#226) * feat: add transactions table * feat: add transactions service with makeinvoice method * feat: use internal transactions WIP * feat: check unsettled transactions * feat: use transactions service in nip47 package WIP * feat: use transactions service in NIP-47 handlers * fix: transaction list colors * fix: tests * chore: remove old payments table * fix: return budget usage as sats * feat: use internal transactions table for keysend payments * feat: consume nwc_payment_received event in transaction service (WIP) * feat: update existing transaction from nwc_payment_received event in transactions service * feat: update existing transaction from nwc_payment_sent event in transactions service * feat: handle async payment failed events in transactions service * fix: tests * feat: correctly implement NIP-47 NOT_FOUND error code * feat: intercept self payments * feat: isolated balance and visibility * feat: validate keysend payment does not exceed app internal balance * feat: budget check in transactions service, correctly pass payment errors to NIP-47 response also reduce query duplication * fix: order transactions when looking up transaction * feat: add fee reserves to unsettled outgoing transactions * chore: rename app permissions max amount field * chore: rename transaction amount values to be clearly millisats * chore: merge balance type and visibility into isolated property on apps table * chore: move duplicated permission check from nip-47 controllers to handler * fix: app name in transaction list * Feat: permissions revamp v2 (#273) * feat: revamp permissions component * chore: changes * chore: changes * chore: add view mode for show app screen * chore: further changes * feat: new illustration for linking account (#254) * feat: new illustration for linking account * fix: update paths * fix: icon props (#256) * fix: use date from frontend * chore: add expiryselect component * chore: further changes * chore: further changes * chore: add date-fns for date picker * chore: further changes * chore: further changes * fix: add central LDK gossip node to help gossip new public channels (#262) * fix: make dialog responsive (#258) * chore: further changes * typo * chore: spacing issues * chore: use scopes from capabilities * chore: change scope type descriptions * chore: styling fixes * chore: fix typings * chore: budget renewal component * fix: LDK mark channel as inactive and show error if counterparty forwarding info missing (#267) fix: mark channel as inactive and show error if counterparty forwarding info missing * chore: remove unnecessary dark classes (#255) * fix: links to open first channel in sidebar and onboarding checklist (#268) * feat: improve migrate node UI (#269) * fix: migrate node copy (#270) * fix: stop nostr when app is shutdown and use context to stop lnclient (#271) * fix: permissions revamp WIP * feat: basic isolated apps UI * fix: new app connection, edit app connection, deep linking --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> * fix: make transactions table ID autoincrement * fix: do not send unrelated notifications to isolated apps * fix: nip-47 notifications not receiving updated transaction state * fix: migrate existing tables to have autoincrementing primary keys (#274) * fix: migrate existing tables to have autoincrementing primary keys * fix: recreate request and response event tables after apps * fix: remove null from request_events app_id * fix: do not crash when reloading app created page * chore: update pragma commands, add busy_timeout * fix: remove unnecessary migration of user_configs table * chore: update comment on autoincrement migration * feat: sqlite database config improvements * fix: autoincrement migration to delete unlinked app permissions * chore: update tests for dynamic budgets (WIP) * fix: get balance tests * chore: add extra event handler tests * chore: add extra event handler test * chore: add extra multi_pay_invoice tests * chore: transactions service tests (WIP) * chore: add transactions service payment tests * chore: add tests for self payments * fix: notifications tests * chore: add notifications tests for transactions service * chore: add fee reserve tests for transactions service * chore: add list transactions tests * chore: add keysend tests for transactions service * feat: subscribe for payments and invoices (#281) * fix: db transaction should be passed as pointer * feat(lnd): subscribe for payments and invoices * chore: rearrange check for settled * chore: remove TODO * chore: retry on error and add select * chore: publish payment failed event * chore: use json logging * feat: add lnd notification types * chore: remove sleep * fix: incorrect key on transaction list items * fix: test * fix: disable isolated app type on non-supported backends --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com>
2024-07-19 23:30:22 +07:00
for _, appPermission := range permissionsMap[dbApp.ID] {
apiApp.Scopes = append(apiApp.Scopes, appPermission.Scope)
apiApp.ExpiresAt = appPermission.ExpiresAt
Feat: dynamic budgets (#226) * feat: add transactions table * feat: add transactions service with makeinvoice method * feat: use internal transactions WIP * feat: check unsettled transactions * feat: use transactions service in nip47 package WIP * feat: use transactions service in NIP-47 handlers * fix: transaction list colors * fix: tests * chore: remove old payments table * fix: return budget usage as sats * feat: use internal transactions table for keysend payments * feat: consume nwc_payment_received event in transaction service (WIP) * feat: update existing transaction from nwc_payment_received event in transactions service * feat: update existing transaction from nwc_payment_sent event in transactions service * feat: handle async payment failed events in transactions service * fix: tests * feat: correctly implement NIP-47 NOT_FOUND error code * feat: intercept self payments * feat: isolated balance and visibility * feat: validate keysend payment does not exceed app internal balance * feat: budget check in transactions service, correctly pass payment errors to NIP-47 response also reduce query duplication * fix: order transactions when looking up transaction * feat: add fee reserves to unsettled outgoing transactions * chore: rename app permissions max amount field * chore: rename transaction amount values to be clearly millisats * chore: merge balance type and visibility into isolated property on apps table * chore: move duplicated permission check from nip-47 controllers to handler * fix: app name in transaction list * Feat: permissions revamp v2 (#273) * feat: revamp permissions component * chore: changes * chore: changes * chore: add view mode for show app screen * chore: further changes * feat: new illustration for linking account (#254) * feat: new illustration for linking account * fix: update paths * fix: icon props (#256) * fix: use date from frontend * chore: add expiryselect component * chore: further changes * chore: further changes * chore: add date-fns for date picker * chore: further changes * chore: further changes * fix: add central LDK gossip node to help gossip new public channels (#262) * fix: make dialog responsive (#258) * chore: further changes * typo * chore: spacing issues * chore: use scopes from capabilities * chore: change scope type descriptions * chore: styling fixes * chore: fix typings * chore: budget renewal component * fix: LDK mark channel as inactive and show error if counterparty forwarding info missing (#267) fix: mark channel as inactive and show error if counterparty forwarding info missing * chore: remove unnecessary dark classes (#255) * fix: links to open first channel in sidebar and onboarding checklist (#268) * feat: improve migrate node UI (#269) * fix: migrate node copy (#270) * fix: stop nostr when app is shutdown and use context to stop lnclient (#271) * fix: permissions revamp WIP * feat: basic isolated apps UI * fix: new app connection, edit app connection, deep linking --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> * fix: make transactions table ID autoincrement * fix: do not send unrelated notifications to isolated apps * fix: nip-47 notifications not receiving updated transaction state * fix: migrate existing tables to have autoincrementing primary keys (#274) * fix: migrate existing tables to have autoincrementing primary keys * fix: recreate request and response event tables after apps * fix: remove null from request_events app_id * fix: do not crash when reloading app created page * chore: update pragma commands, add busy_timeout * fix: remove unnecessary migration of user_configs table * chore: update comment on autoincrement migration * feat: sqlite database config improvements * fix: autoincrement migration to delete unlinked app permissions * chore: update tests for dynamic budgets (WIP) * fix: get balance tests * chore: add extra event handler tests * chore: add extra event handler test * chore: add extra multi_pay_invoice tests * chore: transactions service tests (WIP) * chore: add transactions service payment tests * chore: add tests for self payments * fix: notifications tests * chore: add notifications tests for transactions service * chore: add fee reserve tests for transactions service * chore: add list transactions tests * chore: add keysend tests for transactions service * feat: subscribe for payments and invoices (#281) * fix: db transaction should be passed as pointer * feat(lnd): subscribe for payments and invoices * chore: rearrange check for settled * chore: remove TODO * chore: retry on error and add select * chore: publish payment failed event * chore: use json logging * feat: add lnd notification types * chore: remove sleep * fix: incorrect key on transaction list items * fix: test * fix: disable isolated app type on non-supported backends --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com>
2024-07-19 23:30:22 +07:00
if appPermission.Scope == constants.PAY_INVOICE_SCOPE {
apiApp.BudgetRenewal = appPermission.BudgetRenewal
Feat: dynamic budgets (#226) * feat: add transactions table * feat: add transactions service with makeinvoice method * feat: use internal transactions WIP * feat: check unsettled transactions * feat: use transactions service in nip47 package WIP * feat: use transactions service in NIP-47 handlers * fix: transaction list colors * fix: tests * chore: remove old payments table * fix: return budget usage as sats * feat: use internal transactions table for keysend payments * feat: consume nwc_payment_received event in transaction service (WIP) * feat: update existing transaction from nwc_payment_received event in transactions service * feat: update existing transaction from nwc_payment_sent event in transactions service * feat: handle async payment failed events in transactions service * fix: tests * feat: correctly implement NIP-47 NOT_FOUND error code * feat: intercept self payments * feat: isolated balance and visibility * feat: validate keysend payment does not exceed app internal balance * feat: budget check in transactions service, correctly pass payment errors to NIP-47 response also reduce query duplication * fix: order transactions when looking up transaction * feat: add fee reserves to unsettled outgoing transactions * chore: rename app permissions max amount field * chore: rename transaction amount values to be clearly millisats * chore: merge balance type and visibility into isolated property on apps table * chore: move duplicated permission check from nip-47 controllers to handler * fix: app name in transaction list * Feat: permissions revamp v2 (#273) * feat: revamp permissions component * chore: changes * chore: changes * chore: add view mode for show app screen * chore: further changes * feat: new illustration for linking account (#254) * feat: new illustration for linking account * fix: update paths * fix: icon props (#256) * fix: use date from frontend * chore: add expiryselect component * chore: further changes * chore: further changes * chore: add date-fns for date picker * chore: further changes * chore: further changes * fix: add central LDK gossip node to help gossip new public channels (#262) * fix: make dialog responsive (#258) * chore: further changes * typo * chore: spacing issues * chore: use scopes from capabilities * chore: change scope type descriptions * chore: styling fixes * chore: fix typings * chore: budget renewal component * fix: LDK mark channel as inactive and show error if counterparty forwarding info missing (#267) fix: mark channel as inactive and show error if counterparty forwarding info missing * chore: remove unnecessary dark classes (#255) * fix: links to open first channel in sidebar and onboarding checklist (#268) * feat: improve migrate node UI (#269) * fix: migrate node copy (#270) * fix: stop nostr when app is shutdown and use context to stop lnclient (#271) * fix: permissions revamp WIP * feat: basic isolated apps UI * fix: new app connection, edit app connection, deep linking --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> * fix: make transactions table ID autoincrement * fix: do not send unrelated notifications to isolated apps * fix: nip-47 notifications not receiving updated transaction state * fix: migrate existing tables to have autoincrementing primary keys (#274) * fix: migrate existing tables to have autoincrementing primary keys * fix: recreate request and response event tables after apps * fix: remove null from request_events app_id * fix: do not crash when reloading app created page * chore: update pragma commands, add busy_timeout * fix: remove unnecessary migration of user_configs table * chore: update comment on autoincrement migration * feat: sqlite database config improvements * fix: autoincrement migration to delete unlinked app permissions * chore: update tests for dynamic budgets (WIP) * fix: get balance tests * chore: add extra event handler tests * chore: add extra event handler test * chore: add extra multi_pay_invoice tests * chore: transactions service tests (WIP) * chore: add transactions service payment tests * chore: add tests for self payments * fix: notifications tests * chore: add notifications tests for transactions service * chore: add fee reserve tests for transactions service * chore: add list transactions tests * chore: add keysend tests for transactions service * feat: subscribe for payments and invoices (#281) * fix: db transaction should be passed as pointer * feat(lnd): subscribe for payments and invoices * chore: rearrange check for settled * chore: remove TODO * chore: retry on error and add select * chore: publish payment failed event * chore: use json logging * feat: add lnd notification types * chore: remove sleep * fix: incorrect key on transaction list items * fix: test * fix: disable isolated app type on non-supported backends --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com>
2024-07-19 23:30:22 +07:00
apiApp.MaxAmountSat = uint64(appPermission.MaxAmountSat)
apiApp.BudgetUsage = queries.GetBudgetUsageSat(api.db, &appPermission)
2024-05-30 00:06:06 +07:00
}
}
var lastEvent db.RequestEvent
lastEventResult := api.db.Where("app_id = ?", dbApp.ID).Order("id desc").Limit(1).Find(&lastEvent)
2024-05-30 00:06:06 +07:00
if lastEventResult.RowsAffected > 0 {
apiApp.LastEventAt = &lastEvent.CreatedAt
}
feat: add uncle jim internal app (#557) * feat: add uncle jim internal app * fix: wrong number in instructions * chore: simplify alby jim internal app copy * Feat: app metadata (#570) * chore: wg.Add() before go (#559) * chore: code cleanup (#558) * Update README.md Add command to make the install script executable in the instructions. * feat: add migration card in wallet screen (#555) * feat: add migration card in wallet screen * chore: transfer funds if channel exists * chore: typo * chore: improve copy * chore: add transfer funds button * fix: remove duplicate icon --------- Co-authored-by: Roland Bewick <roland.bewick@gmail.com> * chore: run extra workflows on PR (#563) * chore: run extra workflows on PR * fix: pull request workflows * build(deps): bump github.com/nbd-wtf/go-nostr from 0.34.5 to 0.34.10 (#551) Bumps [github.com/nbd-wtf/go-nostr](https://github.com/nbd-wtf/go-nostr) from 0.34.5 to 0.34.10. - [Commits](https://github.com/nbd-wtf/go-nostr/compare/v0.34.5...v0.34.10) --- updated-dependencies: - dependency-name: github.com/nbd-wtf/go-nostr dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump gopkg.in/DataDog/dd-trace-go.v1 from 1.66.0 to 1.67.0 (#552) Bumps gopkg.in/DataDog/dd-trace-go.v1 from 1.66.0 to 1.67.0. --- updated-dependencies: - dependency-name: gopkg.in/DataDog/dd-trace-go.v1 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix: do not render 0 on withdraw onchain funds page when reserve balance is 0 (#549) * chore: update fly default kill timeout to ensure app gracefully shuts down (#547) * feat: app metadata * fix(wails): parse max length in log output endpoint (#568) * fix: alby account image and name on transaction list * fix: vertically center transaction item content * fix: use slashed zero on wallet balance * chore: align app image with app name in transaction list * fix: ensure auth with correct user if refresh token expires (#572) * fix: do not allow editing name of Alby Account connection * fix: change "Create Wallet" to "Create Subaccount" * fix: subaccount copy * chore: update friends and family app icon * fix: update app store images (#574) * fix: update app store images * chore: update paper scissors hodl and zapplanner icons * chore: update lume and habla news icons * chore: resize and compress zapplanner and rps logos --------- Co-authored-by: Roland Bewick <roland.bewick@gmail.com> * feat: add new auto channel flow that works with existing channels (#556) * feat: add new auto channel flow that works with existing channels * chore: remove "first" from auto channel copy * feat: new transaction list item design --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Matjaž Lipuš <matjazl@gmail.com> Co-authored-by: BtcPins <pardus79@gmail.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> Co-authored-by: Adithya Vardhan <imadithyavardhan@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix: copy * fix: less detailed icon for uncle jim app * fix: shorten app description --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Matjaž Lipuš <matjazl@gmail.com> Co-authored-by: BtcPins <pardus79@gmail.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> Co-authored-by: Adithya Vardhan <imadithyavardhan@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: René Aaron <rene@twentyuno.net> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com>
2024-09-02 17:40:34 +07:00
var metadata Metadata
if dbApp.Metadata != nil {
jsonErr := json.Unmarshal(dbApp.Metadata, &metadata)
if jsonErr != nil {
logger.Logger.WithError(jsonErr).WithFields(logrus.Fields{
"app_id": dbApp.ID,
}).Error("Failed to deserialize app metadata")
}
apiApp.Metadata = metadata
}
2024-05-30 00:06:06 +07:00
apiApps = append(apiApps, apiApp)
}
return apiApps, nil
}
func (api *api) ListChannels(ctx context.Context) ([]Channel, error) {
2024-05-30 00:06:06 +07:00
if api.svc.GetLNClient() == nil {
return nil, errors.New("LNClient not started")
}
channels, err := api.svc.GetLNClient().ListChannels(ctx)
if err != nil {
return nil, err
}
apiChannels := []Channel{}
for _, channel := range channels {
status := "offline"
if channel.Active {
status = "online"
} else if channel.Confirmations != nil && channel.ConfirmationsRequired != nil && *channel.ConfirmationsRequired > *channel.Confirmations {
status = "opening"
}
apiChannels = append(apiChannels, Channel{
LocalBalance: channel.LocalBalance,
LocalSpendableBalance: channel.LocalSpendableBalance,
RemoteBalance: channel.RemoteBalance,
Id: channel.Id,
RemotePubkey: channel.RemotePubkey,
FundingTxId: channel.FundingTxId,
FundingTxVout: channel.FundingTxVout,
Active: channel.Active,
Public: channel.Public,
InternalChannel: channel.InternalChannel,
Confirmations: channel.Confirmations,
ConfirmationsRequired: channel.ConfirmationsRequired,
ForwardingFeeBaseMsat: channel.ForwardingFeeBaseMsat,
UnspendablePunishmentReserve: channel.UnspendablePunishmentReserve,
CounterpartyUnspendablePunishmentReserve: channel.CounterpartyUnspendablePunishmentReserve,
Error: channel.Error,
IsOutbound: channel.IsOutbound,
Status: status,
})
}
return apiChannels, nil
2024-05-30 00:06:06 +07:00
}
func (api *api) GetChannelPeerSuggestions(ctx context.Context) ([]alby.ChannelPeerSuggestion, error) {
2024-06-17 19:42:09 +07:00
return api.albyOAuthSvc.GetChannelPeerSuggestions(ctx)
2024-05-30 00:06:06 +07:00
}
func (api *api) ResetRouter(key string) error {
if api.svc.GetLNClient() == nil {
return errors.New("LNClient not started")
}
err := api.svc.GetLNClient().ResetRouter(key)
if err != nil {
return err
}
// Because the above method has to stop the node to reset the router,
// We also need to stop the lnclient and ask the user to start it again
return api.Stop()
}
func (api *api) ChangeUnlockPassword(changeUnlockPasswordRequest *ChangeUnlockPasswordRequest) error {
if api.svc.GetLNClient() == nil {
return errors.New("LNClient not started")
}
autoUnlockPassword, err := api.cfg.Get("AutoUnlockPassword", "")
if err != nil {
return err
}
if autoUnlockPassword != "" {
return errors.New("Please disable auto-unlock before using this feature")
}
err = api.cfg.ChangeUnlockPassword(changeUnlockPasswordRequest.CurrentUnlockPassword, changeUnlockPasswordRequest.NewUnlockPassword)
2024-05-30 00:06:06 +07:00
if err != nil {
2024-06-17 19:42:09 +07:00
logger.Logger.WithError(err).Error("failed to change unlock password")
2024-05-30 00:06:06 +07:00
return err
}
// Because all the encrypted fields have changed
// we also need to stop the lnclient and ask the user to start it again
return api.Stop()
}
func (api *api) SetAutoUnlockPassword(unlockPassword string) error {
if api.svc.GetLNClient() == nil {
return errors.New("LNClient not started")
}
err := api.cfg.SetAutoUnlockPassword(unlockPassword)
if err != nil {
logger.Logger.WithError(err).Error("failed to set auto unlock password")
return err
}
return nil
}
2024-05-30 00:06:06 +07:00
func (api *api) Stop() error {
if !startMutex.TryLock() {
// do not allow to stop twice in case this is somehow called twice
return errors.New("app is busy")
}
defer startMutex.Unlock()
2024-06-17 19:42:09 +07:00
logger.Logger.Info("Running Stop command")
2024-05-30 00:06:06 +07:00
if api.svc.GetLNClient() == nil {
return errors.New("LNClient not started")
}
2024-06-17 19:42:09 +07:00
// stop the lnclient, nostr relay etc.
2024-05-30 00:06:06 +07:00
// The user will be forced to re-enter their unlock password to restart the node
api.svc.StopApp()
2024-06-17 19:42:09 +07:00
return nil
2024-05-30 00:06:06 +07:00
}
func (api *api) GetNodeConnectionInfo(ctx context.Context) (*lnclient.NodeConnectionInfo, error) {
if api.svc.GetLNClient() == nil {
return nil, errors.New("LNClient not started")
}
return api.svc.GetLNClient().GetNodeConnectionInfo(ctx)
}
func (api *api) GetNodeStatus(ctx context.Context) (*lnclient.NodeStatus, error) {
if api.svc.GetLNClient() == nil {
return nil, errors.New("LNClient not started")
}
return api.svc.GetLNClient().GetNodeStatus(ctx)
}
func (api *api) ListPeers(ctx context.Context) ([]lnclient.PeerDetails, error) {
if api.svc.GetLNClient() == nil {
return nil, errors.New("LNClient not started")
}
return api.svc.GetLNClient().ListPeers(ctx)
}
func (api *api) ConnectPeer(ctx context.Context, connectPeerRequest *ConnectPeerRequest) error {
if api.svc.GetLNClient() == nil {
return errors.New("LNClient not started")
}
return api.svc.GetLNClient().ConnectPeer(ctx, connectPeerRequest)
}
func (api *api) OpenChannel(ctx context.Context, openChannelRequest *OpenChannelRequest) (*OpenChannelResponse, error) {
if api.svc.GetLNClient() == nil {
return nil, errors.New("LNClient not started")
}
return api.svc.GetLNClient().OpenChannel(ctx, openChannelRequest)
}
func (api *api) DisconnectPeer(ctx context.Context, peerId string) error {
if api.svc.GetLNClient() == nil {
return errors.New("LNClient not started")
}
2024-06-17 19:42:09 +07:00
logger.Logger.WithFields(logrus.Fields{
"peer_id": peerId,
}).Info("Disconnecting peer")
return api.svc.GetLNClient().DisconnectPeer(ctx, peerId)
}
2024-05-30 00:06:06 +07:00
func (api *api) CloseChannel(ctx context.Context, peerId, channelId string, force bool) (*CloseChannelResponse, error) {
if api.svc.GetLNClient() == nil {
return nil, errors.New("LNClient not started")
}
2024-06-17 19:42:09 +07:00
logger.Logger.WithFields(logrus.Fields{
2024-05-30 00:06:06 +07:00
"peer_id": peerId,
"channel_id": channelId,
"force": force,
}).Info("Closing channel")
return api.svc.GetLNClient().CloseChannel(ctx, &lnclient.CloseChannelRequest{
NodeId: peerId,
ChannelId: channelId,
Force: force,
})
}
func (api *api) UpdateChannel(ctx context.Context, updateChannelRequest *UpdateChannelRequest) error {
if api.svc.GetLNClient() == nil {
return errors.New("LNClient not started")
}
logger.Logger.WithFields(logrus.Fields{
"request": updateChannelRequest,
}).Info("updating channel")
return api.svc.GetLNClient().UpdateChannel(ctx, updateChannelRequest)
}
func (api *api) GetNewOnchainAddress(ctx context.Context) (string, error) {
2024-05-30 00:06:06 +07:00
if api.svc.GetLNClient() == nil {
return "", errors.New("LNClient not started")
2024-05-30 00:06:06 +07:00
}
address, err := api.svc.GetLNClient().GetNewOnchainAddress(ctx)
if err != nil {
return "", err
2024-05-30 00:06:06 +07:00
}
err = api.cfg.SetUpdate(config.OnchainAddressKey, address, "")
if err != nil {
logger.Logger.WithError(err).Error("Failed to save new onchain address to config")
}
return address, nil
}
func (api *api) GetUnusedOnchainAddress(ctx context.Context) (string, error) {
if api.svc.GetLNClient() == nil {
return "", errors.New("LNClient not started")
}
2024-06-17 19:42:09 +07:00
currentAddress, err := api.cfg.Get(config.OnchainAddressKey, "")
if err != nil {
2024-06-17 19:42:09 +07:00
logger.Logger.WithError(err).Error("Failed to get current address from config")
return "", err
}
if currentAddress != "" {
// check if address has any transactions
response, err := api.RequestEsploraApi("/address/" + currentAddress + "/txs")
if err != nil {
2024-06-17 19:42:09 +07:00
logger.Logger.WithError(err).Error("Failed to get current address transactions")
return currentAddress, nil
}
transactions, ok := response.([]interface{})
if !ok {
2024-06-17 19:42:09 +07:00
logger.Logger.WithField("response", response).Error("Failed to cast esplora address txs response", response)
return currentAddress, nil
}
if len(transactions) == 0 {
// address has not been used yet
return currentAddress, nil
}
}
newAddress, err := api.GetNewOnchainAddress(ctx)
if err != nil {
2024-06-17 19:42:09 +07:00
logger.Logger.WithError(err).Error("Failed to retrieve new onchain address")
return "", err
}
return newAddress, nil
2024-05-30 00:06:06 +07:00
}
func (api *api) SignMessage(ctx context.Context, message string) (*SignMessageResponse, error) {
if api.svc.GetLNClient() == nil {
return nil, errors.New("LNClient not started")
}
signature, err := api.svc.GetLNClient().SignMessage(ctx, message)
if err != nil {
return nil, err
}
return &SignMessageResponse{
Message: message,
Signature: signature,
}, nil
}
func (api *api) RedeemOnchainFunds(ctx context.Context, toAddress string, amount uint64, sendAll bool) (*RedeemOnchainFundsResponse, error) {
2024-05-30 00:06:06 +07:00
if api.svc.GetLNClient() == nil {
return nil, errors.New("LNClient not started")
}
txId, err := api.svc.GetLNClient().RedeemOnchainFunds(ctx, toAddress, amount, sendAll)
2024-05-30 00:06:06 +07:00
if err != nil {
return nil, err
}
return &RedeemOnchainFundsResponse{
TxId: txId,
}, nil
}
func (api *api) GetBalances(ctx context.Context) (*BalancesResponse, error) {
if api.svc.GetLNClient() == nil {
return nil, errors.New("LNClient not started")
}
balances, err := api.svc.GetLNClient().GetBalances(ctx)
if err != nil {
return nil, err
}
return balances, nil
}
// TODO: remove dependency on this endpoint
2024-05-30 00:06:06 +07:00
func (api *api) RequestMempoolApi(endpoint string) (interface{}, error) {
2024-06-17 19:42:09 +07:00
url := api.cfg.GetEnv().MempoolApi + endpoint
2024-05-30 00:06:06 +07:00
client := http.Client{
Timeout: time.Second * 10,
}
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
2024-06-17 19:42:09 +07:00
logger.Logger.WithError(err).WithFields(logrus.Fields{
2024-05-30 00:06:06 +07:00
"url": url,
}).Error("Failed to create http request")
return nil, err
}
res, err := client.Do(req)
if err != nil {
2024-06-17 19:42:09 +07:00
logger.Logger.WithError(err).WithFields(logrus.Fields{
2024-05-30 00:06:06 +07:00
"url": url,
}).Error("Failed to send request")
return nil, err
}
defer res.Body.Close()
body, readErr := io.ReadAll(res.Body)
if readErr != nil {
2024-06-17 19:42:09 +07:00
logger.Logger.WithError(err).WithFields(logrus.Fields{
2024-05-30 00:06:06 +07:00
"url": url,
}).Error("Failed to read response body")
return nil, errors.New("failed to read response body")
}
var jsonContent interface{}
jsonErr := json.Unmarshal(body, &jsonContent)
if jsonErr != nil {
2024-06-17 19:42:09 +07:00
logger.Logger.WithError(jsonErr).WithFields(logrus.Fields{
2024-05-30 00:06:06 +07:00
"url": url,
}).Error("Failed to deserialize json")
return nil, fmt.Errorf("failed to deserialize json %s %s", url, string(body))
}
return jsonContent, nil
}
func (api *api) GetInfo(ctx context.Context) (*InfoResponse, error) {
info := InfoResponse{}
2024-06-17 19:42:09 +07:00
backendType, _ := api.cfg.Get("LNBackendType", "")
ldkVssEnabled, _ := api.cfg.Get("LdkVssEnabled", "")
autoUnlockPassword, _ := api.cfg.Get("AutoUnlockPassword", "")
info.SetupCompleted = api.cfg.SetupCompleted()
if api.startupError != nil {
info.StartupError = api.startupError.Error()
info.StartupErrorTime = api.startupErrorTime
}
2024-05-30 00:06:06 +07:00
info.Running = api.svc.GetLNClient() != nil
info.BackendType = backendType
2024-06-17 19:42:09 +07:00
info.AlbyAuthUrl = api.albyOAuthSvc.GetAuthUrl()
info.OAuthRedirect = !api.cfg.GetEnv().IsDefaultClientId()
2024-06-22 12:22:01 +07:00
info.Version = version.Tag
info.EnableAdvancedSetup = api.cfg.GetEnv().EnableAdvancedSetup
info.LdkVssEnabled = ldkVssEnabled == "true"
info.VssSupported = backendType == config.LDKBackendType && api.cfg.GetEnv().LDKVssUrl != ""
info.AutoUnlockPasswordEnabled = autoUnlockPassword != ""
info.AutoUnlockPasswordSupported = api.cfg.GetEnv().IsDefaultClientId()
2024-06-17 19:42:09 +07:00
albyUserIdentifier, err := api.albyOAuthSvc.GetUserIdentifier()
2024-05-30 00:06:06 +07:00
if err != nil {
2024-06-17 19:42:09 +07:00
logger.Logger.WithError(err).Error("Failed to get alby user identifier")
2024-05-30 00:06:06 +07:00
return nil, err
}
info.AlbyUserIdentifier = albyUserIdentifier
2024-06-17 19:42:09 +07:00
info.AlbyAccountConnected = api.albyOAuthSvc.IsConnected(ctx)
2024-05-30 00:06:06 +07:00
if api.svc.GetLNClient() != nil {
nodeInfo, err := api.svc.GetLNClient().GetInfo(ctx)
if err != nil {
2024-06-17 19:42:09 +07:00
logger.Logger.WithError(err).Error("Failed to get nodeInfo")
2024-05-30 00:06:06 +07:00
return nil, err
}
info.Network = nodeInfo.Network
}
2024-06-17 19:42:09 +07:00
info.NextBackupReminder, _ = api.cfg.Get("NextBackupReminder", "")
2024-05-30 00:06:06 +07:00
return &info, nil
}
func (api *api) GetMnemonic(unlockPassword string) (*MnemonicResponse, error) {
if !api.cfg.CheckUnlockPassword(unlockPassword) {
return nil, fmt.Errorf("wrong password")
}
mnemonic, err := api.cfg.Get("Mnemonic", unlockPassword)
if err != nil {
return nil, fmt.Errorf("failed to fetch encryption key: %w", err)
}
resp := MnemonicResponse{
Mnemonic: mnemonic,
}
return &resp, err
2024-05-30 00:06:06 +07:00
}
func (api *api) SetNextBackupReminder(backupReminderRequest *BackupReminderRequest) error {
err := api.cfg.SetUpdate("NextBackupReminder", backupReminderRequest.NextBackupReminder, "")
if err != nil {
logger.Logger.WithError(err).Error("Failed to save next backup reminder to config")
}
2024-05-30 00:06:06 +07:00
return nil
}
var startMutex sync.Mutex
func (api *api) Start(startRequest *StartRequest) {
api.startupError = nil
err := api.StartInternal(startRequest)
if err != nil {
logger.Logger.WithError(err).Error("Failed to start node")
api.startupError = err
api.startupErrorTime = time.Now()
}
}
func (api *api) StartInternal(startRequest *StartRequest) (err error) {
if !startMutex.TryLock() {
// do not allow to start twice in case this is somehow called twice
return errors.New("app is busy")
}
defer startMutex.Unlock()
2024-05-30 00:06:06 +07:00
return api.svc.StartApp(startRequest.UnlockPassword)
}
func (api *api) Setup(ctx context.Context, setupRequest *SetupRequest) error {
if !startMutex.TryLock() {
// do not allow to start twice in case this is somehow called twice
return errors.New("app is busy")
}
defer startMutex.Unlock()
2024-05-30 00:06:06 +07:00
info, err := api.GetInfo(ctx)
if err != nil {
2024-06-17 19:42:09 +07:00
logger.Logger.WithError(err).Error("Failed to get info")
2024-05-30 00:06:06 +07:00
return err
}
if info.SetupCompleted {
2024-06-17 19:42:09 +07:00
logger.Logger.Error("Cannot re-setup node")
2024-05-30 00:06:06 +07:00
return errors.New("setup already completed")
}
if setupRequest.UnlockPassword == "" {
return errors.New("no unlock password provided")
}
err = api.cfg.SaveUnlockPasswordCheck(setupRequest.UnlockPassword)
if err != nil {
return err
}
2024-05-30 00:06:06 +07:00
// update next backup reminder
err = api.cfg.SetUpdate("NextBackupReminder", setupRequest.NextBackupReminder, "")
if err != nil {
logger.Logger.WithError(err).Error("Failed to save next backup reminder")
}
2024-05-30 00:06:06 +07:00
// only update non-empty values
if setupRequest.LNBackendType != "" {
err = api.cfg.SetUpdate("LNBackendType", setupRequest.LNBackendType, "")
if err != nil {
logger.Logger.WithError(err).Error("Failed to save backend type")
return err
}
2024-05-30 00:06:06 +07:00
}
if setupRequest.BreezAPIKey != "" {
err = api.cfg.SetUpdate("BreezAPIKey", setupRequest.BreezAPIKey, setupRequest.UnlockPassword)
if err != nil {
logger.Logger.WithError(err).Error("Failed to save breez api key")
return err
}
2024-05-30 00:06:06 +07:00
}
if setupRequest.Mnemonic != "" {
err = api.cfg.SetUpdate("Mnemonic", setupRequest.Mnemonic, setupRequest.UnlockPassword)
if err != nil {
logger.Logger.WithError(err).Error("Failed to save encrypted mnemonic")
return err
}
2024-05-30 00:06:06 +07:00
}
if setupRequest.GreenlightInviteCode != "" {
err = api.cfg.SetUpdate("GreenlightInviteCode", setupRequest.GreenlightInviteCode, setupRequest.UnlockPassword)
if err != nil {
logger.Logger.WithError(err).Error("Failed to save greenlight invite code")
return err
}
2024-05-30 00:06:06 +07:00
}
if setupRequest.LNDAddress != "" {
err = api.cfg.SetUpdate("LNDAddress", setupRequest.LNDAddress, setupRequest.UnlockPassword)
if err != nil {
logger.Logger.WithError(err).Error("Failed to save lnd address")
return err
}
2024-05-30 00:06:06 +07:00
}
if setupRequest.LNDCertHex != "" {
err = api.cfg.SetUpdate("LNDCertHex", setupRequest.LNDCertHex, setupRequest.UnlockPassword)
if err != nil {
logger.Logger.WithError(err).Error("Failed to save lnd cert hex")
return err
}
2024-05-30 00:06:06 +07:00
}
if setupRequest.LNDMacaroonHex != "" {
err = api.cfg.SetUpdate("LNDMacaroonHex", setupRequest.LNDMacaroonHex, setupRequest.UnlockPassword)
if err != nil {
logger.Logger.WithError(err).Error("Failed to save lnd macaroon hex")
return err
}
2024-05-30 00:06:06 +07:00
}
if setupRequest.PhoenixdAddress != "" {
err = api.cfg.SetUpdate("PhoenixdAddress", setupRequest.PhoenixdAddress, setupRequest.UnlockPassword)
if err != nil {
logger.Logger.WithError(err).Error("Failed to save phoenix address")
return err
}
}
if setupRequest.PhoenixdAuthorization != "" {
err = api.cfg.SetUpdate("PhoenixdAuthorization", setupRequest.PhoenixdAuthorization, setupRequest.UnlockPassword)
if err != nil {
logger.Logger.WithError(err).Error("Failed to save phoenix auth")
return err
}
}
2024-06-14 19:12:22 +03:00
if setupRequest.CashuMintUrl != "" {
err = api.cfg.SetUpdate("CashuMintUrl", setupRequest.CashuMintUrl, setupRequest.UnlockPassword)
if err != nil {
logger.Logger.WithError(err).Error("Failed to save cashu mint url")
return err
}
2024-06-14 19:12:22 +03:00
}
2024-05-30 00:06:06 +07:00
return nil
}
func (api *api) GetWalletCapabilities(ctx context.Context) (*WalletCapabilitiesResponse, error) {
if api.svc.GetLNClient() == nil {
return nil, errors.New("LNClient not started")
}
methods := api.svc.GetLNClient().GetSupportedNIP47Methods()
notificationTypes := api.svc.GetLNClient().GetSupportedNIP47NotificationTypes()
scopes, err := permissions.RequestMethodsToScopes(methods)
if err != nil {
return nil, err
}
if len(notificationTypes) > 0 {
Feat: dynamic budgets (#226) * feat: add transactions table * feat: add transactions service with makeinvoice method * feat: use internal transactions WIP * feat: check unsettled transactions * feat: use transactions service in nip47 package WIP * feat: use transactions service in NIP-47 handlers * fix: transaction list colors * fix: tests * chore: remove old payments table * fix: return budget usage as sats * feat: use internal transactions table for keysend payments * feat: consume nwc_payment_received event in transaction service (WIP) * feat: update existing transaction from nwc_payment_received event in transactions service * feat: update existing transaction from nwc_payment_sent event in transactions service * feat: handle async payment failed events in transactions service * fix: tests * feat: correctly implement NIP-47 NOT_FOUND error code * feat: intercept self payments * feat: isolated balance and visibility * feat: validate keysend payment does not exceed app internal balance * feat: budget check in transactions service, correctly pass payment errors to NIP-47 response also reduce query duplication * fix: order transactions when looking up transaction * feat: add fee reserves to unsettled outgoing transactions * chore: rename app permissions max amount field * chore: rename transaction amount values to be clearly millisats * chore: merge balance type and visibility into isolated property on apps table * chore: move duplicated permission check from nip-47 controllers to handler * fix: app name in transaction list * Feat: permissions revamp v2 (#273) * feat: revamp permissions component * chore: changes * chore: changes * chore: add view mode for show app screen * chore: further changes * feat: new illustration for linking account (#254) * feat: new illustration for linking account * fix: update paths * fix: icon props (#256) * fix: use date from frontend * chore: add expiryselect component * chore: further changes * chore: further changes * chore: add date-fns for date picker * chore: further changes * chore: further changes * fix: add central LDK gossip node to help gossip new public channels (#262) * fix: make dialog responsive (#258) * chore: further changes * typo * chore: spacing issues * chore: use scopes from capabilities * chore: change scope type descriptions * chore: styling fixes * chore: fix typings * chore: budget renewal component * fix: LDK mark channel as inactive and show error if counterparty forwarding info missing (#267) fix: mark channel as inactive and show error if counterparty forwarding info missing * chore: remove unnecessary dark classes (#255) * fix: links to open first channel in sidebar and onboarding checklist (#268) * feat: improve migrate node UI (#269) * fix: migrate node copy (#270) * fix: stop nostr when app is shutdown and use context to stop lnclient (#271) * fix: permissions revamp WIP * feat: basic isolated apps UI * fix: new app connection, edit app connection, deep linking --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com> * fix: make transactions table ID autoincrement * fix: do not send unrelated notifications to isolated apps * fix: nip-47 notifications not receiving updated transaction state * fix: migrate existing tables to have autoincrementing primary keys (#274) * fix: migrate existing tables to have autoincrementing primary keys * fix: recreate request and response event tables after apps * fix: remove null from request_events app_id * fix: do not crash when reloading app created page * chore: update pragma commands, add busy_timeout * fix: remove unnecessary migration of user_configs table * chore: update comment on autoincrement migration * feat: sqlite database config improvements * fix: autoincrement migration to delete unlinked app permissions * chore: update tests for dynamic budgets (WIP) * fix: get balance tests * chore: add extra event handler tests * chore: add extra event handler test * chore: add extra multi_pay_invoice tests * chore: transactions service tests (WIP) * chore: add transactions service payment tests * chore: add tests for self payments * fix: notifications tests * chore: add notifications tests for transactions service * chore: add fee reserve tests for transactions service * chore: add list transactions tests * chore: add keysend tests for transactions service * feat: subscribe for payments and invoices (#281) * fix: db transaction should be passed as pointer * feat(lnd): subscribe for payments and invoices * chore: rearrange check for settled * chore: remove TODO * chore: retry on error and add select * chore: publish payment failed event * chore: use json logging * feat: add lnd notification types * chore: remove sleep * fix: incorrect key on transaction list items * fix: test * fix: disable isolated app type on non-supported backends --------- Co-authored-by: im-adithya <imadithyavardhan@gmail.com> Co-authored-by: René Aaron <100827540+reneaaron@users.noreply.github.com> Co-authored-by: Michael Bumann <hello@michaelbumann.com>
2024-07-19 23:30:22 +07:00
scopes = append(scopes, constants.NOTIFICATIONS_SCOPE)
}
return &WalletCapabilitiesResponse{
Methods: methods,
NotificationTypes: notificationTypes,
Scopes: scopes,
}, nil
}
2024-05-30 00:06:06 +07:00
func (api *api) SendPaymentProbes(ctx context.Context, sendPaymentProbesRequest *SendPaymentProbesRequest) (*SendPaymentProbesResponse, error) {
if api.svc.GetLNClient() == nil {
return nil, errors.New("LNClient not started")
}
var errMessage string
err := api.svc.GetLNClient().SendPaymentProbes(ctx, sendPaymentProbesRequest.Invoice)
if err != nil {
errMessage = err.Error()
}
return &SendPaymentProbesResponse{Error: errMessage}, nil
}
func (api *api) MigrateNodeStorage(ctx context.Context, to string) error {
if api.svc.GetLNClient() == nil {
return errors.New("LNClient not started")
}
if to != "VSS" {
return fmt.Errorf("Migration type not supported: %s", to)
}
ldkVssEnabled, err := api.cfg.Get("LdkVssEnabled", "")
if err != nil {
return err
}
if ldkVssEnabled == "true" {
return errors.New("VSS already enabled")
}
if api.cfg.GetEnv().LDKVssUrl == "" {
return errors.New("No VSS URL set")
}
api.cfg.SetUpdate("LdkVssEnabled", "true", "")
api.cfg.SetUpdate("LdkMigrateStorage", "VSS", "")
return api.Stop()
}
2024-05-30 00:06:06 +07:00
func (api *api) SendSpontaneousPaymentProbes(ctx context.Context, sendSpontaneousPaymentProbesRequest *SendSpontaneousPaymentProbesRequest) (*SendSpontaneousPaymentProbesResponse, error) {
if api.svc.GetLNClient() == nil {
return nil, errors.New("LNClient not started")
}
var errMessage string
err := api.svc.GetLNClient().SendSpontaneousPaymentProbes(ctx, sendSpontaneousPaymentProbesRequest.Amount, sendSpontaneousPaymentProbesRequest.NodeId)
if err != nil {
errMessage = err.Error()
}
return &SendSpontaneousPaymentProbesResponse{Error: errMessage}, nil
}
func (api *api) GetNetworkGraph(ctx context.Context, nodeIds []string) (NetworkGraphResponse, error) {
2024-05-30 00:06:06 +07:00
if api.svc.GetLNClient() == nil {
return nil, errors.New("LNClient not started")
}
return api.svc.GetLNClient().GetNetworkGraph(ctx, nodeIds)
2024-05-30 00:06:06 +07:00
}
func (api *api) SyncWallet() error {
if api.svc.GetLNClient() == nil {
return errors.New("LNClient not started")
}
api.svc.GetLNClient().UpdateLastWalletSyncRequest()
return nil
}
func (api *api) GetLogOutput(ctx context.Context, logType string, getLogRequest *GetLogOutputRequest) (*GetLogOutputResponse, error) {
var err error
var logData []byte
if logType == LogTypeNode {
if api.svc.GetLNClient() == nil {
return nil, errors.New("LNClient not started")
}
logData, err = api.svc.GetLNClient().GetLogOutput(ctx, getLogRequest.MaxLen)
if err != nil {
return nil, err
}
} else if logType == LogTypeApp {
2024-06-17 19:42:09 +07:00
logFileName := logger.GetLogFilePath()
if logFileName == "" {
logData = []byte("file log is disabled")
} else {
logData, err = utils.ReadFileTail(logFileName, getLogRequest.MaxLen)
if err != nil {
return nil, err
}
2024-05-30 00:06:06 +07:00
}
} else {
return nil, fmt.Errorf("invalid log type: '%s'", logType)
}
return &GetLogOutputResponse{Log: string(logData)}, nil
}
func (api *api) Health(ctx context.Context) (*HealthResponse, error) {
var alarms []HealthAlarm
albyInfo, err := api.albyOAuthSvc.GetInfo(ctx)
if err != nil {
return nil, err
}
if !albyInfo.Healthy {
alarms = append(alarms, NewHealthAlarm(HealthAlarmKindAlbyService, albyInfo.Incidents))
}
isNostrRelayReady := api.svc.IsRelayReady()
if !isNostrRelayReady {
alarms = append(alarms, NewHealthAlarm(HealthAlarmKindNostrRelayOffline, nil))
}
lnClient := api.svc.GetLNClient()
if lnClient != nil {
nodeStatus, err := lnClient.GetNodeStatus(ctx)
if err != nil {
return nil, err
}
if nodeStatus == nil || !nodeStatus.IsReady {
alarms = append(alarms, NewHealthAlarm(HealthAlarmKindNodeNotReady, nodeStatus))
}
channels, err := lnClient.ListChannels(ctx)
if err != nil {
return nil, err
}
offlineChannels := slices.DeleteFunc(channels, func(channel lnclient.Channel) bool {
return channel.Active
})
if len(offlineChannels) > 0 {
alarms = append(alarms, NewHealthAlarm(HealthAlarmKindChannelsOffline, nil))
}
}
return &HealthResponse{Alarms: alarms}, nil
}
func (api *api) GetCustomNodeCommands() (*CustomNodeCommandsResponse, error) {
lnClient := api.svc.GetLNClient()
if lnClient == nil {
return nil, errors.New("LNClient not started")
}
allCommandDefs := lnClient.GetCustomNodeCommandDefinitions()
commandDefs := make([]CustomNodeCommandDef, 0, len(allCommandDefs))
for _, commandDef := range allCommandDefs {
argDefs := make([]CustomNodeCommandArgDef, 0, len(commandDef.Args))
for _, argDef := range commandDef.Args {
argDefs = append(argDefs, CustomNodeCommandArgDef{
Name: argDef.Name,
Description: argDef.Description,
})
}
commandDefs = append(commandDefs, CustomNodeCommandDef{
Name: commandDef.Name,
Description: commandDef.Description,
Args: argDefs,
})
}
return &CustomNodeCommandsResponse{Commands: commandDefs}, nil
}
func (api *api) ExecuteCustomNodeCommand(ctx context.Context, command string) (interface{}, error) {
lnClient := api.svc.GetLNClient()
if lnClient == nil {
return nil, errors.New("LNClient not started")
}
// Split command line into arguments. Command name must be the first argument.
parsedArgs, err := utils.ParseCommandLine(command)
if err != nil {
return nil, fmt.Errorf("failed to parse node command: %w", err)
} else if len(parsedArgs) == 0 {
return nil, errors.New("no command provided")
}
// Look up the requested command definition.
allCommandDefs := lnClient.GetCustomNodeCommandDefinitions()
commandDefIdx := slices.IndexFunc(allCommandDefs, func(def lnclient.CustomNodeCommandDef) bool {
return def.Name == parsedArgs[0]
})
if commandDefIdx < 0 {
return nil, fmt.Errorf("unknown command: %q", parsedArgs[0])
}
// Build flag set.
commandDef := allCommandDefs[commandDefIdx]
flagSet := flag.NewFlagSet(commandDef.Name, flag.ContinueOnError)
for _, argDef := range commandDef.Args {
flagSet.String(argDef.Name, "", argDef.Description)
}
if err = flagSet.Parse(parsedArgs[1:]); err != nil {
return nil, fmt.Errorf("failed to parse command arguments: %w", err)
}
// Collect flags that have been set.
argValues := make(map[string]string)
flagSet.Visit(func(f *flag.Flag) {
argValues[f.Name] = f.Value.String()
})
reqArgs := make([]lnclient.CustomNodeCommandArg, 0, len(argValues))
for _, argDef := range commandDef.Args {
if argValue, ok := argValues[argDef.Name]; ok {
reqArgs = append(reqArgs, lnclient.CustomNodeCommandArg{
Name: argDef.Name,
Value: argValue,
})
}
}
nodeResp, err := lnClient.ExecuteCustomNodeCommand(ctx, &lnclient.CustomNodeCommandRequest{
Name: commandDef.Name,
Args: reqArgs,
})
if err != nil {
return nil, fmt.Errorf("node failed to execute custom command: %w", err)
}
return nodeResp.Response, nil
}
2024-05-30 00:06:06 +07:00
func (api *api) parseExpiresAt(expiresAtString string) (*time.Time, error) {
var expiresAt *time.Time
if expiresAtString != "" {
var err error
expiresAtValue, err := time.Parse(time.RFC3339, expiresAtString)
if err != nil {
2024-06-17 19:42:09 +07:00
logger.Logger.WithField("expiresAt", expiresAtString).Error("Invalid expiresAt")
2024-05-30 00:06:06 +07:00
return nil, fmt.Errorf("invalid expiresAt: %v", err)
}
expiresAt = &expiresAtValue
}
return expiresAt, nil
}