fedc8cb2208e2b7b77b0f728f10f5dc904da1474
[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  * If access to a local mempool is not feasible, feerate estimates should be fetched from a set of
13  * third-parties hosting them. Note that this enables them to affect the propagation of your
14  * pre-signed transactions at any time and therefore endangers the safety of channels funds. It
15  * should be considered carefully as a deployment.
16  * 
17  * Note that all of the functions implemented here *must* be reentrant-safe (obviously - they're
18  * called from inside the library in response to chain events, P2P events, or timer events).
19  */
20 public class FeeEstimator : CommonBase {
21         internal readonly bindings.LDKFeeEstimator bindings_instance;
22         internal FeeEstimator(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
23         private FeeEstimator(bindings.LDKFeeEstimator arg) : base(bindings.LDKFeeEstimator_new(arg)) {
24                 this.ptrs_to.AddLast(arg);
25                 this.bindings_instance = arg;
26         }
27         ~FeeEstimator() {
28                 if (ptr != 0) { bindings.FeeEstimator_free(ptr); }
29         }
30
31         public interface FeeEstimatorInterface {
32                 /**
33                  * Gets estimated satoshis of fee required per 1000 Weight-Units.
34                  * 
35                  * LDK will wrap this method and ensure that the value returned is no smaller than 253
36                  * (ie 1 satoshi-per-byte rounded up to ensure later round-downs don't put us below 1 satoshi-per-byte).
37                  * 
38                  * The following unit conversions can be used to convert to sats/KW:
39                  * satoshis-per-byte * 250
40                  * satoshis-per-kbyte / 4
41                  */
42                 int get_est_sat_per_1000_weight(ConfirmationTarget _confirmation_target);
43         }
44         private class LDKFeeEstimatorHolder { internal FeeEstimator held; }
45         private class LDKFeeEstimatorImpl : bindings.LDKFeeEstimator {
46                 internal LDKFeeEstimatorImpl(FeeEstimatorInterface arg, LDKFeeEstimatorHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
47                 private FeeEstimatorInterface arg;
48                 private LDKFeeEstimatorHolder impl_holder;
49                 public int get_est_sat_per_1000_weight(ConfirmationTarget _confirmation_target) {
50                         int ret = arg.get_est_sat_per_1000_weight(_confirmation_target);
51                                 GC.KeepAlive(arg);
52                         return ret;
53                 }
54         }
55         public static FeeEstimator new_impl(FeeEstimatorInterface arg) {
56                 LDKFeeEstimatorHolder impl_holder = new LDKFeeEstimatorHolder();
57                 impl_holder.held = new FeeEstimator(new LDKFeeEstimatorImpl(arg, impl_holder));
58                 return impl_holder.held;
59         }
60         /**
61          * Gets estimated satoshis of fee required per 1000 Weight-Units.
62          * 
63          * LDK will wrap this method and ensure that the value returned is no smaller than 253
64          * (ie 1 satoshi-per-byte rounded up to ensure later round-downs don't put us below 1 satoshi-per-byte).
65          * 
66          * The following unit conversions can be used to convert to sats/KW:
67          * satoshis-per-byte * 250
68          * satoshis-per-kbyte / 4
69          */
70         public int get_est_sat_per_1000_weight(ConfirmationTarget confirmation_target) {
71                 int ret = bindings.FeeEstimator_get_est_sat_per_1000_weight(this.ptr, confirmation_target);
72                 GC.KeepAlive(this);
73                 GC.KeepAlive(confirmation_target);
74                 return ret;
75         }
76
77 }
78 } } }