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 Result_NoneIOErrorZ persist_manager(ChannelManager channel_manager);
16 /**Persist the given [`NetworkGraph`] to disk, returning an error if persistence failed.
18 Result_NoneIOErrorZ persist_graph(NetworkGraph network_graph);
19 /**Persist the given [`WriteableScore`] to disk, returning an error if persistence failed.
21 Result_NoneIOErrorZ persist_scorer(WriteableScore scorer);
25 * Trait that handles persisting a [`ChannelManager`], [`NetworkGraph`], and [`WriteableScore`] to disk.
27 public class Persister : CommonBase {
28 internal bindings.LDKPersister bindings_instance;
29 internal long instance_idx;
31 internal Persister(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
33 if (ptr != 0) { bindings.Persister_free(ptr); }
36 private class LDKPersisterHolder { internal Persister held; }
37 private class LDKPersisterImpl : bindings.LDKPersister {
38 internal LDKPersisterImpl(PersisterInterface arg, LDKPersisterHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
39 private PersisterInterface arg;
40 private LDKPersisterHolder impl_holder;
41 public long persist_manager(long _channel_manager) {
42 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); }
43 Result_NoneIOErrorZ ret = arg.persist_manager(_channel_manager_hu_conv);
45 long result = ret == null ? 0 : ret.clone_ptr();
48 public long persist_graph(long _network_graph) {
49 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); }
50 Result_NoneIOErrorZ ret = arg.persist_graph(_network_graph_hu_conv);
52 long result = ret == null ? 0 : ret.clone_ptr();
55 public long persist_scorer(long _scorer) {
56 WriteableScore ret_hu_conv = new WriteableScore(null, _scorer);
57 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
58 Result_NoneIOErrorZ ret = arg.persist_scorer(ret_hu_conv);
60 long result = ret == null ? 0 : ret.clone_ptr();
65 /** Creates a new instance of Persister from a given implementation */
66 public static Persister new_impl(PersisterInterface arg) {
67 LDKPersisterHolder impl_holder = new LDKPersisterHolder();
68 LDKPersisterImpl impl = new LDKPersisterImpl(arg, impl_holder);
69 long[] ptr_idx = bindings.LDKPersister_new(impl);
71 impl_holder.held = new Persister(null, ptr_idx[0]);
72 impl_holder.held.instance_idx = ptr_idx[1];
73 impl_holder.held.bindings_instance = impl;
74 return impl_holder.held;
78 * Persist the given ['ChannelManager'] to disk, returning an error if persistence failed.
80 public Result_NoneIOErrorZ persist_manager(org.ldk.structs.ChannelManager channel_manager) {
81 long ret = bindings.Persister_persist_manager(this.ptr, channel_manager == null ? 0 : channel_manager.ptr);
83 GC.KeepAlive(channel_manager);
84 if (ret >= 0 && ret <= 4096) { return null; }
85 Result_NoneIOErrorZ ret_hu_conv = Result_NoneIOErrorZ.constr_from_ptr(ret);
86 if (this != null) { this.ptrs_to.AddLast(channel_manager); };
91 * Persist the given [`NetworkGraph`] to disk, returning an error if persistence failed.
93 public Result_NoneIOErrorZ persist_graph(org.ldk.structs.NetworkGraph network_graph) {
94 long ret = bindings.Persister_persist_graph(this.ptr, network_graph == null ? 0 : network_graph.ptr);
96 GC.KeepAlive(network_graph);
97 if (ret >= 0 && ret <= 4096) { return null; }
98 Result_NoneIOErrorZ ret_hu_conv = Result_NoneIOErrorZ.constr_from_ptr(ret);
99 if (this != null) { this.ptrs_to.AddLast(network_graph); };
104 * Persist the given [`WriteableScore`] to disk, returning an error if persistence failed.
106 public Result_NoneIOErrorZ persist_scorer(org.ldk.structs.WriteableScore scorer) {
107 long ret = bindings.Persister_persist_scorer(this.ptr, scorer.ptr);
109 GC.KeepAlive(scorer);
110 if (ret >= 0 && ret <= 4096) { return null; }
111 Result_NoneIOErrorZ ret_hu_conv = Result_NoneIOErrorZ.constr_from_ptr(ret);
112 if (this != null) { this.ptrs_to.AddLast(scorer); };