| 615 | } |
| 616 | |
| 617 | size_t psbt_input_get_weight(const struct wally_psbt *psbt, |
| 618 | size_t in, |
| 619 | enum PSBT_GUESS guess) |
| 620 | { |
| 621 | size_t weight; |
| 622 | const struct wally_map_item *redeem_script; |
| 623 | struct wally_psbt_input *input = &psbt->inputs[in]; |
| 624 | struct wally_tx_output *utxo_out = NULL; |
| 625 | |
| 626 | if (input->utxo) |
| 627 | utxo_out = &input->utxo->outputs[input->index]; |
| 628 | |
| 629 | redeem_script = wally_map_get_integer(&psbt->inputs[in].psbt_fields, /* PSBT_IN_REDEEM_SCRIPT */ 0x04); |
| 630 | |
| 631 | /* txid + txout + sequence */ |
| 632 | weight = (32 + 4 + 4) * 4; |
| 633 | if (redeem_script) { |
| 634 | weight += |
| 635 | (redeem_script->value_len + |
| 636 | varint_size(redeem_script->value_len)) * 4; |
| 637 | } else if ((guess & PSBT_GUESS_2OF2) |
| 638 | && utxo_out |
| 639 | && is_p2wsh(utxo_out->script, utxo_out->script_len, NULL)) { |
| 640 | weight = bitcoin_tx_input_weight(false, |
| 641 | bitcoin_tx_2of2_input_witness_weight()); |
| 642 | } else if (utxo_out |
| 643 | && is_p2wpkh(utxo_out->script, utxo_out->script_len, NULL)) { |
| 644 | weight = bitcoin_tx_input_weight(false, |
| 645 | bitcoin_tx_input_witness_weight(UTXO_P2SH_P2WPKH)); |
| 646 | } else if (utxo_out |
| 647 | && is_p2tr(utxo_out->script, utxo_out->script_len, NULL)) { |
| 648 | weight = bitcoin_tx_input_weight(false, |
| 649 | bitcoin_tx_input_witness_weight(UTXO_P2TR)); |
| 650 | } else { |
| 651 | weight += varint_size(0) * 4; |
| 652 | } |
| 653 | |
| 654 | return weight; |
| 655 | } |
| 656 | |
| 657 | struct amount_sat psbt_output_get_amount(const struct wally_psbt *psbt, |
| 658 | size_t out) |
no test coverage detected