core-lightning/bitcoin/feerate.c
Rusty Russell 4ffda340d3 check: make sure all files outside contrib/ include "config.h" first.
And turn "" includes into full-path (which makes it easier to put
config.h first, and finds some cases check-includes.sh missed
previously).

config.h sets _GNU_SOURCE which really needs to be done before any
'#includes': we mainly got away with it with glibc, but other platforms
like Alpine may have stricter requirements.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-12-06 10:05:39 +10:30

40 lines
797 B
C

#include "config.h"
#include <bitcoin/feerate.h>
u32 feerate_from_style(u32 feerate, enum feerate_style style)
{
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();
}