2016-11-29 20:51:50 +01:00
|
|
|
#include "wire.h"
|
2019-07-18 07:17:16 +02:00
|
|
|
#include <assert.h>
|
2019-03-11 20:03:14 +01:00
|
|
|
#include <bitcoin/chainparams.h>
|
2017-03-29 12:56:15 +02:00
|
|
|
#include <bitcoin/preimage.h>
|
2016-11-29 20:51:50 +01:00
|
|
|
#include <bitcoin/pubkey.h>
|
2017-02-21 05:45:28 +01:00
|
|
|
#include <bitcoin/shadouble.h>
|
2017-12-18 07:41:52 +01:00
|
|
|
#include <bitcoin/tx.h>
|
2017-04-12 08:10:15 +02:00
|
|
|
#include <ccan/build_assert/build_assert.h>
|
2018-02-26 03:32:58 +01:00
|
|
|
#include <ccan/crypto/siphash24/siphash24.h>
|
2016-11-29 20:51:50 +01:00
|
|
|
#include <ccan/endian/endian.h>
|
|
|
|
#include <ccan/mem/mem.h>
|
2020-01-26 13:52:29 +01:00
|
|
|
#include <ccan/short_types/short_types.h>
|
2017-01-25 00:32:53 +01:00
|
|
|
#include <ccan/tal/str/str.h>
|
2019-02-20 12:31:48 +01:00
|
|
|
#include <common/amount.h>
|
2020-01-26 13:52:29 +01:00
|
|
|
#include <common/errcode.h>
|
common/node_id: new type.
Node ids are pubkeys, but we only use them as pubkeys for routing and checking
gossip messages. So we're packing and unpacking them constantly, and wasting
some space and time.
This introduces a new type, explicitly the SEC1 compressed encoding
(33 bytes). We ensure its validity when we load from the db, or get it
from JSON. We still use 'struct pubkey' for peer messages, which checks
validity.
Results from 5 runs, min-max(mean +/- stddev):
store_load_msec,vsz_kb,store_rewrite_sec,listnodes_sec,listchannels_sec,routing_sec,peer_write_all_sec
39475-39572(39518+/-36),2880732,41.150000-41.390000(41.298+/-0.085),2.260000-2.550000(2.336+/-0.11),44.390000-65.150000(58.648+/-7.5),32.740000-33.020000(32.89+/-0.093),44.130000-45.090000(44.566+/-0.32)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-04-08 08:34:06 +02:00
|
|
|
#include <common/node_id.h>
|
2017-08-28 18:02:01 +02:00
|
|
|
#include <common/type_to_string.h>
|
|
|
|
#include <common/utils.h>
|
2016-11-29 20:51:50 +01:00
|
|
|
|
2019-07-18 07:20:32 +02:00
|
|
|
#ifndef SUPERVERBOSE
|
|
|
|
#define SUPERVERBOSE(...)
|
|
|
|
#endif
|
|
|
|
|
2019-09-25 22:38:45 +02:00
|
|
|
extern const struct chainparams *chainparams;
|
|
|
|
|
2016-11-29 20:51:50 +01:00
|
|
|
/* Sets *cursor to NULL and returns NULL when extraction fails. */
|
2017-06-06 05:03:31 +02:00
|
|
|
const void *fromwire_fail(const u8 **cursor, size_t *max)
|
2016-11-29 20:51:50 +01:00
|
|
|
{
|
|
|
|
*cursor = NULL;
|
|
|
|
*max = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const u8 *fromwire(const u8 **cursor, size_t *max, void *copy, size_t n)
|
|
|
|
{
|
|
|
|
const u8 *p = *cursor;
|
|
|
|
|
|
|
|
if (*max < n) {
|
|
|
|
/* Just make sure we don't leak uninitialized mem! */
|
|
|
|
if (copy)
|
|
|
|
memset(copy, 0, n);
|
2019-07-18 07:20:32 +02:00
|
|
|
if (*cursor)
|
|
|
|
SUPERVERBOSE("less than encoding length");
|
2017-06-06 05:03:31 +02:00
|
|
|
return fromwire_fail(cursor, max);
|
2016-11-29 20:51:50 +01:00
|
|
|
}
|
|
|
|
*cursor += n;
|
|
|
|
*max -= n;
|
|
|
|
if (copy)
|
|
|
|
memcpy(copy, p, n);
|
|
|
|
return memcheck(p, n);
|
|
|
|
}
|
|
|
|
|
2017-01-04 04:39:21 +01:00
|
|
|
int fromwire_peektype(const u8 *cursor)
|
|
|
|
{
|
|
|
|
be16 be_type;
|
|
|
|
size_t max = tal_count(cursor);
|
|
|
|
|
|
|
|
fromwire(&cursor, &max, &be_type, sizeof(be_type));
|
|
|
|
if (!cursor)
|
|
|
|
return -1;
|
|
|
|
return be16_to_cpu(be_type);
|
|
|
|
}
|
|
|
|
|
2016-11-29 20:51:50 +01:00
|
|
|
u8 fromwire_u8(const u8 **cursor, size_t *max)
|
|
|
|
{
|
|
|
|
u8 ret;
|
|
|
|
|
|
|
|
if (!fromwire(cursor, max, &ret, sizeof(ret)))
|
|
|
|
return 0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
u16 fromwire_u16(const u8 **cursor, size_t *max)
|
|
|
|
{
|
|
|
|
be16 ret;
|
|
|
|
|
|
|
|
if (!fromwire(cursor, max, &ret, sizeof(ret)))
|
|
|
|
return 0;
|
|
|
|
return be16_to_cpu(ret);
|
|
|
|
}
|
2017-01-04 04:39:20 +01:00
|
|
|
|
2016-11-29 20:51:50 +01:00
|
|
|
u32 fromwire_u32(const u8 **cursor, size_t *max)
|
|
|
|
{
|
|
|
|
be32 ret;
|
|
|
|
|
|
|
|
if (!fromwire(cursor, max, &ret, sizeof(ret)))
|
|
|
|
return 0;
|
|
|
|
return be32_to_cpu(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 fromwire_u64(const u8 **cursor, size_t *max)
|
|
|
|
{
|
|
|
|
be64 ret;
|
|
|
|
|
|
|
|
if (!fromwire(cursor, max, &ret, sizeof(ret)))
|
|
|
|
return 0;
|
|
|
|
return be64_to_cpu(ret);
|
|
|
|
}
|
|
|
|
|
2019-07-18 07:17:16 +02:00
|
|
|
static u64 fromwire_tlv_uint(const u8 **cursor, size_t *max, size_t maxlen)
|
|
|
|
{
|
|
|
|
u8 bytes[8];
|
|
|
|
size_t length;
|
|
|
|
be64 val;
|
|
|
|
|
|
|
|
assert(maxlen <= sizeof(bytes));
|
|
|
|
|
2019-09-20 08:55:49 +02:00
|
|
|
/* BOLT #1:
|
2019-07-18 07:17:16 +02:00
|
|
|
*
|
|
|
|
* - if `length` is not exactly equal to that required for the
|
|
|
|
* known encoding for `type`:
|
|
|
|
* - MUST fail to parse the `tlv_stream`.
|
|
|
|
*/
|
|
|
|
length = *max;
|
|
|
|
if (length > maxlen) {
|
2019-07-18 07:20:32 +02:00
|
|
|
SUPERVERBOSE("greater than encoding length");
|
2019-07-18 07:17:16 +02:00
|
|
|
fromwire_fail(cursor, max);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(bytes, 0, sizeof(bytes));
|
|
|
|
fromwire(cursor, max, bytes + sizeof(bytes) - length, length);
|
|
|
|
|
2019-09-20 08:55:49 +02:00
|
|
|
/* BOLT #1:
|
2019-07-18 07:17:16 +02:00
|
|
|
* - if variable-length fields within the known encoding for `type` are
|
|
|
|
* not minimal:
|
|
|
|
* - MUST fail to parse the `tlv_stream`.
|
|
|
|
*/
|
|
|
|
if (length > 0 && bytes[sizeof(bytes) - length] == 0) {
|
2019-07-18 07:20:32 +02:00
|
|
|
SUPERVERBOSE("not minimal");
|
2019-07-18 07:17:16 +02:00
|
|
|
fromwire_fail(cursor, max);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
BUILD_ASSERT(sizeof(val) == sizeof(bytes));
|
|
|
|
memcpy(&val, bytes, sizeof(bytes));
|
|
|
|
return be64_to_cpu(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
u16 fromwire_tu16(const u8 **cursor, size_t *max)
|
|
|
|
{
|
|
|
|
return fromwire_tlv_uint(cursor, max, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 fromwire_tu32(const u8 **cursor, size_t *max)
|
|
|
|
{
|
|
|
|
return fromwire_tlv_uint(cursor, max, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 fromwire_tu64(const u8 **cursor, size_t *max)
|
|
|
|
{
|
|
|
|
return fromwire_tlv_uint(cursor, max, 8);
|
|
|
|
}
|
|
|
|
|
2017-01-04 04:39:21 +01:00
|
|
|
bool fromwire_bool(const u8 **cursor, size_t *max)
|
|
|
|
{
|
|
|
|
u8 ret;
|
|
|
|
|
|
|
|
if (!fromwire(cursor, max, &ret, sizeof(ret)))
|
|
|
|
return false;
|
|
|
|
if (ret != 0 && ret != 1)
|
2017-06-06 05:03:31 +02:00
|
|
|
fromwire_fail(cursor, max);
|
2017-01-04 04:39:21 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-01-26 13:52:29 +01:00
|
|
|
errcode_t fromwire_errcode_t(const u8 **cursor, size_t *max)
|
2020-01-12 15:33:59 +01:00
|
|
|
{
|
2020-01-26 13:52:29 +01:00
|
|
|
errcode_t ret;
|
|
|
|
|
|
|
|
ret = (s32)fromwire_u32(cursor, max);
|
2020-01-12 15:33:59 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-07-30 07:25:12 +02:00
|
|
|
bigsize_t fromwire_bigsize(const u8 **cursor, size_t *max)
|
2019-04-03 02:18:06 +02:00
|
|
|
{
|
2019-07-30 07:25:12 +02:00
|
|
|
bigsize_t v;
|
|
|
|
size_t len = bigsize_get(*cursor, *max, &v);
|
|
|
|
|
|
|
|
if (len == 0) {
|
|
|
|
fromwire_fail(cursor, max);
|
|
|
|
return 0;
|
2019-04-03 02:18:06 +02:00
|
|
|
}
|
2019-07-30 07:25:12 +02:00
|
|
|
assert(len <= *max);
|
|
|
|
fromwire(cursor, max, NULL, len);
|
|
|
|
return v;
|
2019-04-03 02:18:06 +02:00
|
|
|
}
|
|
|
|
|
2016-12-02 08:41:06 +01:00
|
|
|
void fromwire_pubkey(const u8 **cursor, size_t *max, struct pubkey *pubkey)
|
2016-11-29 20:51:50 +01:00
|
|
|
{
|
pubkey: rename PUBKEY_DER_LEN to PUBKEY_CMPR_LEN.
Pubkeys are not not actually DER encoding, but Pieter Wuille corrected
me: it's SEC 1 documented encoding.
Results from 5 runs, min-max(mean +/- stddev):
store_load_msec,vsz_kb,store_rewrite_sec,listnodes_sec,listchannels_sec,routing_sec,peer_write_all_sec
38922-39297(39180.6+/-1.3e+02),2880728,41.040000-41.160000(41.106+/-0.05),2.270000-2.530000(2.338+/-0.097),44.570000-53.980000(49.696+/-3),32.840000-33.080000(32.95+/-0.095),43.060000-44.950000(43.696+/-0.72)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-04-08 08:34:05 +02:00
|
|
|
u8 der[PUBKEY_CMPR_LEN];
|
2016-11-29 20:51:50 +01:00
|
|
|
|
|
|
|
if (!fromwire(cursor, max, der, sizeof(der)))
|
|
|
|
return;
|
|
|
|
|
2019-07-18 07:20:32 +02:00
|
|
|
if (!pubkey_from_der(der, sizeof(der), pubkey)) {
|
|
|
|
SUPERVERBOSE("not a valid point");
|
2017-06-06 05:03:31 +02:00
|
|
|
fromwire_fail(cursor, max);
|
2019-07-18 07:20:32 +02:00
|
|
|
}
|
2016-11-29 20:51:50 +01:00
|
|
|
}
|
|
|
|
|
common/node_id: new type.
Node ids are pubkeys, but we only use them as pubkeys for routing and checking
gossip messages. So we're packing and unpacking them constantly, and wasting
some space and time.
This introduces a new type, explicitly the SEC1 compressed encoding
(33 bytes). We ensure its validity when we load from the db, or get it
from JSON. We still use 'struct pubkey' for peer messages, which checks
validity.
Results from 5 runs, min-max(mean +/- stddev):
store_load_msec,vsz_kb,store_rewrite_sec,listnodes_sec,listchannels_sec,routing_sec,peer_write_all_sec
39475-39572(39518+/-36),2880732,41.150000-41.390000(41.298+/-0.085),2.260000-2.550000(2.336+/-0.11),44.390000-65.150000(58.648+/-7.5),32.740000-33.020000(32.89+/-0.093),44.130000-45.090000(44.566+/-0.32)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-04-08 08:34:06 +02:00
|
|
|
void fromwire_node_id(const u8 **cursor, size_t *max, struct node_id *id)
|
|
|
|
{
|
|
|
|
fromwire(cursor, max, &id->k, sizeof(id->k));
|
|
|
|
}
|
|
|
|
|
2017-05-06 04:19:44 +02:00
|
|
|
void fromwire_secret(const u8 **cursor, size_t *max, struct secret *secret)
|
|
|
|
{
|
|
|
|
fromwire(cursor, max, secret->data, sizeof(secret->data));
|
|
|
|
}
|
|
|
|
|
2017-02-21 05:45:28 +01:00
|
|
|
void fromwire_privkey(const u8 **cursor, size_t *max, struct privkey *privkey)
|
|
|
|
{
|
2017-05-06 04:19:44 +02:00
|
|
|
fromwire_secret(cursor, max, &privkey->secret);
|
2017-02-21 05:45:28 +01:00
|
|
|
}
|
|
|
|
|
2017-01-25 00:33:42 +01:00
|
|
|
void fromwire_secp256k1_ecdsa_signature(const u8 **cursor,
|
|
|
|
size_t *max, secp256k1_ecdsa_signature *sig)
|
2016-11-29 20:51:50 +01:00
|
|
|
{
|
|
|
|
u8 compact[64];
|
|
|
|
|
|
|
|
if (!fromwire(cursor, max, compact, sizeof(compact)))
|
|
|
|
return;
|
|
|
|
|
2017-01-25 00:33:42 +01:00
|
|
|
if (secp256k1_ecdsa_signature_parse_compact(secp256k1_ctx, sig, compact)
|
2016-11-29 20:51:50 +01:00
|
|
|
!= 1)
|
2017-06-06 05:03:31 +02:00
|
|
|
fromwire_fail(cursor, max);
|
2016-11-29 20:51:50 +01:00
|
|
|
}
|
|
|
|
|
2017-10-26 05:01:19 +02:00
|
|
|
void fromwire_secp256k1_ecdsa_recoverable_signature(const u8 **cursor,
|
|
|
|
size_t *max,
|
|
|
|
secp256k1_ecdsa_recoverable_signature *rsig)
|
|
|
|
{
|
|
|
|
u8 compact[64];
|
|
|
|
int recid;
|
|
|
|
|
|
|
|
fromwire(cursor, max, compact, sizeof(compact));
|
|
|
|
recid = fromwire_u8(cursor, max);
|
|
|
|
|
|
|
|
if (secp256k1_ecdsa_recoverable_signature_parse_compact(secp256k1_ctx,
|
|
|
|
rsig, compact,
|
|
|
|
recid) != 1)
|
|
|
|
fromwire_fail(cursor, max);
|
|
|
|
}
|
|
|
|
|
2016-11-29 20:51:50 +01:00
|
|
|
void fromwire_channel_id(const u8 **cursor, size_t *max,
|
|
|
|
struct channel_id *channel_id)
|
2017-03-02 13:21:49 +01:00
|
|
|
{
|
|
|
|
fromwire(cursor, max, channel_id, sizeof(*channel_id));
|
|
|
|
}
|
|
|
|
|
|
|
|
void fromwire_short_channel_id(const u8 **cursor, size_t *max,
|
|
|
|
struct short_channel_id *short_channel_id)
|
2016-11-29 20:51:50 +01:00
|
|
|
{
|
2018-03-01 10:22:24 +01:00
|
|
|
short_channel_id->u64 = fromwire_u64(cursor, max);
|
2016-11-29 20:51:50 +01:00
|
|
|
}
|
2017-01-04 04:39:20 +01:00
|
|
|
|
2019-01-15 05:11:27 +01:00
|
|
|
void fromwire_short_channel_id_dir(const u8 **cursor, size_t *max,
|
|
|
|
struct short_channel_id_dir *scidd)
|
|
|
|
{
|
|
|
|
fromwire_short_channel_id(cursor, max, &scidd->scid);
|
|
|
|
scidd->dir = fromwire_bool(cursor, max);
|
|
|
|
}
|
|
|
|
|
2016-11-29 20:51:50 +01:00
|
|
|
void fromwire_sha256(const u8 **cursor, size_t *max, struct sha256 *sha256)
|
|
|
|
{
|
|
|
|
fromwire(cursor, max, sha256, sizeof(*sha256));
|
|
|
|
}
|
|
|
|
|
2017-02-21 05:45:28 +01:00
|
|
|
void fromwire_sha256_double(const u8 **cursor, size_t *max,
|
|
|
|
struct sha256_double *sha256d)
|
|
|
|
{
|
|
|
|
fromwire_sha256(cursor, max, &sha256d->sha);
|
|
|
|
}
|
|
|
|
|
2017-12-18 07:41:52 +01:00
|
|
|
void fromwire_bitcoin_txid(const u8 **cursor, size_t *max,
|
|
|
|
struct bitcoin_txid *txid)
|
|
|
|
{
|
|
|
|
fromwire_sha256_double(cursor, max, &txid->shad);
|
|
|
|
}
|
|
|
|
|
2018-12-03 00:15:06 +01:00
|
|
|
void fromwire_bitcoin_signature(const u8 **cursor, size_t *max,
|
|
|
|
struct bitcoin_signature *sig)
|
|
|
|
{
|
|
|
|
fromwire_secp256k1_ecdsa_signature(cursor, max, &sig->s);
|
|
|
|
sig->sighash_type = fromwire_u8(cursor, max);
|
|
|
|
if (!sighash_type_valid(sig->sighash_type))
|
|
|
|
fromwire_fail(cursor, max);
|
|
|
|
}
|
|
|
|
|
2017-12-18 07:44:10 +01:00
|
|
|
void fromwire_bitcoin_blkid(const u8 **cursor, size_t *max,
|
|
|
|
struct bitcoin_blkid *blkid)
|
|
|
|
{
|
|
|
|
fromwire_sha256_double(cursor, max, &blkid->shad);
|
|
|
|
}
|
|
|
|
|
2017-03-29 12:56:15 +02:00
|
|
|
void fromwire_preimage(const u8 **cursor, size_t *max, struct preimage *preimage)
|
|
|
|
{
|
|
|
|
fromwire(cursor, max, preimage, sizeof(*preimage));
|
|
|
|
}
|
|
|
|
|
2017-08-18 06:43:52 +02:00
|
|
|
void fromwire_ripemd160(const u8 **cursor, size_t *max, struct ripemd160 *ripemd)
|
|
|
|
{
|
|
|
|
fromwire(cursor, max, ripemd, sizeof(*ripemd));
|
|
|
|
}
|
|
|
|
|
2016-11-29 20:51:50 +01:00
|
|
|
void fromwire_u8_array(const u8 **cursor, size_t *max, u8 *arr, size_t num)
|
|
|
|
{
|
|
|
|
fromwire(cursor, max, arr, num);
|
|
|
|
}
|
|
|
|
|
2017-01-04 04:39:20 +01:00
|
|
|
void fromwire_pad(const u8 **cursor, size_t *max, size_t num)
|
2016-11-29 20:51:50 +01:00
|
|
|
{
|
2017-01-04 04:39:20 +01:00
|
|
|
fromwire(cursor, max, NULL, num);
|
2016-11-29 20:51:50 +01:00
|
|
|
}
|
2017-01-04 04:39:20 +01:00
|
|
|
|
2018-02-08 02:25:12 +01:00
|
|
|
/*
|
|
|
|
* Don't allow control chars except spaces: we only use this for stuff
|
|
|
|
* from subdaemons, who shouldn't do that.
|
|
|
|
*/
|
|
|
|
char *fromwire_wirestring(const tal_t *ctx, const u8 **cursor, size_t *max)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < *max; i++) {
|
|
|
|
if ((*cursor)[i] == '\0') {
|
|
|
|
char *str = tal_arr(ctx, char, i + 1);
|
|
|
|
fromwire(cursor, max, str, i + 1);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
if ((*cursor)[i] < ' ')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fromwire_fail(cursor, max);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-03-02 13:21:49 +01:00
|
|
|
REGISTER_TYPE_TO_HEXSTR(channel_id);
|
2017-04-12 08:10:15 +02:00
|
|
|
|
|
|
|
/* BOLT #2:
|
|
|
|
*
|
2018-06-17 12:13:44 +02:00
|
|
|
* This message introduces the `channel_id` to identify the channel. It's
|
2017-06-06 01:48:10 +02:00
|
|
|
* derived from the funding transaction by combining the `funding_txid` and
|
2018-06-17 12:13:44 +02:00
|
|
|
* the `funding_output_index`, using big-endian exclusive-OR
|
|
|
|
* (i.e. `funding_output_index` alters the last 2 bytes).
|
2017-04-12 08:10:15 +02:00
|
|
|
*/
|
|
|
|
void derive_channel_id(struct channel_id *channel_id,
|
2019-02-07 15:40:28 +01:00
|
|
|
const struct bitcoin_txid *txid, u16 txout)
|
2017-04-12 08:10:15 +02:00
|
|
|
{
|
|
|
|
BUILD_ASSERT(sizeof(*channel_id) == sizeof(*txid));
|
|
|
|
memcpy(channel_id, txid, sizeof(*channel_id));
|
|
|
|
channel_id->id[sizeof(*channel_id)-2] ^= txout >> 8;
|
|
|
|
channel_id->id[sizeof(*channel_id)-1] ^= txout;
|
|
|
|
}
|
|
|
|
|
2018-02-08 02:25:12 +01:00
|
|
|
struct bitcoin_tx *fromwire_bitcoin_tx(const tal_t *ctx,
|
|
|
|
const u8 **cursor, size_t *max)
|
2018-01-04 18:19:02 +01:00
|
|
|
{
|
2018-02-08 02:25:12 +01:00
|
|
|
return pull_bitcoin_tx(ctx, cursor, max);
|
2018-01-04 18:19:02 +01:00
|
|
|
}
|
2018-02-26 03:32:58 +01:00
|
|
|
|
|
|
|
void fromwire_siphash_seed(const u8 **cursor, size_t *max,
|
|
|
|
struct siphash_seed *seed)
|
|
|
|
{
|
|
|
|
fromwire(cursor, max, seed, sizeof(*seed));
|
|
|
|
}
|
2019-02-20 12:31:48 +01:00
|
|
|
|
|
|
|
struct amount_msat fromwire_amount_msat(const u8 **cursor, size_t *max)
|
|
|
|
{
|
|
|
|
struct amount_msat msat;
|
|
|
|
|
2019-02-21 04:45:56 +01:00
|
|
|
msat.millisatoshis = fromwire_u64(cursor, max); /* Raw: primitive */
|
2019-02-20 12:31:48 +01:00
|
|
|
return msat;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct amount_sat fromwire_amount_sat(const u8 **cursor, size_t *max)
|
|
|
|
{
|
|
|
|
struct amount_sat sat;
|
|
|
|
|
2019-02-21 04:45:56 +01:00
|
|
|
sat.satoshis = fromwire_u64(cursor, max); /* Raw: primitive */
|
2019-02-20 12:31:48 +01:00
|
|
|
return sat;
|
|
|
|
}
|
|
|
|
|
2019-03-11 20:03:14 +01:00
|
|
|
void fromwire_bip32_key_version(const u8** cursor, size_t *max,
|
|
|
|
struct bip32_key_version *version)
|
|
|
|
{
|
|
|
|
version->bip32_pubkey_version = fromwire_u32(cursor, max);
|
|
|
|
version->bip32_privkey_version = fromwire_u32(cursor, max);
|
|
|
|
}
|
2019-08-15 19:41:23 +02:00
|
|
|
|
|
|
|
struct bitcoin_tx_output *fromwire_bitcoin_tx_output(const tal_t *ctx,
|
|
|
|
const u8 **cursor, size_t *max)
|
|
|
|
{
|
|
|
|
struct bitcoin_tx_output *output = tal(ctx, struct bitcoin_tx_output);
|
|
|
|
output->amount = fromwire_amount_sat(cursor, max);
|
|
|
|
u16 script_len = fromwire_u16(cursor, max);
|
|
|
|
output->script = tal_arr(output, u8, script_len);
|
|
|
|
fromwire_u8_array(cursor, max, output->script, script_len);
|
|
|
|
return output;
|
|
|
|
}
|
2019-09-25 22:38:45 +02:00
|
|
|
|
2020-02-04 01:10:43 +01:00
|
|
|
struct witscript *fromwire_witscript(const tal_t *ctx, const u8 **cursor, size_t *max)
|
|
|
|
{
|
|
|
|
struct witscript *retval;
|
|
|
|
u16 len = fromwire_u16(cursor, max);
|
|
|
|
if (!len)
|
|
|
|
return NULL;
|
|
|
|
retval = tal(ctx, struct witscript);
|
|
|
|
retval->ptr = tal_arr(retval, u8, len);
|
|
|
|
fromwire_u8_array(cursor, max, retval->ptr, len);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2019-09-25 22:38:45 +02:00
|
|
|
void fromwire_chainparams(const u8 **cursor, size_t *max,
|
|
|
|
const struct chainparams **chainparams)
|
|
|
|
{
|
|
|
|
struct bitcoin_blkid genesis;
|
|
|
|
fromwire_bitcoin_blkid(cursor, max, &genesis);
|
|
|
|
*chainparams = chainparams_by_chainhash(&genesis);
|
|
|
|
}
|