45694cded4acacb48dea2b77f4cb4360fa511f39
[ldk-java] / c_sharp / src / org / ldk / structs / FeeEstimator.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  * A trait which should be implemented to provide feerate information on a number of time
10  * horizons.
11  * 
12  * Note that all of the functions implemented here *must* be reentrant-safe (obviously - they're
13  * called from inside the library in response to chain events, P2P events, or timer events).
14  */
15 public class FeeEstimator : CommonBase {
16         internal readonly bindings.LDKFeeEstimator bindings_instance;
17         internal FeeEstimator(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
18         private FeeEstimator(bindings.LDKFeeEstimator arg) : base(bindings.LDKFeeEstimator_new(arg)) {
19                 this.ptrs_to.AddLast(arg);
20                 this.bindings_instance = arg;
21         }
22         ~FeeEstimator() {
23                 if (ptr != 0) { bindings.FeeEstimator_free(ptr); }
24         }
25
26         public interface FeeEstimatorInterface {
27                 /**
28                  * Gets estimated satoshis of fee required per 1000 Weight-Units.
29                  * 
30                  * LDK will wrap this method and ensure that the value returned is no smaller than 253
31                  * (ie 1 satoshi-per-byte rounded up to ensure later round-downs don't put us below 1 satoshi-per-byte).
32                  * 
33                  * The following unit conversions can be used to convert to sats/KW:
34                  * satoshis-per-byte * 250
35                  * satoshis-per-kbyte / 4
36                  */
37                 int get_est_sat_per_1000_weight(ConfirmationTarget _confirmation_target);
38         }
39         private class LDKFeeEstimatorHolder { internal FeeEstimator held; }
40         private class LDKFeeEstimatorImpl : bindings.LDKFeeEstimator {
41                 internal LDKFeeEstimatorImpl(FeeEstimatorInterface arg, LDKFeeEstimatorHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
42                 private FeeEstimatorInterface arg;
43                 private LDKFeeEstimatorHolder impl_holder;
44                 public int get_est_sat_per_1000_weight(ConfirmationTarget _confirmation_target) {
45                         int ret = arg.get_est_sat_per_1000_weight(_confirmation_target);
46                                 GC.KeepAlive(arg);
47                         return ret;
48                 }
49         }
50         public static FeeEstimator new_impl(FeeEstimatorInterface arg) {
51                 LDKFeeEstimatorHolder impl_holder = new LDKFeeEstimatorHolder();
52                 impl_holder.held = new FeeEstimator(new LDKFeeEstimatorImpl(arg, impl_holder));
53                 return impl_holder.held;
54         }
55         /**
56          * Gets estimated satoshis of fee required per 1000 Weight-Units.
57          * 
58          * LDK will wrap this method and ensure that the value returned is no smaller than 253
59          * (ie 1 satoshi-per-byte rounded up to ensure later round-downs don't put us below 1 satoshi-per-byte).
60          * 
61          * The following unit conversions can be used to convert to sats/KW:
62          * satoshis-per-byte * 250
63          * satoshis-per-kbyte / 4
64          */
65         public int get_est_sat_per_1000_weight(ConfirmationTarget confirmation_target) {
66                 int ret = bindings.FeeEstimator_get_est_sat_per_1000_weight(this.ptr, confirmation_target);
67                 GC.KeepAlive(this);
68                 GC.KeepAlive(confirmation_target);
69                 return ret;
70         }
71
72 }
73 } } }