core-lightning/lightningd/json.c
Rusty Russell 7401b26824 cleanup: remove unneeded includes in C files.
Before:
 Ten builds, laptop -j5, no ccache:

```
real	0m36.686000-38.956000(38.608+/-0.65)s
user	2m32.864000-42.253000(40.7545+/-2.7)s
sys	0m16.618000-18.316000(17.8531+/-0.48)s
```

 Ten builds, laptop -j5, ccache (warm):

```
real	0m8.212000-8.577000(8.39989+/-0.13)s
user	0m12.731000-13.212000(12.9751+/-0.17)s
sys	0m3.697000-3.902000(3.83722+/-0.064)s
```

After:
 Ten builds, laptop -j5, no ccache: 8% faster

```
real	0m33.802000-35.773000(35.468+/-0.54)s
user	2m19.073000-27.754000(26.2542+/-2.3)s
sys	0m15.784000-17.173000(16.7165+/-0.37)s
```

 Ten builds, laptop -j5, ccache (warm): 1% faster

```
real	0m8.200000-8.485000(8.30138+/-0.097)s
user	0m12.485000-13.100000(12.7344+/-0.19)s
sys	0m3.702000-3.889000(3.78787+/-0.056)s
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-17 09:43:22 +09:30

74 lines
2.3 KiB
C

#include <ccan/str/hex/hex.h>
#include <common/json_command.h>
#include <common/json_helpers.h>
#include <common/json_tok.h>
#include <lightningd/chaintopology.h>
#include <lightningd/json.h>
struct command_result *param_pubkey(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t *tok,
struct pubkey **pubkey)
{
*pubkey = tal(cmd, struct pubkey);
if (json_to_pubkey(buffer, tok, *pubkey))
return NULL;
return command_fail_badparam(cmd, name, buffer, tok,
"should be a compressed pubkey");
}
struct command_result *param_feerate_style(struct command *cmd,
const char *name,
const char *buffer,
const jsmntok_t *tok,
enum feerate_style **style)
{
*style = tal(cmd, enum feerate_style);
if (json_tok_streq(buffer, tok,
feerate_style_name(FEERATE_PER_KSIPA))) {
**style = FEERATE_PER_KSIPA;
return NULL;
} else if (json_tok_streq(buffer, tok,
feerate_style_name(FEERATE_PER_KBYTE))) {
**style = FEERATE_PER_KBYTE;
return NULL;
}
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"'%s' should be '%s' or '%s', not '%.*s'",
name,
feerate_style_name(FEERATE_PER_KSIPA),
feerate_style_name(FEERATE_PER_KBYTE),
json_tok_full_len(tok), json_tok_full(buffer, tok));
}
struct command_result *param_feerate(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t *tok,
u32 **feerate)
{
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);
}
/* We used SLOW, NORMAL, and URGENT as feerate targets previously,
* and many commands rely on this syntax now.
* It's also really more natural for an user interface. */
if (json_tok_streq(buffer, tok, "slow"))
return param_feerate_estimate(cmd, feerate, FEERATE_MIN);
else if (json_tok_streq(buffer, tok, "normal"))
return param_feerate_estimate(cmd, feerate, FEERATE_OPENING);
else if (json_tok_streq(buffer, tok, "urgent"))
return param_feerate_estimate(cmd, feerate, FEERATE_UNILATERAL_CLOSE);
/* It's a number... */
return param_feerate_val(cmd, name, buffer, tok, feerate);
}
bool
json_tok_channel_id(const char *buffer, const jsmntok_t *tok,
struct channel_id *cid)
{
return hex_decode(buffer + tok->start, tok->end - tok->start,
cid, sizeof(*cid));
}