mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-24 01:24:26 +01:00
bitcoin_tx: bitcoin_txid_from_hex helper.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
24
bitcoin_tx.c
24
bitcoin_tx.c
@@ -287,3 +287,27 @@ struct bitcoin_tx *bitcoin_tx_from_file(const tal_t *ctx,
|
||||
|
||||
return tx;
|
||||
}
|
||||
|
||||
/* <sigh>. Bitcoind represents hashes as little-endian for RPC. This didn't
|
||||
* stick for blockids (everyone else uses big-endian, eg. block explorers),
|
||||
* but it did stick for txids. */
|
||||
static void reverse_bytes(u8 *arr, size_t len)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < len / 2; i++) {
|
||||
unsigned char tmp = arr[i];
|
||||
arr[i] = arr[len - 1 - i];
|
||||
arr[len - 1 - i] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
bool bitcoin_txid_from_hex(const char *hexstr, size_t hexstr_len,
|
||||
struct sha256_double *txid)
|
||||
{
|
||||
if (!hex_decode(hexstr, hexstr_len, txid, sizeof(*txid)))
|
||||
return false;
|
||||
reverse_bytes(txid->sha.u.u8, sizeof(txid->sha.u.u8));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user