Documentation
¶
Overview ¶
Package nwc is an implementation of the NWC Nostr Wallet Connect protocol for communicating with lightning (and potentially other kinds of wallets) using nostr ephemeral event messages.
Index ¶
- Variables
- type Client
- type Error
- type GetBalanceRequest
- type GetBalanceResponse
- type GetInfo
- type GetInfoRequest
- type GetInfoResponse
- type Invoice
- type InvoiceResponse
- type ListTransactions
- type ListTransactionsRequest
- type ListTransactionsResponse
- type LookupInvoice
- type LookupInvoiceRequest
- type LookupInvoiceResponse
- type MakeInvoiceRequest
- type MakeInvoiceResponse
- type Msat
- type MultiPayInvoiceRequest
- type MultiPayInvoiceResponse
- type MultiPayKeysendRequest
- type MultiPayKeysendResponse
- type Notification
- type Notifier
- type PayInvoiceRequest
- type PayInvoiceResponse
- type PayKeysendRequest
- type PayKeysendResponse
- type PaymentReceivedNotification
- type PaymentSentNotification
- type Request
- type Requester
- type Response
- type Resulter
- type Server
- type TLV
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( PaymentSent = []byte("payment_sent") PaymentReceived = []byte("payment_received") )
var Errors = struct { // RateLimited - The client is sending commands too fast.It should retry in a few seconds. RateLimited, NotImplemented, InsufficientBalance, QuotaExceeded, Restricted, Unauthorized, Internal, Other []byte }{ []byte("RATE_LIMITED"), []byte("NOT_IMPLEMENTED"), []byte("INSUFFICIENT_BALANCE"), []byte("QUOTA_EXCEEDED"), []byte("RESTRICTED"), []byte("UNAUTHORIZED"), []byte("INTERNAL"), []byte("OTHER"), }
var Keys = struct { Method, Params, ResultType, Error, Result, Invoice, Amount, Preimage, FeesPaid, Id, TLVRecords, Type, Value, Pubkey, Description, DescriptionHash, Expiry, CreatedAt, ExpiresAt, Metadata, SettledAt, From, Until, Offset, Unpaid, Balance, Notifications, NotificationType, Notification, PaymentHash []byte }{ []byte("method"), []byte("params"), []byte("result_type"), []byte("error"), []byte("result"), []byte("invoice"), []byte("amount"), []byte("preimage"), []byte("fees_paid"), []byte("id"), []byte("tlv_records"), []byte("type"), []byte("value"), []byte("pubkey"), []byte("description"), []byte("description_hash"), []byte("expiry"), []byte("created_at"), []byte("expires_at"), []byte("metadata"), []byte("settled_at"), []byte("from"), []byte("until"), []byte("offset"), []byte("unpaid"), []byte("balance"), []byte("notifications"), []byte("notification_type"), []byte("notification"), []byte("payment_hash"), }
Keys are the proper JSON bytes for the JSON object keys of the structs of the same-named type used lower in the following. Anonymous struct syntax is used to make neater addressing of these fields as symbols.
var Kinds = []*kind.T{ kind.WalletInfo, kind.WalletRequest, kind.WalletResponse, kind.WalletNotification, }
var Methods = struct { PayInvoice, MultiPayInvoice, PayKeysend, MultiPayKeysend, MakeInvoice, LookupInvoice, ListTransactions, GetBalance, GetInfo []byte }{ []byte("pay_invoice"), []byte("multi_pay_invoice"), []byte("pay_keysend"), []byte("multi_pay_keysend"), []byte("make_invoice"), []byte("lookup_invoice"), []byte("list_transactions"), []byte("get_balance"), []byte("get_info"), }
Methods are the text of the value of the Method field of Request.Method and Response.ResultType in a form that allows more convenient reference than using a map or package scoped variable. These appear in the API Request and Response types.
var Notifications = struct { PaymentReceived, PaymentSent []byte }{ []byte("payment_received"), []byte("payment_sent"), }
Notifications are the proper strings for the Notification.NotificationType
Functions ¶
This section is empty.
Types ¶
type GetBalanceRequest ¶
type GetBalanceRequest struct {
Request
}
func NewGetBalanceRequest ¶
func NewGetBalanceRequest() *GetBalanceRequest
type GetBalanceResponse ¶
func NewGetBalanceResponse ¶
func NewGetBalanceResponse(balance Msat) *GetBalanceResponse
type GetInfoRequest ¶
type GetInfoRequest struct {
Request
}
func NewGetInfoRequest ¶
func NewGetInfoRequest() GetInfoRequest
type GetInfoResponse ¶
func NewGetInfoResponse ¶
func NewGetInfoResponse(gi GetInfo) GetInfoResponse
type InvoiceResponse ¶
type InvoiceResponse struct {
Type []byte // incoming or outgoing
Invoice []byte // optional
Description []byte // optional
DescriptionHash []byte // optional
Preimage []byte // optional if unpaid
PaymentHash []byte
Amount Msat
FeesPaid Msat
CreatedAt int64
ExpiresAt int64 // optional if not applicable
Metadata []any // optional, probably like tags but retardation can be retarded so allow also numbers and floats
}
type ListTransactions ¶
type ListTransactionsRequest ¶
type ListTransactionsRequest struct {
Request
ListTransactions
}
func NewListTransactionsRequest ¶
func NewListTransactionsRequest(req ListTransactions) *ListTransactionsRequest
type ListTransactionsResponse ¶
type ListTransactionsResponse struct {
Response
Transactions []LookupInvoice
}
func NewListTransactionsResponse ¶
func NewListTransactionsResponse(txs []LookupInvoice) ListTransactionsResponse
type LookupInvoice ¶
type LookupInvoice struct {
Response
InvoiceResponse
SettledAt int64 // optional if unpaid
}
type LookupInvoiceRequest ¶
func NewLookupInvoiceRequest ¶
func NewLookupInvoiceRequest(paymentHash, invoice []byte) *LookupInvoiceRequest
type LookupInvoiceResponse ¶
type LookupInvoiceResponse struct {
Response
LookupInvoice
}
func NewLookupInvoiceResponse ¶
func NewLookupInvoiceResponse(resp LookupInvoice) LookupInvoiceResponse
type MakeInvoiceRequest ¶
type MakeInvoiceRequest struct {
Request
Amount Msat
Description []byte // optional
DescriptionHash []byte // optional
Expiry int // optional
}
func NewMakeInvoiceRequest ¶
func NewMakeInvoiceRequest(amount Msat, description, descriptionHash []byte, expiry int) MakeInvoiceRequest
type MakeInvoiceResponse ¶
type MakeInvoiceResponse struct {
Response
InvoiceResponse
}
func NewMakeInvoiceResponse ¶
func NewMakeInvoiceResponse(resp InvoiceResponse) MakeInvoiceResponse
type Msat ¶
type Msat uint64
Msat is milli-sat, max possible value is 1000 x 21 x 100 000 000 (well, under 19 places of 64 bits in base 10)
type MultiPayInvoiceRequest ¶
func NewMultiPayInvoiceRequest ¶
func NewMultiPayInvoiceRequest(invoices []Invoice) MultiPayInvoiceRequest
type MultiPayInvoiceResponse ¶
type MultiPayInvoiceResponse = PayInvoiceResponse
func NewMultiPayInvoiceResponse ¶
func NewMultiPayInvoiceResponse(preimage []byte, feesPaid Msat) MultiPayInvoiceResponse
type MultiPayKeysendRequest ¶
type MultiPayKeysendRequest struct {
Request
Keysends []PayKeysendRequest
}
func NewMultiPayKeysendRequest ¶
func NewMultiPayKeysendRequest(keysends []PayKeysendRequest) MultiPayKeysendRequest
type MultiPayKeysendResponse ¶
type MultiPayKeysendResponse = PayKeysendResponse
func NewMultiPayKKeysendResponse ¶
func NewMultiPayKKeysendResponse(preimage []byte, feesPaid Msat) MultiPayKeysendResponse
type Notification ¶
type Notification struct {
Type []byte
}
func (Notification) NotificationType ¶
func (n Notification) NotificationType() []byte
type PayInvoiceRequest ¶
func NewPayInvoiceRequest ¶
func NewPayInvoiceRequest[V string | []byte]( invoice V, amount Msat, ) PayInvoiceRequest
func (PayInvoiceRequest) Marshal ¶
func (p PayInvoiceRequest) Marshal(dst []byte) (b []byte)
Example ¶
ir := NewPayInvoiceRequest("lnbc50n1...", 0)
var b []byte
var err error
if b = ir.Marshal(b); chk.E(err) {
return
}
fmt.Printf("%s\n", b)
b = b[:0]
ir = NewPayInvoiceRequest("lnbc50n1...", 123)
if b = ir.Marshal(b); chk.E(err) {
return
}
fmt.Printf("%s\n", b)
Output: {"method":"pay_invoice","params":{"invoice":"lnbc50n1..."}} {"method":"pay_invoice","params":{"invoice":"lnbc50n1...","amount":123}}
type PayInvoiceResponse ¶
type PayInvoiceResponse struct {
Response
Preimage []byte
FeesPaid Msat // optional, omitted if zero
}
func NewPayInvoiceResponse ¶
func NewPayInvoiceResponse(preimage []byte, feesPaid Msat) PayInvoiceResponse
func (PayInvoiceResponse) Marshal ¶
func (p PayInvoiceResponse) Marshal(dst []byte) (b []byte)
type PayKeysendRequest ¶
type PayKeysendRequest struct {
Request
Amount Msat
Pubkey []byte
Preimage []byte // optional
TLVRecords []TLV // optional
}
func NewPayKeysendRequest ¶
func NewPayKeysendRequest(amount Msat, pubkey, preimage []byte, tlvRecords []TLV) PayKeysendRequest
type PayKeysendResponse ¶
type PayKeysendResponse = PayInvoiceResponse
func NewPayKeysendResponse ¶
func NewPayKeysendResponse(preimage []byte, feesPaid Msat) PayKeysendResponse
type PaymentReceivedNotification ¶
type PaymentReceivedNotification struct {
LookupInvoiceResponse
}
type PaymentSentNotification ¶
type PaymentSentNotification struct {
LookupInvoiceResponse
}