mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 07:34:24 +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:
@@ -35,7 +35,7 @@ struct bitcoin_tx *create_commit_tx(const tal_t *ctx,
|
|||||||
if (!proto_to_pubkey(theirs->final_key, &theirkey))
|
if (!proto_to_pubkey(theirs->final_key, &theirkey))
|
||||||
return tal_free(tx);
|
return tal_free(tx);
|
||||||
|
|
||||||
if (!proto_to_locktime(theirs->delay, &locktime))
|
if (!proto_to_rel_locktime(theirs->delay, &locktime))
|
||||||
return tal_free(tx);
|
return tal_free(tx);
|
||||||
|
|
||||||
/* First output is a P2SH to a complex redeem script (usu. for me) */
|
/* First output is a P2SH to a complex redeem script (usu. for me) */
|
||||||
|
|||||||
@@ -81,13 +81,19 @@ void proto_to_sha256(const Sha256Hash *pb, struct sha256 *hash)
|
|||||||
memcpy(hash->u.u8 + 24, &pb->d, 8);
|
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) {
|
switch (l->locktime_case) {
|
||||||
case LOCKTIME__LOCKTIME_SECONDS:
|
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;
|
break;
|
||||||
case LOCKTIME__LOCKTIME_BLOCKS:
|
case LOCKTIME__LOCKTIME_BLOCKS:
|
||||||
|
if (l->blocks >= 500000000)
|
||||||
|
return false;
|
||||||
*locktime = l->blocks;
|
*locktime = l->blocks;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -95,3 +101,13 @@ bool proto_to_locktime(const Locktime *l, uint32_t *locktime)
|
|||||||
}
|
}
|
||||||
return true;
|
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);
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,5 +19,6 @@ struct sha256;
|
|||||||
Sha256Hash *sha256_to_proto(const tal_t *ctx, const struct sha256 *hash);
|
Sha256Hash *sha256_to_proto(const tal_t *ctx, const struct sha256 *hash);
|
||||||
void proto_to_sha256(const Sha256Hash *pb, struct sha256 *hash);
|
void proto_to_sha256(const Sha256Hash *pb, struct sha256 *hash);
|
||||||
|
|
||||||
bool proto_to_locktime(const Locktime *l, uint32_t *locktime);
|
bool proto_to_rel_locktime(const Locktime *l, uint32_t *locktime);
|
||||||
|
bool proto_to_abs_locktime(const Locktime *l, uint32_t *locktime);
|
||||||
#endif /* LIGHTNING_PROTOBUF_CONVERT_H */
|
#endif /* LIGHTNING_PROTOBUF_CONVERT_H */
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ int main(int argc, char *argv[])
|
|||||||
o1 = pkt_from_file(argv[2], PKT__PKT_OPEN)->open;
|
o1 = pkt_from_file(argv[2], PKT__PKT_OPEN)->open;
|
||||||
o2 = pkt_from_file(argv[3], PKT__PKT_OPEN)->open;
|
o2 = pkt_from_file(argv[3], PKT__PKT_OPEN)->open;
|
||||||
a = pkt_from_file(argv[4], PKT__PKT_OPEN_ANCHOR)->open_anchor;
|
a = pkt_from_file(argv[4], PKT__PKT_OPEN_ANCHOR)->open_anchor;
|
||||||
if (!proto_to_locktime(o2->delay, &locktime))
|
if (!proto_to_rel_locktime(o2->delay, &locktime))
|
||||||
errx(1, "Invalid locktime in o2");
|
errx(1, "Invalid locktime in o2");
|
||||||
|
|
||||||
/* We need our private key to spend commit output. */
|
/* We need our private key to spend commit output. */
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
o1 = pkt_from_file(argv[4], PKT__PKT_OPEN)->open;
|
o1 = pkt_from_file(argv[4], PKT__PKT_OPEN)->open;
|
||||||
o2 = pkt_from_file(argv[5], PKT__PKT_OPEN)->open;
|
o2 = pkt_from_file(argv[5], PKT__PKT_OPEN)->open;
|
||||||
if (!proto_to_locktime(o1->delay, &locktime_seconds))
|
if (!proto_to_rel_locktime(o1->delay, &locktime_seconds))
|
||||||
errx(1, "Invalid locktime in o2");
|
errx(1, "Invalid locktime in o2");
|
||||||
|
|
||||||
if (!pubkey_from_hexstr(argv[6], &outpubkey))
|
if (!pubkey_from_hexstr(argv[6], &outpubkey))
|
||||||
|
|||||||
Reference in New Issue
Block a user