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

Function bitcoin_wscript_htlc_receive_ripemd

bitcoin/script.c:714–763  ·  view source on GitHub ↗

BOLT #3: * * #### Received HTLC Outputs * * This output sends funds to either the remote node after the HTLC-timeout or * using the revocation key, or to an HTLC-success transaction with a * successful payment preimage. The output is a P2WSH, with a witness script * (no `option_anchors`): * * # To remote node with revocation key * OP_DUP OP_HASH160 <RIPEMD160(SHA256(revocationpub

Source from the content-addressed store, hash-verified

712 * OP_ENDIF
713 */
714u8 *bitcoin_wscript_htlc_receive_ripemd(const tal_t *ctx,
715 const struct abs_locktime *htlc_abstimeout,
716 const struct pubkey *localhtlckey,
717 const struct pubkey *remotehtlckey,
718 const struct ripemd160 *payment_ripemd,
719 const struct pubkey *revocationkey,
720 bool option_anchor_outputs)
721{
722 u8 *script = tal_arr(ctx, u8, 0);
723 struct ripemd160 ripemd;
724
725 add_op(&script, OP_DUP);
726 add_op(&script, OP_HASH160);
727 pubkey_to_hash160(revocationkey, &ripemd);
728 script_push_bytes(&script, &ripemd, sizeof(ripemd));
729 add_op(&script, OP_EQUAL);
730 add_op(&script, OP_IF);
731 add_op(&script, OP_CHECKSIG);
732 add_op(&script, OP_ELSE);
733 add_push_key(&script, remotehtlckey);
734 add_op(&script, OP_SWAP);
735 add_op(&script, OP_SIZE);
736 add_number(&script, 32);
737 add_op(&script, OP_EQUAL);
738 add_op(&script, OP_IF);
739 add_op(&script, OP_HASH160);
740 script_push_bytes(&script,
741 payment_ripemd->u.u8, sizeof(payment_ripemd->u.u8));
742 add_op(&script, OP_EQUALVERIFY);
743 add_number(&script, 2);
744 add_op(&script, OP_SWAP);
745 add_push_key(&script, localhtlckey);
746 add_number(&script, 2);
747 add_op(&script, OP_CHECKMULTISIG);
748 add_op(&script, OP_ELSE);
749 add_op(&script, OP_DROP);
750 add_number(&script, htlc_abstimeout->locktime);
751 add_op(&script, OP_CHECKLOCKTIMEVERIFY);
752 add_op(&script, OP_DROP);
753 add_op(&script, OP_CHECKSIG);
754 add_op(&script, OP_ENDIF);
755 if (option_anchor_outputs) {
756 add_number(&script, 1);
757 add_op(&script, OP_CHECKSEQUENCEVERIFY);
758 add_op(&script, OP_DROP);
759 }
760 add_op(&script, OP_ENDIF);
761
762 return script;
763}
764
765u8 *bitcoin_wscript_htlc_receive(const tal_t *ctx,
766 const struct abs_locktime *htlc_abstimeout,

Callers 2

htlc_received_wscriptFunction · 0.85

Calls 5

add_opFunction · 0.85
add_push_keyFunction · 0.85
add_numberFunction · 0.85
pubkey_to_hash160Function · 0.70
script_push_bytesFunction · 0.70

Tested by

no test coverage detected