mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
bitcoin/feerate: new exposure for feerate parsing outside lightningd.
This exposes the numeric part of param_feerate() as param_feerate_val(). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
af4955c28e
commit
a9427f1a8d
@@ -4,6 +4,7 @@ BITCOIN_SRC := \
|
|||||||
bitcoin/base58.c \
|
bitcoin/base58.c \
|
||||||
bitcoin/block.c \
|
bitcoin/block.c \
|
||||||
bitcoin/chainparams.c \
|
bitcoin/chainparams.c \
|
||||||
|
bitcoin/feerate.c \
|
||||||
bitcoin/locktime.c \
|
bitcoin/locktime.c \
|
||||||
bitcoin/preimage.c \
|
bitcoin/preimage.c \
|
||||||
bitcoin/privkey.c \
|
bitcoin/privkey.c \
|
||||||
|
|||||||
40
bitcoin/feerate.c
Normal file
40
bitcoin/feerate.c
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#include <bitcoin/feerate.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdlib.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();
|
||||||
|
}
|
||||||
@@ -33,6 +33,11 @@
|
|||||||
*/
|
*/
|
||||||
#define FEERATE_FLOOR 253
|
#define FEERATE_FLOOR 253
|
||||||
|
|
||||||
|
enum feerate_style {
|
||||||
|
FEERATE_PER_KSIPA,
|
||||||
|
FEERATE_PER_KBYTE
|
||||||
|
};
|
||||||
|
|
||||||
static inline u32 feerate_floor(void)
|
static inline u32 feerate_floor(void)
|
||||||
{
|
{
|
||||||
/* Assert that bitcoind will see this as above minRelayTxFee */
|
/* Assert that bitcoind will see this as above minRelayTxFee */
|
||||||
@@ -47,4 +52,9 @@ static inline u32 feerate_floor(void)
|
|||||||
|
|
||||||
return FEERATE_FLOOR;
|
return FEERATE_FLOOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u32 feerate_from_style(u32 feerate, enum feerate_style style);
|
||||||
|
u32 feerate_to_style(u32 feerate_perkw, enum feerate_style style);
|
||||||
|
const char *feerate_style_name(enum feerate_style style);
|
||||||
|
|
||||||
#endif /* LIGHTNING_BITCOIN_FEERATE_H */
|
#endif /* LIGHTNING_BITCOIN_FEERATE_H */
|
||||||
|
|||||||
@@ -21,9 +21,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
|
|||||||
/* Generated stub for amount_sat_eq */
|
/* Generated stub for amount_sat_eq */
|
||||||
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
||||||
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
||||||
/* Generated stub for amount_sat_less */
|
|
||||||
bool amount_sat_less(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
|
||||||
{ fprintf(stderr, "amount_sat_less called!\n"); abort(); }
|
|
||||||
/* Generated stub for amount_sat_sub */
|
/* Generated stub for amount_sat_sub */
|
||||||
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
||||||
struct amount_sat a UNNEEDED,
|
struct amount_sat a UNNEEDED,
|
||||||
|
|||||||
@@ -22,9 +22,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
|
|||||||
/* Generated stub for amount_sat_eq */
|
/* Generated stub for amount_sat_eq */
|
||||||
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
||||||
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
||||||
/* Generated stub for amount_sat_less */
|
|
||||||
bool amount_sat_less(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
|
||||||
{ fprintf(stderr, "amount_sat_less called!\n"); abort(); }
|
|
||||||
/* Generated stub for amount_sat_sub */
|
/* Generated stub for amount_sat_sub */
|
||||||
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
||||||
struct amount_sat a UNNEEDED,
|
struct amount_sat a UNNEEDED,
|
||||||
|
|||||||
@@ -47,9 +47,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
|
|||||||
/* Generated stub for amount_sat_eq */
|
/* Generated stub for amount_sat_eq */
|
||||||
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
||||||
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
||||||
/* Generated stub for amount_sat_less */
|
|
||||||
bool amount_sat_less(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
|
||||||
{ fprintf(stderr, "amount_sat_less called!\n"); abort(); }
|
|
||||||
/* Generated stub for amount_sat_sub */
|
/* Generated stub for amount_sat_sub */
|
||||||
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
||||||
struct amount_sat a UNNEEDED,
|
struct amount_sat a UNNEEDED,
|
||||||
|
|||||||
@@ -50,9 +50,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
|
|||||||
/* Generated stub for amount_sat_eq */
|
/* Generated stub for amount_sat_eq */
|
||||||
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
||||||
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
||||||
/* Generated stub for amount_sat_less */
|
|
||||||
bool amount_sat_less(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
|
||||||
{ fprintf(stderr, "amount_sat_less called!\n"); abort(); }
|
|
||||||
/* Generated stub for amount_sat_sub */
|
/* Generated stub for amount_sat_sub */
|
||||||
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
||||||
struct amount_sat a UNNEEDED,
|
struct amount_sat a UNNEEDED,
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include <bitcoin/feerate.h>
|
||||||
#include <ccan/crypto/sha256/sha256.h>
|
#include <ccan/crypto/sha256/sha256.h>
|
||||||
#include <ccan/json_escape/json_escape.h>
|
#include <ccan/json_escape/json_escape.h>
|
||||||
#include <ccan/str/hex/hex.h>
|
#include <ccan/str/hex/hex.h>
|
||||||
@@ -330,3 +331,51 @@ struct command_result *param_secrets_array(struct command *cmd,
|
|||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct command_result *param_feerate_val(struct command *cmd,
|
||||||
|
const char *name, const char *buffer,
|
||||||
|
const jsmntok_t *tok,
|
||||||
|
u32 **feerate_per_kw)
|
||||||
|
{
|
||||||
|
jsmntok_t base = *tok, suffix = *tok;
|
||||||
|
enum feerate_style style;
|
||||||
|
unsigned int num;
|
||||||
|
|
||||||
|
/* We have to split the number and suffix. */
|
||||||
|
suffix.start = suffix.end;
|
||||||
|
while (suffix.start > base.start && !isdigit(buffer[suffix.start-1])) {
|
||||||
|
suffix.start--;
|
||||||
|
base.end--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!json_to_number(buffer, &base, &num)) {
|
||||||
|
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||||
|
"'%s' prefix should be an integer, not '%.*s'",
|
||||||
|
name, base.end - base.start,
|
||||||
|
buffer + base.start);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json_tok_streq(buffer, &suffix, "")
|
||||||
|
|| json_tok_streq(buffer, &suffix,
|
||||||
|
feerate_style_name(FEERATE_PER_KBYTE))) {
|
||||||
|
style = FEERATE_PER_KBYTE;
|
||||||
|
} else if (json_tok_streq(buffer, &suffix,
|
||||||
|
feerate_style_name(FEERATE_PER_KSIPA))) {
|
||||||
|
style = FEERATE_PER_KSIPA;
|
||||||
|
} else {
|
||||||
|
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||||
|
"'%s' suffix should be '%s' or '%s', not '%.*s'",
|
||||||
|
name,
|
||||||
|
feerate_style_name(FEERATE_PER_KSIPA),
|
||||||
|
feerate_style_name(FEERATE_PER_KBYTE),
|
||||||
|
suffix.end - suffix.start,
|
||||||
|
buffer + suffix.start);
|
||||||
|
}
|
||||||
|
|
||||||
|
*feerate_per_kw = tal(cmd, u32);
|
||||||
|
**feerate_per_kw = feerate_from_style(num, style);
|
||||||
|
if (**feerate_per_kw < FEERATE_FLOOR)
|
||||||
|
**feerate_per_kw = FEERATE_FLOOR;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -131,4 +131,9 @@ struct command_result *param_secrets_array(struct command *cmd,
|
|||||||
const jsmntok_t *tok,
|
const jsmntok_t *tok,
|
||||||
struct secret **secrets);
|
struct secret **secrets);
|
||||||
|
|
||||||
|
struct command_result *param_feerate_val(struct command *cmd,
|
||||||
|
const char *name, const char *buffer,
|
||||||
|
const jsmntok_t *tok,
|
||||||
|
u32 **feerate_per_kw);
|
||||||
|
|
||||||
#endif /* LIGHTNING_COMMON_JSON_TOK_H */
|
#endif /* LIGHTNING_COMMON_JSON_TOK_H */
|
||||||
|
|||||||
@@ -27,9 +27,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
|
|||||||
/* Generated stub for amount_sat_eq */
|
/* Generated stub for amount_sat_eq */
|
||||||
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
||||||
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
||||||
/* Generated stub for amount_sat_less */
|
|
||||||
bool amount_sat_less(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
|
||||||
{ fprintf(stderr, "amount_sat_less called!\n"); abort(); }
|
|
||||||
/* Generated stub for amount_sat_sub */
|
/* Generated stub for amount_sat_sub */
|
||||||
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
||||||
struct amount_sat a UNNEEDED,
|
struct amount_sat a UNNEEDED,
|
||||||
|
|||||||
@@ -22,9 +22,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
|
|||||||
/* Generated stub for amount_sat_eq */
|
/* Generated stub for amount_sat_eq */
|
||||||
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
||||||
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
||||||
/* Generated stub for amount_sat_less */
|
|
||||||
bool amount_sat_less(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
|
||||||
{ fprintf(stderr, "amount_sat_less called!\n"); abort(); }
|
|
||||||
/* Generated stub for amount_sat_sub */
|
/* Generated stub for amount_sat_sub */
|
||||||
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
||||||
struct amount_sat a UNNEEDED,
|
struct amount_sat a UNNEEDED,
|
||||||
|
|||||||
@@ -23,9 +23,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
|
|||||||
/* Generated stub for amount_sat_eq */
|
/* Generated stub for amount_sat_eq */
|
||||||
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
||||||
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
||||||
/* Generated stub for amount_sat_less */
|
|
||||||
bool amount_sat_less(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
|
||||||
{ fprintf(stderr, "amount_sat_less called!\n"); abort(); }
|
|
||||||
/* Generated stub for amount_sat_sub */
|
/* Generated stub for amount_sat_sub */
|
||||||
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
||||||
struct amount_sat a UNNEEDED,
|
struct amount_sat a UNNEEDED,
|
||||||
|
|||||||
@@ -22,9 +22,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
|
|||||||
/* Generated stub for amount_sat_eq */
|
/* Generated stub for amount_sat_eq */
|
||||||
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
||||||
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
||||||
/* Generated stub for amount_sat_less */
|
|
||||||
bool amount_sat_less(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
|
||||||
{ fprintf(stderr, "amount_sat_less called!\n"); abort(); }
|
|
||||||
/* Generated stub for amount_sat_sub */
|
/* Generated stub for amount_sat_sub */
|
||||||
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
||||||
struct amount_sat a UNNEEDED,
|
struct amount_sat a UNNEEDED,
|
||||||
|
|||||||
@@ -19,9 +19,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
|
|||||||
/* Generated stub for amount_sat_eq */
|
/* Generated stub for amount_sat_eq */
|
||||||
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
||||||
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
||||||
/* Generated stub for amount_sat_less */
|
|
||||||
bool amount_sat_less(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
|
||||||
{ fprintf(stderr, "amount_sat_less called!\n"); abort(); }
|
|
||||||
/* Generated stub for amount_sat_sub */
|
/* Generated stub for amount_sat_sub */
|
||||||
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
||||||
struct amount_sat a UNNEEDED,
|
struct amount_sat a UNNEEDED,
|
||||||
|
|||||||
@@ -21,9 +21,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
|
|||||||
/* Generated stub for amount_sat_eq */
|
/* Generated stub for amount_sat_eq */
|
||||||
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
||||||
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
||||||
/* Generated stub for amount_sat_less */
|
|
||||||
bool amount_sat_less(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
|
||||||
{ fprintf(stderr, "amount_sat_less called!\n"); abort(); }
|
|
||||||
/* Generated stub for amount_sat_sub */
|
/* Generated stub for amount_sat_sub */
|
||||||
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
||||||
struct amount_sat a UNNEEDED,
|
struct amount_sat a UNNEEDED,
|
||||||
|
|||||||
@@ -19,9 +19,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
|
|||||||
/* Generated stub for amount_sat_eq */
|
/* Generated stub for amount_sat_eq */
|
||||||
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
||||||
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
||||||
/* Generated stub for amount_sat_less */
|
|
||||||
bool amount_sat_less(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
|
||||||
{ fprintf(stderr, "amount_sat_less called!\n"); abort(); }
|
|
||||||
/* Generated stub for amount_sat_sub */
|
/* Generated stub for amount_sat_sub */
|
||||||
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
||||||
struct amount_sat a UNNEEDED,
|
struct amount_sat a UNNEEDED,
|
||||||
|
|||||||
@@ -24,9 +24,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
|
|||||||
/* Generated stub for amount_sat_eq */
|
/* Generated stub for amount_sat_eq */
|
||||||
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
||||||
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
||||||
/* Generated stub for amount_sat_less */
|
|
||||||
bool amount_sat_less(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
|
||||||
{ fprintf(stderr, "amount_sat_less called!\n"); abort(); }
|
|
||||||
/* Generated stub for amount_sat_sub */
|
/* Generated stub for amount_sat_sub */
|
||||||
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
||||||
struct amount_sat a UNNEEDED,
|
struct amount_sat a UNNEEDED,
|
||||||
|
|||||||
@@ -23,9 +23,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
|
|||||||
/* Generated stub for amount_sat_eq */
|
/* Generated stub for amount_sat_eq */
|
||||||
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
||||||
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
||||||
/* Generated stub for amount_sat_less */
|
|
||||||
bool amount_sat_less(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
|
||||||
{ fprintf(stderr, "amount_sat_less called!\n"); abort(); }
|
|
||||||
/* Generated stub for amount_sat_sub */
|
/* Generated stub for amount_sat_sub */
|
||||||
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
||||||
struct amount_sat a UNNEEDED,
|
struct amount_sat a UNNEEDED,
|
||||||
|
|||||||
@@ -20,9 +20,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
|
|||||||
/* Generated stub for amount_sat_eq */
|
/* Generated stub for amount_sat_eq */
|
||||||
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
||||||
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
||||||
/* Generated stub for amount_sat_less */
|
|
||||||
bool amount_sat_less(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
|
||||||
{ fprintf(stderr, "amount_sat_less called!\n"); abort(); }
|
|
||||||
/* Generated stub for amount_sat_sub */
|
/* Generated stub for amount_sat_sub */
|
||||||
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
||||||
struct amount_sat a UNNEEDED,
|
struct amount_sat a UNNEEDED,
|
||||||
|
|||||||
@@ -36,9 +36,6 @@ void amount_msat_from_u64(struct amount_msat *msat UNNEEDED, u64 millisatoshis U
|
|||||||
/* Generated stub for amount_sat_eq */
|
/* Generated stub for amount_sat_eq */
|
||||||
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
||||||
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
||||||
/* Generated stub for amount_sat_less */
|
|
||||||
bool amount_sat_less(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
|
||||||
{ fprintf(stderr, "amount_sat_less called!\n"); abort(); }
|
|
||||||
/* Generated stub for amount_sat_sub */
|
/* Generated stub for amount_sat_sub */
|
||||||
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
||||||
struct amount_sat a UNNEEDED,
|
struct amount_sat a UNNEEDED,
|
||||||
|
|||||||
@@ -26,9 +26,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
|
|||||||
/* Generated stub for amount_sat_eq */
|
/* Generated stub for amount_sat_eq */
|
||||||
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
||||||
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
||||||
/* Generated stub for amount_sat_less */
|
|
||||||
bool amount_sat_less(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
|
||||||
{ fprintf(stderr, "amount_sat_less called!\n"); abort(); }
|
|
||||||
/* Generated stub for amount_sat_sub */
|
/* Generated stub for amount_sat_sub */
|
||||||
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
||||||
struct amount_sat a UNNEEDED,
|
struct amount_sat a UNNEEDED,
|
||||||
|
|||||||
@@ -26,9 +26,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
|
|||||||
/* Generated stub for amount_sat_eq */
|
/* Generated stub for amount_sat_eq */
|
||||||
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
||||||
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
||||||
/* Generated stub for amount_sat_less */
|
|
||||||
bool amount_sat_less(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
|
||||||
{ fprintf(stderr, "amount_sat_less called!\n"); abort(); }
|
|
||||||
/* Generated stub for amount_sat_sub */
|
/* Generated stub for amount_sat_sub */
|
||||||
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
||||||
struct amount_sat a UNNEEDED,
|
struct amount_sat a UNNEEDED,
|
||||||
|
|||||||
@@ -466,32 +466,6 @@ u32 penalty_feerate(struct chain_topology *topo)
|
|||||||
return try_get_feerate(topo, FEERATE_PENALTY);
|
return try_get_feerate(topo, FEERATE_PENALTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct command_result *json_feerates(struct command *cmd,
|
static struct command_result *json_feerates(struct command *cmd,
|
||||||
const char *buffer,
|
const char *buffer,
|
||||||
const jsmntok_t *obj UNNEEDED,
|
const jsmntok_t *obj UNNEEDED,
|
||||||
@@ -516,7 +490,7 @@ static struct command_result *json_feerates(struct command *cmd,
|
|||||||
}
|
}
|
||||||
|
|
||||||
response = json_stream_success(cmd);
|
response = json_stream_success(cmd);
|
||||||
json_object_start(response, json_feerate_style_name(*style));
|
json_object_start(response, feerate_style_name(*style));
|
||||||
for (size_t i = 0; i < ARRAY_SIZE(feerates); i++) {
|
for (size_t i = 0; i < ARRAY_SIZE(feerates); i++) {
|
||||||
if (!feerates[i] || i == FEERATE_MIN || i == FEERATE_MAX)
|
if (!feerates[i] || i == FEERATE_MIN || i == FEERATE_MAX)
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -159,10 +159,6 @@ u32 delayed_to_us_feerate(struct chain_topology *topo);
|
|||||||
u32 htlc_resolution_feerate(struct chain_topology *topo);
|
u32 htlc_resolution_feerate(struct chain_topology *topo);
|
||||||
u32 penalty_feerate(struct chain_topology *topo);
|
u32 penalty_feerate(struct chain_topology *topo);
|
||||||
|
|
||||||
/* We always use feerate-per-ksipa, ie. perkw */
|
|
||||||
u32 feerate_from_style(u32 feerate, enum feerate_style style);
|
|
||||||
u32 feerate_to_style(u32 feerate_perkw, enum feerate_style style);
|
|
||||||
|
|
||||||
const char *feerate_name(enum feerate feerate);
|
const char *feerate_name(enum feerate feerate);
|
||||||
|
|
||||||
/* Set feerate_per_kw to this estimate & return NULL, or fail cmd */
|
/* Set feerate_per_kw to this estimate & return NULL, or fail cmd */
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <bitcoin/address.h>
|
#include <bitcoin/address.h>
|
||||||
#include <bitcoin/base58.h>
|
#include <bitcoin/base58.h>
|
||||||
#include <bitcoin/feerate.h>
|
|
||||||
#include <bitcoin/script.h>
|
#include <bitcoin/script.h>
|
||||||
#include <ccan/json_escape/json_escape.h>
|
#include <ccan/json_escape/json_escape.h>
|
||||||
#include <ccan/mem/mem.h>
|
#include <ccan/mem/mem.h>
|
||||||
@@ -69,17 +68,6 @@ struct command_result *param_short_channel_id(struct command *cmd,
|
|||||||
json_tok_full(buffer, tok));
|
json_tok_full(buffer, tok));
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *json_feerate_style_name(enum feerate_style style)
|
|
||||||
{
|
|
||||||
switch (style) {
|
|
||||||
case FEERATE_PER_KBYTE:
|
|
||||||
return "perkb";
|
|
||||||
case FEERATE_PER_KSIPA:
|
|
||||||
return "perkw";
|
|
||||||
}
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
struct command_result *param_feerate_style(struct command *cmd,
|
struct command_result *param_feerate_style(struct command *cmd,
|
||||||
const char *name,
|
const char *name,
|
||||||
const char *buffer,
|
const char *buffer,
|
||||||
@@ -88,11 +76,11 @@ struct command_result *param_feerate_style(struct command *cmd,
|
|||||||
{
|
{
|
||||||
*style = tal(cmd, enum feerate_style);
|
*style = tal(cmd, enum feerate_style);
|
||||||
if (json_tok_streq(buffer, tok,
|
if (json_tok_streq(buffer, tok,
|
||||||
json_feerate_style_name(FEERATE_PER_KSIPA))) {
|
feerate_style_name(FEERATE_PER_KSIPA))) {
|
||||||
**style = FEERATE_PER_KSIPA;
|
**style = FEERATE_PER_KSIPA;
|
||||||
return NULL;
|
return NULL;
|
||||||
} else if (json_tok_streq(buffer, tok,
|
} else if (json_tok_streq(buffer, tok,
|
||||||
json_feerate_style_name(FEERATE_PER_KBYTE))) {
|
feerate_style_name(FEERATE_PER_KBYTE))) {
|
||||||
**style = FEERATE_PER_KBYTE;
|
**style = FEERATE_PER_KBYTE;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -100,8 +88,8 @@ struct command_result *param_feerate_style(struct command *cmd,
|
|||||||
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||||
"'%s' should be '%s' or '%s', not '%.*s'",
|
"'%s' should be '%s' or '%s', not '%.*s'",
|
||||||
name,
|
name,
|
||||||
json_feerate_style_name(FEERATE_PER_KSIPA),
|
feerate_style_name(FEERATE_PER_KSIPA),
|
||||||
json_feerate_style_name(FEERATE_PER_KBYTE),
|
feerate_style_name(FEERATE_PER_KBYTE),
|
||||||
json_tok_full_len(tok), json_tok_full(buffer, tok));
|
json_tok_full_len(tok), json_tok_full(buffer, tok));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,10 +97,6 @@ struct command_result *param_feerate(struct command *cmd, const char *name,
|
|||||||
const char *buffer, const jsmntok_t *tok,
|
const char *buffer, const jsmntok_t *tok,
|
||||||
u32 **feerate)
|
u32 **feerate)
|
||||||
{
|
{
|
||||||
jsmntok_t base = *tok, suffix = *tok;
|
|
||||||
enum feerate_style style;
|
|
||||||
unsigned int num;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < NUM_FEERATES; i++) {
|
for (size_t i = 0; i < NUM_FEERATES; i++) {
|
||||||
if (json_tok_streq(buffer, tok, feerate_name(i)))
|
if (json_tok_streq(buffer, tok, feerate_name(i)))
|
||||||
return param_feerate_estimate(cmd, feerate, i);
|
return param_feerate_estimate(cmd, feerate, i);
|
||||||
@@ -127,42 +111,8 @@ struct command_result *param_feerate(struct command *cmd, const char *name,
|
|||||||
else if (json_tok_streq(buffer, tok, "urgent"))
|
else if (json_tok_streq(buffer, tok, "urgent"))
|
||||||
return param_feerate_estimate(cmd, feerate, FEERATE_UNILATERAL_CLOSE);
|
return param_feerate_estimate(cmd, feerate, FEERATE_UNILATERAL_CLOSE);
|
||||||
|
|
||||||
/* We have to split the number and suffix. */
|
/* It's a number... */
|
||||||
suffix.start = suffix.end;
|
return param_feerate_val(cmd, name, buffer, tok, feerate);
|
||||||
while (suffix.start > base.start && !isdigit(buffer[suffix.start-1])) {
|
|
||||||
suffix.start--;
|
|
||||||
base.end--;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!json_to_number(buffer, &base, &num)) {
|
|
||||||
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
|
||||||
"'%s' prefix should be an integer, not '%.*s'",
|
|
||||||
name, base.end - base.start,
|
|
||||||
buffer + base.start);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (json_tok_streq(buffer, &suffix, "")
|
|
||||||
|| json_tok_streq(buffer, &suffix,
|
|
||||||
json_feerate_style_name(FEERATE_PER_KBYTE))) {
|
|
||||||
style = FEERATE_PER_KBYTE;
|
|
||||||
} else if (json_tok_streq(buffer, &suffix,
|
|
||||||
json_feerate_style_name(FEERATE_PER_KSIPA))) {
|
|
||||||
style = FEERATE_PER_KSIPA;
|
|
||||||
} else {
|
|
||||||
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
|
||||||
"'%s' suffix should be '%s' or '%s', not '%.*s'",
|
|
||||||
name,
|
|
||||||
json_feerate_style_name(FEERATE_PER_KSIPA),
|
|
||||||
json_feerate_style_name(FEERATE_PER_KBYTE),
|
|
||||||
suffix.end - suffix.start,
|
|
||||||
buffer + suffix.start);
|
|
||||||
}
|
|
||||||
|
|
||||||
*feerate = tal(cmd, u32);
|
|
||||||
**feerate = feerate_from_style(num, style);
|
|
||||||
if (**feerate < FEERATE_FLOOR)
|
|
||||||
**feerate = FEERATE_FLOOR;
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#ifndef LIGHTNING_LIGHTNINGD_JSON_H
|
#ifndef LIGHTNING_LIGHTNINGD_JSON_H
|
||||||
#define LIGHTNING_LIGHTNINGD_JSON_H
|
#define LIGHTNING_LIGHTNINGD_JSON_H
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include <bitcoin/feerate.h>
|
||||||
#include <bitcoin/privkey.h>
|
#include <bitcoin/privkey.h>
|
||||||
#include <ccan/short_types/short_types.h>
|
#include <ccan/short_types/short_types.h>
|
||||||
#include <ccan/tal/tal.h>
|
#include <ccan/tal/tal.h>
|
||||||
@@ -38,11 +39,6 @@ struct command_result *param_short_channel_id(struct command *cmd,
|
|||||||
const jsmntok_t *tok,
|
const jsmntok_t *tok,
|
||||||
struct short_channel_id **scid);
|
struct short_channel_id **scid);
|
||||||
|
|
||||||
enum feerate_style {
|
|
||||||
FEERATE_PER_KSIPA,
|
|
||||||
FEERATE_PER_KBYTE
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Extract a feerate style. */
|
/* Extract a feerate style. */
|
||||||
struct command_result *param_feerate_style(struct command *cmd,
|
struct command_result *param_feerate_style(struct command *cmd,
|
||||||
const char *name,
|
const char *name,
|
||||||
|
|||||||
@@ -12,9 +12,6 @@ void db_commit_transaction(struct db *db UNNEEDED)
|
|||||||
/* Generated stub for fatal */
|
/* Generated stub for fatal */
|
||||||
void fatal(const char *fmt UNNEEDED, ...)
|
void fatal(const char *fmt UNNEEDED, ...)
|
||||||
{ fprintf(stderr, "fatal called!\n"); abort(); }
|
{ fprintf(stderr, "fatal called!\n"); abort(); }
|
||||||
/* Generated stub for feerate_from_style */
|
|
||||||
u32 feerate_from_style(u32 feerate UNNEEDED, enum feerate_style style UNNEEDED)
|
|
||||||
{ fprintf(stderr, "feerate_from_style called!\n"); abort(); }
|
|
||||||
/* Generated stub for feerate_name */
|
/* Generated stub for feerate_name */
|
||||||
const char *feerate_name(enum feerate feerate UNNEEDED)
|
const char *feerate_name(enum feerate feerate UNNEEDED)
|
||||||
{ fprintf(stderr, "feerate_name called!\n"); abort(); }
|
{ fprintf(stderr, "feerate_name called!\n"); abort(); }
|
||||||
@@ -80,6 +77,12 @@ struct command_result *param_feerate_estimate(struct command *cmd UNNEEDED,
|
|||||||
u32 **feerate_per_kw UNNEEDED,
|
u32 **feerate_per_kw UNNEEDED,
|
||||||
enum feerate feerate UNNEEDED)
|
enum feerate feerate UNNEEDED)
|
||||||
{ fprintf(stderr, "param_feerate_estimate called!\n"); abort(); }
|
{ fprintf(stderr, "param_feerate_estimate called!\n"); abort(); }
|
||||||
|
/* Generated stub for param_feerate_val */
|
||||||
|
struct command_result *param_feerate_val(struct command *cmd UNNEEDED,
|
||||||
|
const char *name UNNEEDED, const char *buffer UNNEEDED,
|
||||||
|
const jsmntok_t *tok UNNEEDED,
|
||||||
|
u32 **feerate_per_kw UNNEEDED)
|
||||||
|
{ fprintf(stderr, "param_feerate_val called!\n"); abort(); }
|
||||||
/* Generated stub for param_ignore */
|
/* Generated stub for param_ignore */
|
||||||
struct command_result *param_ignore(struct command *cmd UNNEEDED, const char *name UNNEEDED,
|
struct command_result *param_ignore(struct command *cmd UNNEEDED, const char *name UNNEEDED,
|
||||||
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ PLUGINS := \
|
|||||||
|
|
||||||
PLUGIN_COMMON_OBJS := \
|
PLUGIN_COMMON_OBJS := \
|
||||||
bitcoin/base58.o \
|
bitcoin/base58.o \
|
||||||
|
bitcoin/feerate.o \
|
||||||
bitcoin/privkey.o \
|
bitcoin/privkey.o \
|
||||||
bitcoin/psbt.o \
|
bitcoin/psbt.o \
|
||||||
bitcoin/pubkey.o \
|
bitcoin/pubkey.o \
|
||||||
|
|||||||
@@ -702,7 +702,7 @@ u8 *towire_incorrect_cltv_expiry(const tal_t *ctx UNNEEDED, u32 cltv_expiry UNNE
|
|||||||
u8 *towire_incorrect_or_unknown_payment_details(const tal_t *ctx UNNEEDED, struct amount_msat htlc_msat UNNEEDED, u32 height UNNEEDED)
|
u8 *towire_incorrect_or_unknown_payment_details(const tal_t *ctx UNNEEDED, struct amount_msat htlc_msat UNNEEDED, u32 height UNNEEDED)
|
||||||
{ fprintf(stderr, "towire_incorrect_or_unknown_payment_details called!\n"); abort(); }
|
{ fprintf(stderr, "towire_incorrect_or_unknown_payment_details called!\n"); abort(); }
|
||||||
/* Generated stub for towire_invalid_onion_payload */
|
/* Generated stub for towire_invalid_onion_payload */
|
||||||
u8 *towire_invalid_onion_payload(const tal_t *ctx UNNEEDED, varint type UNNEEDED, u16 offset UNNEEDED)
|
u8 *towire_invalid_onion_payload(const tal_t *ctx UNNEEDED, bigsize type UNNEEDED, u16 offset UNNEEDED)
|
||||||
{ fprintf(stderr, "towire_invalid_onion_payload called!\n"); abort(); }
|
{ fprintf(stderr, "towire_invalid_onion_payload called!\n"); abort(); }
|
||||||
/* Generated stub for towire_invalid_realm */
|
/* Generated stub for towire_invalid_realm */
|
||||||
u8 *towire_invalid_realm(const tal_t *ctx UNNEEDED)
|
u8 *towire_invalid_realm(const tal_t *ctx UNNEEDED)
|
||||||
|
|||||||
Reference in New Issue
Block a user