I am deeply, deeply unhappy with this code. I initially tried parsing the * entire PSBT, but that turns out not to be possible without decoding the * tranaction. Literally WTF */
| 150 | * entire PSBT, but that turns out not to be possible without decoding the |
| 151 | * tranaction. Literally WTF */ |
| 152 | const u8 *psbt_fixup(const tal_t *ctx, const u8 *psbtblob) |
| 153 | { |
| 154 | const u8 *prev_cursor, *cursor = psbtblob; |
| 155 | size_t max = tal_bytelen(psbtblob); |
| 156 | u8 *ret; |
| 157 | struct keypair *kp, *changed_kp; |
| 158 | |
| 159 | /* Skip magic */ |
| 160 | fromwire_pad(&cursor, &max, 5); |
| 161 | |
| 162 | /* Skip global map */ |
| 163 | while ((kp = fromwire_keypair(tmpctx, &cursor, &max)) != NULL); |
| 164 | |
| 165 | /* Now input map */ |
| 166 | changed_kp = NULL; |
| 167 | prev_cursor = cursor; |
| 168 | while ((kp = fromwire_keypair(tmpctx, &cursor, &max)) != NULL) { |
| 169 | /* PSBT_IN_PARTIAL_SIG = 0x02 */ |
| 170 | if (kp->keytype == 2 && fixup_sig(kp)) { |
| 171 | changed_kp = kp; |
| 172 | break; |
| 173 | } |
| 174 | prev_cursor = cursor; |
| 175 | } |
| 176 | |
| 177 | if (!changed_kp) |
| 178 | return NULL; |
| 179 | |
| 180 | ret = tal_dup_arr(ctx, u8, psbtblob, prev_cursor - psbtblob, 0); |
| 181 | towire_keypair(&ret, changed_kp); |
| 182 | towire_u8_array(&ret, cursor, max); |
| 183 | |
| 184 | return ret; |
| 185 | } |
no test coverage detected