Nostrduino
Loading...
Searching...
No Matches
Data Structures | Public Member Functions
nostr::NWC Class Reference

#include <NWC.h>

Public Member Functions

 ~NWC ()
 
 NWC (Transport *transport, NostrString nwcUrl, const NostrLimits &limits=NostrLimits(), NWCEncryptionPolicy encryptionPolicy=NWCEncryptionPolicy::RequireNip44)
 
void loop ()
 
void close ()
 
bool isReady () const
 
bool isValid () const
 
Nip47Encryption getEncryption () const
 
void payInvoice (NostrString invoice, MilliSats amount=MILLISATS_UNSPECIFIED, std::function< void(PayInvoiceResponse)> onRes=nullptr, std::function< void(NostrString, NostrString)> onErr=nullptr)
 
void multiPayInvoice (std::initializer_list< Invoice > invoices, std::function< void(MultiPayInvoiceResponse)> onRes=nullptr, std::function< void(NostrString, NostrString)> onErr=nullptr)
 
void multiPayInvoice (const std::vector< Invoice > &invoices, std::function< void(MultiPayInvoiceResponse)> onRes=nullptr, std::function< void(NostrString, NostrString)> onErr=nullptr)
 
void payKeySend (NostrString pubkey, MilliSats amount, NostrString preimage="", std::initializer_list< TLVRecords > tlv={}, std::function< void(PayKeySendResponse)> onRes=nullptr, std::function< void(NostrString, NostrString)> onErr=nullptr)
 
void payKeySend (NostrString pubkey, MilliSats amount, NostrString preimage, const std::vector< TLVRecords > &tlv, std::function< void(PayKeySendResponse)> onRes=nullptr, std::function< void(NostrString, NostrString)> onErr=nullptr)
 
void multiPayKeySend (std::initializer_list< KeySend > keySends, std::function< void(MultiPayKeySendResponse)> onRes=nullptr, std::function< void(NostrString, NostrString)> onErr=nullptr)
 
void multiPayKeySend (const std::vector< KeySend > &keySends, std::function< void(MultiPayKeySendResponse)> onRes=nullptr, std::function< void(NostrString, NostrString)> onErr=nullptr)
 
void makeInvoice (MilliSats amount, NostrString description="", NostrString descriptionHash="", unsigned long expiry=0, std::function< void(MakeInvoiceResponse)> onRes=nullptr, std::function< void(NostrString, NostrString)> onErr=nullptr)
 
void lookUpPaymentHash (NostrString paymentHash, std::function< void(LookUpInvoiceResponse)> onRes=nullptr, std::function< void(NostrString, NostrString)> onErr=nullptr)
 
void lookUpInvoice (NostrString invoice, std::function< void(LookUpInvoiceResponse)> onRes=nullptr, std::function< void(NostrString, NostrString)> onErr=nullptr)
 
void listTransactions (unsigned long from=0, unsigned long until=0, int limit=0, int offset=0, bool unpaid=false, NostrString type="", std::function< void(ListTransactionsResponse)> onRes=nullptr, std::function< void(NostrString, NostrString)> onErr=nullptr)
 
void getBalance (std::function< void(GetBalanceResponse)> onRes=nullptr, std::function< void(NostrString, NostrString)> onErr=nullptr)
 
void getInfo (std::function< void(GetInfoResponse)> onRes=nullptr, std::function< void(NostrString, NostrString)> onErr=nullptr)
 
void subscribeNotifications (std::function< void(NotificationResponse)> onRes, std::function< void(NostrString, NostrString)> onErr)
 
void setSeenTracker (NostrSeenCallback callback)
 

Detailed Description

A class to interact with the Nostr Wallet Connect services without dealing with the underlying transport

Constructor & Destructor Documentation

◆ ~NWC()

NWC::~NWC ( )

◆ NWC()

