Browse Source

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>
keysend
Rusty Russell 5 years ago
committed by Christian Decker
parent
commit
a9427f1a8d
  1. 1
      bitcoin/Makefile
  2. 40
      bitcoin/feerate.c
  3. 10
      bitcoin/feerate.h
  4. 3
      bitcoin/test/run-bitcoin_block_from_hex.c
  5. 3
      bitcoin/test/run-tx-encode.c
  6. 3
      cli/test/run-large-input.c
  7. 3
      cli/test/run-remove-hint.c
  8. 49
      common/json_tok.c
  9. 5
      common/json_tok.h
  10. 3
      common/test/run-bigsize.c
  11. 3
      common/test/run-cryptomsg.c
  12. 3
      common/test/run-derive_basepoints.c
  13. 3
      common/test/run-features.c
  14. 3
      common/test/run-gossip_rcvd_filter.c
  15. 3
      common/test/run-ip_port_parsing.c
  16. 3
      common/test/run-json_remove.c
  17. 3
      common/test/run-key_derive.c
  18. 3
      common/test/run-lock.c
  19. 3
      common/test/run-softref.c
  20. 3
      common/test/run-sphinx.c
  21. 3
      connectd/test/run-initiator-success.c
  22. 3
      connectd/test/run-responder-success.c
  23. 28
      lightningd/chaintopology.c
  24. 4
      lightningd/chaintopology.h
  25. 62
      lightningd/json.c
  26. 6
      lightningd/json.h
  27. 9
      lightningd/test/run-jsonrpc.c
  28. 1
      plugins/Makefile
  29. 2
      wallet/test/run-wallet.c

1
bitcoin/Makefile

@ -4,6 +4,7 @@ BITCOIN_SRC := \
bitcoin/base58.c \
bitcoin/block.c \
bitcoin/chainparams.c \
bitcoin/feerate.c \
bitcoin/locktime.c \
bitcoin/preimage.c \
bitcoin/privkey.c \

40
bitcoin/feerate.c

@ -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();
}

10
bitcoin/feerate.h

