mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
htlc_wire: marshal/unmarshal shachain object.
We want to hand it to onchaind. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
aa23a2a93f
commit
a4f290daba
@ -1,3 +1,5 @@
|
|||||||
|
#include <ccan/array_size/array_size.h>
|
||||||
|
#include <ccan/crypto/shachain/shachain.h>
|
||||||
#include <lightningd/htlc_wire.h>
|
#include <lightningd/htlc_wire.h>
|
||||||
#include <wire/wire.h>
|
#include <wire/wire.h>
|
||||||
|
|
||||||
@ -43,6 +45,19 @@ void towire_side(u8 **pptr, const enum side side)
|
|||||||
towire_u8(pptr, side);
|
towire_u8(pptr, side);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void towire_shachain(u8 **pptr, const struct shachain *shachain)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
towire_u64(pptr, shachain->min_index);
|
||||||
|
towire_u32(pptr, shachain->num_valid);
|
||||||
|
|
||||||
|
for (i = 0; i < shachain->num_valid; i++) {
|
||||||
|
towire_u64(pptr, shachain->known[i].index);
|
||||||
|
towire_sha256(pptr, &shachain->known[i].hash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void fromwire_added_htlc(const u8 **cursor, size_t *max,
|
void fromwire_added_htlc(const u8 **cursor, size_t *max,
|
||||||
struct added_htlc *added)
|
struct added_htlc *added)
|
||||||
{
|
{
|
||||||
@ -99,3 +114,20 @@ enum side fromwire_side(const u8 **cursor, size_t *max)
|
|||||||
}
|
}
|
||||||
return side;
|
return side;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void fromwire_shachain(const u8 **cursor, size_t *max,
|
||||||
|
struct shachain *shachain)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
shachain->min_index = fromwire_u64(cursor, max);
|
||||||
|
shachain->num_valid = fromwire_u32(cursor, max);
|
||||||
|
if (shachain->num_valid > ARRAY_SIZE(shachain->known)) {
|
||||||
|
fromwire_fail(cursor, max);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (i = 0; i < shachain->num_valid; i++) {
|
||||||
|
shachain->known[i].index = fromwire_u64(cursor, max);
|
||||||
|
fromwire_sha256(cursor, max, &shachain->known[i].hash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
#include <lightningd/sphinx.h>
|
#include <lightningd/sphinx.h>
|
||||||
#include <wire/gen_onion_wire.h>
|
#include <wire/gen_onion_wire.h>
|
||||||
|
|
||||||
|
struct shachain;
|
||||||
|
|
||||||
/* These are how we communicate about HTLC state to the master daemon */
|
/* These are how we communicate about HTLC state to the master daemon */
|
||||||
struct added_htlc {
|
struct added_htlc {
|
||||||
u64 id;
|
u64 id;
|
||||||
@ -38,6 +40,7 @@ void towire_failed_htlc(u8 **pptr, const struct failed_htlc *failed);
|
|||||||
void towire_changed_htlc(u8 **pptr, const struct changed_htlc *changed);
|
void towire_changed_htlc(u8 **pptr, const struct changed_htlc *changed);
|
||||||
void towire_htlc_state(u8 **pptr, const enum htlc_state hstate);
|
void towire_htlc_state(u8 **pptr, const enum htlc_state hstate);
|
||||||
void towire_side(u8 **pptr, const enum side side);
|
void towire_side(u8 **pptr, const enum side side);
|
||||||
|
void towire_shachain(u8 **pptr, const struct shachain *shachain);
|
||||||
|
|
||||||
void fromwire_added_htlc(const u8 **cursor, size_t *max,
|
void fromwire_added_htlc(const u8 **cursor, size_t *max,
|
||||||
struct added_htlc *added);
|
struct added_htlc *added);
|
||||||
@ -49,4 +52,6 @@ void fromwire_changed_htlc(const u8 **cursor, size_t *max,
|
|||||||
struct changed_htlc *changed);
|
struct changed_htlc *changed);
|
||||||
enum htlc_state fromwire_htlc_state(const u8 **cursor, size_t *max);
|
enum htlc_state fromwire_htlc_state(const u8 **cursor, size_t *max);
|
||||||
enum side fromwire_side(const u8 **cursor, size_t *max);
|
enum side fromwire_side(const u8 **cursor, size_t *max);
|
||||||
|
void fromwire_shachain(const u8 **cursor, size_t *max,
|
||||||
|
struct shachain *shachain);
|
||||||
#endif /* LIGHTNING_LIGHTNINGD_HTLC_WIRE_H */
|
#endif /* LIGHTNING_LIGHTNINGD_HTLC_WIRE_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user