NWC::NWC ( Transport transport,
NostrString  nwcUrl,
const NostrLimits limits = NostrLimits(),
NWCEncryptionPolicy  encryptionPolicy = NWCEncryptionPolicy::RequireNip44 
)

Initialize a standalone NWC service

Parameters
transportA transport object, you can get one for the esp32 platform using nostr::esp32::ESP32Platform::getTransport() , for other platforms you need to implement the Transport interface
nwcUrlThe NWC connection URL
limitsResource and protocol limits
encryptionPolicyEncryption policy used after the verified NIP-47 info event has been processed

The default NWCEncryptionPolicy::RequireNip44 requires nip44_v2. A legacy wallet can be enabled explicitly:

Member Function Documentation

◆ close()

void NWC::close ( )

Close the service, after this you should throw away the NWC object

◆ getBalance()

void NWC::getBalance ( std::function< void(GetBalanceResponse)>  onRes = nullptr,
std::function< void(NostrString, NostrString)>  onErr = nullptr 
)

Get the balance

Parameters
onResA callback that will be called when the balance is retrieved (optional)
onErrA callback that will be called when the balance retrieval fails (optional)

◆ getEncryption()

Nip47Encryption nostr::NWC::getEncryption ( ) const
inline

The encryption selected from the wallet info event.

◆ getInfo()

void NWC::getInfo ( std::function< void(GetInfoResponse)>  onRes = nullptr,
std::function< void(NostrString, NostrString)>  onErr = nullptr 
)

Get the info

Parameters
onResA callback that will be called when the info is retrieved (optional)
onErrA callback that will be called when the info retrieval fails (optional)

◆ isReady()

bool nostr::NWC::isReady ( ) const
inline

Whether the wallet info event has been processed and requests can be sent.

◆ isValid()

bool nostr::NWC::isValid ( ) const
inline

Whether the supplied NWC connection string is valid.

◆ listTransactions()

void NWC::listTransactions ( unsigned long  from = 0,
unsigned long  until = 0,
int  limit = 0,
int  offset = 0,
bool  unpaid = false,
NostrString  type = "",
std::function< void(ListTransactionsResponse)>  onRes = nullptr,
std::function< void(NostrString, NostrString)>  onErr = nullptr 
)

List transactions

Parameters
fromThe start time of the transactions to list (optional)
untilThe end time of the transactions to list (optional)
limitThe maximum number of transactions to list (optional)
offsetThe offset of the transactions to list (optional)
unpaidWhether to list only unpaid transactions (optional)
typeThe type of transactions to list (optional)
onResA callback that will be called when the transactions are listed (optional)
onErrA callback that will be called when the transactions listing fails (optional)

◆ lookUpInvoice()

void NWC::lookUpInvoice ( NostrString  invoice,
std::function< void(LookUpInvoiceResponse)>  onRes = nullptr,
std::function< void(NostrString, NostrString)>  onErr = nullptr 
)

Look up an invoice

Parameters
invoiceThe invoice to look up
onResA callback that will be called when the invoice is found (optional)
onErrA callback that will be called when the invoice is not found (optional)

◆ lookUpPaymentHash()

void NWC::lookUpPaymentHash ( NostrString  paymentHash,
std::function< void(LookUpInvoiceResponse)>  onRes = nullptr,
std::function< void(NostrString, NostrString)>  onErr = nullptr 
)

Look up a payment hash

Parameters
paymentHashThe payment hash to look up
onResA callback that will be called when the payment is found (optional)
onErrA callback that will be called when the payment is not found (optional)

◆ loop()

void NWC::loop ( )

Tick the main loop. This should be called in the loop() function of your sketch

◆ makeInvoice()

void NWC::makeInvoice ( MilliSats  amount,
NostrString  description = "",
NostrString  descriptionHash = "",
unsigned long  expiry = 0,
std::function< void(MakeInvoiceResponse)>  onRes = nullptr,
std::function< void(NostrString, NostrString)>  onErr = nullptr 
)

Create a lightning invoice

