964cf0021f086937648e26dfb59d9dec40d44c36
[ldk-java] / c_sharp / src / org / ldk / structs / FeeEstimator.cs
1
2 using org.ldk.impl;
3 using org.ldk.enums;
4 using org.ldk.util;
5 using System;
6
7 namespace org { namespace ldk { namespace structs {
8
9
10
11 /** An implementation of FeeEstimator */
12 public interface FeeEstimatorInterface {
13         /**Gets estimated satoshis of fee required per 1000 Weight-Units.
14          * 
15          * LDK will wrap this method and ensure that the value returned is no smaller than 253
16          * (ie 1 satoshi-per-byte rounded up to ensure later round-downs don't put us below 1 satoshi-per-byte).
17          * 
18          * The following unit conversions can be used to convert to sats/KW:
19          * satoshis-per-byte * 250
20          * satoshis-per-kbyte / 4
21          */
22         int get_est_sat_per_1000_weight(ConfirmationTarget confirmation_target);
23 }
24
25 /**
26  * A trait which should be implemented to provide feerate information on a number of time
27  * horizons.
28  * 
29  * If access to a local mempool is not feasible, feerate estimates should be fetched from a set of
30  * third-parties hosting them. Note that this enables them to affect the propagation of your
31  * pre-signed transactions at any time and therefore endangers the safety of channels funds. It
32  * should be considered carefully as a deployment.
33  * 
34  * Note that all of the functions implemented here *must* be reentrant-safe (obviously - they're
35  * called from inside the library in response to chain events, P2P events, or timer events).
36  */
37 public class FeeEstimator : CommonBase {
38         internal bindings.LDKFeeEstimator bindings_instance;
39         internal long instance_idx;
40
41         internal FeeEstimator(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
42         ~FeeEstimator() {
43                 if (ptr != 0) { bindings.FeeEstimator_free(ptr); }
44         }
45
46         private class LDKFeeEstimatorHolder { internal FeeEstimator held; }
47         private class LDKFeeEstimatorImpl : bindings.LDKFeeEstimator {
48                 internal LDKFeeEstimatorImpl(FeeEstimatorInterface arg, LDKFeeEstimatorHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
49                 private FeeEstimatorInterface arg;
50                 private LDKFeeEstimatorHolder impl_holder;
51                 public int get_est_sat_per_1000_weight(ConfirmationTarget _confirmation_target) {
52                         int ret = arg.get_est_sat_per_1000_weight(_confirmation_target);
53                                 GC.KeepAlive(arg);
54                         return ret;
55                 }
56         }
57
58         /** Creates a new instance of FeeEstimator from a given implementation */
59         public static FeeEstimator new_impl(FeeEstimatorInterface arg) {
60                 LDKFeeEstimatorHolder impl_holder = new LDKFeeEstimatorHolder();
61                 LDKFeeEstimatorImpl impl = new LDKFeeEstimatorImpl(arg, impl_holder);
62                 long[] ptr_idx = bindings.LDKFeeEstimator_new(impl);
63
64                 impl_holder.held = new FeeEstimator(null, ptr_idx[0]);
65                 impl_holder.held.instance_idx = ptr_idx[1];
66                 impl_holder.held.bindings_instance = impl;
67                 return impl_holder.held;
68         }
69
70         /**
71          * Gets estimated satoshis of fee required per 1000 Weight-Units.
72          * 
73          * LDK will wrap this method and ensure that the value returned is no smaller than 253
74          * (ie 1 satoshi-per-byte rounded up to ensure later round-downs don't put us below 1 satoshi-per-byte).
75          * 
76          * The following unit conversions can be used to convert to sats/KW:
77          * satoshis-per-byte * 250
78          * satoshis-per-kbyte / 4
79          */
80         public int get_est_sat_per_1000_weight(ConfirmationTarget confirmation_target) {
81                 int ret = bindings.FeeEstimator_get_est_sat_per_1000_weight(this.ptr, confirmation_target);
82                 GC.KeepAlive(this);
83                 GC.KeepAlive(confirmation_target);
84                 return ret;
85         }
86
87 }
88 } } }