| 166 | } |
| 167 | |
| 168 | static int parse_htlc(char *argv[], struct existing_htlc ***htlcs) |
| 169 | { |
| 170 | struct existing_htlc *exist = tal(*htlcs, struct existing_htlc); |
| 171 | int argnum = 0; |
| 172 | |
| 173 | exist->id = tal_count(*htlcs); |
| 174 | if (streq(argv[argnum], "local")) |
| 175 | exist->state = SENT_ADD_ACK_REVOCATION; |
| 176 | else if (streq(argv[argnum], "remote")) |
| 177 | exist->state = RCVD_ADD_ACK_REVOCATION; |
| 178 | else |
| 179 | errx(1, "Bad htlc offer: %s should be 'local' or 'remote'", |
| 180 | argv[argnum]); |
| 181 | argnum++; |
| 182 | exist->payment_preimage = tal(*htlcs, struct preimage); |
| 183 | if (!hex_decode(argv[argnum], strlen(argv[argnum]), |
| 184 | exist->payment_preimage, sizeof(*exist->payment_preimage))) |
| 185 | errx(1, "Bad payment-preimage %s", argv[argnum]); |
| 186 | |
| 187 | sha256(&exist->payment_hash, exist->payment_preimage, |
| 188 | sizeof(*exist->payment_preimage)); |
| 189 | argnum++; |
| 190 | if (!parse_amount_msat(&exist->amount, |
| 191 | argv[argnum], strlen(argv[argnum]))) |
| 192 | errx(1, "Bad htlc amount %s", argv[argnum]); |
| 193 | argnum++; |
| 194 | exist->cltv_expiry = atoi(argv[argnum]); |
| 195 | argnum++; |
| 196 | |
| 197 | printf("# HTLC %"PRIu64": %s amount=%s preimage=%s payment_hash=%s cltv=%u\n", |
| 198 | exist->id, argv[0], |
| 199 | type_to_string(tmpctx, struct amount_msat, &exist->amount), |
| 200 | type_to_string(tmpctx, struct preimage, exist->payment_preimage), |
| 201 | type_to_string(tmpctx, struct sha256, &exist->payment_hash), |
| 202 | exist->cltv_expiry); |
| 203 | |
| 204 | tal_arr_expand(htlcs, exist); |
| 205 | return argnum; |
| 206 | } |
| 207 | |
| 208 | static const struct preimage *preimage_of(const struct sha256 *hash, |
| 209 | const struct existing_htlc **htlcs) |
no test coverage detected