7 namespace org { namespace ldk { namespace structs {
11 /** An implementation of Persister */
12 public interface PersisterInterface {
13 /**Persist the given ['ChannelManager'] to disk, returning an error if persistence failed.
15 * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
17 Result_NoneIOErrorZ persist_manager(ChannelManager channel_manager);
18 /**Persist the given [`NetworkGraph`] to disk, returning an error if persistence failed.
20 Result_NoneIOErrorZ persist_graph(NetworkGraph network_graph);
21 /**Persist the given [`WriteableScore`] to disk, returning an error if persistence failed.
23 Result_NoneIOErrorZ persist_scorer(WriteableScore scorer);
27 * Trait that handles persisting a [`ChannelManager`], [`NetworkGraph`], and [`WriteableScore`] to disk.
29 * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
31 public class Persister : CommonBase {
32 internal bindings.LDKPersister bindings_instance;
33 internal long instance_idx;
35 internal Persister(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
37 if (ptr != 0) { bindings.Persister_free(ptr); }
40 private class LDKPersisterHolder { internal Persister held; }
41 private class LDKPersisterImpl : bindings.LDKPersister {
42 internal LDKPersisterImpl(PersisterInterface arg, LDKPersisterHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
43 private PersisterInterface arg;
44 private LDKPersisterHolder impl_holder;
45 public long persist_manager(long _channel_manager) {
46 org.ldk.structs.ChannelManager _channel_manager_hu_conv = null; if (_channel_manager < 0 || _channel_manager > 4096) { _channel_manager_hu_conv = new org.ldk.structs.ChannelManager(null, _channel_manager); }
47 Result_NoneIOErrorZ ret = arg.persist_manager(_channel_manager_hu_conv);
49 long result = ret.clone_ptr();
52 public long persist_graph(long _network_graph) {
53 org.ldk.structs.NetworkGraph _network_graph_hu_conv = null; if (_network_graph < 0 || _network_graph > 4096) { _network_graph_hu_conv = new org.ldk.structs.NetworkGraph(null, _network_graph); }
54 Result_NoneIOErrorZ ret = arg.persist_graph(_network_graph_hu_conv);
56 long result = ret.clone_ptr();
59 public long persist_scorer(long _scorer) {
60 WriteableScore ret_hu_conv = new WriteableScore(null, _scorer);
61 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
62 Result_NoneIOErrorZ ret = arg.persist_scorer(ret_hu_conv);
64 long result = ret.clone_ptr();
69 /** Creates a new instance of Persister from a given implementation */
70 public static Persister new_impl(PersisterInterface arg) {
71 LDKPersisterHolder impl_holder = new LDKPersisterHolder();
72 LDKPersisterImpl impl = new LDKPersisterImpl(arg, impl_holder);
73 long[] ptr_idx = bindings.LDKPersister_new(impl);
75 impl_holder.held = new Persister(null, ptr_idx[0]);
76 impl_holder.held.instance_idx = ptr_idx[1];
77 impl_holder.held.bindings_instance = impl;
78 return impl_holder.held;
82 * Persist the given ['ChannelManager'] to disk, returning an error if persistence failed.
84 * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
86 public Result_NoneIOErrorZ persist_manager(org.ldk.structs.ChannelManager channel_manager) {
87 long ret = bindings.Persister_persist_manager(this.ptr, channel_manager.ptr);
89 GC.KeepAlive(channel_manager);
90 if (ret >= 0 && ret <= 4096) { return null; }
91 Result_NoneIOErrorZ ret_hu_conv = Result_NoneIOErrorZ.constr_from_ptr(ret);
92 if (this != null) { this.ptrs_to.AddLast(channel_manager); };
97 * Persist the given [`NetworkGraph`] to disk, returning an error if persistence failed.
99 public Result_NoneIOErrorZ persist_graph(org.ldk.structs.NetworkGraph network_graph) {
100 long ret = bindings.Persister_persist_graph(this.ptr, network_graph.ptr);
102 GC.KeepAlive(network_graph);
103 if (ret >= 0 && ret <= 4096) { return null; }
104 Result_NoneIOErrorZ ret_hu_conv = Result_NoneIOErrorZ.constr_from_ptr(ret);
105 if (this != null) { this.ptrs_to.AddLast(network_graph); };
110 * Persist the given [`WriteableScore`] to disk, returning an error if persistence failed.
112 public Result_NoneIOErrorZ persist_scorer(org.ldk.structs.WriteableScore scorer) {
113 long ret = bindings.Persister_persist_scorer(this.ptr, scorer.ptr);
115 GC.KeepAlive(scorer);
116 if (ret >= 0 && ret <= 4096) { return null; }
117 Result_NoneIOErrorZ ret_hu_conv = Result_NoneIOErrorZ.constr_from_ptr(ret);
118 if (this != null) { this.ptrs_to.AddLast(scorer); };