Ejemplo n.º 1
0
    /// <summary>
    /// Estimates fees for 1w, 3d, 1d, 12h, 6h, 3h, 1h, 30m, 20m.
    /// </summary>
    public static async Task <AllFeeEstimate> EstimateAllFeeAsync(this IRPCClient rpc, EstimateSmartFeeMode estimateMode = EstimateSmartFeeMode.Conservative, bool simulateIfRegTest = false, CancellationToken cancel = default)
    {
        var smartEstimations = (simulateIfRegTest && rpc.Network == Network.RegTest)
                        ? SimulateRegTestFeeEstimation(estimateMode)
                        : await GetFeeEstimationsAsync(rpc, estimateMode, cancel).ConfigureAwait(false);

        var mempoolInfo = await rpc.GetMempoolInfoAsync(cancel).ConfigureAwait(false);

        var sanityFeeRate = mempoolInfo.GetSanityFeeRate();
        var rpcStatus     = await rpc.GetRpcStatusAsync(cancel).ConfigureAwait(false);

        var minEstimations = GetFeeEstimationsFromMempoolInfo(mempoolInfo);

        var fixedEstimations = smartEstimations
                               .GroupJoin(
            minEstimations,
            outer => outer.Key,
            inner => inner.Key,
            (outer, inner) => new { Estimation = outer, MinimumFromMemPool = inner })
                               .SelectMany(x =>
                                           x.MinimumFromMemPool.DefaultIfEmpty(),
                                           (a, b) => (
                                               Target: a.Estimation.Key,
                                               FeeRate: Math.Max((int)sanityFeeRate.SatoshiPerByte, Math.Max(a.Estimation.Value, b.Value))))
                               .ToDictionary(x => x.Target, x => x.FeeRate);

        return(new AllFeeEstimate(
                   estimateMode,
                   fixedEstimations,
                   rpcStatus.Synchronized));
    }
Ejemplo n.º 2
0
        public static async Task <AllFeeEstimate> EstimateAllFeeAsync(this IRPCClient rpc, EstimateSmartFeeMode estimateMode = EstimateSmartFeeMode.Conservative, bool simulateIfRegTest = false, bool tolerateBitcoinCoreBrainfuck = true)
        {
            var rpcStatus = await rpc.GetRpcStatusAsync(CancellationToken.None).ConfigureAwait(false);

            var estimations = await rpc.EstimateHalfFeesAsync(new Dictionary <int, int>(), 2, 0, Constants.SevenDaysConfirmationTarget, 0, estimateMode, simulateIfRegTest, tolerateBitcoinCoreBrainfuck).ConfigureAwait(false);

            var allFeeEstimate = new AllFeeEstimate(estimateMode, estimations, rpcStatus.Synchronized);

            return(allFeeEstimate);
        }
Ejemplo n.º 3
0
        public static async Task <AllFeeEstimate> EstimateAllFeeAsync(this IRPCClient rpc, EstimateSmartFeeMode estimateMode = EstimateSmartFeeMode.Conservative, bool simulateIfRegTest = false)
        {
            var rpcStatus = await rpc.GetRpcStatusAsync(CancellationToken.None).ConfigureAwait(false);

            var mempoolInfo = await rpc.GetMempoolInfoAsync().ConfigureAwait(false);

            var sanityFeeRate = mempoolInfo.GetSanityFeeRate();
            var estimations   = await rpc.EstimateHalfFeesAsync(new Dictionary <int, int>(), 2, 0, Constants.SevenDaysConfirmationTarget, 0, sanityFeeRate, estimateMode, simulateIfRegTest).ConfigureAwait(false);

            var allFeeEstimate = new AllFeeEstimate(estimateMode, estimations, rpcStatus.Synchronized);

            return(allFeeEstimate);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Estimates fees for 1w, 3d, 1d, 12h, 6h, 3h, 1h, 30m, 20m.
        /// </summary>
        public static async Task <AllFeeEstimate> EstimateAllFeeAsync(this IRPCClient rpc, EstimateSmartFeeMode estimateMode = EstimateSmartFeeMode.Conservative, bool simulateIfRegTest = false)
        {
            var estimations = (simulateIfRegTest && rpc.Network == Network.RegTest)
                                ? SimulateRegTestFeeEstimation(estimateMode)
                                : await GetFeeEstimationsAsync(rpc, estimateMode).ConfigureAwait(false);

            var rpcStatus = await rpc.GetRpcStatusAsync(CancellationToken.None).ConfigureAwait(false);

            var mempoolInfo = await rpc.GetMempoolInfoAsync().ConfigureAwait(false);

            var sanityFeeRate = mempoolInfo.GetSanityFeeRate();

            return(new AllFeeEstimate(
                       estimateMode,
                       estimations.ToDictionary(x => x.Key, x => Math.Max(x.Value, (int)sanityFeeRate.SatoshiPerByte)),
                       rpcStatus.Synchronized));
        }