X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=c_sharp%2Fsrc%2Forg%2Fldk%2Fstructs%2FFeeEstimator.cs;h=964cf0021f086937648e26dfb59d9dec40d44c36;hb=8de7213fbf663ff60322896282dad51e8ab2f001;hp=fedc8cb2208e2b7b77b0f728f10f5dc904da1474;hpb=afc50e5d491a11364849383b75a8f939df703bac;p=ldk-java diff --git a/c_sharp/src/org/ldk/structs/FeeEstimator.cs b/c_sharp/src/org/ldk/structs/FeeEstimator.cs index fedc8cb2..964cf002 100644 --- a/c_sharp/src/org/ldk/structs/FeeEstimator.cs +++ b/c_sharp/src/org/ldk/structs/FeeEstimator.cs @@ -1,3 +1,4 @@ + using org.ldk.impl; using org.ldk.enums; using org.ldk.util; @@ -5,6 +6,22 @@ using System; namespace org { namespace ldk { namespace structs { + + +/** An implementation of FeeEstimator */ +public interface FeeEstimatorInterface { + /**Gets estimated satoshis of fee required per 1000 Weight-Units. + * + * LDK will wrap this method and ensure that the value returned is no smaller than 253 + * (ie 1 satoshi-per-byte rounded up to ensure later round-downs don't put us below 1 satoshi-per-byte). + * + * The following unit conversions can be used to convert to sats/KW: + * satoshis-per-byte * 250 + * satoshis-per-kbyte / 4 + */ + int get_est_sat_per_1000_weight(ConfirmationTarget confirmation_target); +} + /** * A trait which should be implemented to provide feerate information on a number of time * horizons. @@ -18,29 +35,14 @@ namespace org { namespace ldk { namespace structs { * called from inside the library in response to chain events, P2P events, or timer events). */ public class FeeEstimator : CommonBase { - internal readonly bindings.LDKFeeEstimator bindings_instance; + internal bindings.LDKFeeEstimator bindings_instance; + internal long instance_idx; + internal FeeEstimator(object _dummy, long ptr) : base(ptr) { bindings_instance = null; } - private FeeEstimator(bindings.LDKFeeEstimator arg) : base(bindings.LDKFeeEstimator_new(arg)) { - this.ptrs_to.AddLast(arg); - this.bindings_instance = arg; - } ~FeeEstimator() { if (ptr != 0) { bindings.FeeEstimator_free(ptr); } } - public interface FeeEstimatorInterface { - /** - * Gets estimated satoshis of fee required per 1000 Weight-Units. - * - * LDK will wrap this method and ensure that the value returned is no smaller than 253 - * (ie 1 satoshi-per-byte rounded up to ensure later round-downs don't put us below 1 satoshi-per-byte). - * - * The following unit conversions can be used to convert to sats/KW: - * satoshis-per-byte * 250 - * satoshis-per-kbyte / 4 - */ - int get_est_sat_per_1000_weight(ConfirmationTarget _confirmation_target); - } private class LDKFeeEstimatorHolder { internal FeeEstimator held; } private class LDKFeeEstimatorImpl : bindings.LDKFeeEstimator { internal LDKFeeEstimatorImpl(FeeEstimatorInterface arg, LDKFeeEstimatorHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; } @@ -52,11 +54,19 @@ public class FeeEstimator : CommonBase { return ret; } } + + /** Creates a new instance of FeeEstimator from a given implementation */ public static FeeEstimator new_impl(FeeEstimatorInterface arg) { LDKFeeEstimatorHolder impl_holder = new LDKFeeEstimatorHolder(); - impl_holder.held = new FeeEstimator(new LDKFeeEstimatorImpl(arg, impl_holder)); + LDKFeeEstimatorImpl impl = new LDKFeeEstimatorImpl(arg, impl_holder); + long[] ptr_idx = bindings.LDKFeeEstimator_new(impl); + + impl_holder.held = new FeeEstimator(null, ptr_idx[0]); + impl_holder.held.instance_idx = ptr_idx[1]; + impl_holder.held.bindings_instance = impl; return impl_holder.held; } + /** * Gets estimated satoshis of fee required per 1000 Weight-Units. *