-
Notifications
You must be signed in to change notification settings - Fork 9
/
commando.c
36 lines (27 loc) · 891 Bytes
/
commando.c
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
#include "lnsocket.h"
#include "cursor.h"
#include "endian.h"
#include "commando.h"
#include "export.h"
int EXPORT commando_make_rpc_msg(const char *method, const char *params,
const char *rune, unsigned int req_id, unsigned char *buf, int buflen)
{
struct cursor msgbuf;
int ok;
make_cursor(buf, buf+buflen, &msgbuf);
params = (params == NULL || params[0] == '\0') ? "[]" : params;
if (!cursor_push_u16(&msgbuf, COMMANDO_CMD))
return 0;
if (!cursor_push_u64(&msgbuf, (u64)req_id))
return 0;
ok = cursor_push_str(&msgbuf, "{\"method\":\"") &&
cursor_push_str(&msgbuf, method) &&
cursor_push_str(&msgbuf, "\",\"params\":") &&
cursor_push_str(&msgbuf, params) &&
cursor_push_str(&msgbuf, ",\"rune\":\"") &&
cursor_push_str(&msgbuf, rune) &&
cursor_push_str(&msgbuf, "\",\"id\":\"d0\",\"jsonrpc\":\"2.0\"}");
if (!ok)
return 0;
return msgbuf.p - msgbuf.start;
}