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