@ -24,35 +24,40 @@ enum class FeeEstimateMode {
} ;
} ;
/**
/**
* Fee rate in satoshis per kilo byte: CAmount / k B
* Fee rate in satoshis per kilo virtual byte: CAmount / k v B
*/
*/
class CFeeRate
class CFeeRate
{
{
private :
private :
CAmount nSatoshisPerK ; // unit is satoshis-per-1,000-bytes
/** Fee rate in sat/kvB (satoshis per 1000 virtualbytes) */
CAmount nSatoshisPerK ;
public :
public :
/** Fee rate of 0 satoshis per k B */
/** Fee rate of 0 satoshis per k v B */
CFeeRate ( ) : nSatoshisPerK ( 0 ) { }
CFeeRate ( ) : nSatoshisPerK ( 0 ) { }
template < typename I >
template < typename I >
explicit CFeeRate ( const I _nSatoshisPerK ) : nSatoshisPerK ( _nSatoshisPerK ) {
explicit CFeeRate ( const I _nSatoshisPerK ) : nSatoshisPerK ( _nSatoshisPerK ) {
// We've previously had bugs creep in from silent double->int conversion...
// We've previously had bugs creep in from silent double->int conversion...
static_assert ( std : : is_integral < I > : : value , " CFeeRate should be used without floats " ) ;
static_assert ( std : : is_integral < I > : : value , " CFeeRate should be used without floats " ) ;
}
}
/** Constructor for a fee rate in satoshis per kvB (sat/kvB).
/**
* Construct a fee rate from a fee in satoshis and a vsize in vB .
*
*
* Passing a num_bytes value of COIN ( 1e8 ) returns a fee rate in satoshis per vB ( sat / vB ) ,
* param @ [ in ] nFeePaid The fee paid by a transaction , in satoshis
* e . g . ( nFeePaid * 1e8 / 1e3 ) = = ( nFeePaid / 1e5 ) ,
* param @ [ in ] num_bytes The vsize of a transaction , in vbytes
* where 1e5 is the ratio to convert from BTC / kvB to sat / vB .
*/
*/
CFeeRate ( const CAmount & nFeePaid , uint32_t num_bytes ) ;
CFeeRate ( const CAmount & nFeePaid , uint32_t num_bytes ) ;
/**
/**
* Return the fee in satoshis for the given size in bytes .
* Return the fee in satoshis for the given vsize in vbytes .
* If the calculated fee would have fractional satoshis , then the returned fee will always be rounded up to the nearest satoshi .
* If the calculated fee would have fractional satoshis , then the
* returned fee will always be rounded up to the nearest satoshi .
*/
*/
CAmount GetFee ( uint32_t num_bytes ) const ;
CAmount GetFee ( uint32_t num_bytes ) const ;
/**
/**
* Return the fee in satoshis for a size of 1000 bytes
* Return the fee in satoshis for a v size of 1000 v bytes
*/
*/
CAmount GetFeePerK ( ) const { return GetFee ( 1000 ) ; }
CAmount GetFeePerK ( ) const { return GetFee ( 1000 ) ; }
friend bool operator < ( const CFeeRate & a , const CFeeRate & b ) { return a . nSatoshisPerK < b . nSatoshisPerK ; }
friend bool operator < ( const CFeeRate & a , const CFeeRate & b ) { return a . nSatoshisPerK < b . nSatoshisPerK ; }