app

package
v0.2.1-alpha Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2022 License: MIT Imports: 20 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.

View Source
const (
	// ReceiveTopic is the pubsub topic for received messages.
	ReceiveTopic = "message.receive"
)

Variables

View Source
var DefaultOptions = model.MessageOptions{
	FeeLimitMsat: 3000,
	Anonymous:    false,
}

DefaultOptions defines the default message options to be used when no overrides have been set.

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

	PubSubBus *gochannel.GoChannel

	Tomb *tomb.Tomb
}

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(ctx context.Context, discID uint64,
	pageOpts model.PageOptions) ([]model.Message, error)

GetDiscussionHistory returns the requested range of messages for a specific discussion.

func (*App) GetDiscussionStatistics

func (app *App) GetDiscussionStatistics(_ 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) 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) 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 a persistent publisher listening for received messages from 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) SendPayment

func (app *App) SendPayment(ctx context.Context,
	payload string, amtMsat int64, discID uint64, payReq string,
	opts model.MessageOptions) (*model.Message, error)

SendPayment 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) SubscribeMessages

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

SubscribeMessages returns a channel over which received messages are sent.

func (*App) UpdateDiscussionLastRead

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

UpdateDiscussionLastRead updates a discussion's last read message.

type ErrKind

type ErrKind int

ErrKind defines the kind of an error.

const (
	MarshalError ErrKind = iota
	Cancelled
	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