X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=sidebyside;f=c_sharp%2Fsrc%2Forg%2Fldk%2Fstructs%2FPersister.cs;h=6f707579ff7cc75cea567a394c0eadbf9d5233ec;hb=8de7213fbf663ff60322896282dad51e8ab2f001;hp=0f9bbe37e72187ad9a4e3951b9e69d6d73abd812;hpb=afc50e5d491a11364849383b75a8f939df703bac;p=ldk-java diff --git a/c_sharp/src/org/ldk/structs/Persister.cs b/c_sharp/src/org/ldk/structs/Persister.cs index 0f9bbe37..6f707579 100644 --- a/c_sharp/src/org/ldk/structs/Persister.cs +++ b/c_sharp/src/org/ldk/structs/Persister.cs @@ -1,3 +1,4 @@ + using org.ldk.impl; using org.ldk.enums; using org.ldk.util; @@ -5,34 +6,33 @@ using System; namespace org { namespace ldk { namespace structs { + + +/** An implementation of Persister */ +public interface PersisterInterface { + /**Persist the given ['ChannelManager'] to disk, returning an error if persistence failed. + */ + Result_NoneIOErrorZ persist_manager(ChannelManager channel_manager); + /**Persist the given [`NetworkGraph`] to disk, returning an error if persistence failed. + */ + Result_NoneIOErrorZ persist_graph(NetworkGraph network_graph); + /**Persist the given [`WriteableScore`] to disk, returning an error if persistence failed. + */ + Result_NoneIOErrorZ persist_scorer(WriteableScore scorer); +} + /** * Trait that handles persisting a [`ChannelManager`], [`NetworkGraph`], and [`WriteableScore`] to disk. */ public class Persister : CommonBase { - internal readonly bindings.LDKPersister bindings_instance; + internal bindings.LDKPersister bindings_instance; + internal long instance_idx; + internal Persister(object _dummy, long ptr) : base(ptr) { bindings_instance = null; } - private Persister(bindings.LDKPersister arg) : base(bindings.LDKPersister_new(arg)) { - this.ptrs_to.AddLast(arg); - this.bindings_instance = arg; - } ~Persister() { if (ptr != 0) { bindings.Persister_free(ptr); } } - public interface PersisterInterface { - /** - * Persist the given ['ChannelManager'] to disk, returning an error if persistence failed. - */ - Result_NoneErrorZ persist_manager(ChannelManager _channel_manager); - /** - * Persist the given [`NetworkGraph`] to disk, returning an error if persistence failed. - */ - Result_NoneErrorZ persist_graph(NetworkGraph _network_graph); - /** - * Persist the given [`WriteableScore`] to disk, returning an error if persistence failed. - */ - Result_NoneErrorZ persist_scorer(WriteableScore _scorer); - } private class LDKPersisterHolder { internal Persister held; } private class LDKPersisterImpl : bindings.LDKPersister { internal LDKPersisterImpl(PersisterInterface arg, LDKPersisterHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; } @@ -40,14 +40,14 @@ public class Persister : CommonBase { private LDKPersisterHolder impl_holder; public long persist_manager(long _channel_manager) { 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); } - Result_NoneErrorZ ret = arg.persist_manager(_channel_manager_hu_conv); + Result_NoneIOErrorZ ret = arg.persist_manager(_channel_manager_hu_conv); GC.KeepAlive(arg); long result = ret == null ? 0 : ret.clone_ptr(); return result; } public long persist_graph(long _network_graph) { 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); } - Result_NoneErrorZ ret = arg.persist_graph(_network_graph_hu_conv); + Result_NoneIOErrorZ ret = arg.persist_graph(_network_graph_hu_conv); GC.KeepAlive(arg); long result = ret == null ? 0 : ret.clone_ptr(); return result; @@ -55,26 +55,34 @@ public class Persister : CommonBase { public long persist_scorer(long _scorer) { WriteableScore ret_hu_conv = new WriteableScore(null, _scorer); if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); }; - Result_NoneErrorZ ret = arg.persist_scorer(ret_hu_conv); + Result_NoneIOErrorZ ret = arg.persist_scorer(ret_hu_conv); GC.KeepAlive(arg); long result = ret == null ? 0 : ret.clone_ptr(); return result; } } + + /** Creates a new instance of Persister from a given implementation */ public static Persister new_impl(PersisterInterface arg) { LDKPersisterHolder impl_holder = new LDKPersisterHolder(); - impl_holder.held = new Persister(new LDKPersisterImpl(arg, impl_holder)); + LDKPersisterImpl impl = new LDKPersisterImpl(arg, impl_holder); + long[] ptr_idx = bindings.LDKPersister_new(impl); + + impl_holder.held = new Persister(null, ptr_idx[0]); + impl_holder.held.instance_idx = ptr_idx[1]; + impl_holder.held.bindings_instance = impl; return impl_holder.held; } + /** * Persist the given ['ChannelManager'] to disk, returning an error if persistence failed. */ - public Result_NoneErrorZ persist_manager(org.ldk.structs.ChannelManager channel_manager) { + public Result_NoneIOErrorZ persist_manager(org.ldk.structs.ChannelManager channel_manager) { long ret = bindings.Persister_persist_manager(this.ptr, channel_manager == null ? 0 : channel_manager.ptr); GC.KeepAlive(this); GC.KeepAlive(channel_manager); if (ret >= 0 && ret <= 4096) { return null; } - Result_NoneErrorZ ret_hu_conv = Result_NoneErrorZ.constr_from_ptr(ret); + Result_NoneIOErrorZ ret_hu_conv = Result_NoneIOErrorZ.constr_from_ptr(ret); if (this != null) { this.ptrs_to.AddLast(channel_manager); }; return ret_hu_conv; } @@ -82,12 +90,12 @@ public class Persister : CommonBase { /** * Persist the given [`NetworkGraph`] to disk, returning an error if persistence failed. */ - public Result_NoneErrorZ persist_graph(org.ldk.structs.NetworkGraph network_graph) { + public Result_NoneIOErrorZ persist_graph(org.ldk.structs.NetworkGraph network_graph) { long ret = bindings.Persister_persist_graph(this.ptr, network_graph == null ? 0 : network_graph.ptr); GC.KeepAlive(this); GC.KeepAlive(network_graph); if (ret >= 0 && ret <= 4096) { return null; } - Result_NoneErrorZ ret_hu_conv = Result_NoneErrorZ.constr_from_ptr(ret); + Result_NoneIOErrorZ ret_hu_conv = Result_NoneIOErrorZ.constr_from_ptr(ret); if (this != null) { this.ptrs_to.AddLast(network_graph); }; return ret_hu_conv; } @@ -95,12 +103,12 @@ public class Persister : CommonBase { /** * Persist the given [`WriteableScore`] to disk, returning an error if persistence failed. */ - public Result_NoneErrorZ persist_scorer(org.ldk.structs.WriteableScore scorer) { + public Result_NoneIOErrorZ persist_scorer(org.ldk.structs.WriteableScore scorer) { long ret = bindings.Persister_persist_scorer(this.ptr, scorer.ptr); GC.KeepAlive(this); GC.KeepAlive(scorer); if (ret >= 0 && ret <= 4096) { return null; } - Result_NoneErrorZ ret_hu_conv = Result_NoneErrorZ.constr_from_ptr(ret); + Result_NoneIOErrorZ ret_hu_conv = Result_NoneIOErrorZ.constr_from_ptr(ret); if (this != null) { this.ptrs_to.AddLast(scorer); }; return ret_hu_conv; }