-/// A fixed penalty in msats to apply to each channel.
-///
-/// Default value: 500 msat
-#[no_mangle]
-pub extern "C" fn ScoringParameters_get_base_penalty_msat(this_ptr: &ScoringParameters) -> u64 {
- let mut inner_val = &mut this_ptr.get_native_mut_ref().base_penalty_msat;
- *inner_val
-}
-/// A fixed penalty in msats to apply to each channel.
-///
-/// Default value: 500 msat
-#[no_mangle]
-pub extern "C" fn ScoringParameters_set_base_penalty_msat(this_ptr: &mut ScoringParameters, mut val: u64) {
- unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.base_penalty_msat = val;
-}
-/// A penalty in msats to apply to a channel upon failing to relay a payment.
-///
-/// This accumulates for each failure but may be reduced over time based on
-/// [`failure_penalty_half_life`] or when successfully routing through a channel.
-///
-/// Default value: 1,024,000 msat
-///
-/// [`failure_penalty_half_life`]: Self::failure_penalty_half_life
-#[no_mangle]
-pub extern "C" fn ScoringParameters_get_failure_penalty_msat(this_ptr: &ScoringParameters) -> u64 {
- let mut inner_val = &mut this_ptr.get_native_mut_ref().failure_penalty_msat;
- *inner_val
-}
-/// A penalty in msats to apply to a channel upon failing to relay a payment.
-///
-/// This accumulates for each failure but may be reduced over time based on
-/// [`failure_penalty_half_life`] or when successfully routing through a channel.
-///
-/// Default value: 1,024,000 msat
-///
-/// [`failure_penalty_half_life`]: Self::failure_penalty_half_life
-#[no_mangle]
-pub extern "C" fn ScoringParameters_set_failure_penalty_msat(this_ptr: &mut ScoringParameters, mut val: u64) {
- unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.failure_penalty_msat = val;
-}
-/// When the amount being sent over a channel is this many 1024ths of the total channel
-/// capacity, we begin applying [`overuse_penalty_msat_per_1024th`].
-///
-/// Default value: 128 1024ths (i.e. begin penalizing when an HTLC uses 1/8th of a channel)
-///
-/// [`overuse_penalty_msat_per_1024th`]: Self::overuse_penalty_msat_per_1024th
-#[no_mangle]
-pub extern "C" fn ScoringParameters_get_overuse_penalty_start_1024th(this_ptr: &ScoringParameters) -> u16 {
- let mut inner_val = &mut this_ptr.get_native_mut_ref().overuse_penalty_start_1024th;
- *inner_val
-}
-/// When the amount being sent over a channel is this many 1024ths of the total channel
-/// capacity, we begin applying [`overuse_penalty_msat_per_1024th`].
-///
-/// Default value: 128 1024ths (i.e. begin penalizing when an HTLC uses 1/8th of a channel)
-///
-/// [`overuse_penalty_msat_per_1024th`]: Self::overuse_penalty_msat_per_1024th
-#[no_mangle]
-pub extern "C" fn ScoringParameters_set_overuse_penalty_start_1024th(this_ptr: &mut ScoringParameters, mut val: u16) {
- unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.overuse_penalty_start_1024th = val;
-}
-/// A penalty applied, per whole 1024ths of the channel capacity which the amount being sent
-/// over the channel exceeds [`overuse_penalty_start_1024th`] by.
-///
-/// Default value: 20 msat (i.e. 2560 msat penalty to use 1/4th of a channel, 7680 msat penalty
-/// to use half a channel, and 12,560 msat penalty to use 3/4ths of a channel)
-///
-/// [`overuse_penalty_start_1024th`]: Self::overuse_penalty_start_1024th
-#[no_mangle]
-pub extern "C" fn ScoringParameters_get_overuse_penalty_msat_per_1024th(this_ptr: &ScoringParameters) -> u64 {
- let mut inner_val = &mut this_ptr.get_native_mut_ref().overuse_penalty_msat_per_1024th;
- *inner_val
-}
-/// A penalty applied, per whole 1024ths of the channel capacity which the amount being sent
-/// over the channel exceeds [`overuse_penalty_start_1024th`] by.
-///
-/// Default value: 20 msat (i.e. 2560 msat penalty to use 1/4th of a channel, 7680 msat penalty
-/// to use half a channel, and 12,560 msat penalty to use 3/4ths of a channel)
-///
-/// [`overuse_penalty_start_1024th`]: Self::overuse_penalty_start_1024th
-#[no_mangle]
-pub extern "C" fn ScoringParameters_set_overuse_penalty_msat_per_1024th(this_ptr: &mut ScoringParameters, mut val: u64) {
- unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.overuse_penalty_msat_per_1024th = val;
-}
-/// The time required to elapse before any accumulated [`failure_penalty_msat`] penalties are
-/// cut in half.
-///
-/// Successfully routing through a channel will immediately cut the penalty in half as well.
-///
-/// Default value: 1 hour
-///
-/// # Note
-///
-/// When built with the `no-std` feature, time will never elapse. Therefore, this penalty will
-/// never decay.
-///
-/// [`failure_penalty_msat`]: Self::failure_penalty_msat
-#[no_mangle]
-pub extern "C" fn ScoringParameters_get_failure_penalty_half_life(this_ptr: &ScoringParameters) -> u64 {
- let mut inner_val = &mut this_ptr.get_native_mut_ref().failure_penalty_half_life;
- inner_val.as_secs()
-}
-/// The time required to elapse before any accumulated [`failure_penalty_msat`] penalties are
-/// cut in half.
-///
-/// Successfully routing through a channel will immediately cut the penalty in half as well.
-///
-/// Default value: 1 hour
-///
-/// # Note
-///
-/// When built with the `no-std` feature, time will never elapse. Therefore, this penalty will
-/// never decay.
-///
-/// [`failure_penalty_msat`]: Self::failure_penalty_msat
-#[no_mangle]
-pub extern "C" fn ScoringParameters_set_failure_penalty_half_life(this_ptr: &mut ScoringParameters, mut val: u64) {
- unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.failure_penalty_half_life = core::time::Duration::from_secs(val);
-}
-/// Constructs a new ScoringParameters given each field
-#[must_use]
-#[no_mangle]
-pub extern "C" fn ScoringParameters_new(mut base_penalty_msat_arg: u64, mut failure_penalty_msat_arg: u64, mut overuse_penalty_start_1024th_arg: u16, mut overuse_penalty_msat_per_1024th_arg: u64, mut failure_penalty_half_life_arg: u64) -> ScoringParameters {
- ScoringParameters { inner: ObjOps::heap_alloc(nativeScoringParameters {
- base_penalty_msat: base_penalty_msat_arg,
- failure_penalty_msat: failure_penalty_msat_arg,
- overuse_penalty_start_1024th: overuse_penalty_start_1024th_arg,
- overuse_penalty_msat_per_1024th: overuse_penalty_msat_per_1024th_arg,
- failure_penalty_half_life: core::time::Duration::from_secs(failure_penalty_half_life_arg),
- }), is_owned: true }
-}
-#[no_mangle]
-/// Serialize the ScoringParameters object into a byte array which can be read by ScoringParameters_read
-pub extern "C" fn ScoringParameters_write(obj: &ScoringParameters) -> crate::c_types::derived::CVec_u8Z {
- crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
-}
-#[no_mangle]
-pub(crate) extern "C" fn ScoringParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
- crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeScoringParameters) })
-}
-#[no_mangle]
-/// Read a ScoringParameters from a byte array, created by ScoringParameters_write
-pub extern "C" fn ScoringParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ScoringParametersDecodeErrorZ {
- let res: Result<lightning::routing::scoring::ScoringParameters, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
- let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::scoring::ScoringParameters { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
- local_res
-}
-/// Creates a new scorer using the given scoring parameters.
-#[must_use]
-#[no_mangle]
-pub extern "C" fn Scorer_new(mut params: crate::lightning::routing::scoring::ScoringParameters) -> Scorer {
- let mut ret = lightning::routing::scoring::Scorer::new(*unsafe { Box::from_raw(params.take_inner()) });
- Scorer { inner: ObjOps::heap_alloc(ret), is_owned: true }
-}
-
-/// Creates a "default" Scorer. See struct and individual field documentaiton for details on which values are used.
-#[must_use]
-#[no_mangle]
-pub extern "C" fn Scorer_default() -> Scorer {
- Scorer { inner: ObjOps::heap_alloc(Default::default()), is_owned: true }
-}
-/// Creates a "default" ScoringParameters. See struct and individual field documentaiton for details on which values are used.
-#[must_use]
-#[no_mangle]
-pub extern "C" fn ScoringParameters_default() -> ScoringParameters {
- ScoringParameters { inner: ObjOps::heap_alloc(Default::default()), is_owned: true }
-}
-impl From<nativeScorer> for crate::lightning::routing::scoring::Score {
- fn from(obj: nativeScorer) -> Self {
- let mut rust_obj = Scorer { inner: ObjOps::heap_alloc(obj), is_owned: true };
- let mut ret = Scorer_as_Score(&rust_obj);
- // 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
- rust_obj.inner = core::ptr::null_mut();
- ret.free = Some(Scorer_free_void);
- ret
- }
-}
-/// Constructs a new Score which calls the relevant methods on this_arg.
-/// This copies the `inner` pointer in this_arg and thus the returned Score must be freed before this_arg is
-#[no_mangle]
-pub extern "C" fn Scorer_as_Score(this_arg: &Scorer) -> crate::lightning::routing::scoring::Score {
- crate::lightning::routing::scoring::Score {
- this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
- free: None,
- channel_penalty_msat: Scorer_Score_channel_penalty_msat,
- payment_path_failed: Scorer_Score_payment_path_failed,
- payment_path_successful: Scorer_Score_payment_path_successful,
- write: Scorer_write_void,
- }
-}
-
-#[must_use]
-extern "C" fn Scorer_Score_channel_penalty_msat(this_arg: *const c_void, mut short_channel_id: u64, mut send_amt_msat: u64, mut capacity_msat: u64, _source: &crate::lightning::routing::network_graph::NodeId, _target: &crate::lightning::routing::network_graph::NodeId) -> u64 {
- let mut ret = <nativeScorer as lightning::routing::scoring::Score<>>::channel_penalty_msat(unsafe { &mut *(this_arg as *mut nativeScorer) }, short_channel_id, send_amt_msat, capacity_msat, _source.get_native_ref(), _target.get_native_ref());
- ret
-}
-extern "C" fn Scorer_Score_payment_path_failed(this_arg: *mut c_void, mut _path: crate::c_types::derived::CVec_RouteHopZ, mut short_channel_id: u64) {
- let mut local__path = Vec::new(); for mut item in _path.as_slice().iter() { local__path.push( { item.get_native_ref() }); };
- <nativeScorer as lightning::routing::scoring::Score<>>::payment_path_failed(unsafe { &mut *(this_arg as *mut nativeScorer) }, &local__path[..], short_channel_id)
-}
-extern "C" fn Scorer_Score_payment_path_successful(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ) {
- let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
- <nativeScorer as lightning::routing::scoring::Score<>>::payment_path_successful(unsafe { &mut *(this_arg as *mut nativeScorer) }, &local_path[..])
-}
-
-#[no_mangle]
-/// Serialize the Scorer object into a byte array which can be read by Scorer_read
-pub extern "C" fn Scorer_write(obj: &Scorer) -> crate::c_types::derived::CVec_u8Z {
- crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
-}
-#[no_mangle]
-pub(crate) extern "C" fn Scorer_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
- crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeScorer) })
-}
-#[no_mangle]
-/// Read a Scorer from a byte array, created by Scorer_write
-pub extern "C" fn Scorer_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ScorerDecodeErrorZ {
- let res: Result<lightning::routing::scoring::Scorer, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
- let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::scoring::Scorer { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
- local_res
-}