This only works on a non-final psbt because we're ALL SEGWIT! */
| 773 | |
| 774 | /* This only works on a non-final psbt because we're ALL SEGWIT! */ |
| 775 | void psbt_txid(const tal_t *ctx, |
| 776 | const struct wally_psbt *psbt, struct bitcoin_txid *txid, |
| 777 | struct wally_tx **wtx) |
| 778 | { |
| 779 | struct wally_tx *tx; |
| 780 | |
| 781 | /* You can *almost* take txid of global tx. But @niftynei thought |
| 782 | * about this far more than me and pointed out that P2SH |
| 783 | * inputs would not be represented, so here we go. */ |
| 784 | tal_wally_start(); |
| 785 | wally_tx_clone_alloc(psbt->tx, 0, &tx); |
| 786 | |
| 787 | for (size_t i = 0; i < tx->num_inputs; i++) { |
| 788 | if (psbt->inputs[i].final_scriptsig) { |
| 789 | wally_tx_set_input_script(tx, i, |
| 790 | psbt->inputs[i].final_scriptsig, |
| 791 | psbt->inputs[i].final_scriptsig_len); |
| 792 | } else if (psbt->inputs[i].redeem_script) { |
| 793 | u8 *script; |
| 794 | |
| 795 | /* P2SH requires push of the redeemscript, from libwally src */ |
| 796 | script = tal_arr(tmpctx, u8, 0); |
| 797 | script_push_bytes(&script, |
| 798 | psbt->inputs[i].redeem_script, |
| 799 | psbt->inputs[i].redeem_script_len); |
| 800 | wally_tx_set_input_script(tx, i, script, tal_bytelen(script)); |
| 801 | } |
| 802 | } |
| 803 | tal_wally_end_onto(ctx, tx, struct wally_tx); |
| 804 | |
| 805 | wally_txid(tx, txid); |
| 806 | if (wtx) |
| 807 | *wtx = tx; |
| 808 | else |
| 809 | wally_tx_free(tx); |
| 810 | } |
| 811 | |
| 812 | struct amount_sat psbt_compute_fee(const struct wally_psbt *psbt) |
| 813 | { |
no test coverage detected