daemon: struct rval to represent r values.

We've been stuffing these into sha256s, but they're actually nonces.
Create a new structure for that for clarity.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2016-06-29 06:49:20 +09:30
parent 1abc676c4f
commit 156d1be9ed
9 changed files with 211 additions and 15 deletions

View File

@@ -50,6 +50,49 @@ void sha256_hash__free_unpacked
assert(message->base.descriptor == &sha256_hash__descriptor);
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void rval__init
(Rval *message)
{
static Rval init_value = RVAL__INIT;
*message = init_value;
}
size_t rval__get_packed_size
(const Rval *message)
{
assert(message->base.descriptor == &rval__descriptor);
return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t rval__pack
(const Rval *message,
uint8_t *out)
{
assert(message->base.descriptor == &rval__descriptor);
return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t rval__pack_to_buffer
(const Rval *message,
ProtobufCBuffer *buffer)
{
assert(message->base.descriptor == &rval__descriptor);
return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
Rval *
rval__unpack
(ProtobufCAllocator *allocator,
size_t len,
const uint8_t *data)
{
return (Rval *)
protobuf_c_message_unpack (&rval__descriptor,
allocator, len, data);
}
void rval__free_unpacked
(Rval *message,
ProtobufCAllocator *allocator)
{
assert(message->base.descriptor == &rval__descriptor);
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void signature__init
(Signature *message)
{
@@ -987,6 +1030,83 @@ const ProtobufCMessageDescriptor sha256_hash__descriptor =
(ProtobufCMessageInit) sha256_hash__init,
NULL,NULL,NULL /* reserved[123] */
};
static const ProtobufCFieldDescriptor rval__field_descriptors[4] =
{
{
"a",
1,
PROTOBUF_C_LABEL_REQUIRED,
PROTOBUF_C_TYPE_FIXED64,
0, /* quantifier_offset */
offsetof(Rval, a),
NULL,
NULL,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
{
"b",
2,
PROTOBUF_C_LABEL_REQUIRED,
PROTOBUF_C_TYPE_FIXED64,
0, /* quantifier_offset */
offsetof(Rval, b),
NULL,
NULL,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
{
"c",
3,
PROTOBUF_C_LABEL_REQUIRED,
PROTOBUF_C_TYPE_FIXED64,
0, /* quantifier_offset */
offsetof(Rval, c),
NULL,
NULL,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
{
"d",
4,
PROTOBUF_C_LABEL_REQUIRED,
PROTOBUF_C_TYPE_FIXED64,
0, /* quantifier_offset */
offsetof(Rval, d),
NULL,
NULL,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
};
static const unsigned rval__field_indices_by_name[] = {
0, /* field[0] = a */
1, /* field[1] = b */
2, /* field[2] = c */
3, /* field[3] = d */
};
static const ProtobufCIntRange rval__number_ranges[1 + 1] =
{
{ 1, 0 },
{ 0, 4 }
};
const ProtobufCMessageDescriptor rval__descriptor =
{
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
"rval",
"Rval",
"Rval",
"",
sizeof(Rval),
4,
rval__field_descriptors,
rval__field_indices_by_name,
1, rval__number_ranges,
(ProtobufCMessageInit) rval__init,
NULL,NULL,NULL /* reserved[123] */
};
static const ProtobufCFieldDescriptor signature__field_descriptors[8] =
{
{
@@ -1770,7 +1890,7 @@ static const ProtobufCFieldDescriptor update_fulfill_htlc__field_descriptors[2]
PROTOBUF_C_TYPE_MESSAGE,
0, /* quantifier_offset */
offsetof(UpdateFulfillHtlc, r),
&sha256_hash__descriptor,
&rval__descriptor,
NULL,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */