-
Notifications
You must be signed in to change notification settings - Fork 3
/
api_clnsocket.go
40 lines (33 loc) · 1.08 KB
/
api_clnsocket.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
package lightning
// ClnSocketLightningAPI struct.
type ClnSocketLightningAPI struct {
ClnRawLightningAPI
}
// Compile time check for the interface.
var _ LightingAPICalls = &ClnSocketLightningAPI{}
// NewClnSocketLightningAPIRaw gets a new API - usage "unix", "/home/ubuntu/.lightning/bitcoin/lightning-rpc".
func NewClnSocketLightningAPIRaw(socketType string, address string) LightingAPICalls {
api := &ClnSocketLightningAPI{}
connection := NewUnixConnection(socketType, address)
if connection == nil {
return nil
}
api.Name = "clnsocket"
api.connection = connection
return api
}
// NewClnSocketLightningAPI return a new lightning API.
func NewClnSocketLightningAPI(getData GetDataCall) LightingAPICalls {
if getData == nil {
return nil
}
data, err := getData()
if data == nil || err != nil {
return nil
}
// "unix" corresponds to SOCK_STREAM
// "unixgram" corresponds to SOCK_DGRAM
// "unixpacket" corresponds to SOCK_SEQPACKET
// We chose stream oriented socket since datagram oriented one has problems with size
return NewClnSocketLightningAPIRaw("unix", data.Endpoint)
}