forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 1
/
lnchannel_api.c
87 lines (66 loc) · 2.05 KB
/
lnchannel_api.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "include/lnchannel_api.h"
#include "lnchannel_internal.h"
#include "log.h"
#include "db.h"
#include <ccan/mem/mem.h>
#include <ccan/str/hex/hex.h>
#include <ccan/structeq/structeq.h>
#include <ccan/tal/str/str.h>
#include <ccan/tal/tal.h>
#include <ccan/crypto/sha256/sha256.h>
#include <ccan/short_types/short_types.h>
#include <ccan/tal/tal.h>
struct LNcore
{
struct lightningd_state *dstate_sample;
u32 workspace_num;
};
struct LNworkspace
{
struct lightningd_state *dstate;
};
LNCHANNEL_API struct LNcore* LNAPI_init()
{
struct LNcore *core = tal(NULL, struct LNcore);
struct lightningd_state *dstate = talz(core, struct lightningd_state);
dstate->log_book = new_log_book(dstate, 1024 * 1024, LOG_INFORM);
dstate->base_log = new_log(dstate, dstate->log_book,
"lightning-lite:");
lite_init(dstate);
btcnetwork_init(dstate);
log_info(dstate->base_log, "Hello world!");
dstate->testnet = true;
dstate->default_redeem_address = NULL;
core->dstate_sample = dstate;
core->workspace_num = 0;
return core;
}
LNCHANNEL_API void LNAPI_uninit(struct LNcore* pcore)
{
tal_free(pcore);
}
LNCHANNEL_API struct LNworkspace* LNAPI_assign_workspace(struct LNcore* pcore)
{
struct LNworkspace *ws = tal(pcore, struct LNworkspace);
struct lightningd_state *dstate = tal_dup(ws, struct lightningd_state, pcore->dstate_sample);
ws->dstate = dstate;
//dstate in workspace use same lite and btc-network implement, but separated log and db entry
//TODO: bind destructor for dstate
dstate->log_book = new_log_book(dstate, 20 * 1024 * 1024, LOG_INFORM);
dstate->base_log = new_log(dstate, dstate->log_book,
"lightning-lite(%u):", pcore->workspace_num);
db_init(dstate);
log_info(dstate->base_log, "Start a workspace");
pcore->workspace_num++;
return ws;
}
LNCHANNEL_API int LNAPI_release_workspace(struct LNworkspace* ws)
{
//TODO: clear db and log ...
tal_free(ws);
return 0;
}
static int check_failure(struct LNchannel *lnchn)
{
return 0;
}