nwc

package
v1.2.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2024 License: Unlicense Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	PaymentSent     = B("payment_sent")
	PaymentReceived = B("payment_received")
)
View Source
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 B
}{
	B("RATE_LIMITED"),
	B("NOT_IMPLEMENTED"),
	B("INSUFFICIENT_BALANCE"),
	B("QUOTA_EXCEEDED"),
	B("RESTRICTED"),
	B("UNAUTHORIZED"),
	B("INTERNAL"),
	B("OTHER"),
}
View Source
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 B
}{
	B("method"),
	B("params"),
	B("result_type"),
	B("error"),
	B("result"),
	B("invoice"),
	B("amount"),
	B("preimage"),
	B("fees_paid"),
	B("id"),
	B("tlv_records"),
	B("type"),
	B("value"),
	B("pubkey"),
	B("description"),
	B("description_hash"),
	B("expiry"),
	B("created_at"),
	B("expires_at"),
	B("metadata"),
	B("settled_at"),
	B("from"),
	B("until"),
	B("offset"),
	B("unpaid"),
	B("balance"),
	B("notifications"),
	B("notification_type"),
	B("notification"),
	B("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.

View Source
var Methods = struct {
	PayInvoice,
	MultiPayInvoice,
	PayKeysend,
	MultiPayKeysend,
	MakeInvoice,
	LookupInvoice,
	ListTransactions,
	GetBalance,
	GetInfo B
}{
	B("pay_invoice"),
	B("multi_pay_invoice"),
	B("pay_keysend"),
	B("multi_pay_keysend"),
	B("make_invoice"),
	B("lookup_invoice"),
	B("list_transactions"),
	B("get_balance"),
	B("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.

View Source
var Notifications = struct {
	PaymentReceived, PaymentSent B
}{
	B("payment_received"),
	B("payment_sent"),
}

Notifications are the proper strings for the Notification.NotificationType

Functions

This section is empty.

Types

type B

type B = []byte

type Client

type Client struct {
}

type Ctx

type Ctx = context.T

type E

type E = error

type Error

type Error struct {
	Code    B
	Message B
}

type GetBalanceRequest

type GetBalanceRequest struct {
	Request
}

func NewGetBalanceRequest

func NewGetBalanceRequest() *GetBalanceRequest

type GetBalanceResponse

type GetBalanceResponse struct {
	Response
	Balance Msat
}

func NewGetBalanceResponse

func NewGetBalanceResponse(balance Msat) *GetBalanceResponse

type GetInfo

type GetInfo struct {
	Alias       B
	Color       B // Hex string
	Pubkey      B
	Network     B // mainnet/testnet/signet/regtest
	BlockHeight uint64
	BlockHash   B
	Methods     B // pay_invoice, get_balance, make_invoice, lookup_invoice, list_transactions, get_info (list of methods)
}

type GetInfoRequest

type GetInfoRequest struct {
	Request
}

func NewGetInfoRequest

func NewGetInfoRequest() GetInfoRequest

type GetInfoResponse

type GetInfoResponse struct {
	Response
	GetInfo
}

func NewGetInfoResponse

func NewGetInfoResponse(gi GetInfo) GetInfoResponse

type Invoice

type Invoice struct {
	Id      B // nil for request, required for responses (omitted if nil)
	Invoice B
	Amount  Msat // optional, omitted if zero
}

type InvoiceResponse

type InvoiceResponse struct {
	Type            B // incoming or outgoing
	Invoice         B // optional
	Description     B // optional
	DescriptionHash B // optional
	Preimage        B // optional if unpaid
	PaymentHash     B
	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 ListTransactions struct {
	From   int64 // optional
	Until  int64 // optional
	Limit  int   // optional
	Offset int   // optional
	Unpaid bool  // optional default false
	Type   B     // incoming/outgoing/empty for "both"
}

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

type LookupInvoiceRequest struct {
	Request
	PaymentHash, Invoice B
}

func NewLookupInvoiceRequest

func NewLookupInvoiceRequest(paymentHash, invoice B) *LookupInvoiceRequest

type LookupInvoiceResponse

type LookupInvoiceResponse struct {
	Response
	LookupInvoice
}

func NewLookupInvoiceResponse

func NewLookupInvoiceResponse(resp LookupInvoice) LookupInvoiceResponse

type MakeInvoiceRequest

type MakeInvoiceRequest struct {
	Request
	Amount          Msat
	Description     B // optional
	DescriptionHash B // optional
	Expiry          N // optional
}

func NewMakeInvoiceRequest

func NewMakeInvoiceRequest(amount Msat, description, descriptionHash B,
	expiry N) 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)

func (Msat) Bytes

func (m Msat) Bytes(dst B) (b B)

type MultiPayInvoiceRequest

type MultiPayInvoiceRequest struct {
	Request
	Invoices []Invoice
}

func NewMultiPayInvoiceRequest

func NewMultiPayInvoiceRequest(invoices []Invoice) MultiPayInvoiceRequest

type MultiPayInvoiceResponse

type MultiPayInvoiceResponse = PayInvoiceResponse

func NewMultiPayInvoiceResponse

func NewMultiPayInvoiceResponse(preimage B, 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 B, feesPaid Msat) MultiPayKeysendResponse

type N

type N = int

type Notification

type Notification struct {
	Type B
}

func (Notification) NotificationType

func (n Notification) NotificationType() B

type Notifier

type Notifier interface {
	NotificationType() B
}

type PayInvoiceRequest

type PayInvoiceRequest struct {
	Request
	Invoice
}

func NewPayInvoiceRequest

func NewPayInvoiceRequest[V S | B](invoice V, amount Msat) PayInvoiceRequest

func (PayInvoiceRequest) MarshalJSON

func (p PayInvoiceRequest) MarshalJSON(dst B) (b B, err E)
Example
ir := NewPayInvoiceRequest("lnbc50n1...", 0)
var b B
var err E
if b, err = ir.MarshalJSON(b); chk.E(err) {
	return
}
fmt.Printf("%s\n", b)
b = b[:0]
ir = NewPayInvoiceRequest("lnbc50n1...", 123)
if b, err = ir.MarshalJSON(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}}

func (PayInvoiceRequest) UnmarshalJSON

func (p PayInvoiceRequest) UnmarshalJSON(b B) (r B, err E)

type PayInvoiceResponse

type PayInvoiceResponse struct {
	Response
	Preimage B
	FeesPaid Msat // optional, omitted if zero
}

func NewPayInvoiceResponse

func NewPayInvoiceResponse(preimage B, feesPaid Msat) PayInvoiceResponse

func (PayInvoiceResponse) MarshalJSON

func (p PayInvoiceResponse) MarshalJSON(dst B) (b B, err E)

func (PayInvoiceResponse) UnmarshalJSON

func (p PayInvoiceResponse) UnmarshalJSON(b B) (r B, err E)

type PayKeysendRequest

type PayKeysendRequest struct {
	Request
	Amount     Msat
	Pubkey     B
	Preimage   B     // optional
	TLVRecords []TLV // optional
}

func NewPayKeysendRequest

func NewPayKeysendRequest(amount Msat, pubkey, preimage B, tlvRecords []TLV) PayKeysendRequest

type PayKeysendResponse

type PayKeysendResponse = PayInvoiceResponse

func NewPayKeysendResponse

func NewPayKeysendResponse(preimage B, feesPaid Msat) PayKeysendResponse

type PaymentReceivedNotification

type PaymentReceivedNotification struct {
	LookupInvoiceResponse
}

type PaymentSentNotification

type PaymentSentNotification struct {
	LookupInvoiceResponse
}

type Request

type Request struct {
	Method B
}

func (Request) RequestType

func (r Request) RequestType() B

type Requester

type Requester interface {
	RequestType() B
}

type Response

type Response struct {
	Type B
	Error
}

func (Response) ResultType

func (r Response) ResultType() B

type Resulter

type Resulter interface {
	ResultType() B
}

type S

type S = string

type Server

type Server struct {
}

type TLV

type TLV struct {
	Type  uint64
	Value B
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL