| 604 | } |
| 605 | |
| 606 | struct bitcoin_tx *bitcoin_tx_from_hex(const tal_t *ctx, const char *hex, |
| 607 | size_t hexlen) |
| 608 | { |
| 609 | const char *end; |
| 610 | u8 *linear_tx; |
| 611 | const u8 *p; |
| 612 | struct bitcoin_tx *tx; |
| 613 | size_t len; |
| 614 | |
| 615 | end = memchr(hex, '\n', hexlen); |
| 616 | if (!end) |
| 617 | end = hex + hexlen; |
| 618 | |
| 619 | len = hex_data_size(end - hex); |
| 620 | p = linear_tx = tal_arr(ctx, u8, len); |
| 621 | if (!hex_decode(hex, end - hex, linear_tx, len)) |
| 622 | goto fail; |
| 623 | |
| 624 | tx = pull_bitcoin_tx(ctx, &p, &len); |
| 625 | if (!tx) |
| 626 | goto fail; |
| 627 | |
| 628 | if (len) |
| 629 | goto fail_free_tx; |
| 630 | |
| 631 | tal_free(linear_tx); |
| 632 | |
| 633 | return tx; |
| 634 | |
| 635 | fail_free_tx: |
| 636 | tal_free(tx); |
| 637 | fail: |
| 638 | tal_free(linear_tx); |
| 639 | return NULL; |
| 640 | } |
| 641 | |
| 642 | /* <sigh>. Bitcoind represents hashes as little-endian for RPC. */ |
| 643 | static void reverse_bytes(u8 *arr, size_t len) |