Skip to content

Commit

Permalink
rpc: add delexpiredinvoice and autocleaninvoice commands
Browse files Browse the repository at this point in the history
Adds two commands, delexpiredinvoice and autocleaninvoice.
  • Loading branch information
niftynei committed Aug 16, 2019
1 parent 6110b36 commit 9250564
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
40 changes: 38 additions & 2 deletions glightning/lightning.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,42 @@ func (l *Lightning) WaitInvoice(label string) (*CompletedInvoice, error) {
return &result, err
}

type DeleteExpiredInvoiceReq struct {
MaxExpiryTime uint64 `json:"maxexpirytime,omitempty"`
}

func (r *DeleteExpiredInvoiceReq) Name() string {
return "delexpiredinvoice"
}

func (l *Lightning) DeleteExpiredInvoicesSince(unixTime uint64) error {
var result interface{}
return l.client.Request(&DeleteExpiredInvoiceReq{unixTime}, &result)
}

type AutoCleanInvoiceRequest struct {
CycleSeconds uint32 `json:"cycle_seconds"`
ExpiredBySeconds uint32 `json:"expired_by,omitempty"`
}

type AutoCleanResult struct{}

func (r *AutoCleanInvoiceRequest) Name() string {
return "autocleaninvoice"
}

func (l *Lightning) DisableInvoiceAutoclean() error {
return l.SetInvoiceAutoclean(0, 0)
}

// Perform cleanup every {cycle_seconds} (default 3600), or disable autoclean if 0.
// Clean up expired invoices that have expired for {expired_by} seconds (default 86400).
func (l *Lightning) SetInvoiceAutoclean(intervalSeconds, expiredBySeconds uint32) error {
var result string
err := l.client.Request(&AutoCleanInvoiceRequest{intervalSeconds, expiredBySeconds}, &result)
return err
}

type DecodePayRequest struct {
Bolt11 string `json:"bolt11"`
Description string `json:"description,omitempty"`
Expand Down Expand Up @@ -1870,8 +1906,8 @@ type ChannelInfo struct {
}

type SetChannelFeeRequest struct {
Id string `json:"id"`
BaseMilliSatoshis string `json:"base,omitempty"`
Id string `json:"id"`
BaseMilliSatoshis string `json:"base,omitempty"`
PartPerMillion uint32 `json:"ppm,omitempty"`
}

Expand Down
33 changes: 33 additions & 0 deletions glightning/lightning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1994,6 +1994,39 @@ func TestGetPayStatus(t *testing.T) {
assert.Equal(t, errors.New("No status for bolt11 found."), err)
}

func TestDelExpiredInvoice(t *testing.T) {
request := "{\"jsonrpc\":\"2.0\",\"method\":\"delexpiredinvoice\",\"params\":{\"maxexpirytime\":40000000},\"id\":1}"
reply := wrapResult(1, `{}`)
lightning, requestQ, replyQ := startupServer(t)
go runServerSide(t, request, reply, replyQ, requestQ)
err := lightning.DeleteExpiredInvoicesSince(uint64(40000000))
if err != nil {
t.Fatal(err)
}
}

func TestAutoclean(t *testing.T) {
request := "{\"jsonrpc\":\"2.0\",\"method\":\"autocleaninvoice\",\"params\":{\"cycle_seconds\":200,\"expired_by\":100},\"id\":1}"
reply := wrapResult(1, `"Autocleaning 100-second old invoices every 200 seconds"`)
lightning, requestQ, replyQ := startupServer(t)
go runServerSide(t, request, reply, replyQ, requestQ)
err := lightning.SetInvoiceAutoclean(uint32(200), uint32(100))
if err != nil {
t.Fatal(err)
}
}

func TestDisableAutoclean(t *testing.T) {
request := "{\"jsonrpc\":\"2.0\",\"method\":\"autocleaninvoice\",\"params\":{\"cycle_seconds\":0},\"id\":1}"
reply := wrapResult(1, `"Autoclean timer disabled"`)
lightning, requestQ, replyQ := startupServer(t)
go runServerSide(t, request, reply, replyQ, requestQ)
err := lightning.DisableInvoiceAutoclean()
if err != nil {
t.Fatal(err)
}
}

func TestSetChannelFee(t *testing.T) {
request := "{\"jsonrpc\":\"2.0\",\"method\":\"setchannelfee\",\"params\":{\"base\":\"1000\",\"id\":\"all\",\"ppm\":400},\"id\":1}"
reply := wrapResult(1, `{"base":1000,"ppm":400,"channels":[{"peer_id":"02502091854ba31bddef5be51584c4014c3edd7d65936b6841fa9a9f6366313a54","channel_id":"04a59bdc9f8708ff5457726725c10d161d8b4ad1330b6d92d1d5196994a2478e","short_channel_id":"1442x1x0"}]}`)
Expand Down

0 comments on commit 9250564

Please sign in to comment.