app

package
v0.3.0-alpha Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2022 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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()
)
View Source
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

func BuildInfo() (commitDesc string, hash string)

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

func WithDefaultFeeLimitMsat(defaultLimitMsat int64) func(*App) error

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

func (app *App) AddContact(_ context.Context, contact *model.Contact) (*model.Contact, error)

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) Cleanup

func (app *App) Cleanup() (err error)

Cleanup performs cleanup and shutdown.

func (*App) ConnectNode

func (app *App) ConnectNode(ctx context.Context, address string, hostport string) error

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

func (app *App) GetContacts(_ context.Context) ([]model.Contact, error)

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

func (app *App) GetDiscussions(_ context.Context) ([]model.Discussion, error)

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) GetNodes

func (app *App) GetNodes(ctx context.Context) ([]model.Node, error)

GetNodes returns all nodes visible in the underlying lightning network.

func (*App) GetNodesByAddress

func (app *App) GetNodesByAddress(ctx context.Context, address string) ([]model.Node, error)

GetNodesByAddress returns the visible nodes, filtered based on address.

func (*App) GetNodesByAlias

func (app *App) GetNodesByAlias(ctx context.Context, aliasSubstr string) ([]model.Node, error)

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

func (app *App) GetSelfBalance(ctx context.Context) (*model.SelfBalance, error)

GetSelfBalance returns the current node's balance.

func (*App) GetSelfInfo

func (app *App) GetSelfInfo(ctx context.Context) (*model.SelfInfo, error)

GetSelfInfo returns the current node's information.

func (*App) Init

func (app *App) Init(ctx context.Context, infoTimeoutSecs uint) error

Init performs any initializations needed at the logic layer, and also opens all persistent subscriptions to the Lightning daemon.

func (*App) LookupInvoice

func (app *App) LookupInvoice(ctx context.Context, payReq string) (*model.Invoice, error)

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

func (app *App) RemoveContactByAddress(_ context.Context, address string) error

RemoveContactByAddress removes the contact matching the passed address from database.

func (*App) RemoveContactByID

func (app *App) RemoveContactByID(_ context.Context, id uint64) error

RemoveContactByID removes the contact matching the passed id from database.

func (*App) RemoveDiscussion

func (app *App) RemoveDiscussion(_ context.Context, id uint64) error

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 *App) SubscribeInvoices(ctx context.Context) (<-chan *model.Invoice, error)

func (*App) SubscribeMessages

func (app *App) SubscribeMessages(ctx context.Context) (<-chan model.MessageAggregate, error)

SubscribeMessages returns a subscription for message notifications. The subscriber is responsible for draining the channel once the subscription terminates.

func (*App) SubscribePayments

func (app *App) SubscribePayments(ctx context.Context) (<-chan *model.Payment, error)

func (*App) UpdateDiscussionLastRead

func (app *App) UpdateDiscussionLastRead(_ context.Context, discID, readMsgID uint64) error

UpdateDiscussionLastRead updates a discussion's last read message.

type BusError

type BusError struct {
	// contains filtered or unexported fields
}

func (BusError) Error

func (be BusError) Error() string

type ErrKind

type ErrKind int

ErrKind defines the kind of an error.

const (
	Cancelled ErrKind = iota
	DeadlineExceeded
	NetworkError
	PermissionError
	NoRouteFound
	InvalidAddress
	InsufficientBalance
	ContactAlreadyExists
	ContactNotFound
	DiscussionAlreadyExists
	DiscussionNotFound
	UnknownError
	InternalError
)

Declaration of error kind enumeration.

type Error

type Error struct {
	Kind ErrKind

	Err error
	// contains filtered or unexported fields
}

Error represents an application error and contains error details.

func (Error) Error

func (e Error) Error() string

func (Error) Unwrap

func (e Error) Unwrap() error

Unwrap returns the underlying error of an Error.

Jump to

Keyboard shortcuts

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