[C#] Run tests against release library in determinism CI run
[ldk-java] / src / main / java / org / ldk / structs / FeeEstimator.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  * A trait which should be implemented to provide feerate information on a number of time
12  * horizons.
13  * 
14  * If access to a local mempool is not feasible, feerate estimates should be fetched from a set of
15  * third-parties hosting them. Note that this enables them to affect the propagation of your
16  * pre-signed transactions at any time and therefore endangers the safety of channels funds. It
17  * should be considered carefully as a deployment.
18  * 
19  * Note that all of the functions implemented here *must* be reentrant-safe (obviously - they're
20  * called from inside the library in response to chain events, P2P events, or timer events).
21  * 
22  * LDK may generate a substantial number of fee-estimation calls in some cases. You should
23  * pre-calculate and cache the fee estimate results to ensure you don't substantially slow HTLC
24  * handling.
25  */
26 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
27 public class FeeEstimator extends CommonBase {
28         final bindings.LDKFeeEstimator bindings_instance;
29         FeeEstimator(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
30         private FeeEstimator(bindings.LDKFeeEstimator arg) {
31                 super(bindings.LDKFeeEstimator_new(arg));
32                 this.ptrs_to.add(arg);
33                 this.bindings_instance = arg;
34         }
35         @Override @SuppressWarnings("deprecation")
36         protected void finalize() throws Throwable {
37                 if (ptr != 0) { bindings.FeeEstimator_free(ptr); } super.finalize();
38         }
39         /**
40          * Destroys the object, freeing associated resources. After this call, any access
41          * to this object may result in a SEGFAULT or worse.
42          *
43          * You should generally NEVER call this method. You should let the garbage collector
44          * do this for you when it finalizes objects. However, it may be useful for types
45          * which represent locks and should be closed immediately to avoid holding locks
46          * until the GC runs.
47          */
48         public void destroy() {
49                 if (ptr != 0) { bindings.FeeEstimator_free(ptr); }
50                 ptr = 0;
51         }
52         public static interface FeeEstimatorInterface {
53                 /**
54                  * Gets estimated satoshis of fee required per 1000 Weight-Units.
55                  * 
56                  * LDK will wrap this method and ensure that the value returned is no smaller than 253
57                  * (ie 1 satoshi-per-byte rounded up to ensure later round-downs don't put us below 1 satoshi-per-byte).
58                  * 
59                  * The following unit conversions can be used to convert to sats/KW:
60                  * satoshis-per-byte * 250
61                  * satoshis-per-kbyte / 4
62                  */
63                 int get_est_sat_per_1000_weight(ConfirmationTarget confirmation_target);
64         }
65         private static class LDKFeeEstimatorHolder { FeeEstimator held; }
66         public static FeeEstimator new_impl(FeeEstimatorInterface arg) {
67                 final LDKFeeEstimatorHolder impl_holder = new LDKFeeEstimatorHolder();
68                 impl_holder.held = new FeeEstimator(new bindings.LDKFeeEstimator() {
69                         @Override public int get_est_sat_per_1000_weight(ConfirmationTarget confirmation_target) {
70                                 int ret = arg.get_est_sat_per_1000_weight(confirmation_target);
71                                 Reference.reachabilityFence(arg);
72                                 return ret;
73                         }
74                 });
75                 return impl_holder.held;
76         }
77         /**
78          * Gets estimated satoshis of fee required per 1000 Weight-Units.
79          * 
80          * LDK will wrap this method and ensure that the value returned is no smaller than 253
81          * (ie 1 satoshi-per-byte rounded up to ensure later round-downs don't put us below 1 satoshi-per-byte).
82          * 
83          * The following unit conversions can be used to convert to sats/KW:
84          * satoshis-per-byte * 250
85          * satoshis-per-kbyte / 4
86          */
87         public int get_est_sat_per_1000_weight(org.ldk.enums.ConfirmationTarget confirmation_target) {
88                 int ret = bindings.FeeEstimator_get_est_sat_per_1000_weight(this.ptr, confirmation_target);
89                 Reference.reachabilityFence(this);
90                 Reference.reachabilityFence(confirmation_target);
91                 return ret;
92         }
93
94 }