LDKConfirmationTarget_Sentinel,
} LDKConfirmationTarget;
+/**
+ * Represents an IO Error. Note that some information is lost in the conversion from Rust.
+ */
+typedef enum LDKIOError {
+ LDKIOError_NotFound,
+ LDKIOError_PermissionDenied,
+ LDKIOError_ConnectionRefused,
+ LDKIOError_ConnectionReset,
+ LDKIOError_ConnectionAborted,
+ LDKIOError_NotConnected,
+ LDKIOError_AddrInUse,
+ LDKIOError_AddrNotAvailable,
+ LDKIOError_BrokenPipe,
+ LDKIOError_AlreadyExists,
+ LDKIOError_WouldBlock,
+ LDKIOError_InvalidInput,
+ LDKIOError_InvalidData,
+ LDKIOError_TimedOut,
+ LDKIOError_WriteZero,
+ LDKIOError_Interrupted,
+ LDKIOError_Other,
+ LDKIOError_UnexpectedEof,
+ /**
+ * Must be last for serialization purposes
+ */
+ LDKIOError_Sentinel,
+} LDKIOError;
+
/**
* An enum representing the available verbosity levels of the logger.
*/
bool result_ok;
} LDKCResult_TransactionNoneZ;
+/**
+ * The contents of CResult_NoneErrorZ
+ */
+typedef union LDKCResult_NoneErrorZPtr {
+ /**
+ * Note that this value is always NULL, as there are no contents in the OK variant
+ */
+ void *result;
+ /**
+ * A pointer to the contents in the error state.
+ * Reading from this pointer when `result_ok` is set is undefined.
+ */
+ enum LDKIOError *err;
+} LDKCResult_NoneErrorZPtr;
+
+/**
+ * A CResult_NoneErrorZ represents the result of a fallible operation,
+ * containing a () on success and a crate::c_types::IOError on failure.
+ * `result_ok` indicates the overall state, and the contents are provided via `contents`.
+ */
+typedef struct LDKCResult_NoneErrorZ {
+ /**
+ * The contents of this CResult_NoneErrorZ, accessible via either
+ * `err` or `result` depending on the state of `result_ok`.
+ */
+ union LDKCResult_NoneErrorZPtr contents;
+ /**
+ * Whether this CResult_NoneErrorZ represents a success state.
+ */
+ bool result_ok;
+} LDKCResult_NoneErrorZ;
+
+/**
+ * A dynamically-allocated array of crate::c_types::derived::C2Tuple_BlockHashChannelMonitorZs of arbitrary size.
+ * This corresponds to std::vector in C++
+ */
+typedef struct LDKCVec_C2Tuple_BlockHashChannelMonitorZZ {
+ /**
+ * The elements in the array.
+ * If datalen is non-0 this must be a valid, non-NULL pointer allocated by malloc().
+ */
+ struct LDKC2Tuple_BlockHashChannelMonitorZ *data;
+ /**
+ * The number of elements pointed to by `data`.
+ */
+ uintptr_t datalen;
+} LDKCVec_C2Tuple_BlockHashChannelMonitorZZ;
+
+/**
+ * The contents of CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ
+ */
+typedef union LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZPtr {
+ /**
+ * A pointer to the contents in the success state.
+ * Reading from this pointer when `result_ok` is not set is undefined.
+ */
+ struct LDKCVec_C2Tuple_BlockHashChannelMonitorZZ *result;
+ /**
+ * A pointer to the contents in the error state.
+ * Reading from this pointer when `result_ok` is set is undefined.
+ */
+ enum LDKIOError *err;
+} LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZPtr;
+
+/**
+ * A CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ represents the result of a fallible operation,
+ * containing a crate::c_types::derived::CVec_C2Tuple_BlockHashChannelMonitorZZ on success and a crate::c_types::IOError on failure.
+ * `result_ok` indicates the overall state, and the contents are provided via `contents`.
+ */
+typedef struct LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ {
+ /**
+ * The contents of this CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ, accessible via either
+ * `err` or `result` depending on the state of `result_ok`.
+ */
+ union LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZPtr contents;
+ /**
+ * Whether this CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ represents a success state.
+ */
+ bool result_ok;
+} LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ;
+
/**
* A Rust str object, ie a reference to a UTF8-valid string.
* This is *not* null-terminated so cannot be used directly as a C string!
bool is_owned;
} LDKNetGraphMsgHandler;
+
+
+/**
+ * FilesystemPersister persists channel data on disk, where each channel's
+ * data is stored in a file named after its funding outpoint.
+ *
+ * Warning: this module does the best it can with calls to persist data, but it
+ * can only guarantee that the data is passed to the drive. It is up to the
+ * drive manufacturers to do the actual persistence properly, which they often
+ * don't (especially on consumer-grade hardware). Therefore, it is up to the
+ * user to validate their entire storage stack, to ensure the writes are
+ * persistent.
+ * Corollary: especially when dealing with larger amounts of money, it is best
+ * practice to have multiple channel data backups and not rely only on one
+ * FilesystemPersister.
+ */
+typedef struct MUST_USE_STRUCT LDKFilesystemPersister {
+ /**
+ * A pointer to the opaque Rust object.
+ * Nearly everywhere, inner must be non-null, however in places where
+ * the Rust equivalent takes an Option, it may be set to null to indicate None.
+ */
+ LDKnativeFilesystemPersister *inner;
+ /**
+ * Indicates that this is the only struct which contains the same pointer.
+ * Rust functions which take ownership of an object provided via an argument require
+ * this to be true and invalidate the object pointed to by inner.
+ */
+ bool is_owned;
+} LDKFilesystemPersister;
+
extern const uintptr_t MAX_BUF_SIZE;
extern const uint64_t MIN_RELAY_FEE_SAT_PER_1000_WEIGHT;
*/
void CResult_TransactionNoneZ_free(struct LDKCResult_TransactionNoneZ _res);
+/**
+ * Creates a new CResult_NoneErrorZ in the success state.
+ */
+struct LDKCResult_NoneErrorZ CResult_NoneErrorZ_ok(void);
+
+/**
+ * Creates a new CResult_NoneErrorZ in the error state.
+ */
+struct LDKCResult_NoneErrorZ CResult_NoneErrorZ_err(enum LDKIOError e);
+
+/**
+ * Frees any resources used by the CResult_NoneErrorZ.
+ */
+void CResult_NoneErrorZ_free(struct LDKCResult_NoneErrorZ _res);
+
+/**
+ * Frees the buffer pointed to by `data` if `datalen` is non-0.
+ */
+void CVec_C2Tuple_BlockHashChannelMonitorZZ_free(struct LDKCVec_C2Tuple_BlockHashChannelMonitorZZ _res);
+
+/**
+ * Creates a new CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ in the success state.
+ */
+struct LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ_ok(struct LDKCVec_C2Tuple_BlockHashChannelMonitorZZ o);
+
+/**
+ * Creates a new CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ in the error state.
+ */
+struct LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ_err(enum LDKIOError e);
+
+/**
+ * Frees any resources used by the CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ.
+ */
+void CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ_free(struct LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ _res);
+
/**
* Creates a new CResult_NoneAPIErrorZ in the success state.
*/
*/
MUST_USE_RES struct LDKCResult_NoneLightningErrorZ NetworkGraph_update_channel_unsigned(struct LDKNetworkGraph *NONNULL_PTR this_arg, const struct LDKUnsignedChannelUpdate *NONNULL_PTR msg);
+/**
+ * Frees any resources used by the FilesystemPersister, if is_owned is set and inner is non-NULL.
+ */
+void FilesystemPersister_free(struct LDKFilesystemPersister this_obj);
+
+/**
+ * Initialize a new FilesystemPersister and set the path to the individual channels'
+ * files.
+ */
+MUST_USE_RES struct LDKFilesystemPersister FilesystemPersister_new(struct LDKCVec_u8Z path_to_channel_data);
+
+/**
+ * Get the directory which was provided when this persister was initialized.
+ */
+MUST_USE_RES struct LDKCVec_u8Z FilesystemPersister_get_data_dir(const struct LDKFilesystemPersister *NONNULL_PTR this_arg);
+
+/**
+ * Writes the provided `ChannelManager` to the path provided at `FilesystemPersister`
+ * initialization, within a file called \"manager\".
+ */
+MUST_USE_RES struct LDKCResult_NoneErrorZ FilesystemPersister_persist_manager(struct LDKCVec_u8Z data_dir, const struct LDKChannelManager *NONNULL_PTR manager);
+
+/**
+ * Read `ChannelMonitor`s from disk.
+ */
+MUST_USE_RES struct LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ FilesystemPersister_read_channelmonitors(const struct LDKFilesystemPersister *NONNULL_PTR this_arg, struct LDKKeysInterface keys_manager);
+
+/**
+ * Constructs a new Persist which calls the relevant methods on this_arg.
+ * This copies the `inner` pointer in this_arg and thus the returned Persist must be freed before this_arg is
+ */
+struct LDKPersist FilesystemPersister_as_Persist(const struct LDKFilesystemPersister *NONNULL_PTR this_arg);
+
/* Text to put at the end of the generated file */
const LDKChainMonitor* operator &() const { return &self; }
const LDKChainMonitor* operator ->() const { return &self; }
};
+class FilesystemPersister {
+private:
+ LDKFilesystemPersister self;
+public:
+ FilesystemPersister(const FilesystemPersister&) = delete;
+ FilesystemPersister(FilesystemPersister&& o) : self(o.self) { memset(&o, 0, sizeof(FilesystemPersister)); }
+ FilesystemPersister(LDKFilesystemPersister&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKFilesystemPersister)); }
+ operator LDKFilesystemPersister() && { LDKFilesystemPersister res = self; memset(&self, 0, sizeof(LDKFilesystemPersister)); return res; }
+ ~FilesystemPersister() { FilesystemPersister_free(self); }
+ FilesystemPersister& operator=(FilesystemPersister&& o) { FilesystemPersister_free(self); self = o.self; memset(&o, 0, sizeof(FilesystemPersister)); return *this; }
+ LDKFilesystemPersister* operator &() { return &self; }
+ LDKFilesystemPersister* operator ->() { return &self; }
+ const LDKFilesystemPersister* operator &() const { return &self; }
+ const LDKFilesystemPersister* operator ->() const { return &self; }
+};
class ChannelManager {
private:
LDKChannelManager self;
const LDKC2Tuple_SignatureCVec_SignatureZZ* operator &() const { return &self; }
const LDKC2Tuple_SignatureCVec_SignatureZZ* operator ->() const { return &self; }
};
+class CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ {
+private:
+ LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ self;
+public:
+ CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ(const CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ&) = delete;
+ CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ(CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ)); }
+ CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ(LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ)); }
+ operator LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ() && { LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ)); return res; }
+ ~CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ() { CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ_free(self); }
+ CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ& operator=(CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ&& o) { CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ)); return *this; }
+ LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ* operator &() { return &self; }
+ LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ* operator ->() { return &self; }
+ const LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ* operator &() const { return &self; }
+ const LDKCResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ* operator ->() const { return &self; }
+};
class CResult_CVec_u8ZPeerHandleErrorZ {
private:
LDKCResult_CVec_u8ZPeerHandleErrorZ self;
const LDKCResult_NodeInfoDecodeErrorZ* operator &() const { return &self; }
const LDKCResult_NodeInfoDecodeErrorZ* operator ->() const { return &self; }
};
-class CResult_NonePaymentSendFailureZ {
+class CVec_C2Tuple_BlockHashChannelMonitorZZ {
private:
- LDKCResult_NonePaymentSendFailureZ self;
+ LDKCVec_C2Tuple_BlockHashChannelMonitorZZ self;
public:
- CResult_NonePaymentSendFailureZ(const CResult_NonePaymentSendFailureZ&) = delete;
- CResult_NonePaymentSendFailureZ(CResult_NonePaymentSendFailureZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_NonePaymentSendFailureZ)); }
- CResult_NonePaymentSendFailureZ(LDKCResult_NonePaymentSendFailureZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_NonePaymentSendFailureZ)); }
- operator LDKCResult_NonePaymentSendFailureZ() && { LDKCResult_NonePaymentSendFailureZ res = self; memset(&self, 0, sizeof(LDKCResult_NonePaymentSendFailureZ)); return res; }
- ~CResult_NonePaymentSendFailureZ() { CResult_NonePaymentSendFailureZ_free(self); }
- CResult_NonePaymentSendFailureZ& operator=(CResult_NonePaymentSendFailureZ&& o) { CResult_NonePaymentSendFailureZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_NonePaymentSendFailureZ)); return *this; }
- LDKCResult_NonePaymentSendFailureZ* operator &() { return &self; }
- LDKCResult_NonePaymentSendFailureZ* operator ->() { return &self; }
- const LDKCResult_NonePaymentSendFailureZ* operator &() const { return &self; }
- const LDKCResult_NonePaymentSendFailureZ* operator ->() const { return &self; }
+ CVec_C2Tuple_BlockHashChannelMonitorZZ(const CVec_C2Tuple_BlockHashChannelMonitorZZ&) = delete;
+ CVec_C2Tuple_BlockHashChannelMonitorZZ(CVec_C2Tuple_BlockHashChannelMonitorZZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_C2Tuple_BlockHashChannelMonitorZZ)); }
+ CVec_C2Tuple_BlockHashChannelMonitorZZ(LDKCVec_C2Tuple_BlockHashChannelMonitorZZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_C2Tuple_BlockHashChannelMonitorZZ)); }
+ operator LDKCVec_C2Tuple_BlockHashChannelMonitorZZ() && { LDKCVec_C2Tuple_BlockHashChannelMonitorZZ res = self; memset(&self, 0, sizeof(LDKCVec_C2Tuple_BlockHashChannelMonitorZZ)); return res; }
+ ~CVec_C2Tuple_BlockHashChannelMonitorZZ() { CVec_C2Tuple_BlockHashChannelMonitorZZ_free(self); }
+ CVec_C2Tuple_BlockHashChannelMonitorZZ& operator=(CVec_C2Tuple_BlockHashChannelMonitorZZ&& o) { CVec_C2Tuple_BlockHashChannelMonitorZZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_C2Tuple_BlockHashChannelMonitorZZ)); return *this; }
+ LDKCVec_C2Tuple_BlockHashChannelMonitorZZ* operator &() { return &self; }
+ LDKCVec_C2Tuple_BlockHashChannelMonitorZZ* operator ->() { return &self; }
+ const LDKCVec_C2Tuple_BlockHashChannelMonitorZZ* operator &() const { return &self; }
+ const LDKCVec_C2Tuple_BlockHashChannelMonitorZZ* operator ->() const { return &self; }
};
class CResult_RouteLightningErrorZ {
private:
const LDKCVec_u8Z* operator &() const { return &self; }
const LDKCVec_u8Z* operator ->() const { return &self; }
};
+class CResult_NonePaymentSendFailureZ {
+private:
+ LDKCResult_NonePaymentSendFailureZ self;
+public:
+ CResult_NonePaymentSendFailureZ(const CResult_NonePaymentSendFailureZ&) = delete;
+ CResult_NonePaymentSendFailureZ(CResult_NonePaymentSendFailureZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_NonePaymentSendFailureZ)); }
+ CResult_NonePaymentSendFailureZ(LDKCResult_NonePaymentSendFailureZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_NonePaymentSendFailureZ)); }
+ operator LDKCResult_NonePaymentSendFailureZ() && { LDKCResult_NonePaymentSendFailureZ res = self; memset(&self, 0, sizeof(LDKCResult_NonePaymentSendFailureZ)); return res; }
+ ~CResult_NonePaymentSendFailureZ() { CResult_NonePaymentSendFailureZ_free(self); }
+ CResult_NonePaymentSendFailureZ& operator=(CResult_NonePaymentSendFailureZ&& o) { CResult_NonePaymentSendFailureZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_NonePaymentSendFailureZ)); return *this; }
+ LDKCResult_NonePaymentSendFailureZ* operator &() { return &self; }
+ LDKCResult_NonePaymentSendFailureZ* operator ->() { return &self; }
+ const LDKCResult_NonePaymentSendFailureZ* operator &() const { return &self; }
+ const LDKCResult_NonePaymentSendFailureZ* operator ->() const { return &self; }
+};
class CResult_ClosingSignedDecodeErrorZ {
private:
LDKCResult_ClosingSignedDecodeErrorZ self;
const LDKCVec_u64Z* operator &() const { return &self; }
const LDKCVec_u64Z* operator ->() const { return &self; }
};
+class CResult_NoneErrorZ {
+private:
+ LDKCResult_NoneErrorZ self;
+public:
+ CResult_NoneErrorZ(const CResult_NoneErrorZ&) = delete;
+ CResult_NoneErrorZ(CResult_NoneErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_NoneErrorZ)); }
+ CResult_NoneErrorZ(LDKCResult_NoneErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_NoneErrorZ)); }
+ operator LDKCResult_NoneErrorZ() && { LDKCResult_NoneErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_NoneErrorZ)); return res; }
+ ~CResult_NoneErrorZ() { CResult_NoneErrorZ_free(self); }
+ CResult_NoneErrorZ& operator=(CResult_NoneErrorZ&& o) { CResult_NoneErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_NoneErrorZ)); return *this; }
+ LDKCResult_NoneErrorZ* operator &() { return &self; }
+ LDKCResult_NoneErrorZ* operator ->() { return &self; }
+ const LDKCResult_NoneErrorZ* operator &() const { return &self; }
+ const LDKCResult_NoneErrorZ* operator ->() const { return &self; }
+};
class C2Tuple_TxidCVec_C2Tuple_u32ScriptZZZ {
private:
LDKC2Tuple_TxidCVec_C2Tuple_u32ScriptZZZ self;
typedef struct nativeKeysManagerOpaque LDKnativeKeysManager;
struct nativeChainMonitorOpaque;
typedef struct nativeChainMonitorOpaque LDKnativeChainMonitor;
+struct nativeFilesystemPersisterOpaque;
+typedef struct nativeFilesystemPersisterOpaque LDKnativeFilesystemPersister;
struct nativeChannelManagerOpaque;
typedef struct nativeChannelManagerOpaque LDKnativeChannelManager;
struct nativeChainParametersOpaque;
}
}
#[repr(C)]
+/// The contents of CResult_NoneErrorZ
+pub union CResult_NoneErrorZPtr {
+ /// Note that this value is always NULL, as there are no contents in the OK variant
+ pub result: *mut std::ffi::c_void,
+ /// A pointer to the contents in the error state.
+ /// Reading from this pointer when `result_ok` is set is undefined.
+ pub err: *mut crate::c_types::IOError,
+}
+#[repr(C)]
+/// A CResult_NoneErrorZ represents the result of a fallible operation,
+/// containing a () on success and a crate::c_types::IOError on failure.
+/// `result_ok` indicates the overall state, and the contents are provided via `contents`.
+pub struct CResult_NoneErrorZ {
+ /// The contents of this CResult_NoneErrorZ, accessible via either
+ /// `err` or `result` depending on the state of `result_ok`.
+ pub contents: CResult_NoneErrorZPtr,
+ /// Whether this CResult_NoneErrorZ represents a success state.
+ pub result_ok: bool,
+}
+#[no_mangle]
+/// Creates a new CResult_NoneErrorZ in the success state.
+pub extern "C" fn CResult_NoneErrorZ_ok() -> CResult_NoneErrorZ {
+ CResult_NoneErrorZ {
+ contents: CResult_NoneErrorZPtr {
+ result: std::ptr::null_mut(),
+ },
+ result_ok: true,
+ }
+}
+#[no_mangle]
+/// Creates a new CResult_NoneErrorZ in the error state.
+pub extern "C" fn CResult_NoneErrorZ_err(e: crate::c_types::IOError) -> CResult_NoneErrorZ {
+ CResult_NoneErrorZ {
+ contents: CResult_NoneErrorZPtr {
+ err: Box::into_raw(Box::new(e)),
+ },
+ result_ok: false,
+ }
+}
+#[no_mangle]
+/// Frees any resources used by the CResult_NoneErrorZ.
+pub extern "C" fn CResult_NoneErrorZ_free(_res: CResult_NoneErrorZ) { }
+impl Drop for CResult_NoneErrorZ {
+ fn drop(&mut self) {
+ if self.result_ok {
+ } else {
+ if unsafe { !(self.contents.err as *mut ()).is_null() } {
+ let _ = unsafe { Box::from_raw(self.contents.err) };
+ }
+ }
+ }
+}
+impl From<crate::c_types::CResultTempl<u8, crate::c_types::IOError>> for CResult_NoneErrorZ {
+ fn from(mut o: crate::c_types::CResultTempl<u8, crate::c_types::IOError>) -> Self {
+ let contents = if o.result_ok {
+ let _ = unsafe { Box::from_raw(o.contents.result) };
+ o.contents.result = std::ptr::null_mut();
+ CResult_NoneErrorZPtr { result: std::ptr::null_mut() }
+ } else {
+ let err = unsafe { o.contents.err };
+ unsafe { o.contents.err = std::ptr::null_mut(); }
+ CResult_NoneErrorZPtr { err }
+ };
+ Self {
+ contents,
+ result_ok: o.result_ok,
+ }
+ }
+}
+#[repr(C)]
+/// A dynamically-allocated array of crate::c_types::derived::C2Tuple_BlockHashChannelMonitorZs of arbitrary size.
+/// This corresponds to std::vector in C++
+pub struct CVec_C2Tuple_BlockHashChannelMonitorZZ {
+ /// The elements in the array.
+ /// If datalen is non-0 this must be a valid, non-NULL pointer allocated by malloc().
+ pub data: *mut crate::c_types::derived::C2Tuple_BlockHashChannelMonitorZ,
+ /// The number of elements pointed to by `data`.
+ pub datalen: usize
+}
+impl CVec_C2Tuple_BlockHashChannelMonitorZZ {
+ #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec<crate::c_types::derived::C2Tuple_BlockHashChannelMonitorZ> {
+ if self.datalen == 0 { return Vec::new(); }
+ let ret = unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }.into();
+ self.data = std::ptr::null_mut();
+ self.datalen = 0;
+ ret
+ }
+ #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::c_types::derived::C2Tuple_BlockHashChannelMonitorZ] {
+ unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) }
+ }
+}
+impl From<Vec<crate::c_types::derived::C2Tuple_BlockHashChannelMonitorZ>> for CVec_C2Tuple_BlockHashChannelMonitorZZ {
+ fn from(v: Vec<crate::c_types::derived::C2Tuple_BlockHashChannelMonitorZ>) -> Self {
+ let datalen = v.len();
+ let data = Box::into_raw(v.into_boxed_slice());
+ Self { datalen, data: unsafe { (*data).as_mut_ptr() } }
+ }
+}
+#[no_mangle]
+/// Frees the buffer pointed to by `data` if `datalen` is non-0.
+pub extern "C" fn CVec_C2Tuple_BlockHashChannelMonitorZZ_free(_res: CVec_C2Tuple_BlockHashChannelMonitorZZ) { }
+impl Drop for CVec_C2Tuple_BlockHashChannelMonitorZZ {
+ fn drop(&mut self) {
+ if self.datalen == 0 { return; }
+ unsafe { Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) };
+ }
+}
+#[repr(C)]
+/// The contents of CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ
+pub union CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZPtr {
+ /// A pointer to the contents in the success state.
+ /// Reading from this pointer when `result_ok` is not set is undefined.
+ pub result: *mut crate::c_types::derived::CVec_C2Tuple_BlockHashChannelMonitorZZ,
+ /// A pointer to the contents in the error state.
+ /// Reading from this pointer when `result_ok` is set is undefined.
+ pub err: *mut crate::c_types::IOError,
+}
+#[repr(C)]
+/// A CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ represents the result of a fallible operation,
+/// containing a crate::c_types::derived::CVec_C2Tuple_BlockHashChannelMonitorZZ on success and a crate::c_types::IOError on failure.
+/// `result_ok` indicates the overall state, and the contents are provided via `contents`.
+pub struct CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ {
+ /// The contents of this CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ, accessible via either
+ /// `err` or `result` depending on the state of `result_ok`.
+ pub contents: CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZPtr,
+ /// Whether this CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ represents a success state.
+ pub result_ok: bool,
+}
+#[no_mangle]
+/// Creates a new CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ in the success state.
+pub extern "C" fn CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ_ok(o: crate::c_types::derived::CVec_C2Tuple_BlockHashChannelMonitorZZ) -> CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ {
+ CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ {
+ contents: CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZPtr {
+ result: Box::into_raw(Box::new(o)),
+ },
+ result_ok: true,
+ }
+}
+#[no_mangle]
+/// Creates a new CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ in the error state.
+pub extern "C" fn CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ_err(e: crate::c_types::IOError) -> CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ {
+ CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ {
+ contents: CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZPtr {
+ err: Box::into_raw(Box::new(e)),
+ },
+ result_ok: false,
+ }
+}
+#[no_mangle]
+/// Frees any resources used by the CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ.
+pub extern "C" fn CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ_free(_res: CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ) { }
+impl Drop for CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ {
+ fn drop(&mut self) {
+ if self.result_ok {
+ if unsafe { !(self.contents.result as *mut ()).is_null() } {
+ let _ = unsafe { Box::from_raw(self.contents.result) };
+ }
+ } else {
+ if unsafe { !(self.contents.err as *mut ()).is_null() } {
+ let _ = unsafe { Box::from_raw(self.contents.err) };
+ }
+ }
+ }
+}
+impl From<crate::c_types::CResultTempl<crate::c_types::derived::CVec_C2Tuple_BlockHashChannelMonitorZZ, crate::c_types::IOError>> for CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ {
+ fn from(mut o: crate::c_types::CResultTempl<crate::c_types::derived::CVec_C2Tuple_BlockHashChannelMonitorZZ, crate::c_types::IOError>) -> Self {
+ let contents = if o.result_ok {
+ let result = unsafe { o.contents.result };
+ unsafe { o.contents.result = std::ptr::null_mut() };
+ CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZPtr { result }
+ } else {
+ let err = unsafe { o.contents.err };
+ unsafe { o.contents.err = std::ptr::null_mut(); }
+ CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZPtr { err }
+ };
+ Self {
+ contents,
+ result_ok: o.result_ok,
+ }
+ }
+}
+#[repr(C)]
/// The contents of CResult_NoneAPIErrorZ
pub union CResult_NoneAPIErrorZPtr {
/// Note that this value is always NULL, as there are no contents in the OK variant
pub mod c_types;
pub mod bitcoin;
pub mod lightning;
+pub mod lightning_persister;
--- /dev/null
+// This file is Copyright its original authors, visible in version control
+// history and in the source files from which this was generated.
+//
+// This file is licensed under the license available in the LICENSE or LICENSE.md
+// file in the root of this repository or, if no such file exists, the same
+// license as that which applies to the original source files from which this
+// source was automatically generated.
+
+//! Utilities that handle persisting Rust-Lightning data to disk via standard filesystem APIs.
+
+use std::ffi::c_void;
+use bitcoin::hashes::Hash;
+use crate::c_types::*;
+
+
+use lightning_persister::FilesystemPersister as nativeFilesystemPersisterImport;
+type nativeFilesystemPersister = nativeFilesystemPersisterImport;
+
+/// FilesystemPersister persists channel data on disk, where each channel's
+/// data is stored in a file named after its funding outpoint.
+///
+/// Warning: this module does the best it can with calls to persist data, but it
+/// can only guarantee that the data is passed to the drive. It is up to the
+/// drive manufacturers to do the actual persistence properly, which they often
+/// don't (especially on consumer-grade hardware). Therefore, it is up to the
+/// user to validate their entire storage stack, to ensure the writes are
+/// persistent.
+/// Corollary: especially when dealing with larger amounts of money, it is best
+/// practice to have multiple channel data backups and not rely only on one
+/// FilesystemPersister.
+#[must_use]
+#[repr(C)]
+pub struct FilesystemPersister {
+ /// A pointer to the opaque Rust object.
+
+ /// Nearly everywhere, inner must be non-null, however in places where
+ /// the Rust equivalent takes an Option, it may be set to null to indicate None.
+ pub inner: *mut nativeFilesystemPersister,
+ /// Indicates that this is the only struct which contains the same pointer.
+
+ /// Rust functions which take ownership of an object provided via an argument require
+ /// this to be true and invalidate the object pointed to by inner.
+ pub is_owned: bool,
+}
+
+impl Drop for FilesystemPersister {
+ fn drop(&mut self) {
+ if self.is_owned && !<*mut nativeFilesystemPersister>::is_null(self.inner) {
+ let _ = unsafe { Box::from_raw(self.inner) };
+ }
+ }
+}
+/// Frees any resources used by the FilesystemPersister, if is_owned is set and inner is non-NULL.
+#[no_mangle]
+pub extern "C" fn FilesystemPersister_free(this_obj: FilesystemPersister) { }
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+extern "C" fn FilesystemPersister_free_void(this_ptr: *mut c_void) {
+ unsafe { let _ = Box::from_raw(this_ptr as *mut nativeFilesystemPersister); }
+}
+#[allow(unused)]
+/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
+impl FilesystemPersister {
+ pub(crate) fn take_inner(mut self) -> *mut nativeFilesystemPersister {
+ assert!(self.is_owned);
+ let ret = self.inner;
+ self.inner = std::ptr::null_mut();
+ ret
+ }
+}
+/// Initialize a new FilesystemPersister and set the path to the individual channels'
+/// files.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn FilesystemPersister_new(mut path_to_channel_data: crate::c_types::derived::CVec_u8Z) -> FilesystemPersister {
+ let mut ret = lightning_persister::FilesystemPersister::new(String::from_utf8(path_to_channel_data.into_rust()).unwrap());
+ FilesystemPersister { inner: Box::into_raw(Box::new(ret)), is_owned: true }
+}
+
+/// Get the directory which was provided when this persister was initialized.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn FilesystemPersister_get_data_dir(this_arg: &FilesystemPersister) -> crate::c_types::derived::CVec_u8Z {
+ let mut ret = unsafe { &*this_arg.inner }.get_data_dir();
+ ret.into_bytes().into()
+}
+
+/// Writes the provided `ChannelManager` to the path provided at `FilesystemPersister`
+/// initialization, within a file called \"manager\".
+#[must_use]
+#[no_mangle]
+pub extern "C" fn FilesystemPersister_persist_manager(mut data_dir: crate::c_types::derived::CVec_u8Z, manager: &crate::lightning::ln::channelmanager::ChannelManager) -> crate::c_types::derived::CResult_NoneErrorZ {
+ let mut ret = lightning_persister::FilesystemPersister::persist_manager(String::from_utf8(data_dir.into_rust()).unwrap(), unsafe { &*manager.inner });
+ let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::IOError::from_rust(e) }).into() };
+ local_ret
+}
+
+/// Read `ChannelMonitor`s from disk.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn FilesystemPersister_read_channelmonitors(this_arg: &FilesystemPersister, mut keys_manager: crate::lightning::chain::keysinterface::KeysInterface) -> crate::c_types::derived::CResult_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ {
+ let mut ret = unsafe { &*this_arg.inner }.read_channelmonitors(keys_manager);
+ let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = Vec::new(); for mut item in o.drain(..) { local_ret_0.push( { let (mut orig_ret_0_0_0, mut orig_ret_0_0_1) = item; let mut local_ret_0_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0_0.into_inner() }, crate::lightning::chain::channelmonitor::ChannelMonitor { inner: Box::into_raw(Box::new(orig_ret_0_0_1)), is_owned: true }).into(); local_ret_0_0 }); }; local_ret_0.into() }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::IOError::from_rust(e) }).into() };
+ local_ret
+}
+
+impl From<nativeFilesystemPersister> for crate::lightning::chain::channelmonitor::Persist {
+ fn from(obj: nativeFilesystemPersister) -> Self {
+ let mut rust_obj = FilesystemPersister { inner: Box::into_raw(Box::new(obj)), is_owned: true };
+ let mut ret = FilesystemPersister_as_Persist(&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();
+ ret.free = Some(FilesystemPersister_free_void);
+ ret
+ }
+}
+/// Constructs a new Persist which calls the relevant methods on this_arg.
+/// This copies the `inner` pointer in this_arg and thus the returned Persist must be freed before this_arg is
+#[no_mangle]
+pub extern "C" fn FilesystemPersister_as_Persist(this_arg: &FilesystemPersister) -> crate::lightning::chain::channelmonitor::Persist {
+ crate::lightning::chain::channelmonitor::Persist {
+ this_arg: unsafe { (*this_arg).inner as *mut c_void },
+ free: None,
+ persist_new_channel: FilesystemPersister_Persist_persist_new_channel,
+ update_persisted_channel: FilesystemPersister_Persist_update_persisted_channel,
+ }
+}
+
+#[must_use]
+extern "C" fn FilesystemPersister_Persist_persist_new_channel(this_arg: *const c_void, mut funding_txo: crate::lightning::chain::transaction::OutPoint, monitor: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ {
+ let mut ret = <nativeFilesystemPersister as lightning::chain::channelmonitor::Persist<_>>::persist_new_channel(unsafe { &mut *(this_arg as *mut nativeFilesystemPersister) }, *unsafe { Box::from_raw(funding_txo.take_inner()) }, unsafe { &*monitor.inner });
+ let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::chain::channelmonitor::ChannelMonitorUpdateErr::native_into(e) }).into() };
+ local_ret
+}
+#[must_use]
+extern "C" fn FilesystemPersister_Persist_update_persisted_channel(this_arg: *const c_void, mut funding_txo: crate::lightning::chain::transaction::OutPoint, _update: &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate, monitor: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ {
+ let mut ret = <nativeFilesystemPersister as lightning::chain::channelmonitor::Persist<_>>::update_persisted_channel(unsafe { &mut *(this_arg as *mut nativeFilesystemPersister) }, *unsafe { Box::from_raw(funding_txo.take_inner()) }, unsafe { &*_update.inner }, unsafe { &*monitor.inner });
+ let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::chain::channelmonitor::ChannelMonitorUpdateErr::native_into(e) }).into() };
+ local_ret
+}
+