allow fractional feerates (#4324)
This commit is contained in:
@@ -3,6 +3,7 @@ import threading
|
||||
import time
|
||||
import os
|
||||
import stat
|
||||
from decimal import Decimal
|
||||
|
||||
from copy import deepcopy
|
||||
|
||||
@@ -473,12 +474,9 @@ class SimpleConfig(PrintError):
|
||||
|
||||
@classmethod
|
||||
def estimate_fee_for_feerate(cls, fee_per_kb, size):
|
||||
# note: We only allow integer sat/byte values atm.
|
||||
# The GUI for simplicity reasons only displays integer sat/byte,
|
||||
# and for the sake of consistency, we thus only use integer sat/byte in
|
||||
# the backend too.
|
||||
fee_per_byte = int(fee_per_kb / 1000)
|
||||
return int(fee_per_byte * size)
|
||||
fee_per_kb = Decimal(fee_per_kb)
|
||||
fee_per_byte = fee_per_kb / 1000
|
||||
return round(fee_per_byte * size)
|
||||
|
||||
def update_fee_estimates(self, key, value):
|
||||
self.fee_estimates[key] = value
|
||||
|
||||
16
lib/util.py
16
lib/util.py
@@ -24,6 +24,7 @@ import binascii
|
||||
import os, sys, re, json
|
||||
from collections import defaultdict
|
||||
from datetime import datetime
|
||||
import decimal
|
||||
from decimal import Decimal
|
||||
import traceback
|
||||
import urllib
|
||||
@@ -472,8 +473,21 @@ def format_satoshis(x, num_zeros=0, decimal_point=8, precision=None, is_diff=Fal
|
||||
result = " " * (15 - len(result)) + result
|
||||
return result
|
||||
|
||||
|
||||
FEERATE_PRECISION = 1 # num fractional decimal places for sat/byte fee rates
|
||||
_feerate_quanta = Decimal(10) ** (-FEERATE_PRECISION)
|
||||
|
||||
|
||||
def format_fee_satoshis(fee, num_zeros=0):
|
||||
return format_satoshis(fee, num_zeros, 0, precision=1)
|
||||
return format_satoshis(fee, num_zeros, 0, precision=FEERATE_PRECISION)
|
||||
|
||||
|
||||
def quantize_feerate(fee):
|
||||
"""Strip sat/byte fee rate of excess precision."""
|
||||
if fee is None:
|
||||
return None
|
||||
return Decimal(fee).quantize(_feerate_quanta, rounding=decimal.ROUND_HALF_DOWN)
|
||||
|
||||
|
||||
def timestamp_to_datetime(timestamp):
|
||||
if timestamp is None:
|
||||
|
||||
Reference in New Issue
Block a user