| 126 | } |
| 127 | |
| 128 | struct wally_psbt_input *psbt_append_input(struct wally_psbt *psbt, |
| 129 | const struct bitcoin_outpoint *outpoint, |
| 130 | u32 sequence, |
| 131 | const u8 *scriptSig, |
| 132 | const u8 *input_wscript, |
| 133 | const u8 *redeemscript) |
| 134 | { |
| 135 | struct wally_tx_input *tx_in; |
| 136 | size_t input_num = psbt->num_inputs; |
| 137 | const u32 flags = WALLY_PSBT_FLAG_NON_FINAL; /* Skip script/witness */ |
| 138 | int wally_err; |
| 139 | |
| 140 | tal_wally_start(); |
| 141 | if (chainparams->is_elements) { |
| 142 | if (wally_tx_elements_input_init_alloc(outpoint->txid.shad.sha.u.u8, |
| 143 | sizeof(outpoint->txid.shad.sha.u.u8), |
| 144 | outpoint->n, |
| 145 | sequence, NULL, 0, |
| 146 | NULL, |
| 147 | NULL, 0, |
| 148 | NULL, 0, NULL, 0, |
| 149 | NULL, 0, NULL, 0, |
| 150 | NULL, 0, NULL, |
| 151 | &tx_in) != WALLY_OK) |
| 152 | abort(); |
| 153 | } else { |
| 154 | if (wally_tx_input_init_alloc(outpoint->txid.shad.sha.u.u8, |
| 155 | sizeof(outpoint->txid.shad.sha.u.u8), |
| 156 | outpoint->n, |
| 157 | sequence, NULL, 0, NULL, |
| 158 | &tx_in) != WALLY_OK) |
| 159 | abort(); |
| 160 | } |
| 161 | |
| 162 | wally_err = wally_psbt_add_input_at(psbt, input_num, flags, tx_in); |
| 163 | assert(wally_err == WALLY_OK); |
| 164 | wally_tx_input_free(tx_in); |
| 165 | tal_wally_end(psbt); |
| 166 | |
| 167 | if (input_wscript) { |
| 168 | /* Add the prev output's data into the PSBT struct */ |
| 169 | psbt_input_set_witscript(psbt, input_num, input_wscript); |
| 170 | } |
| 171 | |
| 172 | if (redeemscript) { |
| 173 | tal_wally_start(); |
| 174 | wally_err = wally_psbt_input_set_redeem_script(&psbt->inputs[input_num], |
| 175 | redeemscript, |
| 176 | tal_bytelen(redeemscript)); |
| 177 | assert(wally_err == WALLY_OK); |
| 178 | tal_wally_end(psbt); |
| 179 | } |
| 180 | |
| 181 | return &psbt->inputs[input_num]; |
| 182 | } |
| 183 | |
| 184 | void psbt_rm_input(struct wally_psbt *psbt, |
| 185 | size_t remove_at) |