MCPcopy Create free account
hub / github.com/ElementsProject/lightning / psbt_fixup

Function psbt_fixup

wallet/psbt_fixup.c:152–185  ·  view source on GitHub ↗

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 */

Source from the content-addressed store, hash-verified

150 * entire PSBT, but that turns out not to be possible without decoding the
151 * tranaction. Literally WTF */
152const 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}

Callers 1

Calls 6

tal_bytelenFunction · 0.85
fromwire_keypairFunction · 0.85
fixup_sigFunction · 0.85
towire_keypairFunction · 0.85
fromwire_padFunction · 0.50
towire_u8_arrayFunction · 0.50

Tested by

no test coverage detected