lnsocket

package module
v0.0.0-...-4731544 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2022 License: MIT Imports: 10 Imported by: 0

README

lnsocket

A simple C library for sending messages over the lightning network

Thanks to Rusty and the clightning project for much of this code, I have adapted it to be more library friendly.

Motivation

I wanted a way to send custom messages to my lightning node, such as RPC. Building this as a simple C library will allow you to speak the lightning network in native applications, like on mobile.

Dependencies

You'll need libtool, autoconf, and automake for the libsodium & secp256k1 submodules, but otherwise there are no dependencies.

You'll need emscripten for the wasm build.

Building

$ make
iOS
$ make ios

This will build lnsocket.a, libsodium.a and libsecp256k1.a under target/ios for arm64 and ios-sim-x86.

WASM/JS/Web
$ make wasm

This will build lnsocket.js and lnsocket.wasm in target/wasm so that you can connect to the lightning network from your browser via websockets. See lnsocket_example.js for a demo.

Examples

  • See test.c for a ping/pong example

  • See lnrpc.c for an RPC example

Contributing

Send patches to jb55@jb55.com:

$ git config format.subjectPrefix 'PATCH lnsocket'
$ git config sendemail.to 'William Casarin <jb55@jb55.com>'
$ git send-email --annotate HEAD^

See git-send-email.io for configuring your mailer

You can open a PR on github as well

Documentation

Index

Constants

View Source
const (
	COMMANDO_CMD             = 0x4c4f
	COMMANDO_REPLY_CONTINUES = 0x594b
	COMMANDO_REPLY_TERM      = 0x594d
)

Variables

This section is empty.

Functions

func ParseMsgType

func ParseMsgType(bytes []byte) uint16

Types

type CommandoMsg

type CommandoMsg struct {
	Rune      string
	Method    string
	Params    string
	RequestId uint64
}

func NewCommandoMsg

func NewCommandoMsg(token string, method string, params string) CommandoMsg

func (*CommandoMsg) Decode

func (msg *CommandoMsg) Decode(reader io.Reader, size uint32) error

func (*CommandoMsg) Encode

func (msg *CommandoMsg) Encode(buf *bytes.Buffer, pver uint32) error

func (*CommandoMsg) MsgType

func (msg *CommandoMsg) MsgType() lnwire.MessageType

type LNSocket

type LNSocket struct {
	Conn        net.Conn
	PrivKeyECDH *keychain.PrivKeyECDH
}

func (*LNSocket) Connect

func (ln *LNSocket) Connect(hostname string, pubkey string) error

func (*LNSocket) ConnectAndInit

func (ln *LNSocket) ConnectAndInit(hostname string, pubkey string) error

func (*LNSocket) ConnectWith

func (ln *LNSocket) ConnectWith(netAddr *lnwire.NetAddress) error

func (*LNSocket) Disconnect

func (ln *LNSocket) Disconnect()

func (*LNSocket) GenKey

func (ln *LNSocket) GenKey()

func (*LNSocket) PerformInit

func (ln *LNSocket) PerformInit() error

func (*LNSocket) Recv

func (ln *LNSocket) Recv() (uint16, []byte, error)

func (*LNSocket) Rpc

func (ln *LNSocket) Rpc(token string, method string, params string) (string, error)

Directories

Path Synopsis
go module

Jump to

Keyboard shortcuts

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