[Java] Properly convert strings to/from Modified UTF-8
[ldk-java] / src / main / java / org / ldk / structs / FilesystemPersister.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
12  * FilesystemPersister persists channel data on disk, where each channel's
13  * data is stored in a file named after its funding outpoint.
14  * 
15  * Warning: this module does the best it can with calls to persist data, but it
16  * can only guarantee that the data is passed to the drive. It is up to the
17  * drive manufacturers to do the actual persistence properly, which they often
18  * don't (especially on consumer-grade hardware). Therefore, it is up to the
19  * user to validate their entire storage stack, to ensure the writes are
20  * persistent.
21  * Corollary: especially when dealing with larger amounts of money, it is best
22  * practice to have multiple channel data backups and not rely only on one
23  * FilesystemPersister.
24  */
25 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
26 public class FilesystemPersister extends CommonBase {
27         FilesystemPersister(Object _dummy, long ptr) { super(ptr); }
28         @Override @SuppressWarnings("deprecation")
29         protected void finalize() throws Throwable {
30                 super.finalize();
31                 if (ptr != 0) { bindings.FilesystemPersister_free(ptr); }
32         }
33
34         /**
35          * Initialize a new FilesystemPersister and set the path to the individual channels'
36          * files.
37          */
38         public static FilesystemPersister of(java.lang.String path_to_channel_data) {
39                 long ret = bindings.FilesystemPersister_new(path_to_channel_data);
40                 Reference.reachabilityFence(path_to_channel_data);
41                 if (ret >= 0 && ret <= 4096) { return null; }
42                 org.ldk.structs.FilesystemPersister ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.FilesystemPersister(null, ret); }
43                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
44                 return ret_hu_conv;
45         }
46
47         /**
48          * Get the directory which was provided when this persister was initialized.
49          */
50         public String get_data_dir() {
51                 String ret = bindings.FilesystemPersister_get_data_dir(this.ptr);
52                 Reference.reachabilityFence(this);
53                 return ret;
54         }
55
56         /**
57          * Read `ChannelMonitor`s from disk.
58          */
59         public Result_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ read_channelmonitors(org.ldk.structs.EntropySource entropy_source, org.ldk.structs.SignerProvider signer_provider) {
60                 long ret = bindings.FilesystemPersister_read_channelmonitors(this.ptr, entropy_source.ptr, signer_provider.ptr);
61                 Reference.reachabilityFence(this);
62                 Reference.reachabilityFence(entropy_source);
63                 Reference.reachabilityFence(signer_provider);
64                 if (ret >= 0 && ret <= 4096) { return null; }
65                 Result_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ ret_hu_conv = Result_CVec_C2Tuple_BlockHashChannelMonitorZZErrorZ.constr_from_ptr(ret);
66                 if (this != null) { this.ptrs_to.add(entropy_source); };
67                 if (this != null) { this.ptrs_to.add(signer_provider); };
68                 return ret_hu_conv;
69         }
70
71 }