mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-04 14:54:26 +01:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user