Documentation ¶
Index ¶
- Constants
- Variables
- func BuildInfo() (commitDesc string, hash string)
- func Version() string
- func WithDefaultFeeLimitMsat(defaultLimitMsat int64) func(*App) error
- type App
- func (app *App) AddContact(_ context.Context, contact *model.Contact) (*model.Contact, error)
- func (app *App) AddDiscussion(_ context.Context, discussion *model.Discussion) (*model.Discussion, error)
- func (app *App) Cleanup() (err error)
- func (app *App) ConnectNode(ctx context.Context, address string, hostport string) error
- func (app *App) CreateInvoice(ctx context.Context, memo string, amtMsat int64, expiry int64, private bool) (*model.Invoice, error)
- func (app *App) EstimatePayment(ctx context.Context, payload string, amtMsat int64, discID uint64, ...) (*model.Message, error)
- func (app *App) GetContacts(_ context.Context) ([]model.Contact, error)
- func (app *App) GetDiscussionHistory(_ context.Context, discID uint64, pageOpts model.PageOptions) ([]model.MessageAggregate, error)
- func (app *App) GetDiscussionStatistics(ctx context.Context, id uint64) (*model.DiscussionStatistics, error)
- func (app *App) GetDiscussions(_ context.Context) ([]model.Discussion, error)
- func (app *App) GetInvoices(_ context.Context, pageOpts model.PageOptions) ([]*model.Invoice, error)
- func (app *App) GetNodes(ctx context.Context) ([]model.Node, error)
- func (app *App) GetNodesByAddress(ctx context.Context, address string) ([]model.Node, error)
- func (app *App) GetNodesByAlias(ctx context.Context, aliasSubstr string) ([]model.Node, error)
- func (app *App) GetPayments(_ context.Context, pageOpts model.PageOptions) ([]*model.Payment, error)
- func (app *App) GetRoute(ctx context.Context, dest string, amtMsat int64, payReq string, ...) (*model.Route, error)
- func (app *App) GetSelfBalance(ctx context.Context) (*model.SelfBalance, error)
- func (app *App) GetSelfInfo(ctx context.Context) (*model.SelfInfo, error)
- func (app *App) Init(ctx context.Context, infoTimeoutSecs uint) error
- func (app *App) LookupInvoice(ctx context.Context, payReq string) (*model.Invoice, error)
- func (app *App) OpenChannel(ctx context.Context, address string, amtMsat, pushAmtMsat uint64, ...) (*model.ChannelPoint, error)
- func (app *App) RemoveContactByAddress(_ context.Context, address string) error
- func (app *App) RemoveContactByID(_ context.Context, id uint64) error
- func (app *App) RemoveDiscussion(_ context.Context, id uint64) error
- func (app *App) SendMessage(ctx context.Context, discID uint64, amtMsat int64, payReq string, ...) (*model.MessageAggregate, error)
- func (app *App) SendPay(ctx context.Context, payload string, amtMsat int64, discID uint64, ...) (*model.Message, error)
- func (app *App) SendPayment(ctx context.Context, dest string, amtMsat int64, payReq string, ...) (*model.Payment, error)
- func (app *App) SubscribeInvoices(ctx context.Context) (<-chan *model.Invoice, error)
- func (app *App) SubscribeMessages(ctx context.Context) (<-chan model.MessageAggregate, error)
- func (app *App) SubscribePayments(ctx context.Context) (<-chan *model.Payment, error)
- func (app *App) UpdateDiscussionLastRead(_ context.Context, discID, readMsgID uint64) error
- type BusError
- type ErrKind
- type Error
Constants ¶
const ( // PayloadTypeKey is the key of the payload. PayloadTypeKey = 0x117C17A7 + 2*iota // SenderTypeKey is the key of the sender address. SenderTypeKey // SignatureTypeKey is the key of the sender signature. SignatureTypeKey )
Definition of the payload TLV types. These are used as keys for payloads embedded in payment HTLCs over Lightning, and are required to be in the custom TLV range (>=65536). Additionally, odd types are optional, while even fields are mandatory. If an HTLC containing an unknown even type is received, the HTLC is rejected.
Variables ¶
var ( // DefaultOptions defines the default message options to be used when // no overrides have been set. DefaultOptions = model.MessageOptions{ FeeLimitMsat: 3000, Anonymous: false, } // DefaultPaymentOptions defines the default payment options to be used. DefaultPaymentOptions = DefaultOptions.GetPaymentOptions() )
var ErrDiscAnonymousMessage = fmt.Errorf("anonymous message in group discussion is disallowed")
ErrDiscAnonymousMessage indicates that an anonymous send was requested to a group discussion.
Functions ¶
func BuildInfo ¶
BuildInfo returns the commit descriptor as well as the commit hash used in the current c13n build.
func Version ¶
func Version() string
Version returns the application version as a properly formed string, as per the semantic versioning specification 2.0.0.
func WithDefaultFeeLimitMsat ¶
WithDefaultFeeLimitMsat sets the FeeLimitMsat default value for the app instance. The FeeLimitMsat default value is the default maximum fee used for sending a message.
Types ¶
type App ¶
type App struct { Log *slog.Logger Self lnchat.SelfInfo LNManager lnchat.LightManager Database store.Database Tomb *tomb.Tomb // contains filtered or unexported fields }
App defines the c13n application logic.
func New ¶
func New(lnChat lnchat.LightManager, database store.Database, options ...func(*App) error) (*App, error)
New creates a new app instance.
func (*App) AddContact ¶
AddContact adds a contact to the database if it doesn't exist.
func (*App) AddDiscussion ¶
func (app *App) AddDiscussion(_ context.Context, discussion *model.Discussion) (*model.Discussion, error)
AddDiscussion adds a discussion to database.
func (*App) ConnectNode ¶
ConnectNode connects a node as a peer.
func (*App) CreateInvoice ¶
func (app *App) CreateInvoice(ctx context.Context, memo string, amtMsat int64, expiry int64, private bool) (*model.Invoice, error)
CreateInvoice creates an invoice and returns it.
func (*App) EstimatePayment ¶
func (app *App) EstimatePayment(ctx context.Context, payload string, amtMsat int64, discID uint64, opts model.MessageOptions) (*model.Message, error)
EstimatePayment attempts to calculate the details for sending a payment (or message) to a discussion. If the discussion contains multiple participants, one route for each participant is calculated and the fees are cumulative.
func (*App) GetContacts ¶
GetContacts returns all contacts stored in database.
func (*App) GetDiscussionHistory ¶
func (app *App) GetDiscussionHistory(_ context.Context, discID uint64, pageOpts model.PageOptions) ([]model.MessageAggregate, error)
GetDiscussionHistory returns the requested range of messages for a specific discussion.
func (*App) GetDiscussionStatistics ¶
func (app *App) GetDiscussionStatistics(ctx context.Context, id uint64) ( *model.DiscussionStatistics, error)
GetDiscussionStatistics retrieves the discussion messages and calculates statistics.
func (*App) GetDiscussions ¶
GetDiscussions returns all messages stored in database.
func (*App) GetInvoices ¶
func (app *App) GetInvoices(_ context.Context, pageOpts model.PageOptions) ([]*model.Invoice, error)
GetInvoices retrieves stored invoices.
func (*App) GetNodesByAddress ¶
GetNodesByAddress returns the visible nodes, filtered based on address.
func (*App) GetNodesByAlias ¶
GetNodesByAlias returns the visible nodes, filtered based on the provided alias substring.
func (*App) GetPayments ¶
func (app *App) GetPayments(_ context.Context, pageOpts model.PageOptions) ([]*model.Payment, error)
GetPayments retrieves stored payments.
func (*App) GetRoute ¶
func (app *App) GetRoute(ctx context.Context, dest string, amtMsat int64, payReq string, opts lnchat.PaymentOptions) (*model.Route, error)
GetRoute attempts to discover a route that can fulfil a payment.
func (*App) GetSelfBalance ¶
GetSelfBalance returns the current node's balance.
func (*App) GetSelfInfo ¶
GetSelfInfo returns the current node's information.
func (*App) Init ¶
Init performs any initializations needed at the logic layer, and also opens all persistent subscriptions to the Lightning daemon.
func (*App) LookupInvoice ¶
LookupInvoice retrieves an invoice and returns it.
func (*App) OpenChannel ¶
func (app *App) OpenChannel(ctx context.Context, address string, amtMsat, pushAmtMsat uint64, minInputConfs int32, txOptions model.TxFeeOptions) (*model.ChannelPoint, error)
OpenChannel creates a channel with the node identified by the provided Lightning address. The function returns when the funding transaction is published, meaning the channel is pending and not yet considered open.
func (*App) RemoveContactByAddress ¶
RemoveContactByAddress removes the contact matching the passed address from database.
func (*App) RemoveContactByID ¶
RemoveContactByID removes the contact matching the passed id from database.
func (*App) RemoveDiscussion ¶
RemoveDiscussion removes the discussion matching the passed id from database.
func (*App) SendMessage ¶
func (app *App) SendMessage(ctx context.Context, discID uint64, amtMsat int64, payReq string, payload string, opts model.MessageOptions) (*model.MessageAggregate, error)
SendMessage attempts to send a message. If a payment request is provided, a discussion with the recipient is created with default options if it does not exist. Note: Anonymous messages to group discussions are disallowed.
func (*App) SendPay ¶
func (app *App) SendPay(ctx context.Context, payload string, amtMsat int64, discID uint64, payReq string, opts model.MessageOptions) (*model.Message, error)
SendPay attempts to send a payment. A payment fulfils the payment request, if one is provided, otherwise it is addressed to the discussion participants. If payload is present, it is sent along with the payment (respecting the provided and discussion options, if applicable).
func (*App) SendPayment ¶
func (app *App) SendPayment(ctx context.Context, dest string, amtMsat int64, payReq string, opts lnchat.PaymentOptions, tlvs map[uint64][]byte) (*model.Payment, error)
SendPayment attempts to send a payment.
func (*App) SubscribeInvoices ¶
func (*App) SubscribeMessages ¶
SubscribeMessages returns a subscription for message notifications. The subscriber is responsible for draining the channel once the subscription terminates.