Merge pull request #139 from TheBlueMatt/main
[ldk-java] / c_sharp / src / org / ldk / structs / Persister.cs
1 using org.ldk.impl;
2 using org.ldk.enums;
3 using org.ldk.util;
4 using System;
5
6 namespace org { namespace ldk { namespace structs {
7
8 /**
9  * Trait that handles persisting a [`ChannelManager`], [`NetworkGraph`], and [`WriteableScore`] to disk.
10  */
11 public class Persister : CommonBase {
12         internal readonly bindings.LDKPersister bindings_instance;
13         internal Persister(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
14         private Persister(bindings.LDKPersister arg) : base(bindings.LDKPersister_new(arg)) {
15                 this.ptrs_to.AddLast(arg);
16                 this.bindings_instance = arg;
17         }
18         ~Persister() {
19                 if (ptr != 0) { bindings.Persister_free(ptr); }
20         }
21
22         public interface PersisterInterface {
23                 /**
24                  * Persist the given ['ChannelManager'] to disk, returning an error if persistence failed.
25                  */
26                 Result_NoneErrorZ persist_manager(ChannelManager _channel_manager);
27                 /**
28                  * Persist the given [`NetworkGraph`] to disk, returning an error if persistence failed.
29                  */
30                 Result_NoneErrorZ persist_graph(NetworkGraph _network_graph);
31                 /**
32                  * Persist the given [`WriteableScore`] to disk, returning an error if persistence failed.
33                  */
34                 Result_NoneErrorZ persist_scorer(WriteableScore _scorer);
35         }
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_NoneErrorZ ret = arg.persist_manager(_channel_manager_hu_conv);
44                                 GC.KeepAlive(arg);
45                         long result = ret == null ? 0 : ret.clone_ptr();
46                         return result;
47                 }
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_NoneErrorZ ret = arg.persist_graph(_network_graph_hu_conv);
51                                 GC.KeepAlive(arg);
52                         long result = ret == null ? 0 : ret.clone_ptr();
53                         return result;
54                 }
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_NoneErrorZ ret = arg.persist_scorer(ret_hu_conv);
59                                 GC.KeepAlive(arg);
60                         long result = ret == null ? 0 : ret.clone_ptr();
61                         return result;
62                 }
63         }
64         public static Persister new_impl(PersisterInterface arg) {
65                 LDKPersisterHolder impl_holder = new LDKPersisterHolder();
66                 impl_holder.held = new Persister(new LDKPersisterImpl(arg, impl_holder));
67                 return impl_holder.held;
68         }
69         /**
70          * Persist the given ['ChannelManager'] to disk, returning an error if persistence failed.
71          */
72         public Result_NoneErrorZ persist_manager(org.ldk.structs.ChannelManager channel_manager) {
73                 long ret = bindings.Persister_persist_manager(this.ptr, channel_manager == null ? 0 : channel_manager.ptr);
74                 GC.KeepAlive(this);
75                 GC.KeepAlive(channel_manager);
76                 if (ret >= 0 && ret <= 4096) { return null; }
77                 Result_NoneErrorZ ret_hu_conv = Result_NoneErrorZ.constr_from_ptr(ret);
78                 if (this != null) { this.ptrs_to.AddLast(channel_manager); };
79                 return ret_hu_conv;
80         }
81
82         /**
83          * Persist the given [`NetworkGraph`] to disk, returning an error if persistence failed.
84          */
85         public Result_NoneErrorZ persist_graph(org.ldk.structs.NetworkGraph network_graph) {
86                 long ret = bindings.Persister_persist_graph(this.ptr, network_graph == null ? 0 : network_graph.ptr);
87                 GC.KeepAlive(this);
88                 GC.KeepAlive(network_graph);
89                 if (ret >= 0 && ret <= 4096) { return null; }
90                 Result_NoneErrorZ ret_hu_conv = Result_NoneErrorZ.constr_from_ptr(ret);
91                 if (this != null) { this.ptrs_to.AddLast(network_graph); };
92                 return ret_hu_conv;
93         }
94
95         /**
96          * Persist the given [`WriteableScore`] to disk, returning an error if persistence failed.
97          */
98         public Result_NoneErrorZ persist_scorer(org.ldk.structs.WriteableScore scorer) {
99                 long ret = bindings.Persister_persist_scorer(this.ptr, scorer.ptr);
100                 GC.KeepAlive(this);
101                 GC.KeepAlive(scorer);
102                 if (ret >= 0 && ret <= 4096) { return null; }
103                 Result_NoneErrorZ ret_hu_conv = Result_NoneErrorZ.constr_from_ptr(ret);
104                 if (this != null) { this.ptrs_to.AddLast(scorer); };
105                 return ret_hu_conv;
106         }
107
108 }
109 } } }