2018-08-30 08:48:36 -05:00
|
|
|
#include <ccan/str/hex/hex.h>
|
2018-12-08 11:09:28 +10:30
|
|
|
#include <common/json_command.h>
|
2019-01-15 14:24:27 +10:30
|
|
|
#include <common/json_helpers.h>
|
2021-09-16 14:30:42 +09:30
|
|
|
#include <common/json_tok.h>
|
2019-09-29 21:16:40 +08:00
|
|
|
#include <lightningd/chaintopology.h>
|
2021-09-16 14:20:02 +09:30
|
|
|
#include <lightningd/json.h>
|
2018-03-16 03:45:08 +00:00
|
|
|
|
2018-12-16 15:20:06 +10:30
|
|
|
struct command_result *param_pubkey(struct command *cmd, const char *name,
|
|
|
|
const char *buffer, const jsmntok_t *tok,
|
|
|
|
struct pubkey **pubkey)
|
2018-08-14 16:19:31 -05:00
|
|
|
{
|
|
|
|
*pubkey = tal(cmd, struct pubkey);
|
|
|
|
if (json_to_pubkey(buffer, tok, *pubkey))
|
2018-12-16 15:20:06 +10:30
|
|
|
return NULL;
|
2018-08-14 16:19:31 -05:00
|
|
|
|
2020-08-26 06:50:50 +09:30
|
|
|
return command_fail_badparam(cmd, name, buffer, tok,
|
|
|
|
"should be a compressed pubkey");
|
2019-06-05 14:58:53 +09:30
|
|
|
}
|
|
|
|
|
2018-12-16 15:20:06 +10:30
|
|
|
struct command_result *param_feerate_style(struct command *cmd,
|
|
|
|
const char *name,
|
|
|
|
const char *buffer,
|
|
|
|
const jsmntok_t *tok,
|
|
|
|
enum feerate_style **style)
|
2018-08-27 14:41:39 +09:30
|
|
|
{
|
|
|
|
*style = tal(cmd, enum feerate_style);
|
|
|
|
if (json_tok_streq(buffer, tok,
|
2020-07-08 06:20:21 +09:30
|
|
|
feerate_style_name(FEERATE_PER_KSIPA))) {
|
2018-08-27 14:41:39 +09:30
|
|
|
**style = FEERATE_PER_KSIPA;
|
2018-12-16 15:20:06 +10:30
|
|
|
return NULL;
|
2018-08-27 14:41:39 +09:30
|
|
|
} else if (json_tok_streq(buffer, tok,
|
2020-07-08 06:20:21 +09:30
|
|
|
feerate_style_name(FEERATE_PER_KBYTE))) {
|
2018-08-27 14:41:39 +09:30
|
|
|
**style = FEERATE_PER_KBYTE;
|
2018-12-16 15:20:06 +10:30
|
|
|
return NULL;
|
2018-08-27 14:41:39 +09:30
|
|
|
}
|
|
|
|
|
2018-12-16 15:20:06 +10:30
|
|
|
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
|
|
|
"'%s' should be '%s' or '%s', not '%.*s'",
|
|
|
|
name,
|
2020-07-08 06:20:21 +09:30
|
|
|
feerate_style_name(FEERATE_PER_KSIPA),
|
|
|
|
feerate_style_name(FEERATE_PER_KBYTE),
|
2018-12-16 15:20:06 +10:30
|
|
|
json_tok_full_len(tok), json_tok_full(buffer, tok));
|
2018-08-27 14:41:39 +09:30
|
|
|
}
|
|
|
|
|
2018-12-16 15:20:06 +10:30
|
|
|
struct command_result *param_feerate(struct command *cmd, const char *name,
|
|
|
|
const char *buffer, const jsmntok_t *tok,
|
|
|
|
u32 **feerate)
|
2018-08-29 06:16:32 +09:30
|
|
|
{
|
2018-08-29 06:16:34 +09:30
|
|
|
for (size_t i = 0; i < NUM_FEERATES; i++) {
|
|
|
|
if (json_tok_streq(buffer, tok, feerate_name(i)))
|
2018-12-16 15:20:06 +10:30
|
|
|
return param_feerate_estimate(cmd, feerate, i);
|
2018-08-29 06:16:34 +09:30
|
|
|
}
|
chaintopology: better feerate targets differentiation
We kept track of an URGENT, a NORMAL, and a SLOW feerate. They were used
for opening (NORMAL), mutual (NORMAL), UNILATERAL (URGENT) transactions
as well as minimum and maximum estimations, and onchain resolution.
We now keep track of more fine-grained feerates:
- `opening` used for funding and also misc transactions
- `mutual_close` used for the mutual close transaction
- `unilateral_close` used for unilateral close (commitment transactions)
- `delayed_to_us` used for resolving our output from our unilateral close
- `htlc_resolution` used for resolving onchain HTLCs
- `penalty` used for resolving revoked transactions
We don't modify our requests to our Bitcoin backend, as the next commit
will batch them !
Changelog-deprecated: The "urgent", "slow", and "normal" field of the `feerates` command are now deprecated.
Changelog-added: The fields "opening", "mutual_close", "unilateral_close", "delayed_to_us", "htlc_resolution" and "penalty" have been added to the `feerates` command.
2020-03-10 17:52:13 +01:00
|
|
|
/* 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);
|
2018-08-29 06:16:34 +09:30
|
|
|
|
2020-07-08 06:20:21 +09:30
|
|
|
/* It's a number... */
|
|
|
|
return param_feerate_val(cmd, name, buffer, tok, feerate);
|
2018-08-29 06:16:32 +09:30
|
|
|
}
|
|
|
|
|
2018-04-30 12:54:39 +00:00
|
|
|
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));
|
|
|
|
}
|