Parameters
amountThe amount to invoice
descriptionA description of the invoice (optional)
descriptionHashA hash of the description (optional)
expiryThe expiry time of the invoice in seconds (optional)
onResA callback that will be called when the invoice is created (optional)
onErrA callback that will be called when the invoice creation fails (optional)

◆ multiPayInvoice() [1/2]

void NWC::multiPayInvoice ( const std::vector< Invoice > &  invoices,
std::function< void(MultiPayInvoiceResponse)>  onRes = nullptr,
std::function< void(NostrString, NostrString)>  onErr = nullptr 
)

◆ multiPayInvoice() [2/2]

void NWC::multiPayInvoice ( std::initializer_list< Invoice invoices,
std::function< void(MultiPayInvoiceResponse)>  onRes = nullptr,
std::function< void(NostrString, NostrString)>  onErr = nullptr 
)

Pay multiple lightning invoices

Parameters
invoicesA list of invoices to pay
onResA callback that will be called when the payment is successful (nb. it will be called once for each invoice) (optional)
onErrA callback that will be called when the payment fails (optional)

◆ multiPayKeySend() [1/2]

void NWC::multiPayKeySend ( const std::vector< KeySend > &  keySends,
std::function< void(MultiPayKeySendResponse)>  onRes = nullptr,
std::function< void(NostrString, NostrString)>  onErr = nullptr 
)

◆ multiPayKeySend() [2/2]

void NWC::multiPayKeySend ( std::initializer_list< KeySend keySends,
std::function< void(MultiPayKeySendResponse)>  onRes = nullptr,
std::function< void(NostrString, NostrString)>  onErr = nullptr 
)

Send multiple keysend payments

Parameters
keySendsA list of keysend payments to send
onResA callback that will be called when the payment is successful (nb. it will be called once for each keysend) (optional)
onErrA callback that will be called when the payment fails (optional)

◆ payInvoice()

void NWC::payInvoice ( NostrString  invoice,
MilliSats  amount = MILLISATS_UNSPECIFIED,
std::function< void(PayInvoiceResponse)>  onRes = nullptr,
std::function< void(NostrString, NostrString)>  onErr = nullptr 
)

Pay a lightning invoice

Parameters
invoiceThe invoice to pay
amountThe amount to pay, if not specified the full amount will be paid (optional)
onResA callback that will be called when the payment is successful (optional)
onErrA callback that will be called when the payment fails (optional)

◆ payKeySend() [1/2]

void NWC::payKeySend ( NostrString  pubkey,
MilliSats  amount,
NostrString  preimage,
const std::vector< TLVRecords > &  tlv,
std::function< void(PayKeySendResponse)>  onRes = nullptr,
std::function< void(NostrString, NostrString)>  onErr = nullptr 
)

◆ payKeySend() [2/2]

void NWC::payKeySend ( NostrString  pubkey,
MilliSats  amount,
NostrString  preimage = "",
std::initializer_list< TLVRecords tlv = {},
std::function< void(PayKeySendResponse)>  onRes = nullptr,
std::function< void(NostrString, NostrString)>  onErr = nullptr 
)

Send a keysend payment

Parameters
pubkeyThe pubkey to send to
amountThe amount to send
preimageThe preimage to use (optional)
tlvA list of TLV records to include (optional)
onResA callback that will be called when the payment is successful (optional)
onErrA callback that will be called when the payment fails (optional)

◆ setSeenTracker()

void nostr::NWC::setSeenTracker ( NostrSeenCallback  callback)
inline

Set the event tracking policy used by the managed pool.

◆ subscribeNotifications()

void NWC::subscribeNotifications ( std::function< void(NotificationResponse)>  onRes,
std::function< void(NostrString, NostrString)>  onErr 
)

Subscribe to payment notifications

Parameters
onResA callback that will be called when a payment notification is received
onErrA callback that will be called when an error is received (optional)

The documentation for this class was generated from the following files: