cliche

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2022 License: Apache-2.0 Imports: 9 Imported by: 1

README

go-cliche

This is a small library that will start cliché and communicate with it via STDIN and STDOUT, allowing you to send commands, receive replies and also receive events.

See the example below or read the full API docs for more (not much more).

Examples

Starting it:
c := &cliche.Control{
	DataDir: ".",
    BinaryPath: "/usr/local/bin/cliche",
	// or JARPath: "/home/name/Downloads/cliche.jar", (requires java)
}

err := c.Start()
if err != nil {
	log.Fatal(err)
}
Getting general information:
info, err := c.GetInfo()
if err != nil {
	log.Fatal(err)
}
log.Print(info)
Listening for events
go func () {
	for invpaid := range c.IncomingPayments {
		log.Printf("got payment: %d msat", invpaid.Msatoshi)
    }
}
Creating an invoice
inv, err := c.CreateInvoice(cliche.CreateInvoiceParams{
	Msatoshi: 100000, Description: "test invoice"})
if err != nil {
	log.Fatal(err)
}
log.Print(inv)
Making an arbitrary call
resp, err := c.Call("request-hc", map[string]interface{}{
	"pubkey": "02cd1b7bc418fac2dc99f0ba350d60fa6c45fde5ab6017ee14df6425df485fb1dd",
	"host":   "134.209.228.207",
	"port":   80,
})
# resp will be json.RawMessage aka []byte

Other commands are available in the API docs.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChannelInfo added in v0.2.1

type ChannelInfo struct {
	ID             string `json:"id"`
	ShortChannelId string `json:"short_channel_id"`
	Balance        int    `json:"balance"`
	CanReceive     int64  `json:"can_receive"`
	CanSend        int64  `json:"can_send"`
	HostedChannel  struct {
		OverrideProposal *struct {
			OurBalance   int64 `json:"our_balance"`
			TheirBalance int64 `json:"their_balance"`
		} `json:"override_proposal"`
		ResizeProposal *int64 `json:"resize_proposal"`
	} `json:"hosted_channel"`
	Inflight struct {
		Incoming int `json:"incoming"`
		Outgoing int `json:"outgoing"`
		Revealed int `json:"revealed"`
	} `json:"inflight"`
	Peer struct {
		Addr      string `json:"addr"`
		OurPubkey string `json:"our_pubkey"`
		Pubkey    string `json:"pubkey"`
	} `json:"peer"`
	Policy struct {
		BaseFee         int64 `json:"base_fee"`
		CltvDelta       int   `json:"cltv_delta"`
		FeePerMillionth int   `json:"fee_per_millionth"`
		HtlcMax         int64 `json:"htlc_max"`
		HtlcMin         int64 `json:"htlc_min"`
	} `json:"policy,omitempty"`
	Status string `json:"status"`
}

type CheckPaymentResult

type CheckPaymentResult struct {
	PaymentInfo
}

type Control

type Control struct {
	JARPath    string
	BinaryPath string
	DataDir    string

	DontLogStderr bool
	DontLogStdout bool

	PaymentSuccesses chan PaymentSucceededEvent
	PaymentFailures  chan PaymentFailedEvent
	IncomingPayments chan PaymentReceivedEvent
	// contains filtered or unexported fields
}

func (*Control) Call

func (c *Control) Call(method string, params interface{}) (json.RawMessage, error)

func (*Control) CheckPayment

func (c *Control) CheckPayment(hash string) (
	result CheckPaymentResult,
	err error,
)

func (*Control) CreateInvoice

func (c *Control) CreateInvoice(params CreateInvoiceParams) (
	result CreateInvoiceResult,
	err error,
)

func (*Control) GetInfo

func (c *Control) GetInfo() (result GetInfoResult, err error)

func (*Control) ListPayments added in v0.2.0

func (c *Control) ListPayments(count int) (
	result ListPaymentsResult,
	err error,
)

func (*Control) PayInvoice

func (c *Control) PayInvoice(params PayInvoiceParams) (
	result PayInvoiceResult,
	err error,
)

func (*Control) Start

func (c *Control) Start() error

type CreateInvoiceParams

type CreateInvoiceParams struct {
	Description     string `json:"description,omitempty"`
	DescriptionHash string `json:"description_hash,omitempty"`
	Msatoshi        int64  `json:"msatoshi,omitempty"`
	Preimage        string `json:"preimage,omitempty"`
	Label           string `json:"label,omitempty"`
}

type CreateInvoiceResult

type CreateInvoiceResult struct {
	Invoice     string `json:"invoice"`
	PaymentHash string `json:"payment_hash"`
}

type GetInfoResult

type GetInfoResult struct {
	BlockHeight int           `json:"block_height"`
	Channels    []ChannelInfo `json:"channels"`
	FeeRates    struct {
		Num1   int `json:"1"`
		Num10  int `json:"10"`
		Num100 int `json:"100"`
	} `json:"fee_rates"`
	FiatRates struct {
		USD float64 `json:"usd"`
	} `json:"fiat_rates"`
	KnownChannels struct {
		Hosted int `json:"hosted"`
		Normal int `json:"normal"`
	} `json:"known_channels"`
	MainPubkey       string `json:"main_pubkey"`
	OutgoingPayments []struct {
		Hash  string `json:"hash"`
		Htlcs []struct {
			Channel  string `json:"channel"`
			Expiry   int    `json:"expiry"`
			ID       int    `json:"id"`
			Msatoshi int64  `json:"msatoshi"`
		} `json:"htlcs"`
	} `json:"outgoing_payments"`
	Wallets []struct {
		Balance int64  `json:"balance"`
		Label   string `json:"label"`
	} `json:"wallets"`
}

type JSONRPCNotification added in v0.3.0

type JSONRPCNotification struct {
	Method string          `json:"method"`
	Params json.RawMessage `json:"params"`
}

type JSONRPCRequest added in v0.3.0

type JSONRPCRequest struct {
	Id     string      `json:"id"`
	Method string      `json:"method"`
	Params interface{} `json:"params"`
}

type JSONRPCResponse

type JSONRPCResponse struct {
	Id     string          `json:"id"`
	Result json.RawMessage `json:"result,omitempty"`
	Error  *struct {
		Code    int    `json:"code"`
		Message string `json:"message"`
	} `json:"error,omitempty"`
}

type ListPaymentsResult added in v0.2.0

type ListPaymentsResult []PaymentInfo

type PayInvoiceParams

type PayInvoiceParams struct {
	Invoice  string `json:"invoice"`
	Msatoshi int64  `json:"msatoshi,omitempty"`
}

type PayInvoiceResult

type PayInvoiceResult struct {
	Sent        bool   `json:"sent"`
	Payee       string `json:"payee"`
	FeeReserve  int    `json:"fee_reserve"`
	PaymentHash string `json:"payment_hash"`
}

type PaymentFailedEvent

type PaymentFailedEvent struct {
	PaymentHash string   `json:"payment_hash"`
	Parts       int      `json:"parts"`
	Failure     []string `json:"failure"`
}

type PaymentInfo added in v0.2.0

type PaymentInfo struct {
	Status      string `json:"status"`
	SeenAt      int64  `json:"seen_at"`
	Invoice     string `json:"invoice"`
	Preimage    string `json:"preimage"`
	Msatoshi    int64  `json:"msatoshi"`
	UpdatedAt   int64  `json:"updated_at"`
	IsIncoming  bool   `json:"is_incoming"`
	FeeMsatoshi int64  `json:"fee_msatoshi"`
	PaymentHash string `json:"payment_hash"`
}

type PaymentReceivedEvent

type PaymentReceivedEvent struct {
	PaymentHash string `json:"payment_hash"`
	Preimage    string `json:"preimage"`
	Msatoshi    int64  `json:"msatoshi"`
}

type PaymentSucceededEvent

type PaymentSucceededEvent struct {
	PaymentHash string `json:"payment_hash"`
	FeeMsatoshi int64  `json:"fee_msatoshi"`
	Msatoshi    int64  `json:"msatoshi"`
	Preimage    string `json:"preimage"`
	Parts       int    `json:"parts"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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