-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #172 from getAlby/task-get-info
feat: add get info method
- Loading branch information
Showing
9 changed files
with
315 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
DATABASE_URI=file:nwc.db | ||
NOSTR_PRIVKEY= | ||
LN_BACKEND_TYPE=ALBY | ||
ALBY_CLIENT_SECRET= | ||
ALBY_CLIENT_ID= | ||
OAUTH_REDIRECT_URL=http://localhost:8080/alby/callback | ||
COOKIE_SECRET=secretsecret | ||
RELAY=wss://relay.getalby.com/v1 | ||
PUBLIC_RELAY= | ||
PORT=8080 | ||
|
||
# Polar LND Client | ||
#LN_BACKEND_TYPE=LND | ||
#LND_CERT_FILE=/home/YOUR_USERNAME/.polar/networks/1/volumes/lnd/alice/tls.cert | ||
#LND_ADDRESS=127.0.0.1:10001 | ||
#LND_MACAROON_FILE=/home/YOUR_USERNAME/.polar/networks/1/volumes/lnd/alice/data/chain/bitcoin/regtest/admin.macaroon | ||
|
||
# Alby Wallet API Client | ||
#LN_BACKEND_TYPE=ALBY | ||
#ALBY_CLIENT_SECRET= | ||
#ALBY_CLIENT_ID= | ||
#OAUTH_REDIRECT_URL=http://localhost:8080/alby/callback |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"editor.defaultFormatter": "golang.go" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,3 +117,60 @@ Want to support the work on Alby? | |
|
||
Support the Alby team ⚡️hello@getalby.com | ||
You can also contribute to our [bounty program](https://github.com/getAlby/lightning-browser-extension/wiki/Bounties): ⚡️[email protected] | ||
|
||
|
||
## NIP-47 Supported Methods | ||
|
||
✅ NIP-47 info event | ||
|
||
### LND | ||
|
||
✅ `get_info` | ||
|
||
✅ `get_balance` | ||
|
||
✅ `pay_invoice` | ||
|
||
⚠️ `make_invoice` | ||
- ⚠️ invoice in response missing (TODO) | ||
|
||
⚠️ `lookup_invoice` | ||
- ⚠️ invoice in response missing (TODO) | ||
- ⚠️ response does not match spec, missing fields | ||
|
||
❌ `pay_keysend` | ||
|
||
❌ `list_transactions` | ||
|
||
❌ `multi_pay_invoice (TBC)` | ||
|
||
❌ `multi_pay_keysend (TBC)` | ||
|
||
### Alby OAuth API | ||
|
||
✅ `get_info` | ||
- ⚠️ block_hash not supported | ||
- ⚠️ block_height not supported | ||
- ⚠️ pubkey not supported | ||
- ⚠️ color not supported | ||
- ⚠️ network is always `mainnet` | ||
|
||
✅ `get_balance` | ||
|
||
✅ `pay_invoice` | ||
|
||
⚠️ `make_invoice` | ||
- ⚠️ expiry in request not supported | ||
- ⚠️ invoice in response missing (TODO) | ||
|
||
⚠️ `lookup_invoice` | ||
- ⚠️ invoice in response missing (TODO) | ||
- ⚠️ response does not match spec, missing fields (TODO) | ||
|
||
❌ `pay_keysend` | ||
|
||
❌ `list_transactions` | ||
|
||
❌ `multi_pay_invoice (TBC)` | ||
|
||
❌ `multi_pay_keysend (TBC)` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/nbd-wtf/go-nostr" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func (svc *Service) HandleGetInfoEvent(ctx context.Context, request *Nip47Request, event *nostr.Event, app App, ss []byte) (result *nostr.Event, err error) { | ||
|
||
nostrEvent := NostrEvent{App: app, NostrId: event.ID, Content: event.Content, State: "received"} | ||
err = svc.db.Create(&nostrEvent).Error | ||
if err != nil { | ||
svc.Logger.WithFields(logrus.Fields{ | ||
"eventId": event.ID, | ||
"eventKind": event.Kind, | ||
"appId": app.ID, | ||
}).Errorf("Failed to save nostr event: %v", err) | ||
return nil, err | ||
} | ||
|
||
hasPermission, code, message := svc.hasPermission(&app, event, request.Method, nil) | ||
|
||
if !hasPermission { | ||
svc.Logger.WithFields(logrus.Fields{ | ||
"eventId": event.ID, | ||
"eventKind": event.Kind, | ||
"appId": app.ID, | ||
}).Errorf("App does not have permission: %s %s", code, message) | ||
|
||
return svc.createResponse(event, Nip47Response{ | ||
ResultType: request.Method, | ||
Error: &Nip47Error{ | ||
Code: code, | ||
Message: message, | ||
}}, ss) | ||
} | ||
|
||
svc.Logger.WithFields(logrus.Fields{ | ||
"eventId": event.ID, | ||
"eventKind": event.Kind, | ||
"appId": app.ID, | ||
}).Info("Fetching node info") | ||
|
||
info, err := svc.lnClient.GetInfo(ctx, event.PubKey) | ||
if err != nil { | ||
svc.Logger.WithFields(logrus.Fields{ | ||
"eventId": event.ID, | ||
"eventKind": event.Kind, | ||
"appId": app.ID, | ||
}).Infof("Failed to fetch node info: %v", err) | ||
nostrEvent.State = NOSTR_EVENT_STATE_HANDLER_ERROR | ||
svc.db.Save(&nostrEvent) | ||
return svc.createResponse(event, Nip47Response{ | ||
ResultType: request.Method, | ||
Error: &Nip47Error{ | ||
Code: NIP_47_ERROR_INTERNAL, | ||
Message: fmt.Sprintf("Something went wrong while fetching node info: %s", err.Error()), | ||
}, | ||
}, ss) | ||
} | ||
|
||
responsePayload := &Nip47GetInfoResponse{ | ||
Alias: info.Alias, | ||
Color: info.Color, | ||
Pubkey: info.Pubkey, | ||
Network: info.Network, | ||
BlockHeight: info.BlockHeight, | ||
BlockHash: info.BlockHash, | ||
Methods: svc.GetMethods(&app), | ||
} | ||
|
||
nostrEvent.State = NOSTR_EVENT_STATE_HANDLER_EXECUTED | ||
svc.db.Save(&nostrEvent) | ||
return svc.createResponse(event, Nip47Response{ | ||
ResultType: request.Method, | ||
Result: responsePayload, | ||
}, ss) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.