mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 01:43:36 +01:00
faae44713b
We have the FEERATE_FLOOR constant if you don't care, but usually you want to use the current bitcoind lower limit, so call get_feerate_floor() (which is currently the same, but coming!). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
44 lines
907 B
C
44 lines
907 B
C
#include "config.h"
|
|
#include <assert.h>
|
|
#include <bitcoin/feerate.h>
|
|
|
|
u32 feerate_from_style(u32 feerate, enum feerate_style style)
|
|
{
|
|
/* Make sure it's called somewhere! */
|
|
assert(feerate_floor_check() == FEERATE_FLOOR);
|
|
|
|
switch (style) {
|
|
case FEERATE_PER_KSIPA:
|
|
return feerate;
|
|
case FEERATE_PER_KBYTE:
|
|
/* Everyone uses satoshi per kbyte, but we use satoshi per ksipa
|
|
* (don't round down to zero though)! */
|
|
return (feerate + 3) / 4;
|
|
}
|
|
abort();
|
|
}
|
|
|
|
u32 feerate_to_style(u32 feerate_perkw, enum feerate_style style)
|
|
{
|
|
switch (style) {
|
|
case FEERATE_PER_KSIPA:
|
|
return feerate_perkw;
|
|
case FEERATE_PER_KBYTE:
|
|
if ((u64)feerate_perkw * 4 > UINT_MAX)
|
|
return UINT_MAX;
|
|
return feerate_perkw * 4;
|
|
}
|
|
abort();
|
|
}
|
|
|
|
const char *feerate_style_name(enum feerate_style style)
|
|
{
|
|
switch (style) {
|
|
case FEERATE_PER_KBYTE:
|
|
return "perkb";
|
|
case FEERATE_PER_KSIPA:
|
|
return "perkw";
|
|
}
|
|
abort();
|
|
}
|