| 351 | } |
| 352 | |
| 353 | static void report(struct bitcoin_tx *tx, |
| 354 | const u8 *wscript, |
| 355 | const struct privkey *x_remote_funding_privkey, |
| 356 | const struct pubkey *remote_funding_pubkey, |
| 357 | const struct privkey *local_funding_privkey, |
| 358 | const struct pubkey *local_funding_pubkey, |
| 359 | u16 to_self_delay, |
| 360 | const struct privkey *local_htlcsecretkey, |
| 361 | const struct pubkey *localkey, |
| 362 | const struct pubkey *local_htlckey, |
| 363 | const struct pubkey *local_delayedkey, |
| 364 | const struct privkey *x_remote_htlcsecretkey, |
| 365 | const struct pubkey *remotekey, |
| 366 | const struct pubkey *remote_htlckey, |
| 367 | const struct pubkey *remote_revocation_key, |
| 368 | u32 feerate_per_kw, |
| 369 | bool option_anchor_outputs, |
| 370 | bool option_anchors_zero_fee_htlc_tx, |
| 371 | const struct htlc **htlc_map, |
| 372 | size_t total_htlcs) |
| 373 | { |
| 374 | char *txhex; |
| 375 | struct bitcoin_signature localsig, remotesig; |
| 376 | u8 **witness; |
| 377 | |
| 378 | sign_tx_input(tx, 0, |
| 379 | NULL, |
| 380 | wscript, |
| 381 | x_remote_funding_privkey, remote_funding_pubkey, |
| 382 | SIGHASH_ALL, |
| 383 | &remotesig); |
| 384 | printf("remote_signature = %s\n", |
| 385 | fmt_secp256k1_ecdsa_signature(tmpctx, &remotesig.s)); |
| 386 | sign_tx_input(tx, 0, |
| 387 | NULL, |
| 388 | wscript, |
| 389 | local_funding_privkey, local_funding_pubkey, |
| 390 | SIGHASH_ALL, |
| 391 | &localsig); |
| 392 | printf("# local_signature = %s\n", |
| 393 | fmt_secp256k1_ecdsa_signature(tmpctx, &localsig.s)); |
| 394 | |
| 395 | witness = |
| 396 | bitcoin_witness_2of2(tx, &localsig, &remotesig, |
| 397 | local_funding_pubkey, remote_funding_pubkey); |
| 398 | bitcoin_tx_input_set_witness(tx, 0, take(witness)); |
| 399 | txhex = tal_hex(tmpctx, linearize_tx(tx, tx)); |
| 400 | printf("output commit_tx: %s\n", txhex); |
| 401 | |
| 402 | /* Now signatures are attached, this should be correct. But note |
| 403 | * that spec uses worst-case weight, so we will be slightly higher. */ |
| 404 | assert(tx_feerate(tx) >= feerate_per_kw); |
| 405 | /* Of course, trimmed htlcs magnify this! */ |
| 406 | if (tx->wtx->num_outputs == total_htlcs + 2) |
| 407 | assert(tx_feerate(tx) <= feerate_per_kw * 1.01); |
| 408 | |
| 409 | report_htlcs(tx, htlc_map, to_self_delay, |
| 410 | local_htlcsecretkey, localkey, local_htlckey, |
no test coverage detected