| 657 | } |
| 658 | |
| 659 | struct bitcoin_tx *bitcoin_tx_from_hex(const tal_t *ctx, const char *hex, |
| 660 | size_t hexlen) |
| 661 | { |
| 662 | const char *end; |
| 663 | u8 *linear_tx; |
| 664 | const u8 *p; |
| 665 | struct bitcoin_tx *tx; |
| 666 | size_t len; |
| 667 | |
| 668 | end = memchr(hex, '\n', hexlen); |
| 669 | if (!end) |
| 670 | end = hex + hexlen; |
| 671 | |
| 672 | len = hex_data_size(end - hex); |
| 673 | p = linear_tx = tal_arr(ctx, u8, len); |
| 674 | if (!hex_decode(hex, end - hex, linear_tx, len)) |
| 675 | goto fail; |
| 676 | |
| 677 | tx = pull_bitcoin_tx(ctx, &p, &len); |
| 678 | if (!tx) |
| 679 | goto fail; |
| 680 | |
| 681 | if (len) |
| 682 | goto fail_free_tx; |
| 683 | |
| 684 | tal_free(linear_tx); |
| 685 | |
| 686 | return tx; |
| 687 | |
| 688 | fail_free_tx: |
| 689 | tal_free(tx); |
| 690 | fail: |
| 691 | tal_free(linear_tx); |
| 692 | return NULL; |
| 693 | } |
| 694 | |
| 695 | bool bitcoin_txid_from_hex(const char *hexstr, size_t hexstr_len, |
| 696 | struct bitcoin_txid *txid) |