2021-02-01 03:58:50 +01:00
|
|
|
#include "config.h"
|
2016-01-21 21:08:08 +01:00
|
|
|
#include <assert.h>
|
2017-08-28 18:02:01 +02:00
|
|
|
#include <bitcoin/locktime.h>
|
2017-01-04 04:37:15 +01:00
|
|
|
#include <ccan/tal/str/str.h>
|
2017-08-28 18:02:01 +02:00
|
|
|
#include <common/type_to_string.h>
|
2016-01-21 21:08:08 +01:00
|
|
|
|
|
|
|
#define SECONDS_POINT 500000000
|
|
|
|
|
|
|
|
#define BIP68_SECONDS_FLAG (1<<22)
|
|
|
|
#define BIP68_LOCKTIME_MASK (0x0000FFFF)
|
|
|
|
#define BIP68_SECONDS_SHIFT 9
|
|
|
|
|
|
|
|
static bool abs_blocks_to_locktime(u32 blocks, u32 *locktime)
|
|
|
|
{
|
|
|
|
*locktime = blocks;
|
|
|
|
if (*locktime >= SECONDS_POINT)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool abs_is_seconds(u32 locktime)
|
|
|
|
{
|
|
|
|
return locktime >= SECONDS_POINT;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool blocks_to_abs_locktime(u32 blocks, struct abs_locktime *abs)
|
|
|
|
{
|
|
|
|
return abs_blocks_to_locktime(blocks, &abs->locktime);
|
|
|
|
}
|
|
|
|
|
2016-01-21 21:08:08 +01:00
|
|
|
u32 abs_locktime_to_blocks(const struct abs_locktime *abs)
|
|
|
|
{
|
2021-12-04 12:25:06 +01:00
|
|
|
assert(!abs_is_seconds(abs->locktime));
|
2016-01-21 21:08:08 +01:00
|
|
|
return abs->locktime;
|
|
|
|
}
|