forked from niftynei/glightning
/
plugin_htlcacc.go
48 lines (39 loc) · 974 Bytes
/
plugin_htlcacc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"github.com/niftynei/glightning/glightning"
"log"
"os"
)
func main() {
plugin := glightning.NewPlugin(onInit)
plugin.RegisterHooks(&glightning.Hooks{
HtlcAccepted: OnHtlcAccepted,
})
err := plugin.Start(os.Stdin, os.Stdout)
if err != nil {
log.Fatal(err)
}
}
func onInit(plugin *glightning.Plugin, options map[string]string, config *glightning.Config) {
log.Printf("successfully init'd! %s\n", config.RpcFile)
}
func OnHtlcAccepted(event *glightning.HtlcAcceptedEvent) (*glightning.HtlcAcceptedResponse, error) {
log.Printf("htlc_accepted called\n")
onion := event.Onion
log.Printf("has perhop? %t", onion.PerHop != nil)
log.Printf("type is %s", onion.Type)
var on string
if onion.PaymentSecret == "" {
on = ""
} else {
on = "not "
}
log.Printf("payment secret is %sempty", on)
if onion.TotalMilliSatoshi == "" {
on = "empty"
} else {
on = ""
}
log.Printf("amount is %s", on)
return event.Continue(), nil
}