2017-10-23 06:17:38 +02:00
|
|
|
#include <common/wireaddr.h>
|
2017-03-15 10:43:03 +01:00
|
|
|
#include <lightningd/gossip_msg.h>
|
|
|
|
#include <wire/wire.h>
|
|
|
|
|
2018-04-20 10:09:50 +02:00
|
|
|
struct gossip_getnodes_entry *fromwire_gossip_getnodes_entry(const tal_t *ctx,
|
|
|
|
const u8 **pptr, size_t *max)
|
2017-03-15 10:43:03 +01:00
|
|
|
{
|
2017-05-08 23:22:59 +02:00
|
|
|
u8 numaddresses, i;
|
2018-02-08 02:23:46 +01:00
|
|
|
struct gossip_getnodes_entry *entry;
|
|
|
|
|
|
|
|
entry = tal(ctx, struct gossip_getnodes_entry);
|
2017-03-15 10:43:03 +01:00
|
|
|
fromwire_pubkey(pptr, max, &entry->nodeid);
|
2018-01-16 20:44:32 +01:00
|
|
|
entry->last_timestamp = fromwire_u64(pptr, max);
|
|
|
|
|
|
|
|
if (entry->last_timestamp < 0) {
|
|
|
|
entry->addresses = NULL;
|
|
|
|
entry->alias = NULL;
|
2018-02-08 02:23:46 +01:00
|
|
|
return entry;
|
2018-01-16 20:44:32 +01:00
|
|
|
}
|
2017-05-08 23:22:59 +02:00
|
|
|
numaddresses = fromwire_u8(pptr, max);
|
|
|
|
|
2018-02-08 02:23:46 +01:00
|
|
|
entry->addresses = tal_arr(entry, struct wireaddr, numaddresses);
|
2017-05-08 23:22:59 +02:00
|
|
|
for (i=0; i<numaddresses; i++) {
|
2017-09-01 06:18:55 +02:00
|
|
|
/* Gossipd doesn't hand us addresses we can't understand. */
|
2017-10-23 06:17:38 +02:00
|
|
|
if (!fromwire_wireaddr(pptr, max, entry->addresses)) {
|
2017-09-01 06:18:55 +02:00
|
|
|
fromwire_fail(pptr, max);
|
2018-02-08 02:23:46 +01:00
|
|
|
return NULL;
|
2017-09-01 06:18:55 +02:00
|
|
|
}
|
2017-05-08 23:22:59 +02:00
|
|
|
}
|
2018-02-08 02:23:46 +01:00
|
|
|
entry->alias = tal_arr(entry, u8, fromwire_u8(pptr, max));
|
2018-01-16 20:44:32 +01:00
|
|
|
fromwire(pptr, max, entry->alias, tal_len(entry->alias));
|
|
|
|
fromwire(pptr, max, entry->color, sizeof(entry->color));
|
2018-02-08 02:23:46 +01:00
|
|
|
return entry;
|
2017-03-15 10:43:03 +01:00
|
|
|
}
|
2018-02-08 02:23:46 +01:00
|
|
|
|
2018-04-20 10:09:50 +02:00
|
|
|
void towire_gossip_getnodes_entry(u8 **pptr,
|
|
|
|
const struct gossip_getnodes_entry *entry)
|
2017-03-15 10:43:03 +01:00
|
|
|
{
|
2017-05-08 23:22:59 +02:00
|
|
|
u8 i, numaddresses = tal_count(entry->addresses);
|
2017-03-15 10:43:03 +01:00
|
|
|
towire_pubkey(pptr, &entry->nodeid);
|
2018-01-16 20:44:32 +01:00
|
|
|
towire_u64(pptr, entry->last_timestamp);
|
2017-05-08 23:22:59 +02:00
|
|
|
|
2018-01-16 20:44:32 +01:00
|
|
|
if (entry->last_timestamp < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
towire_u8(pptr, numaddresses);
|
2017-05-08 23:22:59 +02:00
|
|
|
for (i=0; i<numaddresses; i++) {
|
2017-10-23 06:17:38 +02:00
|
|
|
towire_wireaddr(pptr, &entry->addresses[i]);
|
2017-05-08 23:22:59 +02:00
|
|
|
}
|
2018-01-16 20:44:32 +01:00
|
|
|
towire_u8(pptr, tal_len(entry->alias));
|
|
|
|
towire(pptr, entry->alias, tal_len(entry->alias));
|
|
|
|
towire(pptr, entry->color, sizeof(entry->color));
|
2017-03-15 10:43:03 +01:00
|
|
|
}
|
2017-03-15 13:36:35 +01:00
|
|
|
|
|
|
|
void fromwire_route_hop(const u8 **pptr, size_t *max, struct route_hop *entry)
|
|
|
|
{
|
|
|
|
fromwire_pubkey(pptr, max, &entry->nodeid);
|
2017-04-29 10:52:40 +02:00
|
|
|
fromwire_short_channel_id(pptr, max, &entry->channel_id);
|
2018-04-09 15:31:23 +02:00
|
|
|
entry->amount = fromwire_u64(pptr, max);
|
2017-03-15 13:36:35 +01:00
|
|
|
entry->delay = fromwire_u32(pptr, max);
|
|
|
|
}
|
|
|
|
void towire_route_hop(u8 **pptr, const struct route_hop *entry)
|
|
|
|
{
|
|
|
|
towire_pubkey(pptr, &entry->nodeid);
|
2017-04-29 10:52:40 +02:00
|
|
|
towire_short_channel_id(pptr, &entry->channel_id);
|
2018-04-09 15:31:23 +02:00
|
|
|
towire_u64(pptr, entry->amount);
|
2017-03-15 13:36:35 +01:00
|
|
|
towire_u32(pptr, entry->delay);
|
|
|
|
}
|
|
|
|
|
2017-03-22 13:30:09 +01:00
|
|
|
void fromwire_gossip_getchannels_entry(const u8 **pptr, size_t *max,
|
2018-04-20 12:06:23 +02:00
|
|
|
struct gossip_getchannels_entry *entry)
|
2017-03-22 13:30:09 +01:00
|
|
|
{
|
|
|
|
fromwire_short_channel_id(pptr, max, &entry->short_channel_id);
|
|
|
|
fromwire_pubkey(pptr, max, &entry->source);
|
|
|
|
fromwire_pubkey(pptr, max, &entry->destination);
|
2018-03-05 23:52:26 +01:00
|
|
|
entry->satoshis = fromwire_u64(pptr, max);
|
2017-03-22 13:30:09 +01:00
|
|
|
entry->active = fromwire_bool(pptr, max);
|
|
|
|
entry->flags = fromwire_u16(pptr, max);
|
2018-01-04 00:51:21 +01:00
|
|
|
entry->public = fromwire_bool(pptr, max);
|
2017-09-01 06:18:54 +02:00
|
|
|
entry->last_update_timestamp = fromwire_u64(pptr, max);
|
|
|
|
if (entry->last_update_timestamp >= 0) {
|
2017-09-01 06:18:54 +02:00
|
|
|
entry->base_fee_msat = fromwire_u32(pptr, max);
|
|
|
|
entry->fee_per_millionth = fromwire_u32(pptr, max);
|
2017-09-01 06:18:54 +02:00
|
|
|
entry->delay = fromwire_u32(pptr, max);
|
|
|
|
}
|
2017-03-22 13:30:09 +01:00
|
|
|
}
|
|
|
|
|
2018-04-20 10:09:50 +02:00
|
|
|
void towire_gossip_getchannels_entry(u8 **pptr,
|
2018-04-20 12:06:23 +02:00
|
|
|
const struct gossip_getchannels_entry *entry)
|
2017-03-22 13:30:09 +01:00
|
|
|
{
|
|
|
|
towire_short_channel_id(pptr, &entry->short_channel_id);
|
|
|
|
towire_pubkey(pptr, &entry->source);
|
|
|
|
towire_pubkey(pptr, &entry->destination);
|
2018-03-05 23:52:26 +01:00
|
|
|
towire_u64(pptr, entry->satoshis);
|
2017-03-22 13:30:09 +01:00
|
|
|
towire_bool(pptr, entry->active);
|
|
|
|
towire_u16(pptr, entry->flags);
|
2018-01-04 00:51:21 +01:00
|
|
|
towire_bool(pptr, entry->public);
|
2017-09-01 06:18:54 +02:00
|
|
|
towire_u64(pptr, entry->last_update_timestamp);
|
|
|
|
if (entry->last_update_timestamp >= 0) {
|
2017-09-01 06:18:54 +02:00
|
|
|
towire_u32(pptr, entry->base_fee_msat);
|
|
|
|
towire_u32(pptr, entry->fee_per_millionth);
|
2017-09-01 06:18:54 +02:00
|
|
|
towire_u32(pptr, entry->delay);
|
|
|
|
}
|
2017-03-22 13:30:09 +01:00
|
|
|
}
|