Refactor GetWalletServiceInfo and update event and notification types

- pkg/protocol/nwc/methods.go
  - Refactored `GetWalletServiceInfo` to improve context and error handling.
  - Simplified tag extraction and processing for encryption and notification types.
  - Optimized handling of WalletServiceInfo capabilities.

- pkg/protocol/nwc/types.go
  - Added `HoldInvoiceAccepted` notification type.
  - Introduced `NotificationTag` constant.

- pkg/encoders/kind/kind.go
  - Renamed `NWCWalletInfo` to `NWCWalletServiceInfo`.
  - Updated references and mappings to reflect the rename.
This commit is contained in:
2025-08-07 18:31:42 +01:00
parent 6c3d22cb38
commit a6350c8e80
3 changed files with 31 additions and 38 deletions

View File

@@ -263,9 +263,9 @@ var (
FileStorageServerList = &T{10096}
// JWTBinding is an event kind that creates a link between a JWT certificate and a pubkey
JWTBinding = &T{13004}
// NWCWalletInfo is an event type that...
NWCWalletInfo = &T{13194}
WalletInfo = NWCWalletInfo
// NWCWalletServiceInfo is an event type that...
NWCWalletServiceInfo = &T{13194}
WalletServiceInfo = &T{13194}
// ReplaceableEnd is an event type that...
ReplaceableEnd = &T{19999}
// EphemeralStart is an event type that...
@@ -384,7 +384,7 @@ var Map = map[uint16]string{
UserEmojiList.K: "UserEmojiList",
DMRelaysList.K: "DMRelaysList",
FileStorageServerList.K: "FileStorageServerList",
NWCWalletInfo.K: "NWCWalletInfo",
NWCWalletServiceInfo.K: "NWCWalletServiceInfo",
LightningPubRPC.K: "LightningPubRPC",
ClientAuthentication.K: "ClientAuthentication",
WalletRequest.K: "WalletRequest",

View File

@@ -19,22 +19,18 @@ import (
func (cl *Client) GetWalletServiceInfo(c context.T, noUnmarshal bool) (
wsi *WalletServiceInfo, raw []byte, err error,
) {
timeout := 10 * time.Second
ctx, cancel := context.Timeout(c, timeout)
ctx, cancel := context.Timeout(c, 10*time.Second)
defer cancel()
var rc *ws.Client
if rc, err = ws.RelayConnect(c, cl.relay); chk.E(err) {
return
}
if err = rc.Connect(c); chk.E(err) {
return
}
var sub *ws.Subscription
if sub, err = rc.Subscribe(
ctx, filters.New(
&filter.F{
Limit: values.ToUintPointer(1),
Kinds: kinds.New(kind.WalletRequest),
Kinds: kinds.New(kind.WalletServiceInfo),
Authors: tag.New(cl.walletPublicKey),
},
),
@@ -43,37 +39,32 @@ func (cl *Client) GetWalletServiceInfo(c context.T, noUnmarshal bool) (
}
defer sub.Unsub()
select {
case <-c.Done():
err = fmt.Errorf("GetWalletServiceInfo canceled")
case <-ctx.Done():
err = fmt.Errorf("context canceled")
return
case ev := <-sub.Events:
var encryptionTypes []EncryptionType
var notificationTypes []NotificationType
encryptionTag := ev.Tags.GetFirst(tag.New("encryption"))
notificationsTag := ev.Tags.GetFirst(tag.New("notifications"))
if encryptionTag != nil {
et := encryptionTag.ToSliceOfBytes()
encType := bytes.Split(et[0], []byte(" "))
for _, e := range encType {
encryptionTypes = append(encryptionTypes, e)
case e := <-sub.Events:
raw = e.Marshal(nil)
if noUnmarshal {
return
}
wsi = &WalletServiceInfo{}
encTag := e.Tags.GetFirst(tag.New(EncryptionTag))
notTag := e.Tags.GetFirst(tag.New(NotificationTag))
if encTag != nil {
et := bytes.Split(encTag.Value(), []byte(" "))
for _, v := range et {
wsi.EncryptionTypes = append(wsi.EncryptionTypes, v)
}
}
if notificationsTag != nil {
nt := notificationsTag.ToSliceOfBytes()
notifs := bytes.Split(nt[0], []byte(" "))
for _, e := range notifs {
notificationTypes = append(notificationTypes, e)
if notTag != nil {
nt := bytes.Split(notTag.Value(), []byte(" "))
for _, v := range nt {
wsi.NotificationTypes = append(wsi.NotificationTypes, v)
}
}
cp := bytes.Split(ev.Content, []byte(" "))
var capabilities []Capability
for _, capability := range cp {
capabilities = append(capabilities, capability)
}
wsi = &WalletServiceInfo{
EncryptionTypes: encryptionTypes,
NotificationTypes: notificationTypes,
Capabilities: capabilities,
caps := bytes.Split(e.Content, []byte(" "))
for _, v := range caps {
wsi.Capabilities = append(wsi.Capabilities, v)
}
}
return

View File

@@ -33,8 +33,10 @@ var (
type NotificationType []byte
var (
PaymentReceived = NotificationType("payment_received")
PaymentSent = NotificationType("payment_sent")
NotificationTag = []byte("notification")
PaymentReceived = NotificationType("payment_received")
PaymentSent = NotificationType("payment_sent")
HoldInvoiceAccepted = NotificationType("hold_invoice_accepted")
)
type WalletServiceInfo struct {