- bindings updates
[rust-lightning] / lightning-c-bindings / src / chain / keysinterface.rs
1 //! keysinterface provides keys into rust-lightning and defines some useful enums which describe
2 //! spendable on-chain outputs which the user owns and is responsible for using just as any other
3 //! on-chain output which is theirs.
4
5 use std::ffi::c_void;
6 use bitcoin::hashes::Hash;
7 use crate::c_types::*;
8
9 /// When on-chain outputs are created by rust-lightning (which our counterparty is not able to
10 /// claim at any point in the future) an event is generated which you must track and be able to
11 /// spend on-chain. The information needed to do this is provided in this enum, including the
12 /// outpoint describing which txid and output index is available, the full output which exists at
13 /// that txid/index, and any keys or other information required to sign.
14 #[must_use]
15 #[derive(Clone)]
16 #[repr(C)]
17 pub enum SpendableOutputDescriptor {
18         /// An output to a script which was provided via KeysInterface, thus you should already know
19         /// how to spend it. No keys are provided as rust-lightning was never given any keys - only the
20         /// script_pubkey as it appears in the output.
21         /// These may include outputs from a transaction punishing our counterparty or claiming an HTLC
22         /// on-chain using the payment preimage or after it has timed out.
23         StaticOutput {
24                 outpoint: crate::chain::transaction::OutPoint,
25                 output: crate::c_types::TxOut,
26         },
27         /// An output to a P2WSH script which can be spent with a single signature after a CSV delay.
28         ///
29         /// The witness in the spending input should be:
30         /// <BIP 143 signature> <empty vector> (MINIMALIF standard rule) <provided witnessScript>
31         ///
32         /// Note that the nSequence field in the spending input must be set to to_self_delay
33         /// (which means the transaction is not broadcastable until at least to_self_delay
34         /// blocks after the outpoint confirms).
35         ///
36         /// These are generally the result of a \"revocable\" output to us, spendable only by us unless
37         /// it is an output from an old state which we broadcast (which should never happen).
38         ///
39         /// To derive the delayed_payment key which is used to sign for this input, you must pass the
40         /// holder delayed_payment_base_key (ie the private key which corresponds to the pubkey in
41         /// ChannelKeys::pubkeys().delayed_payment_basepoint) and the provided per_commitment_point to
42         /// chan_utils::derive_private_key. The public key can be generated without the secret key
43         /// using chan_utils::derive_public_key and only the delayed_payment_basepoint which appears in
44         /// ChannelKeys::pubkeys().
45         ///
46         /// To derive the revocation_pubkey provided here (which is used in the witness
47         /// script generation), you must pass the counterparty revocation_basepoint (which appears in the
48         /// call to ChannelKeys::ready_channel) and the provided per_commitment point
49         /// to chan_utils::derive_public_revocation_key.
50         ///
51         /// The witness script which is hashed and included in the output script_pubkey may be
52         /// regenerated by passing the revocation_pubkey (derived as above), our delayed_payment pubkey
53         /// (derived as above), and the to_self_delay contained here to
54         /// chan_utils::get_revokeable_redeemscript.
55         DynamicOutputP2WSH {
56                 outpoint: crate::chain::transaction::OutPoint,
57                 per_commitment_point: crate::c_types::PublicKey,
58                 to_self_delay: u16,
59                 output: crate::c_types::TxOut,
60                 key_derivation_params: crate::c_types::derived::C2Tuple_u64u64Z,
61                 revocation_pubkey: crate::c_types::PublicKey,
62         },
63         /// An output to a P2WPKH, spendable exclusively by our payment key (ie the private key which
64         /// corresponds to the public key in ChannelKeys::pubkeys().payment_point).
65         /// The witness in the spending input, is, thus, simply:
66         /// <BIP 143 signature> <payment key>
67         ///
68         /// These are generally the result of our counterparty having broadcast the current state,
69         /// allowing us to claim the non-HTLC-encumbered outputs immediately.
70         StaticOutputCounterpartyPayment {
71                 outpoint: crate::chain::transaction::OutPoint,
72                 output: crate::c_types::TxOut,
73                 key_derivation_params: crate::c_types::derived::C2Tuple_u64u64Z,
74         },
75 }
76 use lightning::chain::keysinterface::SpendableOutputDescriptor as nativeSpendableOutputDescriptor;
77 impl SpendableOutputDescriptor {
78         #[allow(unused)]
79         pub(crate) fn to_native(&self) -> nativeSpendableOutputDescriptor {
80                 match self {
81                         SpendableOutputDescriptor::StaticOutput {ref outpoint, ref output, } => {
82                                 let mut outpoint_nonref = (*outpoint).clone();
83                                 let mut output_nonref = (*output).clone();
84                                 nativeSpendableOutputDescriptor::StaticOutput {
85                                         outpoint: *unsafe { Box::from_raw(outpoint_nonref.take_inner()) },
86                                         output: output_nonref.into_rust(),
87                                 }
88                         },
89                         SpendableOutputDescriptor::DynamicOutputP2WSH {ref outpoint, ref per_commitment_point, ref to_self_delay, ref output, ref key_derivation_params, ref revocation_pubkey, } => {
90                                 let mut outpoint_nonref = (*outpoint).clone();
91                                 let mut per_commitment_point_nonref = (*per_commitment_point).clone();
92                                 let mut to_self_delay_nonref = (*to_self_delay).clone();
93                                 let mut output_nonref = (*output).clone();
94                                 let mut key_derivation_params_nonref = (*key_derivation_params).clone();
95                                 let (mut orig_key_derivation_params_nonref_0, mut orig_key_derivation_params_nonref_1) = key_derivation_params_nonref.to_rust(); let mut local_key_derivation_params_nonref = (orig_key_derivation_params_nonref_0, orig_key_derivation_params_nonref_1);
96                                 let mut revocation_pubkey_nonref = (*revocation_pubkey).clone();
97                                 nativeSpendableOutputDescriptor::DynamicOutputP2WSH {
98                                         outpoint: *unsafe { Box::from_raw(outpoint_nonref.take_inner()) },
99                                         per_commitment_point: per_commitment_point_nonref.into_rust(),
100                                         to_self_delay: to_self_delay_nonref,
101                                         output: output_nonref.into_rust(),
102                                         key_derivation_params: local_key_derivation_params_nonref,
103                                         revocation_pubkey: revocation_pubkey_nonref.into_rust(),
104                                 }
105                         },
106                         SpendableOutputDescriptor::StaticOutputCounterpartyPayment {ref outpoint, ref output, ref key_derivation_params, } => {
107                                 let mut outpoint_nonref = (*outpoint).clone();
108                                 let mut output_nonref = (*output).clone();
109                                 let mut key_derivation_params_nonref = (*key_derivation_params).clone();
110                                 let (mut orig_key_derivation_params_nonref_0, mut orig_key_derivation_params_nonref_1) = key_derivation_params_nonref.to_rust(); let mut local_key_derivation_params_nonref = (orig_key_derivation_params_nonref_0, orig_key_derivation_params_nonref_1);
111                                 nativeSpendableOutputDescriptor::StaticOutputCounterpartyPayment {
112                                         outpoint: *unsafe { Box::from_raw(outpoint_nonref.take_inner()) },
113                                         output: output_nonref.into_rust(),
114                                         key_derivation_params: local_key_derivation_params_nonref,
115                                 }
116                         },
117                 }
118         }
119         #[allow(unused)]
120         pub(crate) fn into_native(self) -> nativeSpendableOutputDescriptor {
121                 match self {
122                         SpendableOutputDescriptor::StaticOutput {mut outpoint, mut output, } => {
123                                 nativeSpendableOutputDescriptor::StaticOutput {
124                                         outpoint: *unsafe { Box::from_raw(outpoint.take_inner()) },
125                                         output: output.into_rust(),
126                                 }
127                         },
128                         SpendableOutputDescriptor::DynamicOutputP2WSH {mut outpoint, mut per_commitment_point, mut to_self_delay, mut output, mut key_derivation_params, mut revocation_pubkey, } => {
129                                 let (mut orig_key_derivation_params_0, mut orig_key_derivation_params_1) = key_derivation_params.to_rust(); let mut local_key_derivation_params = (orig_key_derivation_params_0, orig_key_derivation_params_1);
130                                 nativeSpendableOutputDescriptor::DynamicOutputP2WSH {
131                                         outpoint: *unsafe { Box::from_raw(outpoint.take_inner()) },
132                                         per_commitment_point: per_commitment_point.into_rust(),
133                                         to_self_delay: to_self_delay,
134                                         output: output.into_rust(),
135                                         key_derivation_params: local_key_derivation_params,
136                                         revocation_pubkey: revocation_pubkey.into_rust(),
137                                 }
138                         },
139                         SpendableOutputDescriptor::StaticOutputCounterpartyPayment {mut outpoint, mut output, mut key_derivation_params, } => {
140                                 let (mut orig_key_derivation_params_0, mut orig_key_derivation_params_1) = key_derivation_params.to_rust(); let mut local_key_derivation_params = (orig_key_derivation_params_0, orig_key_derivation_params_1);
141                                 nativeSpendableOutputDescriptor::StaticOutputCounterpartyPayment {
142                                         outpoint: *unsafe { Box::from_raw(outpoint.take_inner()) },
143                                         output: output.into_rust(),
144                                         key_derivation_params: local_key_derivation_params,
145                                 }
146                         },
147                 }
148         }
149         #[allow(unused)]
150         pub(crate) fn from_native(native: &nativeSpendableOutputDescriptor) -> Self {
151                 match native {
152                         nativeSpendableOutputDescriptor::StaticOutput {ref outpoint, ref output, } => {
153                                 let mut outpoint_nonref = (*outpoint).clone();
154                                 let mut output_nonref = (*output).clone();
155                                 SpendableOutputDescriptor::StaticOutput {
156                                         outpoint: crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(outpoint_nonref)), is_owned: true },
157                                         output: crate::c_types::TxOut::from_rust(output_nonref),
158                                 }
159                         },
160                         nativeSpendableOutputDescriptor::DynamicOutputP2WSH {ref outpoint, ref per_commitment_point, ref to_self_delay, ref output, ref key_derivation_params, ref revocation_pubkey, } => {
161                                 let mut outpoint_nonref = (*outpoint).clone();
162                                 let mut per_commitment_point_nonref = (*per_commitment_point).clone();
163                                 let mut to_self_delay_nonref = (*to_self_delay).clone();
164                                 let mut output_nonref = (*output).clone();
165                                 let mut key_derivation_params_nonref = (*key_derivation_params).clone();
166                                 let (mut orig_key_derivation_params_nonref_0, mut orig_key_derivation_params_nonref_1) = key_derivation_params_nonref; let mut local_key_derivation_params_nonref = (orig_key_derivation_params_nonref_0, orig_key_derivation_params_nonref_1).into();
167                                 let mut revocation_pubkey_nonref = (*revocation_pubkey).clone();
168                                 SpendableOutputDescriptor::DynamicOutputP2WSH {
169                                         outpoint: crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(outpoint_nonref)), is_owned: true },
170                                         per_commitment_point: crate::c_types::PublicKey::from_rust(&per_commitment_point_nonref),
171                                         to_self_delay: to_self_delay_nonref,
172                                         output: crate::c_types::TxOut::from_rust(output_nonref),
173                                         key_derivation_params: local_key_derivation_params_nonref,
174                                         revocation_pubkey: crate::c_types::PublicKey::from_rust(&revocation_pubkey_nonref),
175                                 }
176                         },
177                         nativeSpendableOutputDescriptor::StaticOutputCounterpartyPayment {ref outpoint, ref output, ref key_derivation_params, } => {
178                                 let mut outpoint_nonref = (*outpoint).clone();
179                                 let mut output_nonref = (*output).clone();
180                                 let mut key_derivation_params_nonref = (*key_derivation_params).clone();
181                                 let (mut orig_key_derivation_params_nonref_0, mut orig_key_derivation_params_nonref_1) = key_derivation_params_nonref; let mut local_key_derivation_params_nonref = (orig_key_derivation_params_nonref_0, orig_key_derivation_params_nonref_1).into();
182                                 SpendableOutputDescriptor::StaticOutputCounterpartyPayment {
183                                         outpoint: crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(outpoint_nonref)), is_owned: true },
184                                         output: crate::c_types::TxOut::from_rust(output_nonref),
185                                         key_derivation_params: local_key_derivation_params_nonref,
186                                 }
187                         },
188                 }
189         }
190         #[allow(unused)]
191         pub(crate) fn native_into(native: nativeSpendableOutputDescriptor) -> Self {
192                 match native {
193                         nativeSpendableOutputDescriptor::StaticOutput {mut outpoint, mut output, } => {
194                                 SpendableOutputDescriptor::StaticOutput {
195                                         outpoint: crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(outpoint)), is_owned: true },
196                                         output: crate::c_types::TxOut::from_rust(output),
197                                 }
198                         },
199                         nativeSpendableOutputDescriptor::DynamicOutputP2WSH {mut outpoint, mut per_commitment_point, mut to_self_delay, mut output, mut key_derivation_params, mut revocation_pubkey, } => {
200                                 let (mut orig_key_derivation_params_0, mut orig_key_derivation_params_1) = key_derivation_params; let mut local_key_derivation_params = (orig_key_derivation_params_0, orig_key_derivation_params_1).into();
201                                 SpendableOutputDescriptor::DynamicOutputP2WSH {
202                                         outpoint: crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(outpoint)), is_owned: true },
203                                         per_commitment_point: crate::c_types::PublicKey::from_rust(&per_commitment_point),
204                                         to_self_delay: to_self_delay,
205                                         output: crate::c_types::TxOut::from_rust(output),
206                                         key_derivation_params: local_key_derivation_params,
207                                         revocation_pubkey: crate::c_types::PublicKey::from_rust(&revocation_pubkey),
208                                 }
209                         },
210                         nativeSpendableOutputDescriptor::StaticOutputCounterpartyPayment {mut outpoint, mut output, mut key_derivation_params, } => {
211                                 let (mut orig_key_derivation_params_0, mut orig_key_derivation_params_1) = key_derivation_params; let mut local_key_derivation_params = (orig_key_derivation_params_0, orig_key_derivation_params_1).into();
212                                 SpendableOutputDescriptor::StaticOutputCounterpartyPayment {
213                                         outpoint: crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(outpoint)), is_owned: true },
214                                         output: crate::c_types::TxOut::from_rust(output),
215                                         key_derivation_params: local_key_derivation_params,
216                                 }
217                         },
218                 }
219         }
220 }
221 #[no_mangle]
222 pub extern "C" fn SpendableOutputDescriptor_free(this_ptr: SpendableOutputDescriptor) { }
223 #[no_mangle]
224 pub extern "C" fn SpendableOutputDescriptor_clone(orig: &SpendableOutputDescriptor) -> SpendableOutputDescriptor {
225         orig.clone()
226 }
227 #[no_mangle]
228 pub extern "C" fn SpendableOutputDescriptor_write(obj: &SpendableOutputDescriptor) -> crate::c_types::derived::CVec_u8Z {
229         crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
230 }
231 #[no_mangle]
232 pub extern "C" fn SpendableOutputDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_SpendableOutputDescriptorDecodeErrorZ {
233         let res = crate::c_types::deserialize_obj(ser);
234         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::chain::keysinterface::SpendableOutputDescriptor::native_into(o) }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) };
235         local_res
236 }
237 /// Set of lightning keys needed to operate a channel as described in BOLT 3.
238 ///
239 /// Signing services could be implemented on a hardware wallet. In this case,
240 /// the current ChannelKeys would be a front-end on top of a communication
241 /// channel connected to your secure device and lightning key material wouldn't
242 /// reside on a hot server. Nevertheless, a this deployment would still need
243 /// to trust the ChannelManager to avoid loss of funds as this latest component
244 /// could ask to sign commitment transaction with HTLCs paying to attacker pubkeys.
245 ///
246 /// A more secure iteration would be to use hashlock (or payment points) to pair
247 /// invoice/incoming HTLCs with outgoing HTLCs to implement a no-trust-ChannelManager
248 /// at the price of more state and computation on the hardware wallet side. In the future,
249 /// we are looking forward to design such interface.
250 ///
251 /// In any case, ChannelMonitor or fallback watchtowers are always going to be trusted
252 /// to act, as liveness and breach reply correctness are always going to be hard requirements
253 /// of LN security model, orthogonal of key management issues.
254 ///
255 /// If you're implementing a custom signer, you almost certainly want to implement
256 /// Readable/Writable to serialize out a unique reference to this set of keys so
257 /// that you can serialize the full ChannelManager object.
258 ///
259 #[repr(C)]
260 pub struct ChannelKeys {
261         pub this_arg: *mut c_void,
262         /// Gets the per-commitment point for a specific commitment number
263         ///
264         /// Note that the commitment number starts at (1 << 48) - 1 and counts backwards.
265         #[must_use]
266         pub get_per_commitment_point: extern "C" fn (this_arg: *const c_void, idx: u64) -> crate::c_types::PublicKey,
267         /// Gets the commitment secret for a specific commitment number as part of the revocation process
268         ///
269         /// An external signer implementation should error here if the commitment was already signed
270         /// and should refuse to sign it in the future.
271         ///
272         /// May be called more than once for the same index.
273         ///
274         /// Note that the commitment number starts at (1 << 48) - 1 and counts backwards.
275         /// TODO: return a Result so we can signal a validation error
276         #[must_use]
277         pub release_commitment_secret: extern "C" fn (this_arg: *const c_void, idx: u64) -> crate::c_types::ThirtyTwoBytes,
278         /// Gets the holder's channel public keys and basepoints
279         pub pubkeys: crate::ln::chan_utils::ChannelPublicKeys,
280         /// Fill in the pubkeys field as a reference to it will be given to Rust after this returns
281         /// Note that this takes a pointer to this object, not the this_ptr like other methods do
282         /// This function pointer may be NULL if pubkeys is filled in when this object is created and never needs updating.
283         pub set_pubkeys: Option<extern "C" fn(&ChannelKeys)>,
284         /// Gets arbitrary identifiers describing the set of keys which are provided back to you in
285         /// some SpendableOutputDescriptor types. These should be sufficient to identify this
286         /// ChannelKeys object uniquely and lookup or re-derive its keys.
287         #[must_use]
288         pub key_derivation_params: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::C2Tuple_u64u64Z,
289         /// Create a signature for a counterparty's commitment transaction and associated HTLC transactions.
290         ///
291         /// Note that if signing fails or is rejected, the channel will be force-closed.
292         #[must_use]
293         pub sign_counterparty_commitment: extern "C" fn (this_arg: *const c_void, commitment_tx: &crate::ln::chan_utils::CommitmentTransaction) -> crate::c_types::derived::CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ,
294         /// Create a signature for a holder's commitment transaction. This will only ever be called with
295         /// the same commitment_tx (or a copy thereof), though there are currently no guarantees
296         /// that it will not be called multiple times.
297         /// An external signer implementation should check that the commitment has not been revoked.
298         #[must_use]
299         pub sign_holder_commitment: extern "C" fn (this_arg: *const c_void, commitment_tx: &crate::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_SignatureNoneZ,
300         /// Create a signature for each HTLC transaction spending a holder's commitment transaction.
301         ///
302         /// Unlike sign_holder_commitment, this may be called multiple times with *different*
303         /// commitment_tx values. While this will never be called with a revoked
304         /// commitment_tx, it is possible that it is called with the second-latest
305         /// commitment_tx (only if we haven't yet revoked it) if some watchtower/secondary
306         /// ChannelMonitor decided to broadcast before it had been updated to the latest.
307         ///
308         /// Either an Err should be returned, or a Vec with one entry for each HTLC which exists in
309         /// commitment_tx.
310         #[must_use]
311         pub sign_holder_commitment_htlc_transactions: extern "C" fn (this_arg: *const c_void, commitment_tx: &crate::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_CVec_SignatureZNoneZ,
312         /// Create a signature for the given input in a transaction spending an HTLC or commitment
313         /// transaction output when our counterparty broadcasts an old state.
314         ///
315         /// A justice transaction may claim multiples outputs at the same time if timelocks are
316         /// similar, but only a signature for the input at index `input` should be signed for here.
317         /// It may be called multiples time for same output(s) if a fee-bump is needed with regards
318         /// to an upcoming timelock expiration.
319         ///
320         /// Amount is value of the output spent by this input, committed to in the BIP 143 signature.
321         ///
322         /// per_commitment_key is revocation secret which was provided by our counterparty when they
323         /// revoked the state which they eventually broadcast. It's not a _holder_ secret key and does
324         /// not allow the spending of any funds by itself (you need our holder revocation_secret to do
325         /// so).
326         ///
327         /// htlc holds HTLC elements (hash, timelock) if the output being spent is a HTLC output, thus
328         /// changing the format of the witness script (which is committed to in the BIP 143
329         /// signatures).
330         #[must_use]
331         pub sign_justice_transaction: extern "C" fn (this_arg: *const c_void, justice_tx: crate::c_types::Transaction, input: usize, amount: u64, per_commitment_key: *const [u8; 32], htlc: &crate::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CResult_SignatureNoneZ,
332         /// Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment
333         /// transaction, either offered or received.
334         ///
335         /// Such a transaction may claim multiples offered outputs at same time if we know the
336         /// preimage for each when we create it, but only the input at index `input` should be
337         /// signed for here. It may be called multiple times for same output(s) if a fee-bump is
338         /// needed with regards to an upcoming timelock expiration.
339         ///
340         /// Witness_script is either a offered or received script as defined in BOLT3 for HTLC
341         /// outputs.
342         ///
343         /// Amount is value of the output spent by this input, committed to in the BIP 143 signature.
344         ///
345         /// Per_commitment_point is the dynamic point corresponding to the channel state
346         /// detected onchain. It has been generated by our counterparty and is used to derive
347         /// channel state keys, which are then included in the witness script and committed to in the
348         /// BIP 143 signature.
349         #[must_use]
350         pub sign_counterparty_htlc_transaction: extern "C" fn (this_arg: *const c_void, htlc_tx: crate::c_types::Transaction, input: usize, amount: u64, per_commitment_point: crate::c_types::PublicKey, htlc: &crate::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CResult_SignatureNoneZ,
351         /// Create a signature for a (proposed) closing transaction.
352         ///
353         /// Note that, due to rounding, there may be one \"missing\" satoshi, and either party may have
354         /// chosen to forgo their output as dust.
355         #[must_use]
356         pub sign_closing_transaction: extern "C" fn (this_arg: *const c_void, closing_tx: crate::c_types::Transaction) -> crate::c_types::derived::CResult_SignatureNoneZ,
357         /// Signs a channel announcement message with our funding key, proving it comes from one
358         /// of the channel participants.
359         ///
360         /// Note that if this fails or is rejected, the channel will not be publicly announced and
361         /// our counterparty may (though likely will not) close the channel on us for violating the
362         /// protocol.
363         #[must_use]
364         pub sign_channel_announcement: extern "C" fn (this_arg: *const c_void, msg: &crate::ln::msgs::UnsignedChannelAnnouncement) -> crate::c_types::derived::CResult_SignatureNoneZ,
365         /// Set the counterparty static channel data, including basepoints,
366         /// counterparty_selected/holder_selected_contest_delay and funding outpoint.
367         /// This is done as soon as the funding outpoint is known.  Since these are static channel data,
368         /// they MUST NOT be allowed to change to different values once set.
369         ///
370         /// channel_parameters.is_populated() MUST be true.
371         ///
372         /// We bind holder_selected_contest_delay late here for API convenience.
373         ///
374         /// Will be called before any signatures are applied.
375         pub ready_channel: extern "C" fn (this_arg: *mut c_void, channel_parameters: &crate::ln::chan_utils::ChannelTransactionParameters),
376         pub clone: Option<extern "C" fn (this_arg: *const c_void) -> *mut c_void>,
377         pub write: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z,
378         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
379 }
380 unsafe impl Send for ChannelKeys {}
381 #[no_mangle]
382 pub extern "C" fn ChannelKeys_clone(orig: &ChannelKeys) -> ChannelKeys {
383         ChannelKeys {
384                 this_arg: if let Some(f) = orig.clone { (f)(orig.this_arg) } else { orig.this_arg },
385                 get_per_commitment_point: orig.get_per_commitment_point.clone(),
386                 release_commitment_secret: orig.release_commitment_secret.clone(),
387                 pubkeys: orig.pubkeys.clone(),
388                 set_pubkeys: orig.set_pubkeys.clone(),
389                 key_derivation_params: orig.key_derivation_params.clone(),
390                 sign_counterparty_commitment: orig.sign_counterparty_commitment.clone(),
391                 sign_holder_commitment: orig.sign_holder_commitment.clone(),
392                 sign_holder_commitment_htlc_transactions: orig.sign_holder_commitment_htlc_transactions.clone(),
393                 sign_justice_transaction: orig.sign_justice_transaction.clone(),
394                 sign_counterparty_htlc_transaction: orig.sign_counterparty_htlc_transaction.clone(),
395                 sign_closing_transaction: orig.sign_closing_transaction.clone(),
396                 sign_channel_announcement: orig.sign_channel_announcement.clone(),
397                 ready_channel: orig.ready_channel.clone(),
398                 clone: orig.clone.clone(),
399                 write: orig.write.clone(),
400                 free: orig.free.clone(),
401         }
402 }
403 impl Clone for ChannelKeys {
404         fn clone(&self) -> Self {
405                 ChannelKeys_clone(self)
406         }
407 }
408 impl lightning::util::ser::Writeable for ChannelKeys {
409         fn write<W: lightning::util::ser::Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
410                 let vec = (self.write)(self.this_arg);
411                 w.write_all(vec.as_slice())
412         }
413 }
414
415 use lightning::chain::keysinterface::ChannelKeys as rustChannelKeys;
416 impl rustChannelKeys for ChannelKeys {
417         fn get_per_commitment_point<T:bitcoin::secp256k1::Signing + bitcoin::secp256k1::Verification>(&self, idx: u64, _secp_ctx: &bitcoin::secp256k1::Secp256k1<T>) -> bitcoin::secp256k1::key::PublicKey {
418                 let mut ret = (self.get_per_commitment_point)(self.this_arg, idx);
419                 ret.into_rust()
420         }
421         fn release_commitment_secret(&self, idx: u64) -> [u8; 32] {
422                 let mut ret = (self.release_commitment_secret)(self.this_arg, idx);
423                 ret.data
424         }
425         fn pubkeys(&self) -> &lightning::ln::chan_utils::ChannelPublicKeys {
426                 if let Some(f) = self.set_pubkeys {
427                         (f)(self);
428                 }
429                 unsafe { &*self.pubkeys.inner }
430         }
431         fn key_derivation_params(&self) -> (u64, u64) {
432                 let mut ret = (self.key_derivation_params)(self.this_arg);
433                 let (mut orig_ret_0, mut orig_ret_1) = ret.to_rust(); let mut local_ret = (orig_ret_0, orig_ret_1);
434                 local_ret
435         }
436         fn sign_counterparty_commitment<T:bitcoin::secp256k1::Signing + bitcoin::secp256k1::Verification>(&self, commitment_tx: &lightning::ln::chan_utils::CommitmentTransaction, _secp_ctx: &bitcoin::secp256k1::Secp256k1<T>) -> Result<(bitcoin::secp256k1::Signature, Vec<bitcoin::secp256k1::Signature>), ()> {
437                 let mut ret = (self.sign_counterparty_commitment)(self.this_arg, &crate::ln::chan_utils::CommitmentTransaction { inner: unsafe { (commitment_tx as *const _) as *mut _ }, is_owned: false });
438                 let mut local_ret = match ret.result_ok { true => Ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).to_rust(); let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.into_rust().drain(..) { local_orig_ret_0_1.push( { item.into_rust() }); }; let mut local_ret_0 = (orig_ret_0_0.into_rust(), local_orig_ret_0_1); local_ret_0 }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
439                 local_ret
440         }
441         fn sign_holder_commitment<T:bitcoin::secp256k1::Signing + bitcoin::secp256k1::Verification>(&self, commitment_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, _secp_ctx: &bitcoin::secp256k1::Secp256k1<T>) -> Result<bitcoin::secp256k1::Signature, ()> {
442                 let mut ret = (self.sign_holder_commitment)(self.this_arg, &crate::ln::chan_utils::HolderCommitmentTransaction { inner: unsafe { (commitment_tx as *const _) as *mut _ }, is_owned: false });
443                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
444                 local_ret
445         }
446         fn sign_holder_commitment_htlc_transactions<T:bitcoin::secp256k1::Signing + bitcoin::secp256k1::Verification>(&self, commitment_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, _secp_ctx: &bitcoin::secp256k1::Secp256k1<T>) -> Result<Vec<bitcoin::secp256k1::Signature>, ()> {
447                 let mut ret = (self.sign_holder_commitment_htlc_transactions)(self.this_arg, &crate::ln::chan_utils::HolderCommitmentTransaction { inner: unsafe { (commitment_tx as *const _) as *mut _ }, is_owned: false });
448                 let mut local_ret = match ret.result_ok { true => Ok( { let mut local_ret_0 = Vec::new(); for mut item in (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust().drain(..) { local_ret_0.push( { item.into_rust() }); }; local_ret_0 }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
449                 local_ret
450         }
451         fn sign_justice_transaction<T:bitcoin::secp256k1::Signing + bitcoin::secp256k1::Verification>(&self, justice_tx: &bitcoin::blockdata::transaction::Transaction, input: usize, amount: u64, per_commitment_key: &bitcoin::secp256k1::key::SecretKey, htlc: &Option<lightning::ln::chan_utils::HTLCOutputInCommitment>, _secp_ctx: &bitcoin::secp256k1::Secp256k1<T>) -> Result<bitcoin::secp256k1::Signature, ()> {
452                 let mut local_justice_tx = ::bitcoin::consensus::encode::serialize(justice_tx);
453                 let mut local_htlc = &crate::ln::chan_utils::HTLCOutputInCommitment { inner: unsafe { (if htlc.is_none() { std::ptr::null() } else {  { (htlc.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
454                 let mut ret = (self.sign_justice_transaction)(self.this_arg, crate::c_types::Transaction::from_vec(local_justice_tx), input, amount, per_commitment_key.as_ref(), local_htlc);
455                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
456                 local_ret
457         }
458         fn sign_counterparty_htlc_transaction<T:bitcoin::secp256k1::Signing + bitcoin::secp256k1::Verification>(&self, htlc_tx: &bitcoin::blockdata::transaction::Transaction, input: usize, amount: u64, per_commitment_point: &bitcoin::secp256k1::key::PublicKey, htlc: &lightning::ln::chan_utils::HTLCOutputInCommitment, _secp_ctx: &bitcoin::secp256k1::Secp256k1<T>) -> Result<bitcoin::secp256k1::Signature, ()> {
459                 let mut local_htlc_tx = ::bitcoin::consensus::encode::serialize(htlc_tx);
460                 let mut ret = (self.sign_counterparty_htlc_transaction)(self.this_arg, crate::c_types::Transaction::from_vec(local_htlc_tx), input, amount, crate::c_types::PublicKey::from_rust(&per_commitment_point), &crate::ln::chan_utils::HTLCOutputInCommitment { inner: unsafe { (htlc as *const _) as *mut _ }, is_owned: false });
461                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
462                 local_ret
463         }
464         fn sign_closing_transaction<T:bitcoin::secp256k1::Signing>(&self, closing_tx: &bitcoin::blockdata::transaction::Transaction, _secp_ctx: &bitcoin::secp256k1::Secp256k1<T>) -> Result<bitcoin::secp256k1::Signature, ()> {
465                 let mut local_closing_tx = ::bitcoin::consensus::encode::serialize(closing_tx);
466                 let mut ret = (self.sign_closing_transaction)(self.this_arg, crate::c_types::Transaction::from_vec(local_closing_tx));
467                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
468                 local_ret
469         }
470         fn sign_channel_announcement<T:bitcoin::secp256k1::Signing>(&self, msg: &lightning::ln::msgs::UnsignedChannelAnnouncement, _secp_ctx: &bitcoin::secp256k1::Secp256k1<T>) -> Result<bitcoin::secp256k1::Signature, ()> {
471                 let mut ret = (self.sign_channel_announcement)(self.this_arg, &crate::ln::msgs::UnsignedChannelAnnouncement { inner: unsafe { (msg as *const _) as *mut _ }, is_owned: false });
472                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
473                 local_ret
474         }
475         fn ready_channel(&mut self, channel_parameters: &lightning::ln::chan_utils::ChannelTransactionParameters) {
476                 (self.ready_channel)(self.this_arg, &crate::ln::chan_utils::ChannelTransactionParameters { inner: unsafe { (channel_parameters as *const _) as *mut _ }, is_owned: false })
477         }
478 }
479
480 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
481 // directly as a Deref trait in higher-level structs:
482 impl std::ops::Deref for ChannelKeys {
483         type Target = Self;
484         fn deref(&self) -> &Self {
485                 self
486         }
487 }
488 /// Calls the free function if one is set
489 #[no_mangle]
490 pub extern "C" fn ChannelKeys_free(this_ptr: ChannelKeys) { }
491 impl Drop for ChannelKeys {
492         fn drop(&mut self) {
493                 if let Some(f) = self.free {
494                         f(self.this_arg);
495                 }
496         }
497 }
498 /// A trait to describe an object which can get user secrets and key material.
499 #[repr(C)]
500 pub struct KeysInterface {
501         pub this_arg: *mut c_void,
502         /// Get node secret key (aka node_id or network_key)
503         #[must_use]
504         pub get_node_secret: extern "C" fn (this_arg: *const c_void) -> crate::c_types::SecretKey,
505         /// Get destination redeemScript to encumber static protocol exit points.
506         #[must_use]
507         pub get_destination_script: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z,
508         /// Get shutdown_pubkey to use as PublicKey at channel closure
509         #[must_use]
510         pub get_shutdown_pubkey: extern "C" fn (this_arg: *const c_void) -> crate::c_types::PublicKey,
511         /// Get a new set of ChannelKeys for per-channel secrets. These MUST be unique even if you
512         /// restarted with some stale data!
513         #[must_use]
514         pub get_channel_keys: extern "C" fn (this_arg: *const c_void, inbound: bool, channel_value_satoshis: u64) -> crate::chain::keysinterface::ChannelKeys,
515         /// Gets a unique, cryptographically-secure, random 32 byte value. This is used for encrypting
516         /// onion packets and for temporary channel IDs. There is no requirement that these be
517         /// persisted anywhere, though they must be unique across restarts.
518         #[must_use]
519         pub get_secure_random_bytes: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes,
520         /// Reads a `ChanKeySigner` for this `KeysInterface` from the given input stream.
521         /// This is only called during deserialization of other objects which contain
522         /// `ChannelKeys`-implementing objects (ie `ChannelMonitor`s and `ChannelManager`s).
523         /// The bytes are exactly those which `<Self::ChanKeySigner as Writeable>::write()` writes, and
524         /// contain no versioning scheme. You may wish to include your own version prefix and ensure
525         /// you've read all of the provided bytes to ensure no corruption occurred.
526         #[must_use]
527         pub read_chan_signer: extern "C" fn (this_arg: *const c_void, reader: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChanKeySignerDecodeErrorZ,
528         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
529 }
530 unsafe impl Send for KeysInterface {}
531 unsafe impl Sync for KeysInterface {}
532
533 use lightning::chain::keysinterface::KeysInterface as rustKeysInterface;
534 impl rustKeysInterface for KeysInterface {
535         type ChanKeySigner = crate::chain::keysinterface::ChannelKeys;
536         fn get_node_secret(&self) -> bitcoin::secp256k1::key::SecretKey {
537                 let mut ret = (self.get_node_secret)(self.this_arg);
538                 ret.into_rust()
539         }
540         fn get_destination_script(&self) -> bitcoin::blockdata::script::Script {
541                 let mut ret = (self.get_destination_script)(self.this_arg);
542                 ::bitcoin::blockdata::script::Script::from(ret.into_rust())
543         }
544         fn get_shutdown_pubkey(&self) -> bitcoin::secp256k1::key::PublicKey {
545                 let mut ret = (self.get_shutdown_pubkey)(self.this_arg);
546                 ret.into_rust()
547         }
548         fn get_channel_keys(&self, inbound: bool, channel_value_satoshis: u64) -> crate::chain::keysinterface::ChannelKeys {
549                 let mut ret = (self.get_channel_keys)(self.this_arg, inbound, channel_value_satoshis);
550                 ret
551         }
552         fn get_secure_random_bytes(&self) -> [u8; 32] {
553                 let mut ret = (self.get_secure_random_bytes)(self.this_arg);
554                 ret.data
555         }
556         fn read_chan_signer(&self, reader: &[u8]) -> Result<crate::chain::keysinterface::ChannelKeys, lightning::ln::msgs::DecodeError> {
557                 let mut local_reader = crate::c_types::u8slice::from_slice(reader);
558                 let mut ret = (self.read_chan_signer)(self.this_arg, local_reader);
559                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }) }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })};
560                 local_ret
561         }
562 }
563
564 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
565 // directly as a Deref trait in higher-level structs:
566 impl std::ops::Deref for KeysInterface {
567         type Target = Self;
568         fn deref(&self) -> &Self {
569                 self
570         }
571 }
572 /// Calls the free function if one is set
573 #[no_mangle]
574 pub extern "C" fn KeysInterface_free(this_ptr: KeysInterface) { }
575 impl Drop for KeysInterface {
576         fn drop(&mut self) {
577                 if let Some(f) = self.free {
578                         f(self.this_arg);
579                 }
580         }
581 }
582
583 use lightning::chain::keysinterface::InMemoryChannelKeys as nativeInMemoryChannelKeysImport;
584 type nativeInMemoryChannelKeys = nativeInMemoryChannelKeysImport;
585
586 /// A simple implementation of ChannelKeys that just keeps the private keys in memory.
587 ///
588 /// This implementation performs no policy checks and is insufficient by itself as
589 /// a secure external signer.
590 #[must_use]
591 #[repr(C)]
592 pub struct InMemoryChannelKeys {
593         /// Nearly everywhere, inner must be non-null, however in places where
594         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
595         pub inner: *mut nativeInMemoryChannelKeys,
596         pub is_owned: bool,
597 }
598
599 impl Drop for InMemoryChannelKeys {
600         fn drop(&mut self) {
601                 if self.is_owned && !self.inner.is_null() {
602                         let _ = unsafe { Box::from_raw(self.inner) };
603                 }
604         }
605 }
606 #[no_mangle]
607 pub extern "C" fn InMemoryChannelKeys_free(this_ptr: InMemoryChannelKeys) { }
608 #[allow(unused)]
609 /// Used only if an object of this type is returned as a trait impl by a method
610 extern "C" fn InMemoryChannelKeys_free_void(this_ptr: *mut c_void) {
611         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInMemoryChannelKeys); }
612 }
613 #[allow(unused)]
614 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
615 impl InMemoryChannelKeys {
616         pub(crate) fn take_inner(mut self) -> *mut nativeInMemoryChannelKeys {
617                 assert!(self.is_owned);
618                 let ret = self.inner;
619                 self.inner = std::ptr::null_mut();
620                 ret
621         }
622 }
623 impl Clone for InMemoryChannelKeys {
624         fn clone(&self) -> Self {
625                 Self {
626                         inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
627                         is_owned: true,
628                 }
629         }
630 }
631 #[allow(unused)]
632 /// Used only if an object of this type is returned as a trait impl by a method
633 pub(crate) extern "C" fn InMemoryChannelKeys_clone_void(this_ptr: *const c_void) -> *mut c_void {
634         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInMemoryChannelKeys)).clone() })) as *mut c_void
635 }
636 #[no_mangle]
637 pub extern "C" fn InMemoryChannelKeys_clone(orig: &InMemoryChannelKeys) -> InMemoryChannelKeys {
638         InMemoryChannelKeys { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true }
639 }
640 /// Private key of anchor tx
641 #[no_mangle]
642 pub extern "C" fn InMemoryChannelKeys_get_funding_key(this_ptr: &InMemoryChannelKeys) -> *const [u8; 32] {
643         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.funding_key;
644         (*inner_val).as_ref()
645 }
646 /// Private key of anchor tx
647 #[no_mangle]
648 pub extern "C" fn InMemoryChannelKeys_set_funding_key(this_ptr: &mut InMemoryChannelKeys, mut val: crate::c_types::SecretKey) {
649         unsafe { &mut *this_ptr.inner }.funding_key = val.into_rust();
650 }
651 /// Holder secret key for blinded revocation pubkey
652 #[no_mangle]
653 pub extern "C" fn InMemoryChannelKeys_get_revocation_base_key(this_ptr: &InMemoryChannelKeys) -> *const [u8; 32] {
654         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.revocation_base_key;
655         (*inner_val).as_ref()
656 }
657 /// Holder secret key for blinded revocation pubkey
658 #[no_mangle]
659 pub extern "C" fn InMemoryChannelKeys_set_revocation_base_key(this_ptr: &mut InMemoryChannelKeys, mut val: crate::c_types::SecretKey) {
660         unsafe { &mut *this_ptr.inner }.revocation_base_key = val.into_rust();
661 }
662 /// Holder secret key used for our balance in counterparty-broadcasted commitment transactions
663 #[no_mangle]
664 pub extern "C" fn InMemoryChannelKeys_get_payment_key(this_ptr: &InMemoryChannelKeys) -> *const [u8; 32] {
665         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.payment_key;
666         (*inner_val).as_ref()
667 }
668 /// Holder secret key used for our balance in counterparty-broadcasted commitment transactions
669 #[no_mangle]
670 pub extern "C" fn InMemoryChannelKeys_set_payment_key(this_ptr: &mut InMemoryChannelKeys, mut val: crate::c_types::SecretKey) {
671         unsafe { &mut *this_ptr.inner }.payment_key = val.into_rust();
672 }
673 /// Holder secret key used in HTLC tx
674 #[no_mangle]
675 pub extern "C" fn InMemoryChannelKeys_get_delayed_payment_base_key(this_ptr: &InMemoryChannelKeys) -> *const [u8; 32] {
676         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.delayed_payment_base_key;
677         (*inner_val).as_ref()
678 }
679 /// Holder secret key used in HTLC tx
680 #[no_mangle]
681 pub extern "C" fn InMemoryChannelKeys_set_delayed_payment_base_key(this_ptr: &mut InMemoryChannelKeys, mut val: crate::c_types::SecretKey) {
682         unsafe { &mut *this_ptr.inner }.delayed_payment_base_key = val.into_rust();
683 }
684 /// Holder htlc secret key used in commitment tx htlc outputs
685 #[no_mangle]
686 pub extern "C" fn InMemoryChannelKeys_get_htlc_base_key(this_ptr: &InMemoryChannelKeys) -> *const [u8; 32] {
687         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_base_key;
688         (*inner_val).as_ref()
689 }
690 /// Holder htlc secret key used in commitment tx htlc outputs
691 #[no_mangle]
692 pub extern "C" fn InMemoryChannelKeys_set_htlc_base_key(this_ptr: &mut InMemoryChannelKeys, mut val: crate::c_types::SecretKey) {
693         unsafe { &mut *this_ptr.inner }.htlc_base_key = val.into_rust();
694 }
695 /// Commitment seed
696 #[no_mangle]
697 pub extern "C" fn InMemoryChannelKeys_get_commitment_seed(this_ptr: &InMemoryChannelKeys) -> *const [u8; 32] {
698         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.commitment_seed;
699         &(*inner_val)
700 }
701 /// Commitment seed
702 #[no_mangle]
703 pub extern "C" fn InMemoryChannelKeys_set_commitment_seed(this_ptr: &mut InMemoryChannelKeys, mut val: crate::c_types::ThirtyTwoBytes) {
704         unsafe { &mut *this_ptr.inner }.commitment_seed = val.data;
705 }
706 /// Create a new InMemoryChannelKeys
707 #[must_use]
708 #[no_mangle]
709 pub extern "C" fn InMemoryChannelKeys_new(mut funding_key: crate::c_types::SecretKey, mut revocation_base_key: crate::c_types::SecretKey, mut payment_key: crate::c_types::SecretKey, mut delayed_payment_base_key: crate::c_types::SecretKey, mut htlc_base_key: crate::c_types::SecretKey, mut commitment_seed: crate::c_types::ThirtyTwoBytes, mut channel_value_satoshis: u64, mut key_derivation_params: crate::c_types::derived::C2Tuple_u64u64Z) -> crate::chain::keysinterface::InMemoryChannelKeys {
710         let (mut orig_key_derivation_params_0, mut orig_key_derivation_params_1) = key_derivation_params.to_rust(); let mut local_key_derivation_params = (orig_key_derivation_params_0, orig_key_derivation_params_1);
711         let mut ret = lightning::chain::keysinterface::InMemoryChannelKeys::new(&bitcoin::secp256k1::Secp256k1::new(), funding_key.into_rust(), revocation_base_key.into_rust(), payment_key.into_rust(), delayed_payment_base_key.into_rust(), htlc_base_key.into_rust(), commitment_seed.data, channel_value_satoshis, local_key_derivation_params);
712         crate::chain::keysinterface::InMemoryChannelKeys { inner: Box::into_raw(Box::new(ret)), is_owned: true }
713 }
714
715 /// Counterparty pubkeys.
716 /// Will panic if ready_channel wasn't called.
717 #[must_use]
718 #[no_mangle]
719 pub extern "C" fn InMemoryChannelKeys_counterparty_pubkeys(this_arg: &InMemoryChannelKeys) -> crate::ln::chan_utils::ChannelPublicKeys {
720         let mut ret = unsafe { &*this_arg.inner }.counterparty_pubkeys();
721         crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
722 }
723
724 /// The contest_delay value specified by our counterparty and applied on holder-broadcastable
725 /// transactions, ie the amount of time that we have to wait to recover our funds if we
726 /// broadcast a transaction.
727 /// Will panic if ready_channel wasn't called.
728 #[must_use]
729 #[no_mangle]
730 pub extern "C" fn InMemoryChannelKeys_counterparty_selected_contest_delay(this_arg: &InMemoryChannelKeys) -> u16 {
731         let mut ret = unsafe { &*this_arg.inner }.counterparty_selected_contest_delay();
732         ret
733 }
734
735 /// The contest_delay value specified by us and applied on transactions broadcastable
736 /// by our counterparty, ie the amount of time that they have to wait to recover their funds
737 /// if they broadcast a transaction.
738 /// Will panic if ready_channel wasn't called.
739 #[must_use]
740 #[no_mangle]
741 pub extern "C" fn InMemoryChannelKeys_holder_selected_contest_delay(this_arg: &InMemoryChannelKeys) -> u16 {
742         let mut ret = unsafe { &*this_arg.inner }.holder_selected_contest_delay();
743         ret
744 }
745
746 /// Whether the holder is the initiator
747 /// Will panic if ready_channel wasn't called.
748 #[must_use]
749 #[no_mangle]
750 pub extern "C" fn InMemoryChannelKeys_is_outbound(this_arg: &InMemoryChannelKeys) -> bool {
751         let mut ret = unsafe { &*this_arg.inner }.is_outbound();
752         ret
753 }
754
755 /// Funding outpoint
756 /// Will panic if ready_channel wasn't called.
757 #[must_use]
758 #[no_mangle]
759 pub extern "C" fn InMemoryChannelKeys_funding_outpoint(this_arg: &InMemoryChannelKeys) -> crate::chain::transaction::OutPoint {
760         let mut ret = unsafe { &*this_arg.inner }.funding_outpoint();
761         crate::chain::transaction::OutPoint { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
762 }
763
764 /// Obtain a ChannelTransactionParameters for this channel, to be used when verifying or
765 /// building transactions.
766 ///
767 /// Will panic if ready_channel wasn't called.
768 #[must_use]
769 #[no_mangle]
770 pub extern "C" fn InMemoryChannelKeys_get_channel_parameters(this_arg: &InMemoryChannelKeys) -> crate::ln::chan_utils::ChannelTransactionParameters {
771         let mut ret = unsafe { &*this_arg.inner }.get_channel_parameters();
772         crate::ln::chan_utils::ChannelTransactionParameters { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
773 }
774
775 impl From<nativeInMemoryChannelKeys> for crate::chain::keysinterface::ChannelKeys {
776         fn from(obj: nativeInMemoryChannelKeys) -> Self {
777                 let mut rust_obj = InMemoryChannelKeys { inner: Box::into_raw(Box::new(obj)), is_owned: true };
778                 let mut ret = InMemoryChannelKeys_as_ChannelKeys(&rust_obj);
779                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
780                 rust_obj.inner = std::ptr::null_mut();
781                 ret.free = Some(InMemoryChannelKeys_free_void);
782                 ret
783         }
784 }
785 #[no_mangle]
786 pub extern "C" fn InMemoryChannelKeys_as_ChannelKeys(this_arg: &InMemoryChannelKeys) -> crate::chain::keysinterface::ChannelKeys {
787         crate::chain::keysinterface::ChannelKeys {
788                 this_arg: unsafe { (*this_arg).inner as *mut c_void },
789                 free: None,
790                 get_per_commitment_point: InMemoryChannelKeys_ChannelKeys_get_per_commitment_point,
791                 release_commitment_secret: InMemoryChannelKeys_ChannelKeys_release_commitment_secret,
792
793                 pubkeys: crate::ln::chan_utils::ChannelPublicKeys { inner: std::ptr::null_mut(), is_owned: true },
794                 set_pubkeys: Some(InMemoryChannelKeys_ChannelKeys_set_pubkeys),
795                 key_derivation_params: InMemoryChannelKeys_ChannelKeys_key_derivation_params,
796                 sign_counterparty_commitment: InMemoryChannelKeys_ChannelKeys_sign_counterparty_commitment,
797                 sign_holder_commitment: InMemoryChannelKeys_ChannelKeys_sign_holder_commitment,
798                 sign_holder_commitment_htlc_transactions: InMemoryChannelKeys_ChannelKeys_sign_holder_commitment_htlc_transactions,
799                 sign_justice_transaction: InMemoryChannelKeys_ChannelKeys_sign_justice_transaction,
800                 sign_counterparty_htlc_transaction: InMemoryChannelKeys_ChannelKeys_sign_counterparty_htlc_transaction,
801                 sign_closing_transaction: InMemoryChannelKeys_ChannelKeys_sign_closing_transaction,
802                 sign_channel_announcement: InMemoryChannelKeys_ChannelKeys_sign_channel_announcement,
803                 ready_channel: InMemoryChannelKeys_ChannelKeys_ready_channel,
804                 clone: Some(InMemoryChannelKeys_clone_void),
805                 write: InMemoryChannelKeys_write_void,
806         }
807 }
808 use lightning::chain::keysinterface::ChannelKeys as ChannelKeysTraitImport;
809 #[must_use]
810 extern "C" fn InMemoryChannelKeys_ChannelKeys_get_per_commitment_point(this_arg: *const c_void, mut idx: u64) -> crate::c_types::PublicKey {
811         let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.get_per_commitment_point(idx, &bitcoin::secp256k1::Secp256k1::new());
812         crate::c_types::PublicKey::from_rust(&ret)
813 }
814 #[must_use]
815 extern "C" fn InMemoryChannelKeys_ChannelKeys_release_commitment_secret(this_arg: *const c_void, mut idx: u64) -> crate::c_types::ThirtyTwoBytes {
816         let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.release_commitment_secret(idx);
817         crate::c_types::ThirtyTwoBytes { data: ret }
818 }
819 #[must_use]
820 extern "C" fn InMemoryChannelKeys_ChannelKeys_pubkeys(this_arg: *const c_void) -> crate::ln::chan_utils::ChannelPublicKeys {
821         let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.pubkeys();
822         crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
823 }
824 extern "C" fn InMemoryChannelKeys_ChannelKeys_set_pubkeys(trait_self_arg: &ChannelKeys) {
825         // This is a bit race-y in the general case, but for our specific use-cases today, we're safe
826         // Specifically, we must ensure that the first time we're called it can never be in parallel
827         if trait_self_arg.pubkeys.inner.is_null() {
828                 unsafe { &mut *(trait_self_arg as *const ChannelKeys  as *mut ChannelKeys) }.pubkeys = InMemoryChannelKeys_ChannelKeys_pubkeys(trait_self_arg.this_arg);
829         }
830 }
831 #[must_use]
832 extern "C" fn InMemoryChannelKeys_ChannelKeys_key_derivation_params(this_arg: *const c_void) -> crate::c_types::derived::C2Tuple_u64u64Z {
833         let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.key_derivation_params();
834         let (mut orig_ret_0, mut orig_ret_1) = ret; let mut local_ret = (orig_ret_0, orig_ret_1).into();
835         local_ret
836 }
837 #[must_use]
838 extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_counterparty_commitment(this_arg: *const c_void, commitment_tx: &crate::ln::chan_utils::CommitmentTransaction) -> crate::c_types::derived::CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ {
839         let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_counterparty_commitment(unsafe { &*commitment_tx.inner }, &bitcoin::secp256k1::Secp256k1::new());
840         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = o; let mut local_orig_ret_0_1 = Vec::new(); for item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { crate::c_types::Signature::from_rust(&item) }); }; let mut local_ret_0 = (crate::c_types::Signature::from_rust(&orig_ret_0_0), local_orig_ret_0_1.into()).into(); local_ret_0 }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) };
841         local_ret
842 }
843 #[must_use]
844 extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_holder_commitment(this_arg: *const c_void, commitment_tx: &crate::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_SignatureNoneZ {
845         let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_holder_commitment(unsafe { &*commitment_tx.inner }, &bitcoin::secp256k1::Secp256k1::new());
846         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) };
847         local_ret
848 }
849 #[must_use]
850 extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_holder_commitment_htlc_transactions(this_arg: *const c_void, commitment_tx: &crate::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_CVec_SignatureZNoneZ {
851         let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_holder_commitment_htlc_transactions(unsafe { &*commitment_tx.inner }, &bitcoin::secp256k1::Secp256k1::new());
852         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = Vec::new(); for item in o.drain(..) { local_ret_0.push( { crate::c_types::Signature::from_rust(&item) }); }; local_ret_0.into() }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) };
853         local_ret
854 }
855 #[must_use]
856 extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_justice_transaction(this_arg: *const c_void, mut justice_tx: crate::c_types::Transaction, mut input: usize, mut amount: u64, per_commitment_key: *const [u8; 32], htlc: &crate::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CResult_SignatureNoneZ {
857         let mut local_htlc = if htlc.inner.is_null() { None } else { Some((* { unsafe { &*htlc.inner } }).clone()) };
858         let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_justice_transaction(&justice_tx.into_bitcoin(), input, amount, &::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *per_commitment_key}[..]).unwrap(), &local_htlc, &bitcoin::secp256k1::Secp256k1::new());
859         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) };
860         local_ret
861 }
862 #[must_use]
863 extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_counterparty_htlc_transaction(this_arg: *const c_void, mut htlc_tx: crate::c_types::Transaction, mut input: usize, mut amount: u64, mut per_commitment_point: crate::c_types::PublicKey, htlc: &crate::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CResult_SignatureNoneZ {
864         let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_counterparty_htlc_transaction(&htlc_tx.into_bitcoin(), input, amount, &per_commitment_point.into_rust(), unsafe { &*htlc.inner }, &bitcoin::secp256k1::Secp256k1::new());
865         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) };
866         local_ret
867 }
868 #[must_use]
869 extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_closing_transaction(this_arg: *const c_void, mut closing_tx: crate::c_types::Transaction) -> crate::c_types::derived::CResult_SignatureNoneZ {
870         let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_closing_transaction(&closing_tx.into_bitcoin(), &bitcoin::secp256k1::Secp256k1::new());
871         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) };
872         local_ret
873 }
874 #[must_use]
875 extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_channel_announcement(this_arg: *const c_void, msg: &crate::ln::msgs::UnsignedChannelAnnouncement) -> crate::c_types::derived::CResult_SignatureNoneZ {
876         let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.sign_channel_announcement(unsafe { &*msg.inner }, &bitcoin::secp256k1::Secp256k1::new());
877         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) };
878         local_ret
879 }
880 extern "C" fn InMemoryChannelKeys_ChannelKeys_ready_channel(this_arg: *mut c_void, channel_parameters: &crate::ln::chan_utils::ChannelTransactionParameters) {
881         unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.ready_channel(unsafe { &*channel_parameters.inner })
882 }
883
884 #[no_mangle]
885 pub extern "C" fn InMemoryChannelKeys_write(obj: &InMemoryChannelKeys) -> crate::c_types::derived::CVec_u8Z {
886         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
887 }
888 #[no_mangle]
889 pub(crate) extern "C" fn InMemoryChannelKeys_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
890         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInMemoryChannelKeys) })
891 }
892 #[no_mangle]
893 pub extern "C" fn InMemoryChannelKeys_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InMemoryChannelKeysDecodeErrorZ {
894         let res = crate::c_types::deserialize_obj(ser);
895         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::chain::keysinterface::InMemoryChannelKeys { inner: Box::into_raw(Box::new(o)), is_owned: true } }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) };
896         local_res
897 }
898
899 use lightning::chain::keysinterface::KeysManager as nativeKeysManagerImport;
900 type nativeKeysManager = nativeKeysManagerImport;
901
902 /// Simple KeysInterface implementor that takes a 32-byte seed for use as a BIP 32 extended key
903 /// and derives keys from that.
904 ///
905 /// Your node_id is seed/0'
906 /// ChannelMonitor closes may use seed/1'
907 /// Cooperative closes may use seed/2'
908 /// The two close keys may be needed to claim on-chain funds!
909 #[must_use]
910 #[repr(C)]
911 pub struct KeysManager {
912         /// Nearly everywhere, inner must be non-null, however in places where
913         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
914         pub inner: *mut nativeKeysManager,
915         pub is_owned: bool,
916 }
917
918 impl Drop for KeysManager {
919         fn drop(&mut self) {
920                 if self.is_owned && !self.inner.is_null() {
921                         let _ = unsafe { Box::from_raw(self.inner) };
922                 }
923         }
924 }
925 #[no_mangle]
926 pub extern "C" fn KeysManager_free(this_ptr: KeysManager) { }
927 #[allow(unused)]
928 /// Used only if an object of this type is returned as a trait impl by a method
929 extern "C" fn KeysManager_free_void(this_ptr: *mut c_void) {
930         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeKeysManager); }
931 }
932 #[allow(unused)]
933 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
934 impl KeysManager {
935         pub(crate) fn take_inner(mut self) -> *mut nativeKeysManager {
936                 assert!(self.is_owned);
937                 let ret = self.inner;
938                 self.inner = std::ptr::null_mut();
939                 ret
940         }
941 }
942 /// Constructs a KeysManager from a 32-byte seed. If the seed is in some way biased (eg your
943 /// CSRNG is busted) this may panic (but more importantly, you will possibly lose funds).
944 /// starting_time isn't strictly required to actually be a time, but it must absolutely,
945 /// without a doubt, be unique to this instance. ie if you start multiple times with the same
946 /// seed, starting_time must be unique to each run. Thus, the easiest way to achieve this is to
947 /// simply use the current time (with very high precision).
948 ///
949 /// The seed MUST be backed up safely prior to use so that the keys can be re-created, however,
950 /// obviously, starting_time should be unique every time you reload the library - it is only
951 /// used to generate new ephemeral key data (which will be stored by the individual channel if
952 /// necessary).
953 ///
954 /// Note that the seed is required to recover certain on-chain funds independent of
955 /// ChannelMonitor data, though a current copy of ChannelMonitor data is also required for any
956 /// channel, and some on-chain during-closing funds.
957 ///
958 /// Note that until the 0.1 release there is no guarantee of backward compatibility between
959 /// versions. Once the library is more fully supported, the docs will be updated to include a
960 /// detailed description of the guarantee.
961 #[must_use]
962 #[no_mangle]
963 pub extern "C" fn KeysManager_new(seed: *const [u8; 32], mut network: crate::bitcoin::network::Network, mut starting_time_secs: u64, mut starting_time_nanos: u32) -> KeysManager {
964         let mut ret = lightning::chain::keysinterface::KeysManager::new(unsafe { &*seed}, network.into_bitcoin(), starting_time_secs, starting_time_nanos);
965         KeysManager { inner: Box::into_raw(Box::new(ret)), is_owned: true }
966 }
967
968 /// Derive an old set of ChannelKeys for per-channel secrets based on a key derivation
969 /// parameters.
970 /// Key derivation parameters are accessible through a per-channel secrets
971 /// ChannelKeys::key_derivation_params and is provided inside DynamicOuputP2WSH in case of
972 /// onchain output detection for which a corresponding delayed_payment_key must be derived.
973 #[must_use]
974 #[no_mangle]
975 pub extern "C" fn KeysManager_derive_channel_keys(this_arg: &KeysManager, mut channel_value_satoshis: u64, mut params_1: u64, mut params_2: u64) -> crate::chain::keysinterface::InMemoryChannelKeys {
976         let mut ret = unsafe { &*this_arg.inner }.derive_channel_keys(channel_value_satoshis, params_1, params_2);
977         crate::chain::keysinterface::InMemoryChannelKeys { inner: Box::into_raw(Box::new(ret)), is_owned: true }
978 }
979
980 impl From<nativeKeysManager> for crate::chain::keysinterface::KeysInterface {
981         fn from(obj: nativeKeysManager) -> Self {
982                 let mut rust_obj = KeysManager { inner: Box::into_raw(Box::new(obj)), is_owned: true };
983                 let mut ret = KeysManager_as_KeysInterface(&rust_obj);
984                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
985                 rust_obj.inner = std::ptr::null_mut();
986                 ret.free = Some(KeysManager_free_void);
987                 ret
988         }
989 }
990 #[no_mangle]
991 pub extern "C" fn KeysManager_as_KeysInterface(this_arg: &KeysManager) -> crate::chain::keysinterface::KeysInterface {
992         crate::chain::keysinterface::KeysInterface {
993                 this_arg: unsafe { (*this_arg).inner as *mut c_void },
994                 free: None,
995                 get_node_secret: KeysManager_KeysInterface_get_node_secret,
996                 get_destination_script: KeysManager_KeysInterface_get_destination_script,
997                 get_shutdown_pubkey: KeysManager_KeysInterface_get_shutdown_pubkey,
998                 get_channel_keys: KeysManager_KeysInterface_get_channel_keys,
999                 get_secure_random_bytes: KeysManager_KeysInterface_get_secure_random_bytes,
1000                 read_chan_signer: KeysManager_KeysInterface_read_chan_signer,
1001         }
1002 }
1003 use lightning::chain::keysinterface::KeysInterface as KeysInterfaceTraitImport;
1004 #[must_use]
1005 extern "C" fn KeysManager_KeysInterface_get_node_secret(this_arg: *const c_void) -> crate::c_types::SecretKey {
1006         let mut ret = unsafe { &mut *(this_arg as *mut nativeKeysManager) }.get_node_secret();
1007         crate::c_types::SecretKey::from_rust(ret)
1008 }
1009 #[must_use]
1010 extern "C" fn KeysManager_KeysInterface_get_destination_script(this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1011         let mut ret = unsafe { &mut *(this_arg as *mut nativeKeysManager) }.get_destination_script();
1012         ret.into_bytes().into()
1013 }
1014 #[must_use]
1015 extern "C" fn KeysManager_KeysInterface_get_shutdown_pubkey(this_arg: *const c_void) -> crate::c_types::PublicKey {
1016         let mut ret = unsafe { &mut *(this_arg as *mut nativeKeysManager) }.get_shutdown_pubkey();
1017         crate::c_types::PublicKey::from_rust(&ret)
1018 }
1019 #[must_use]
1020 extern "C" fn KeysManager_KeysInterface_get_channel_keys(this_arg: *const c_void, mut _inbound: bool, mut channel_value_satoshis: u64) -> crate::chain::keysinterface::ChannelKeys {
1021         let mut ret = unsafe { &mut *(this_arg as *mut nativeKeysManager) }.get_channel_keys(_inbound, channel_value_satoshis);
1022         ret.into()
1023 }
1024 #[must_use]
1025 extern "C" fn KeysManager_KeysInterface_get_secure_random_bytes(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
1026         let mut ret = unsafe { &mut *(this_arg as *mut nativeKeysManager) }.get_secure_random_bytes();
1027         crate::c_types::ThirtyTwoBytes { data: ret }
1028 }
1029 #[must_use]
1030 extern "C" fn KeysManager_KeysInterface_read_chan_signer(this_arg: *const c_void, mut reader: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChanKeySignerDecodeErrorZ {
1031         let mut ret = unsafe { &mut *(this_arg as *mut nativeKeysManager) }.read_chan_signer(reader.to_slice());
1032         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o.into() }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) };
1033         local_ret
1034 }
1035