@@ -935,6 +935,27 @@ pub(crate) fn decode_next_payment_hop<NS: Deref>(
935935 }
936936}
937937
938+ /// Build a payment onion, returning the first hop msat and cltv values as well.
939+ /// `cur_block_height` should be set to the best known block height + 1.
940+ pub fn create_payment_onion < T : secp256k1:: Signing > (
941+ secp_ctx : & Secp256k1 < T > , path : & Path , session_priv : & SecretKey , total_msat : u64 ,
942+ recipient_onion : RecipientOnionFields , cur_block_height : u32 , payment_hash : & PaymentHash ,
943+ keysend_preimage : & Option < PaymentPreimage > , prng_seed : [ u8 ; 32 ]
944+ ) -> Result < ( msgs:: OnionPacket , u64 , u32 ) , APIError > {
945+ let onion_keys = construct_onion_keys ( & secp_ctx, & path, & session_priv)
946+ . map_err ( |_| APIError :: InvalidRoute {
947+ err : "Pubkey along hop was maliciously selected" . to_owned ( )
948+ } ) ?;
949+ let ( onion_payloads, htlc_msat, htlc_cltv) = build_onion_payloads (
950+ & path, total_msat, recipient_onion, cur_block_height, keysend_preimage
951+ ) ?;
952+ let onion_packet = construct_onion_packet ( onion_payloads, onion_keys, prng_seed, payment_hash)
953+ . map_err ( |_| APIError :: InvalidRoute {
954+ err : "Route size too large considering onion data" . to_owned ( )
955+ } ) ?;
956+ Ok ( ( onion_packet, htlc_msat, htlc_cltv) )
957+ }
958+
938959pub ( crate ) fn decode_next_untagged_hop < T , R : ReadableArgs < T > , N : NextPacketBytes > ( shared_secret : [ u8 ; 32 ] , hop_data : & [ u8 ] , hmac_bytes : [ u8 ; 32 ] , read_args : T ) -> Result < ( R , Option < ( [ u8 ; 32 ] , N ) > ) , OnionDecodeErr > {
939960 decode_next_hop ( shared_secret, hop_data, hmac_bytes, None , read_args)
940961}
0 commit comments