public static async Task <EstimateSmartFeeResponse> TryEstimateSmartFeeAsync(this RPCClient rpc, int confirmationTarget, EstimateSmartFeeMode estimateMode = EstimateSmartFeeMode.Conservative, bool simulateIfRegTest = false, bool tryOtherFeeRates = false)
        {
            if (simulateIfRegTest && rpc.Network == Network.RegTest)
            {
                return(SimulateRegTestFeeEstimation(confirmationTarget, estimateMode));
            }

            if (tryOtherFeeRates)
            {
                EstimateSmartFeeResponse response = await rpc.TryEstimateSmartFeeAsync(confirmationTarget, estimateMode);

                if (response != null)
                {
                    return(response);
                }
                else
                {
                    // Hopefully Bitcoin Core brainfart: https://github.com/bitcoin/bitcoin/issues/14431
                    for (int i = 2; i <= Constants.SevenDaysConfirmationTarget; i++)
                    {
                        response = await rpc.TryEstimateSmartFeeAsync(i, estimateMode);

                        if (response != null)
                        {
                            return(response);
                        }
                    }
                }
                // Let's try one more time, whatever.
            }

            return(await rpc.TryEstimateSmartFeeAsync(confirmationTarget, estimateMode));
        }
예제 #2
0
        public static async Task <EstimateSmartFeeResponse> TryEstimateSmartFeeAsync(this IRPCClient rpc, int confirmationTarget, EstimateSmartFeeMode estimateMode = EstimateSmartFeeMode.Conservative, bool simulateIfRegTest = false, bool tryOtherFeeRates = false)
        {
            if (simulateIfRegTest && rpc.Network == Network.RegTest)
            {
                return(SimulateRegTestFeeEstimation(confirmationTarget, estimateMode));
            }

            if (tryOtherFeeRates)
            {
                EstimateSmartFeeResponse response = await rpc.TryEstimateSmartFeeAsync(confirmationTarget, estimateMode);

                if (response is { })
예제 #3
0
        private static EstimateSmartFeeResponse SimulateRegTestFeeEstimation(int confirmationTarget, EstimateSmartFeeMode estimateMode)
        {
            int satoshiPerByte = estimateMode == EstimateSmartFeeMode.Conservative
                                ? (Constants.SevenDaysConfirmationTarget + 1 + 6 - confirmationTarget) / 7
                                : (Constants.SevenDaysConfirmationTarget + 1 + 5 - confirmationTarget) / 7; // Economical

            Money   feePerK = Money.Satoshis(satoshiPerByte * 1000);
            FeeRate feeRate = new FeeRate(feePerK);
            var     resp    = new EstimateSmartFeeResponse {
                Blocks = confirmationTarget, FeeRate = feeRate
            };

            return(resp);
        }
예제 #4
0
        private static EstimateSmartFeeResponse SimulateRegTestFeeEstimation(int confirmationTarget, EstimateSmartFeeMode estimateMode)
        {
            int staoshiPerBytes;

            if (estimateMode == EstimateSmartFeeMode.Conservative)
            {
                staoshiPerBytes = 6 + confirmationTarget;
            }
            else             // Economical
            {
                staoshiPerBytes = 5 + confirmationTarget;
            }

            var resp = new EstimateSmartFeeResponse {
                Blocks = confirmationTarget, FeeRate = new FeeRate(new Money(staoshiPerBytes * 1000, MoneyUnit.Satoshi))
            };

            return(resp);
        }
        private static EstimateSmartFeeResponse SimulateRegTestFeeEstimation(int confirmationTarget, EstimateSmartFeeMode estimateMode)
        {
            int satoshiPerBytes;

            if (estimateMode == EstimateSmartFeeMode.Conservative)
            {
                satoshiPerBytes = ((Constants.SevenDaysConfirmationTarget + 1 + 6) - confirmationTarget) / 7;
            }
            else             // Economical
            {
                satoshiPerBytes = ((Constants.SevenDaysConfirmationTarget + 1 + 5) - confirmationTarget) / 7;
            }

            Money   feePerK = new Money(satoshiPerBytes * 1000, MoneyUnit.Satoshi);
            FeeRate feeRate = new FeeRate(feePerK);
            var     resp    = new EstimateSmartFeeResponse {
                Blocks = confirmationTarget, FeeRate = feeRate
            };

            return(resp);
        }