@ -33,6 +33,11 @@
*/
#define FEERATE_FLOOR 253
enum feerate_style {
FEERATE_PER_KSIPA,
FEERATE_PER_KBYTE
};
static inline u32 feerate_floor(void)
{
/* Assert that bitcoind will see this as above minRelayTxFee */
@ -47,4 +52,9 @@ static inline u32 feerate_floor(void)
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 */

3
bitcoin/test/run-bitcoin_block_from_hex.c

@ -21,9 +21,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
/* Generated stub for amount_sat_eq */
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
{ 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 */
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
struct amount_sat a UNNEEDED,

3
bitcoin/test/run-tx-encode.c

@ -22,9 +22,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
/* Generated stub for amount_sat_eq */
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
{ 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 */
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
struct amount_sat a UNNEEDED,

3
cli/test/run-large-input.c

@ -47,9 +47,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
/* Generated stub for amount_sat_eq */
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
{ 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 */
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
struct amount_sat a UNNEEDED,

3
cli/test/run-remove-hint.c

@ -50,9 +50,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
/* Generated stub for amount_sat_eq */
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
{ 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 */
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
struct amount_sat a UNNEEDED,

49
common/json_tok.c

@ -1,3 +1,4 @@
#include <bitcoin/feerate.h>
#include <ccan/crypto/sha256/sha256.h>
#include <ccan/json_escape/json_escape.h>
#include <ccan/str/hex/hex.h>
@ -330,3 +331,51 @@ struct command_result *param_secrets_array(struct command *cmd,
}
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;
}

5
common/json_tok.h

@ -131,4 +131,9 @@ struct command_result *param_secrets_array(struct command *cmd,
const jsmntok_t *tok,
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 */

3
common/test/run-bigsize.c

@ -27,9 +27,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
/* Generated stub for amount_sat_eq */
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
{ 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 */
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
struct amount_sat a UNNEEDED,

3
common/test/run-cryptomsg.c

@ -22,9 +22,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
/* Generated stub for amount_sat_eq */
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
{ 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 */
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
struct amount_sat a UNNEEDED,

3
common/test/run-derive_basepoints.c

@ -23,9 +23,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
/* Generated stub for amount_sat_eq */
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
{ 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 */
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
struct amount_sat a UNNEEDED,

3
common/test/run-features.c

@ -22,9 +22,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
/* Generated stub for amount_sat_eq */
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
{ 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 */
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
struct amount_sat a UNNEEDED,

3
common/test/run-gossip_rcvd_filter.c

@ -19,9 +19,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
/* Generated stub for amount_sat_eq */
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
{ 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 */
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
struct amount_sat a UNNEEDED,

3
common/test/run-ip_port_parsing.c

@ -21,9 +21,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
/* Generated stub for amount_sat_eq */
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
{ 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 */
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
struct amount_sat a UNNEEDED,

3
common/test/run-json_remove.c

@ -19,9 +19,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
/* Generated stub for amount_sat_eq */
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
{ 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 */
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
struct amount_sat a UNNEEDED,

3
common/test/run-key_derive.c

@ -24,9 +24,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
/* Generated stub for amount_sat_eq */
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
{ 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 */
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
struct amount_sat a UNNEEDED,

3
common/test/run-lock.c

@ -23,9 +23,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
/* Generated stub for amount_sat_eq */
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
{ 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 */
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
struct amount_sat a UNNEEDED,

3
common/test/run-softref.c

@ -20,9 +20,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
/* Generated stub for amount_sat_eq */
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
{ 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 */
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
struct amount_sat a UNNEEDED,

3
common/test/run-sphinx.c

@ -36,9 +36,6 @@ void amount_msat_from_u64(struct amount_msat *msat UNNEEDED, u64 millisatoshis U
/* Generated stub for amount_sat_eq */
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
{ 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 */
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
struct amount_sat a UNNEEDED,

3
connectd/test/run-initiator-success.c

@ -26,9 +26,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
/* Generated stub for amount_sat_eq */
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
{ 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 */
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
struct amount_sat a UNNEEDED,

3
connectd/test/run-responder-success.c

@ -26,9 +26,6 @@ struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
/* Generated stub for amount_sat_eq */
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
{ 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 */
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
struct amount_sat a UNNEEDED,

28
lightningd/chaintopology.c

@ -466,32 +466,6 @@ u32 penalty_feerate(struct chain_topology *topo)
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,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
@ -516,7 +490,7 @@ static struct command_result *json_feerates(struct command *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++) {
if (!feerates[i] || i == FEERATE_MIN || i == FEERATE_MAX)
continue;

4
lightningd/chaintopology.h

@ -159,10 +159,6 @@ u32 delayed_to_us_feerate(struct chain_topology *topo);
u32 htlc_resolution_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);
/* Set feerate_per_kw to this estimate & return NULL, or fail cmd */

62
lightningd/json.c

@ -1,7 +1,6 @@
#include <arpa/inet.h>
#include <bitcoin/address.h>
#include <bitcoin/base58.h>
#include <bitcoin/feerate.h>
#include <bitcoin/script.h>
#include <ccan/json_escape/json_escape.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));
}
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,
const char *name,
const char *buffer,
@ -88,11 +76,11 @@ struct command_result *param_feerate_style(struct command *cmd,
{
*style = tal(cmd, enum feerate_style);
if (json_tok_streq(buffer, tok,
json_feerate_style_name(FEERATE_PER_KSIPA))) {
feerate_style_name(FEERATE_PER_KSIPA))) {
**style = FEERATE_PER_KSIPA;
return NULL;
} else if (json_tok_streq(buffer, tok,
json_feerate_style_name(FEERATE_PER_KBYTE))) {
feerate_style_name(FEERATE_PER_KBYTE))) {
**style = FEERATE_PER_KBYTE;
return NULL;
}
@ -100,8 +88,8 @@ struct command_result *param_feerate_style(struct command *cmd,
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"'%s' should be '%s' or '%s', not '%.*s'",
name,
json_feerate_style_name(FEERATE_PER_KSIPA),
json_feerate_style_name(FEERATE_PER_KBYTE),
feerate_style_name(FEERATE_PER_KSIPA),
feerate_style_name(FEERATE_PER_KBYTE),
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,
u32 **feerate)
{
jsmntok_t base = *tok, suffix = *tok;
enum feerate_style style;
unsigned int num;
for (size_t i = 0; i < NUM_FEERATES; i++) {
if (json_tok_streq(buffer, tok, feerate_name(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"))
return param_feerate_estimate(cmd, feerate, FEERATE_UNILATERAL_CLOSE);
/* 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,
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;
/* It's a number... */
return param_feerate_val(cmd, name, buffer, tok, feerate);
}
bool

6
lightningd/json.h

@ -5,6 +5,7 @@
#ifndef LIGHTNING_LIGHTNINGD_JSON_H
#define LIGHTNING_LIGHTNINGD_JSON_H
#include "config.h"
#include <bitcoin/feerate.h>
#include <bitcoin/privkey.h>
#include <ccan/short_types/short_types.h>
#include <ccan/tal/tal.h>
@ -38,11 +39,6 @@ struct command_result *param_short_channel_id(struct command *cmd,
const jsmntok_t *tok,
struct short_channel_id **scid);
enum feerate_style {
FEERATE_PER_KSIPA,
FEERATE_PER_KBYTE
};
/* Extract a feerate style. */
struct command_result *param_feerate_style(struct command *cmd,
const char *name,

9
lightningd/test/run-jsonrpc.c

@ -12,9 +12,6 @@ void db_commit_transaction(struct db *db UNNEEDED)
/* Generated stub for fatal */
void fatal(const char *fmt UNNEEDED, ...)
{ 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 */
const char *feerate_name(enum feerate feerate UNNEEDED)
{ 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,
enum feerate feerate UNNEEDED)
{ 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 */
struct command_result *param_ignore(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,

1
plugins/Makefile

@ -37,6 +37,7 @@ PLUGINS := \
PLUGIN_COMMON_OBJS := \
bitcoin/base58.o \
bitcoin/feerate.o \
bitcoin/privkey.o \
bitcoin/psbt.o \
bitcoin/pubkey.o \

2
wallet/test/run-wallet.c

@ -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)
{ fprintf(stderr, "towire_incorrect_or_unknown_payment_details called!\n"); abort(); }
/* 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(); }
/* Generated stub for towire_invalid_realm */
u8 *towire_invalid_realm(const tal_t *ctx UNNEEDED)

Loading…
Cancel
Save