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