mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-22 08:34:20 +01:00
bitcoin/tx: fix type of outpoint (n is a u32), simplify json_to_outpoint
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -24,7 +24,7 @@ struct bitcoin_txid {
|
|||||||
|
|
||||||
struct bitcoin_outpoint {
|
struct bitcoin_outpoint {
|
||||||
struct bitcoin_txid txid;
|
struct bitcoin_txid txid;
|
||||||
u16 n;
|
u32 n;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Define bitcoin_txid_eq */
|
/* Define bitcoin_txid_eq */
|
||||||
|
|||||||
@@ -96,26 +96,13 @@ bool json_to_txid(const char *buffer, const jsmntok_t *tok,
|
|||||||
bool json_to_outpoint(const char *buffer, const jsmntok_t *tok,
|
bool json_to_outpoint(const char *buffer, const jsmntok_t *tok,
|
||||||
struct bitcoin_outpoint *op)
|
struct bitcoin_outpoint *op)
|
||||||
{
|
{
|
||||||
size_t len = tok->end - tok->start;
|
jsmntok_t t1, t2;
|
||||||
char str[len + 1];
|
|
||||||
|
|
||||||
if (len < 66)
|
if (!split_tok(buffer, tok, ':', &t1, &t2))
|
||||||
return NULL;
|
|
||||||
|
|
||||||
memcpy(str, buffer+tok->start, len);
|
|
||||||
str[len] = 0x00;
|
|
||||||
|
|
||||||
if (str[64] != ':')
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (!bitcoin_txid_from_hex(str, 64, &op->txid))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
op->n = atoi(str + 65);
|
return json_to_txid(buffer, &t1, &op->txid)
|
||||||
if (op->n < 0)
|
&& json_to_u32(buffer, &t2, &op->n);
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool json_to_channel_id(const char *buffer, const jsmntok_t *tok,
|
bool json_to_channel_id(const char *buffer, const jsmntok_t *tok,
|
||||||
|
|||||||
Reference in New Issue
Block a user