forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pkt.h
125 lines (110 loc) · 3.95 KB
/
pkt.h
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#ifndef LIGHTNING_PKT_H
#define LIGHTNING_PKT_H
/* Simple (non-threadsafe!) wrapper for protobufs.
*
* This could be a simple set of macros, if the protobuf-c people hadn't
* insisted on "prettifing" the names they generate into CamelCase.
*/
#include <ccan/endian/endian.h>
#include <ccan/short_types/short_types.h>
#include <ccan/tal/tal.h>
#include "lightning.pb-c.h"
/* A packet, ready to be de-protobuf'ed. */
struct pkt {
le32 len;
u8 data[];
};
/* Utility helper: dies if there's a problem. */
Pkt *pkt_from_file(const char *filename, Pkt__PktCase expect);
Pkt *any_pkt_from_file(const char *filename);
/* Total length of packet, including header. */
size_t pkt_totlen(const struct pkt *pkt);
struct sha256;
struct bitcoin_compressed_pubkey;
struct signature;
struct pubkey;
/**
* openchannel_pkt - create an openchannel message
* @ctx: tal context to allocate off.
* @seed: psuedo-random seed to shuffle inputs.
* @revocation_hash: first hash value generated from seed.
* @to_me: the pubkey for the commit transactions' P2SH output.
* @commitment_fee: the fee to use for commitment tx.
* @rel_locktime_seconds: relative seconds for commitment locktime.
* @anchor: the anchor transaction details.
*/
struct pkt *openchannel_pkt(const tal_t *ctx,
u64 seed,
const struct sha256 *revocation_hash,
const struct pubkey *to_me,
u64 commitment_fee,
u32 rel_locktime_seconds,
Anchor *anchor);
/**
* open_anchor_sig_pkt - create an open_anchor_sig message
* @ctx: tal context to allocate off.
* @sigs: the der-encoded signatures (tal_count() gives len).
* @num_sigs: the number of sigs.
*/
struct pkt *open_anchor_sig_pkt(const tal_t *ctx, u8 **sigs, size_t num_sigs);
/**
* leak_anchor_sigs_and_pretend_we_didnt_pkt - leak anchor scriptsigs
* @ctx: tal context to allocate off.
* @s: OpenAnchorSig.
*/
struct pkt *leak_anchor_sigs_and_pretend_we_didnt_pkt(const tal_t *ctx,
OpenAnchorScriptsigs *s);
/**
* open_commit_sig_pkt - create an open_commit_sig message
* @ctx: tal context to allocate off.
* @sig: the signature for the commit transaction input.
*/
struct pkt *open_commit_sig_pkt(const tal_t *ctx, const struct signature *sig);
/**
* close_channel_pkt - create an close_channel message
* @ctx: tal context to allocate off.
* @sig: the signature for the close transaction input.
*/
struct pkt *close_channel_pkt(const tal_t *ctx, const struct signature *sig);
/**
* close_channel_complete_pkt - create an close_channel_complete message
* @ctx: tal context to allocate off.
* @sig: the signature for the close transaction input.
*/
struct pkt *close_channel_complete_pkt(const tal_t *ctx,
const struct signature *sig);
/**
* update_pkt - create an update message
* @ctx: tal context to allocate off.
* @revocation_hash: the revocation hash for the next tx.
* @delta: the change in satoshis (to me).
*/
struct pkt *update_pkt(const tal_t *ctx,
const struct sha256 *revocation_hash,
s64 delta);
/**
* update_accept_pkt - create an update_accept message
* @ctx: tal context to allocate off.
* @sig: the signature for the close transaction input.
* @revocation_hash: hash to revoke the next tx.
*/
struct pkt *update_accept_pkt(const tal_t *ctx,
struct signature *sig,
const struct sha256 *revocation_hash);
/**
* update_signature_pkt - create an update_signature message
* @ctx: tal context to allocate off.
* @sig: the signature for the close transaction input.
* @revocation_preimage: preimage to revoke existing (now-obsolete) tx.
*/
struct pkt *update_signature_pkt(const tal_t *ctx,
const struct signature *sig,
const struct sha256 *revocation_preimage);
/**
* update_complete_pkt - create an update_accept message
* @ctx: tal context to allocate off.
* @revocation_preimage: preimage to revoke existing (now-obsolete) tx.
*/
struct pkt *update_complete_pkt(const tal_t *ctx,
const struct sha256 *revocation_preimage);
#endif /* LIGHTNING_PKT_H */