[C#] Drop reference to `assert` which makes building on Win hard
[ldk-java] / c_sharp / src / org / ldk / structs / FilesystemPersister.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 /**
10  * FilesystemPersister persists channel data on disk, where each channel's
11  * data is stored in a file named after its funding outpoint.
12  * 
13  * Warning: this module does the best it can with calls to persist data, but it
14  * can only guarantee that the data is passed to the drive. It is up to the
15  * drive manufacturers to do the actual persistence properly, which they often
16  * don't (especially on consumer-grade hardware). Therefore, it is up to the
17  * user to validate their entire storage stack, to ensure the writes are
18  * persistent.
19  * Corollary: especially when dealing with larger amounts of money, it is best
20  * practice to have multiple channel data backups and not rely only on one
21  * FilesystemPersister.
22  */
23 public class FilesystemPersister : CommonBase {
24         internal FilesystemPersister(object _dummy, long ptr) : base(ptr) { }
25         ~FilesystemPersister() {
26                 if (ptr != 0) { bindings.FilesystemPersister_free(ptr); }
27         }
28
29         /**
30          * Initialize a new FilesystemPersister and set the path to the individual channels'
31          * files.
32          */
33         public static FilesystemPersister of(string path_to_channel_data) {
34                 long ret = bindings.FilesystemPersister_new(path_to_channel_data);
35                 GC.KeepAlive(path_to_channel_data);
36                 if (ret >= 0 && ret <= 4096) { return null; }
37                 org.ldk.structs.FilesystemPersister ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.FilesystemPersister(null, ret); }
38                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
39                 return ret_hu_conv;
40         }
41
42         /**
43          * Get the directory which was provided when this persister was initialized.
44          */
45         public string get_data_dir() {
46                 string ret = bindings.FilesystemPersister_get_data_dir(this.ptr);
47                 GC.KeepAlive(this);
48                 return ret;
49         }
50
51         /**
52          * Read `ChannelMonitor`s from disk.
53          */
54         public Result_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ read_channelmonitors(org.ldk.structs.EntropySource entropy_source, org.ldk.structs.SignerProvider signer_provider) {
55                 long ret = bindings.FilesystemPersister_read_channelmonitors(this.ptr, entropy_source.ptr, signer_provider.ptr);
56                 GC.KeepAlive(this);
57                 GC.KeepAlive(entropy_source);
58                 GC.KeepAlive(signer_provider);
59                 if (ret >= 0 && ret <= 4096) { return null; }
60                 Result_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ ret_hu_conv = Result_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ.constr_from_ptr(ret);
61                 if (this != null) { this.ptrs_to.AddLast(entropy_source); };
62                 if (this != null) { this.ptrs_to.AddLast(signer_provider); };
63                 return ret_hu_conv;
64         }
65
66 }
67 } } }