675ae698f5a8ac45f16a0b280a437b95d9972aac
[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  * Note that all of the functions implemented here *must* be reentrant-safe (obviously - they're
15  * called from inside the library in response to chain events, P2P events, or timer events).
16  */
17 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
18 public class FeeEstimator extends CommonBase {
19         final bindings.LDKFeeEstimator bindings_instance;
20         FeeEstimator(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
21         private FeeEstimator(bindings.LDKFeeEstimator arg) {
22                 super(bindings.LDKFeeEstimator_new(arg));
23                 this.ptrs_to.add(arg);
24                 this.bindings_instance = arg;
25         }
26         @Override @SuppressWarnings("deprecation")
27         protected void finalize() throws Throwable {
28                 if (ptr != 0) { bindings.FeeEstimator_free(ptr); } super.finalize();
29         }
30
31         public static interface FeeEstimatorInterface {
32                 /**
33                  * Gets estimated satoshis of fee required per 1000 Weight-Units.
34                  * 
35                  * Must return a value no smaller than 253 (ie 1 satoshi-per-byte rounded up to ensure later
36                  * round-downs don't put us below 1 satoshi-per-byte).
37                  * 
38                  * This method can be implemented with the following unit conversions:
39                  * max(satoshis-per-byte * 250, 253)
40                  * max(satoshis-per-kbyte / 4, 253)
41                  */
42                 int get_est_sat_per_1000_weight(ConfirmationTarget confirmation_target);
43         }
44         private static class LDKFeeEstimatorHolder { FeeEstimator held; }
45         public static FeeEstimator new_impl(FeeEstimatorInterface arg) {
46                 final LDKFeeEstimatorHolder impl_holder = new LDKFeeEstimatorHolder();
47                 impl_holder.held = new FeeEstimator(new bindings.LDKFeeEstimator() {
48                         @Override public int get_est_sat_per_1000_weight(ConfirmationTarget confirmation_target) {
49                                 int ret = arg.get_est_sat_per_1000_weight(confirmation_target);
50                                 return ret;
51                         }
52                 });
53                 return impl_holder.held;
54         }
55         /**
56          * Gets estimated satoshis of fee required per 1000 Weight-Units.
57          * 
58          * Must return a value no smaller than 253 (ie 1 satoshi-per-byte rounded up to ensure later
59          * round-downs don't put us below 1 satoshi-per-byte).
60          * 
61          * This method can be implemented with the following unit conversions:
62          * max(satoshis-per-byte * 250, 253)
63          * max(satoshis-per-kbyte / 4, 253)
64          */
65         public int get_est_sat_per_1000_weight(org.ldk.enums.ConfirmationTarget confirmation_target) {
66                 int ret = bindings.FeeEstimator_get_est_sat_per_1000_weight(this.ptr, confirmation_target);
67                 Reference.reachabilityFence(this);
68                 Reference.reachabilityFence(confirmation_target);
69                 return ret;
70         }
71
72 }