//! # extern crate lightning_invoice;
//! # extern crate secp256k1;
//! #
+//! # #[cfg(feature = \"no-std\")]
+//! # extern crate core2;
+//! #
//! # use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
//! # use lightning::ln::channelmanager::{ChannelDetails, PaymentId, PaymentSendFailure};
//! # use lightning::ln::msgs::LightningError;
//! # use std::cell::RefCell;
//! # use std::ops::Deref;
//! #
+//! # #[cfg(not(feature = \"std\"))]
+//! # use core2::io;
+//! # #[cfg(feature = \"std\")]
+//! # use std::io;
+//! #
//! # struct FakeEventProvider {}
//! # impl EventsProvider for FakeEventProvider {
//! # fn process_pending_events<H: Deref>(&self, handler: H) where H::Target: EventHandler {}
//! #
//! # struct FakeScorer {}
//! # impl Writeable for FakeScorer {
-//! # fn write<W: Writer>(&self, w: &mut W) -> Result<(), std::io::Error> { unimplemented!(); }
+//! # fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> { unimplemented!(); }
//! # }
//! # impl Score for FakeScorer {
//! # fn channel_penalty_msat(
-//! # &self, _short_channel_id: u64, _send_amt: u64, _chan_amt: Option<u64>, _source: &NodeId, _target: &NodeId
+//! # &self, _short_channel_id: u64, _send_amt: u64, _chan_amt: u64, _source: &NodeId, _target: &NodeId
//! # ) -> u64 { 0 }
//! # fn payment_path_failed(&mut self, _path: &[&RouteHop], _short_channel_id: u64) {}
//! # fn payment_path_successful(&mut self, _path: &[&RouteHop]) {}
//! as updates to the network graph or changes to channel scores should be applied prior to
//! retries, typically by way of composing [`EventHandler`]s accordingly.
-use std::str::FromStr;
-use std::ffi::c_void;
+use alloc::str::FromStr;
+use core::ffi::c_void;
use core::convert::Infallible;
use bitcoin::hashes::Hash;
use crate::c_types::*;
+#[cfg(feature="no-std")]
+use alloc::{vec::Vec, boxed::Box};
use lightning_invoice::payment::InvoicePayer as nativeInvoicePayerImport;
pub(crate) fn take_inner(mut self) -> *mut nativeInvoicePayer {
assert!(self.is_owned);
let ret = ObjOps::untweak_ptr(self.inner);
- self.inner = std::ptr::null_mut();
+ self.inner = core::ptr::null_mut();
ret
}
}
// We're essentially a pointer already, or at least a set of pointers, so allow us to be used
// directly as a Deref trait in higher-level structs:
-impl std::ops::Deref for Payer {
+impl core::ops::Deref for Payer {
type Target = Self;
fn deref(&self) -> &Self {
self
///
/// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
#[must_use]
- pub find_route: extern "C" fn (this_arg: *const c_void, payer: crate::c_types::PublicKey, params: &crate::lightning::routing::router::RouteParameters, payment_hash: *const [u8; 32], first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, scorer: &crate::lightning::routing::scoring::Score) -> crate::c_types::derived::CResult_RouteLightningErrorZ,
+ pub find_route: extern "C" fn (this_arg: *const c_void, payer: crate::c_types::PublicKey, route_params: &crate::lightning::routing::router::RouteParameters, payment_hash: *const [u8; 32], first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, scorer: &crate::lightning::routing::scoring::Score) -> crate::c_types::derived::CResult_RouteLightningErrorZ,
/// Frees any resources associated with this object given its this_arg pointer.
/// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
use lightning_invoice::payment::Router as rustRouter;
impl rustRouter<crate::lightning::routing::scoring::Score> for Router {
- fn find_route(&self, mut payer: &secp256k1::key::PublicKey, mut params: &lightning::routing::router::RouteParameters, mut payment_hash: &lightning::ln::PaymentHash, mut first_hops: Option<&[&lightning::ln::channelmanager::ChannelDetails]>, mut scorer: &crate::lightning::routing::scoring::Score) -> Result<lightning::routing::router::Route, lightning::ln::msgs::LightningError> {
+ fn find_route(&self, mut payer: &secp256k1::key::PublicKey, mut route_params: &lightning::routing::router::RouteParameters, mut payment_hash: &lightning::ln::PaymentHash, mut first_hops: Option<&[&lightning::ln::channelmanager::ChannelDetails]>, mut scorer: &crate::lightning::routing::scoring::Score) -> Result<lightning::routing::router::Route, lightning::ln::msgs::LightningError> {
let mut local_first_hops_base = if first_hops.is_none() { SmartPtr::null() } else { SmartPtr::from_obj( { let mut local_first_hops_0 = Vec::new(); for item in (first_hops.unwrap()).iter() { local_first_hops_0.push( { crate::lightning::ln::channelmanager::ChannelDetails { inner: unsafe { ObjOps::nonnull_ptr_to_inner(((*item) as *const lightning::ln::channelmanager::ChannelDetails<>) as *mut _) }, is_owned: false } }); }; local_first_hops_0.into() }) }; let mut local_first_hops = *local_first_hops_base;
- let mut ret = (self.find_route)(self.this_arg, crate::c_types::PublicKey::from_rust(&payer), &crate::lightning::routing::router::RouteParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((params as *const lightning::routing::router::RouteParameters<>) as *mut _) }, is_owned: false }, &payment_hash.0, local_first_hops, scorer);
+ let mut ret = (self.find_route)(self.this_arg, crate::c_types::PublicKey::from_rust(&payer), &crate::lightning::routing::router::RouteParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((route_params as *const lightning::routing::router::RouteParameters<>) as *mut _) }, is_owned: false }, &payment_hash.0, local_first_hops, scorer);
let mut local_ret = match ret.result_ok { true => Ok( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).take_inner()) } }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })};
local_ret
}
// We're essentially a pointer already, or at least a set of pointers, so allow us to be used
// directly as a Deref trait in higher-level structs:
-impl std::ops::Deref for Router {
+impl core::ops::Deref for Router {
type Target = Self;
fn deref(&self) -> &Self {
self
pub(crate) fn take_inner(mut self) -> *mut nativeRetryAttempts {
assert!(self.is_owned);
let ret = ObjOps::untweak_ptr(self.inner);
- self.inner = std::ptr::null_mut();
+ self.inner = core::ptr::null_mut();
ret
}
}
impl Clone for RetryAttempts {
fn clone(&self) -> Self {
Self {
- inner: if <*mut nativeRetryAttempts>::is_null(self.inner) { std::ptr::null_mut() } else {
+ inner: if <*mut nativeRetryAttempts>::is_null(self.inner) { core::ptr::null_mut() } else {
ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
is_owned: true,
}
#[no_mangle]
pub extern "C" fn RetryAttempts_hash(o: &RetryAttempts) -> u64 {
if o.inner.is_null() { return 0; }
- // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core
+ // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
#[allow(deprecated)]
let mut hasher = core::hash::SipHasher::new();
- std::hash::Hash::hash(o.get_native_ref(), &mut hasher);
- std::hash::Hasher::finish(&hasher)
+ core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
+ core::hash::Hasher::finish(&hasher)
}
/// An error that may occur when making a payment.
#[must_use]
let mut rust_obj = InvoicePayer { inner: ObjOps::heap_alloc(obj), is_owned: true };
let mut ret = InvoicePayer_as_EventHandler(&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 = std::ptr::null_mut();
+ rust_obj.inner = core::ptr::null_mut();
ret.free = Some(InvoicePayer_free_void);
ret
}