mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
open-channel: expect hex txids to be in LE (ie. reversed!) order.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
3ed87c5e6f
commit
50609c6771
@ -15,6 +15,7 @@
|
||||
#include "bitcoin_script.h"
|
||||
#include "bitcoin_address.h"
|
||||
#include "pubkey.h"
|
||||
#include "shadouble.h"
|
||||
#include <openssl/ec.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@ -39,10 +40,24 @@ static void opt_show_bits(char buf[OPT_SHOW_LEN], const u64 *bits)
|
||||
opt_show_ulonglongval_si(buf, &ll);
|
||||
}
|
||||
|
||||
/* <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;
|
||||
}
|
||||
}
|
||||
|
||||
static BitcoinInput *parse_anchor_input(const tal_t *ctx, const char *spec)
|
||||
{
|
||||
BitcoinInput *in = tal(ctx, BitcoinInput);
|
||||
struct sha256 txid;
|
||||
struct sha256_double txid;
|
||||
const char *slash;
|
||||
char *end;
|
||||
long l;
|
||||
@ -55,7 +70,8 @@ static BitcoinInput *parse_anchor_input(const tal_t *ctx, const char *spec)
|
||||
|
||||
if (!hex_decode(spec, slash - spec, &txid, sizeof(txid)))
|
||||
errx(1, "Expected 256-bit hex txid before /");
|
||||
in->txid = sha256_to_proto(in, &txid);
|
||||
reverse_bytes(txid.sha.u.u8, sizeof(txid.sha.u.u8));
|
||||
in->txid = sha256_to_proto(in, &txid.sha);
|
||||
|
||||
in->output = l = strtol(slash + 1, &end, 10);
|
||||
if (end == slash + 1 || *end != '/' || (int64_t)in->output != (int64_t)l)
|
||||
|
Loading…
Reference in New Issue
Block a user