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

@@ -89,6 +89,29 @@ void proto_to_sha256(const Sha256Hash *pb, struct sha256 *hash)
memcpy(hash->u.u8 + 24, &pb->d, 8);
}
Rval *rval_to_proto(const tal_t *ctx, const struct rval *r)
{
Rval *pb = tal(ctx, Rval);
rval__init(pb);
/* Kill me now... */
memcpy(&pb->a, r->r, 8);
memcpy(&pb->b, r->r + 8, 8);
memcpy(&pb->c, r->r + 16, 8);
memcpy(&pb->d, r->r + 24, 8);
return pb;
}
void proto_to_rval(const Rval *pb, struct rval *r)
{
/* Kill me again. */
memcpy(r->r, &pb->a, 8);
memcpy(r->r + 8, &pb->b, 8);
memcpy(r->r + 16, &pb->c, 8);
memcpy(r->r + 24, &pb->d, 8);
}
bool proto_to_rel_locktime(const Locktime *l, struct rel_locktime *locktime)
{
switch (l->locktime_case) {