proto_to_locktime: abs and relative locktime handlers.

Our current proto_to_locktime actually handles relative locktimes,
and HTLCs use absolute.  Fix that.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2015-08-07 12:45:30 +09:30
parent 7f21695a63
commit 9a0163ec85
5 changed files with 23 additions and 6 deletions

View File

@@ -81,13 +81,19 @@ void proto_to_sha256(const Sha256Hash *pb, struct sha256 *hash)
memcpy(hash->u.u8 + 24, &pb->d, 8);
}
bool proto_to_locktime(const Locktime *l, uint32_t *locktime)
static bool proto_to_locktime(const Locktime *l, uint32_t off,
uint32_t *locktime)
{
switch (l->locktime_case) {
case LOCKTIME__LOCKTIME_SECONDS:
*locktime = 500000000 + l->seconds;
*locktime = off + l->seconds;
/* Check for wrap, or too low value */
if (*locktime < 500000000)
return false;
break;
case LOCKTIME__LOCKTIME_BLOCKS:
if (l->blocks >= 500000000)
return false;
*locktime = l->blocks;
break;
default:
@@ -95,3 +101,13 @@ bool proto_to_locktime(const Locktime *l, uint32_t *locktime)
}
return true;
}
bool proto_to_rel_locktime(const Locktime *l, uint32_t *locktime)
{
return proto_to_locktime(l, 500000000, locktime);
}
bool proto_to_abs_locktime(const Locktime *l, uint32_t *locktime)
{
return proto_to_locktime(l, 0, locktime);
}