json: fix up msat amounts in non-_msat fields.

We had json_add_amount_msat_only(), which was designed to be used to
print out msat fields, if we had sats.

However, we misused it, so split it into the three different cases:
1. json_add_amount_sat_msat: We are using it correctly, with a field called
   xxx_msat.
2. json_add_amount_sats_deprecated: We were using it wrong, so deprecate
   the old field and create a new one which does end in _msat.
3. json_add_sats: we were using it to hand sats as a JSON parameter to an
   interface, where "XXXsat".

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Deprecated: Plugins: `rbf_channel` and `openchannel2` hooks `their_funding` (use `their_funding_msat`)
Changelog-Deprecated: Plugins: `openchannel2` hook `dust_limit_satoshis` (use `dust_limit_msat`)
Changelog-Deprecated: Plugins: `openchannel` hook `funding_satoshis` (use `funding_msat`)
Changelog-Deprecated: Plugins: `openchannel` hook `dust_limit_satoshis` (use `dust_limit_msat`)
Changelog-Deprecated: Plugins: `openchannel` hook `channel_reserve_satoshis` (use `channel_reserve_msat`)
Changelog-Deprecated: Plugins: `channel_opened` notification `amount` (use `funding_msat`)
Changelog-Deprecated: JSON-RPC: `listtransactions` `msat` (use `amount_msat`)
Changelog-Deprecated: Plugins: `htlc_accepted` `forward_amount` (use `forward_msat`)
This commit is contained in:
Rusty Russell
2022-06-19 16:46:11 +09:30
parent 6e2a775ef2
commit 36a2491a89
42 changed files with 164 additions and 82 deletions

View File

@@ -806,6 +806,7 @@
"ListTransactions.transactions[].inputs[].type": 4
},
"ListtransactionsTransactionsOutputs": {
"ListTransactions.transactions[].outputs[].amount_msat": 6,
"ListTransactions.transactions[].outputs[].channel": 5,
"ListTransactions.transactions[].outputs[].index": 1,
"ListTransactions.transactions[].outputs[].msat": 2,

View File

@@ -767,7 +767,7 @@ message ListtransactionsTransactionsOutputs {
CHANNEL_UNILATERAL_CHEAT = 10;
}
uint32 index = 1;
Amount msat = 2;
Amount amount_msat = 6;
bytes scriptPubKey = 3;
optional ListtransactionsTransactionsOutputsType item_type = 4;
optional string channel = 5;

View File

@@ -546,7 +546,7 @@ impl From<&responses::ListtransactionsTransactionsOutputs> for pb::Listtransacti
fn from(c: &responses::ListtransactionsTransactionsOutputs) -> Self {
Self {
index: c.index.clone(), // Rule #2 for type u32
msat: Some(c.msat.into()), // Rule #2 for type msat
amount_msat: Some(c.amount_msat.into()), // Rule #2 for type msat
script_pub_key: hex::decode(&c.script_pub_key).unwrap(), // Rule #2 for type hex
item_type: c.item_type.map(|v| v as i32),
channel: c.channel.as_ref().map(|v| v.to_string()), // Rule #2 for type short_channel_id?

View File

@@ -1999,8 +1999,8 @@ pub mod responses {
pub struct ListtransactionsTransactionsOutputs {
#[serde(alias = "index")]
pub index: u32,
#[serde(alias = "msat")]
pub msat: Amount,
#[serde(alias = "amount_msat")]
pub amount_msat: Amount,
#[serde(alias = "scriptPubKey")]
pub script_pub_key: String,
#[serde(skip_serializing_if = "Option::is_none")]

View File

@@ -185,7 +185,7 @@ const char *json_scanv(const tal_t *ctx,
/* '"fieldname" : "value"' or '"value"' if fieldname is NULL. Turns
* any non-printable chars into JSON escapes, but leaves existing escapes alone.
*/
void json_add_string(struct json_stream *result, const char *fieldname, const char *value);
void json_add_string(struct json_stream *result, const char *fieldname, const char *value TAKES);
/* '"fieldname" : "value[:value_len]"' or '"value[:value_len]"' if
* fieldname is NULL. Turns any non-printable chars into JSON

View File

@@ -1,7 +1,9 @@
#include "config.h"
#include <arpa/inet.h>
#include <assert.h>
#include <bitcoin/psbt.h>
#include <ccan/ccan/str/hex/hex.h>
#include <common/configdir.h>
#include <common/json_helpers.h>
#include <common/json_stream.h>
#include <common/type_to_string.h>
@@ -417,19 +419,43 @@ void json_add_amount_sat_compat(struct json_stream *result,
const char *msatfieldname)
{
json_add_u64(result, rawfieldname, sat.satoshis); /* Raw: low-level helper */
json_add_amount_sat_only(result, msatfieldname, sat);
json_add_amount_sat_msat(result, msatfieldname, sat);
}
void json_add_amount_sat_only(struct json_stream *result,
const char *msatfieldname,
struct amount_sat sat)
void json_add_amount_sat_msat(struct json_stream *result,
const char *msatfieldname,
struct amount_sat sat)
{
struct amount_msat msat;
assert(strends(msatfieldname, "_msat"));
if (amount_sat_to_msat(&msat, sat))
json_add_string(result, msatfieldname,
type_to_string(tmpctx, struct amount_msat, &msat));
}
/* When I noticed that we were adding "XXXmsat" fields *not* ending in _msat */
void json_add_amount_sats_deprecated(struct json_stream *result,
const char *fieldname,
const char *msatfieldname,
struct amount_sat sat)
{
if (deprecated_apis) {
struct amount_msat msat;
assert(!strends(fieldname, "_msat"));
if (amount_sat_to_msat(&msat, sat))
json_add_string(result, fieldname,
take(fmt_amount_msat(NULL, msat)));
}
json_add_amount_sat_msat(result, msatfieldname, sat);
}
void json_add_sats(struct json_stream *result,
const char *fieldname,
struct amount_sat sat)
{
json_add_string(result, fieldname, take(fmt_amount_sat(NULL, sat)));
}
void json_add_secret(struct json_stream *response, const char *fieldname,
const struct secret *secret)
{
@@ -451,7 +477,7 @@ void json_add_preimage(struct json_stream *result, const char *fieldname,
void json_add_lease_rates(struct json_stream *result,
const struct lease_rates *rates)
{
json_add_amount_sat_only(result, "lease_fee_base_msat",
json_add_amount_sat_msat(result, "lease_fee_base_msat",
amount_sat(rates->lease_fee_base_sat));
json_add_num(result, "lease_fee_basis", rates->lease_fee_basis);
json_add_num(result, "funding_weight", rates->funding_weight);

View File

@@ -167,11 +167,24 @@ void json_add_amount_msat_only(struct json_stream *result,
NO_NULL_ARGS;
/* Adds an 'msat' field */
void json_add_amount_sat_only(struct json_stream *result,
const char *msatfieldname,
struct amount_sat sat)
void json_add_amount_sat_msat(struct json_stream *result,
const char *msatfieldname,
struct amount_sat sat)
NO_NULL_ARGS;
/* Adds an 'msat' field, and an older deprecated field. */
void json_add_amount_sats_deprecated(struct json_stream *result,
const char *fieldname,
const char *msatfieldname,
struct amount_sat sat)
NO_NULL_ARGS;
/* This is used to create requests, *never* for output (output is always
* msat!) */
void json_add_sats(struct json_stream *result,
const char *fieldname,
struct amount_sat sat);
void json_add_sha256(struct json_stream *result, const char *fieldname,
const struct sha256 *hash);

View File

@@ -8,6 +8,8 @@
#include <stdio.h>
/* AUTOGENERATED MOCKS START */
/* Generated stub for deprecated_apis */
bool deprecated_apis;
/* Generated stub for fromwire_tlv */
bool fromwire_tlv(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
const struct tlv_record_type *types UNNEEDED, size_t num_types UNNEEDED,

View File

@@ -53,6 +53,14 @@ struct amount_asset amount_sat_to_asset(struct amount_sat *sat UNNEEDED, const u
/* Generated stub for amount_tx_fee */
struct amount_sat amount_tx_fee(u32 fee_per_kw UNNEEDED, size_t weight UNNEEDED)
{ fprintf(stderr, "amount_tx_fee called!\n"); abort(); }
/* Generated stub for deprecated_apis */
bool deprecated_apis;
/* Generated stub for fmt_amount_msat */
const char *fmt_amount_msat(const tal_t *ctx UNNEEDED, struct amount_msat msat UNNEEDED)
{ fprintf(stderr, "fmt_amount_msat called!\n"); abort(); }
/* Generated stub for fmt_amount_sat */
const char *fmt_amount_sat(const tal_t *ctx UNNEEDED, struct amount_sat sat UNNEEDED)
{ fprintf(stderr, "fmt_amount_sat called!\n"); abort(); }
/* Generated stub for fromwire_amount_msat */
struct amount_msat fromwire_amount_msat(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_amount_msat called!\n"); abort(); }

View File

@@ -53,6 +53,14 @@ struct amount_asset amount_sat_to_asset(struct amount_sat *sat UNNEEDED, const u
/* Generated stub for amount_tx_fee */
struct amount_sat amount_tx_fee(u32 fee_per_kw UNNEEDED, size_t weight UNNEEDED)
{ fprintf(stderr, "amount_tx_fee called!\n"); abort(); }
/* Generated stub for deprecated_apis */
bool deprecated_apis;
/* Generated stub for fmt_amount_msat */
const char *fmt_amount_msat(const tal_t *ctx UNNEEDED, struct amount_msat msat UNNEEDED)
{ fprintf(stderr, "fmt_amount_msat called!\n"); abort(); }
/* Generated stub for fmt_amount_sat */
const char *fmt_amount_sat(const tal_t *ctx UNNEEDED, struct amount_sat sat UNNEEDED)
{ fprintf(stderr, "fmt_amount_sat called!\n"); abort(); }
/* Generated stub for fmt_wireaddr_without_port */
char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED)
{ fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); }

View File

@@ -22,6 +22,7 @@ DEVTOOLS_COMMON_OBJS := \
common/bolt11.o \
common/blockheight_states.o \
common/channel_id.o \
common/configdir.o \
common/decode_array.o \
common/features.o \
common/fee_states.o \

View File

@@ -5,6 +5,7 @@
#include <ccan/tal/str/str.h>
#include <common/bech32_util.h>
#include <common/bolt12_merkle.h>
#include <common/configdir.h>
#include <common/features.h>
#include <common/iso4217.h>
#include <common/setup.h>
@@ -20,7 +21,6 @@
#define ERROR_USAGE 3
static bool well_formed = true;
bool deprecated_apis = true;
/* Tal wrappers for opt. */
static void *opt_allocfn(size_t size)
@@ -463,6 +463,7 @@ int main(int argc, char *argv[])
char *fail;
common_setup(argv[0]);
deprecated_apis = true;
opt_set_alloc(opt_allocfn, tal_reallocfn, tal_freefn);
opt_register_noarg("--help|-h", opt_usage_and_exit,

View File

@@ -410,7 +410,7 @@ if the funding transaction has been included into a block.
{
"channel_opened": {
"id": "03864ef025fde8fb587d989186ce6a4a186895ee44a926bfc370e2c366597a3f8f",
"funding_satoshis": "100000000msat",
"funding_msat": "100000000msat",
"funding_txid": "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b",
"funding_locked": false
}
@@ -721,7 +721,7 @@ i.e. only definitively resolved HTLCs or confirmed bitcoin transactions.
"part_id": 0, // (`channel_mvt` only, optional)
"credit":"2000000000msat",
"debit":"0msat",
"output_value": "2000000000msat", // ('chain_mvt' only)
"output_msat": "2000000000msat", // ('chain_mvt' only)
"output_count": 2, // ('chain_mvt' only, typically only channel closes)
"fees": "382msat", // ('channel_mvt' only)
"tags": ["deposit"],
@@ -1185,8 +1185,8 @@ the v2 protocol, and it has passed basic sanity checks:
"openchannel2": {
"id": "03864ef025fde8fb587d989186ce6a4a186895ee44a926bfc370e2c366597a3f8f",
"channel_id": "252d1b0a1e57895e84137f28cf19ab2c35847e284c112fefdecc7afeaa5c1de7",
"their_funding": "100000000msat",
"dust_limit_satoshis": "546000msat",
"their_funding_msat": "100000000msat",
"dust_limit_msat": "546000msat",
"max_htlc_value_in_flight_msat": "18446744073709551615msat",
"htlc_minimum_msat": "0msat",
"funding_feerate_per_kw": 7500,
@@ -1323,7 +1323,7 @@ requests an RBF for a channel funding transaction.
"rbf_channel": {
"id": "03864ef025fde8fb587d989186ce6a4a186895ee44a926bfc370e2c366597a3f8f",
"channel_id": "252d1b0a1e57895e84137f28cf19ab2c35847e284c112fefdecc7afeaa5c1de7",
"their_funding": "100000000msat",
"their_funding_msat": "100000000msat",
"funding_feerate_per_kw": 7500,
"feerate_our_max": 10000,
"feerate_our_min": 253,

View File

@@ -40,7 +40,7 @@ On success, an object containing **transactions** is returned. It is an array o
- **channel** (short_channel_id, optional): the channel this input is associated with (*EXPERIMENTAL_FEATURES* only)
- **outputs** (array of objects): Each output, in order:
- **index** (u32): the 0-based output number
- **msat** (msat): the amount of the output
- **amount_msat** (msat): the amount of the output
- **scriptPubKey** (hex): the scriptPubKey
- **type** (string, optional): the purpose of this output (*EXPERIMENTAL_FEATURES* only) (one of "theirs", "deposit", "withdraw", "channel_funding", "channel_mutual_close", "channel_unilateral_close", "channel_sweep", "channel_htlc_success", "channel_htlc_timeout", "channel_penalty", "channel_unilateral_cheat")
- **channel** (short_channel_id, optional): the channel this output is associated with (*EXPERIMENTAL_FEATURES* only)
@@ -104,4 +104,4 @@ RESOURCES
---------
Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:bd9c33dd27be0f25b0212b4115714768ffbec2ff6e72f083613a4464a3f98bc0)
[comment]: # ( SHA256STAMP:74408f25dcf548f1389ab41123748297ba3116ad75afb41b86ecca453b95fec8)

View File

@@ -126,7 +126,7 @@
"additionalProperties": false,
"required": [
"index",
"msat",
"amount_msat",
"scriptPubKey"
],
"properties": {
@@ -134,10 +134,13 @@
"type": "u32",
"description": "the 0-based output number"
},
"msat": {
"amount_msat": {
"type": "msat",
"description": "the amount of the output"
},
"msat": {
"deprecated": true
},
"scriptPubKey": {
"type": "hex",
"description": "the scriptPubKey"

View File

@@ -59,6 +59,8 @@ bool cupdate_different(struct gossip_store *gs UNNEEDED,
const struct half_chan *hc UNNEEDED,
const u8 *cupdate UNNEEDED)
{ fprintf(stderr, "cupdate_different called!\n"); abort(); }
/* Generated stub for deprecated_apis */
bool deprecated_apis;
/* Generated stub for ecdh */
void ecdh(const struct pubkey *point UNNEEDED, struct secret *ss UNNEEDED)
{ fprintf(stderr, "ecdh called!\n"); abort(); }

View File

@@ -27,6 +27,8 @@ bool blinding_next_pubkey(const struct pubkey *pk UNNEEDED,
/* Generated stub for daemon_conn_send */
void daemon_conn_send(struct daemon_conn *dc UNNEEDED, const u8 *msg UNNEEDED)
{ fprintf(stderr, "daemon_conn_send called!\n"); abort(); }
/* Generated stub for deprecated_apis */
bool deprecated_apis;
/* Generated stub for ecdh */
void ecdh(const struct pubkey *point UNNEEDED, struct secret *ss UNNEEDED)
{ fprintf(stderr, "ecdh called!\n"); abort(); }

View File

@@ -45,6 +45,8 @@ bigsize_t *decode_scid_query_flags(const tal_t *ctx UNNEEDED,
/* Generated stub for decode_short_ids */
struct short_channel_id *decode_short_ids(const tal_t *ctx UNNEEDED, const u8 *encoded UNNEEDED)
{ fprintf(stderr, "decode_short_ids called!\n"); abort(); }
/* Generated stub for deprecated_apis */
bool deprecated_apis;
/* Generated stub for ecdh */
void ecdh(const struct pubkey *point UNNEEDED, struct secret *ss UNNEEDED)
{ fprintf(stderr, "ecdh called!\n"); abort(); }

View File

@@ -45,6 +45,8 @@ bigsize_t *decode_scid_query_flags(const tal_t *ctx UNNEEDED,
/* Generated stub for decode_short_ids */
struct short_channel_id *decode_short_ids(const tal_t *ctx UNNEEDED, const u8 *encoded UNNEEDED)
{ fprintf(stderr, "decode_short_ids called!\n"); abort(); }
/* Generated stub for deprecated_apis */
bool deprecated_apis;
/* Generated stub for ecdh */
void ecdh(const struct pubkey *point UNNEEDED, struct secret *ss UNNEEDED)
{ fprintf(stderr, "ecdh called!\n"); abort(); }

View File

@@ -26,6 +26,8 @@ bool blinding_next_pubkey(const struct pubkey *pk UNNEEDED,
const struct sha256 *h UNNEEDED,
struct pubkey *next UNNEEDED)
{ fprintf(stderr, "blinding_next_pubkey called!\n"); abort(); }
/* Generated stub for deprecated_apis */
bool deprecated_apis;
/* Generated stub for ecdh */
void ecdh(const struct pubkey *point UNNEEDED, struct secret *ss UNNEEDED)
{ fprintf(stderr, "ecdh called!\n"); abort(); }

View File

@@ -30,6 +30,8 @@ bool cupdate_different(struct gossip_store *gs UNNEEDED,
const struct half_chan *hc UNNEEDED,
const u8 *cupdate UNNEEDED)
{ fprintf(stderr, "cupdate_different called!\n"); abort(); }
/* Generated stub for deprecated_apis */
bool deprecated_apis;
/* Generated stub for ecdh */
void ecdh(const struct pubkey *point UNNEEDED, struct secret *ss UNNEEDED)
{ fprintf(stderr, "ecdh called!\n"); abort(); }

View File

@@ -195,8 +195,9 @@ static void rbf_channel_hook_serialize(struct rbf_channel_payload *payload,
json_object_start(stream, "rbf_channel");
json_add_node_id(stream, "id", &payload->peer_id);
json_add_channel_id(stream, "channel_id", &payload->channel_id);
json_add_amount_sat_only(stream, "their_funding",
payload->their_funding);
json_add_amount_sats_deprecated(stream,
"their_funding", "their_funding_msat",
payload->their_funding);
json_add_num(stream, "locktime", payload->locktime);
json_add_num(stream, "feerate_our_max",
payload->feerate_our_max);
@@ -204,7 +205,7 @@ static void rbf_channel_hook_serialize(struct rbf_channel_payload *payload,
payload->feerate_our_min);
json_add_num(stream, "funding_feerate_per_kw",
payload->funding_feerate_per_kw);
json_add_amount_sat_only(stream, "channel_max_msat",
json_add_amount_sat_msat(stream, "channel_max_msat",
payload->channel_max);
json_object_end(stream);
}
@@ -263,10 +264,11 @@ static void openchannel2_hook_serialize(struct openchannel2_payload *payload,
json_object_start(stream, "openchannel2");
json_add_node_id(stream, "id", &payload->peer_id);
json_add_channel_id(stream, "channel_id", &payload->channel_id);
json_add_amount_sat_only(stream, "their_funding",
payload->their_funding);
json_add_amount_sat_only(stream, "dust_limit_satoshis",
payload->dust_limit_satoshis);
json_add_amount_sats_deprecated(stream, "their_funding", "their_funding_msat",
payload->their_funding);
json_add_amount_sats_deprecated(stream, "dust_limit_satoshis",
"dust_limit_msat",
payload->dust_limit_satoshis);
json_add_amount_msat_only(stream, "max_htlc_value_in_flight_msat",
payload->max_htlc_value_in_flight_msat);
json_add_amount_msat_only(stream, "htlc_minimum_msat",
@@ -286,10 +288,10 @@ static void openchannel2_hook_serialize(struct openchannel2_payload *payload,
if (tal_bytelen(payload->shutdown_scriptpubkey) != 0)
json_add_hex_talarr(stream, "shutdown_scriptpubkey",
payload->shutdown_scriptpubkey);
json_add_amount_sat_only(stream, "channel_max_msat",
json_add_amount_sat_msat(stream, "channel_max_msat",
payload->channel_max);
if (!amount_sat_zero(payload->requested_lease_amt)) {
json_add_amount_sat_only(stream, "requested_lease_msat",
json_add_amount_sat_msat(stream, "requested_lease_msat",
payload->requested_lease_amt);
json_add_num(stream, "lease_blockheight_start",
payload->lease_blockheight_start);
@@ -1632,8 +1634,8 @@ static void handle_dry_run_finished(struct subd *dualopend, const u8 *msg)
channel->open_attempt = tal_free(channel->open_attempt);
response = json_stream_success(cmd);
json_add_amount_sat_only(response, "our_funding_msat", our_funding);
json_add_amount_sat_only(response, "their_funding_msat", their_funding);
json_add_amount_sat_msat(response, "our_funding_msat", our_funding);
json_add_amount_sat_msat(response, "their_funding_msat", their_funding);
if (rates) {
json_add_lease_rates(response, rates);

View File

@@ -401,7 +401,7 @@ static struct command_result *json_setleaserates(struct command *cmd,
take(towire_gossipd_new_lease_rates(NULL, rates)));
res = json_stream_success(cmd);
json_add_amount_sat_only(res, "lease_fee_base_msat",
json_add_amount_sat_msat(res, "lease_fee_base_msat",
amount_sat(rates->lease_fee_base_sat));
json_add_num(res, "lease_fee_basis", rates->lease_fee_basis);
json_add_num(res, "funding_weight", rates->funding_weight);

View File

@@ -205,7 +205,7 @@ static void channel_opened_notification_serialize(struct json_stream *stream,
{
json_object_start(stream, "channel_opened");
json_add_node_id(stream, "id", node_id);
json_add_amount_sat_only(stream, "amount", *funding_sat);
json_add_amount_sats_deprecated(stream, "amount", "funding_msat", *funding_sat);
json_add_txid(stream, "funding_txid", funding_txid);
json_add_bool(stream, "funding_locked", funding_locked);
json_object_end(stream);
@@ -482,8 +482,9 @@ static void coin_movement_notification_serialize(struct json_stream *stream,
json_add_amount_msat_only(stream, "debit", mvt->debit);
/* Only chain movements */
if (mvt->output_val)
json_add_amount_sat_only(stream, "output_value",
*mvt->output_val);
json_add_amount_sats_deprecated(stream, "output_value",
"output_msat",
*mvt->output_val);
if (mvt->output_count > 0)
json_add_num(stream, "output_count",
mvt->output_count);

View File

@@ -605,14 +605,14 @@ static void openchannel_hook_serialize(struct openchannel_hook_payload *payload,
struct uncommitted_channel *uc = payload->openingd->channel;
json_object_start(stream, "openchannel");
json_add_node_id(stream, "id", &uc->peer->id);
json_add_amount_sat_only(stream, "funding_satoshis",
payload->funding_satoshis);
json_add_amount_sats_deprecated(stream, "funding_satoshis", "funding_msat",
payload->funding_satoshis);
json_add_amount_msat_only(stream, "push_msat", payload->push_msat);
json_add_amount_sat_only(stream, "dust_limit_satoshis",
payload->dust_limit_satoshis);
json_add_amount_sats_deprecated(stream, "dust_limit_satoshis", "dust_limit_msat",
payload->dust_limit_satoshis);
json_add_amount_msat_only(stream, "max_htlc_value_in_flight_msat",
payload->max_htlc_value_in_flight_msat);
json_add_amount_sat_only(stream, "channel_reserve_satoshis",
json_add_amount_sats_deprecated(stream, "channel_reserve_satoshis", "channel_reserve_msat",
payload->channel_reserve_satoshis);
json_add_amount_msat_only(stream, "htlc_minimum_msat",
payload->htlc_minimum_msat);

View File

@@ -639,7 +639,7 @@ static void json_add_channel(struct lightningd *ld,
bitcoin_txid(channel->last_tx, &txid);
json_add_txid(response, "scratch_txid", &txid);
json_add_amount_sat_only(response, "last_tx_fee_msat",
json_add_amount_sat_msat(response, "last_tx_fee_msat",
bitcoin_tx_compute_fee(channel->last_tx));
}
@@ -708,10 +708,10 @@ static void json_add_channel(struct lightningd *ld,
inflight->funding->feerate,
feerate_style_name(
FEERATE_PER_KSIPA)));
json_add_amount_sat_only(response,
json_add_amount_sat_msat(response,
"total_funding_msat",
inflight->funding->total_funds);
json_add_amount_sat_only(response,
json_add_amount_sat_msat(response,
"our_funding_msat",
inflight->funding->our_funds);
/* Add the expected commitment tx id also */

View File

@@ -1044,7 +1044,11 @@ static void htlc_accepted_hook_serialize(struct htlc_accepted_hook_payload *p,
if (p->payload->forward_channel)
json_add_short_channel_id(s, "short_channel_id",
p->payload->forward_channel);
json_add_amount_msat_only(s, "forward_amount",
if (deprecated_apis)
json_add_string(s, "forward_amount",
fmt_amount_msat(tmpctx,
p->payload->amt_to_forward));
json_add_amount_msat_only(s, "forward_msat",
p->payload->amt_to_forward);
json_add_u32(s, "outgoing_cltv_value", p->payload->outgoing_cltv);
/* These are specified together in TLV, so only print total_msat

View File

@@ -316,12 +316,12 @@ void json_add_amount_sat_compat(struct json_stream *result UNNEEDED,
const char *msatfieldname)
{ fprintf(stderr, "json_add_amount_sat_compat called!\n"); abort(); }
/* Generated stub for json_add_amount_sat_only */
void json_add_amount_sat_only(struct json_stream *result UNNEEDED,
const char *msatfieldname UNNEEDED,
struct amount_sat sat)
/* Generated stub for json_add_amount_sat_msat */
void json_add_amount_sat_msat(struct json_stream *result UNNEEDED,
const char *msatfieldname UNNEEDED,
struct amount_sat sat)
{ fprintf(stderr, "json_add_amount_sat_only called!\n"); abort(); }
{ fprintf(stderr, "json_add_amount_sat_msat called!\n"); abort(); }
/* Generated stub for json_add_bolt11 */
void json_add_bolt11(struct json_stream *response UNNEEDED,
const struct bolt11 *b11 UNNEEDED)

View File

@@ -414,7 +414,7 @@ static struct command_result *process_getutxout(struct bitcoin_cli *bcli)
return command_err_bcli_badjson(bcli, err);
response = jsonrpc_stream_success(bcli->cmd);
json_add_amount_sat_only(response, "amount", output.amount);
json_add_sats(response, "amount", output.amount);
json_add_string(response, "script", tal_hex(response, output.script));
return command_finished(bcli->cmd, response);

View File

@@ -511,7 +511,7 @@ json_openchannel2_call(struct command *cmd,
"{openchannel2:"
"{id:%"
",channel_id:%"
",their_funding:%"
",their_funding_msat:%"
",max_htlc_value_in_flight_msat:%"
",htlc_minimum_msat:%"
",funding_feerate_per_kw:%"
@@ -768,15 +768,15 @@ static void json_add_policy(struct json_stream *stream,
funder_opt_name(policy->opt));
json_add_num(stream, "policy_mod", policy->mod);
json_add_bool(stream, "leases_only", policy->leases_only);
json_add_amount_sat_only(stream, "min_their_funding_msat",
json_add_amount_sat_msat(stream, "min_their_funding_msat",
policy->min_their_funding);
json_add_amount_sat_only(stream, "max_their_funding_msat",
json_add_amount_sat_msat(stream, "max_their_funding_msat",
policy->max_their_funding);
json_add_amount_sat_only(stream, "per_channel_min_msat",
json_add_amount_sat_msat(stream, "per_channel_min_msat",
policy->per_channel_min);
json_add_amount_sat_only(stream, "per_channel_max_msat",
json_add_amount_sat_msat(stream, "per_channel_max_msat",
policy->per_channel_max);
json_add_amount_sat_only(stream, "reserve_tank_msat",
json_add_amount_sat_msat(stream, "reserve_tank_msat",
policy->reserve_tank);
json_add_num(stream, "fuzz_percent", policy->fuzz_factor);
json_add_num(stream, "fund_probability", policy->fund_probability);

View File

@@ -73,7 +73,7 @@ void json_add_short_channel_id(struct json_stream *response UNNEEDED,
const struct short_channel_id *id UNNEEDED)
{ fprintf(stderr, "json_add_short_channel_id called!\n"); abort(); }
/* Generated stub for json_add_string */
void json_add_string(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, const char *value UNNEEDED)
void json_add_string(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, const char *value TAKES UNNEEDED)
{ fprintf(stderr, "json_add_string called!\n"); abort(); }
/* Generated stub for json_add_timeabs */
void json_add_timeabs(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,

View File

@@ -378,7 +378,7 @@ static struct command_result *txprepare_continue(struct command *cmd,
}
if (txp->all_output_idx == -1)
json_add_amount_sat_only(req->js, "satoshi", txp->output_total);
json_add_sats(req->js, "satoshi", txp->output_total);
else
json_add_string(req->js, "satoshi", "all");

View File

@@ -18,7 +18,7 @@ def init(plugin, options, configuration):
def channel_opened(plugin, channel_opened, **kwargs):
plugin.log("A channel was opened to us by {}, with an amount"
" of {} and the following funding transaction id: {}"
.format(channel_opened["id"], channel_opened["amount"],
.format(channel_opened["id"], channel_opened["funding_msat"],
channel_opened["funding_txid"]))

View File

@@ -52,13 +52,13 @@ def run_openchannel(funding_sats_str, plugin):
@plugin.hook('openchannel')
def on_openchannel(openchannel, plugin, **kwargs):
return run_openchannel(openchannel['funding_satoshis'], plugin)
return run_openchannel(openchannel['funding_msat'], plugin)
@plugin.hook('openchannel2')
def on_openchannel2(openchannel2, plugin, **kwargs):
""" Support for v2 channel opens """
return run_openchannel(openchannel2['their_funding'], plugin)
return run_openchannel(openchannel2['their_funding_msat'], plugin)
plugin.run()

View File

@@ -21,7 +21,7 @@ def on_openchannel(openchannel, plugin, **kwargs):
print("{} VARS".format(len(openchannel.keys())))
for k in sorted(openchannel.keys()):
print("{}={}".format(k, openchannel[k]))
return run_check(openchannel['funding_satoshis'])
return run_check(openchannel['funding_msat'])
@plugin.hook('openchannel2')
@@ -30,7 +30,7 @@ def on_openchannel2(openchannel2, plugin, **kwargs):
for k in sorted(openchannel2.keys()):
print("{}={}".format(k, openchannel2[k]))
return run_check(openchannel2['their_funding'])
return run_check(openchannel2['their_funding_msat'])
plugin.run()

View File

@@ -3111,7 +3111,7 @@ def test_partial_payment(node_factory, bitcoind, executor):
for i in range(2):
line = l4.daemon.wait_for_log('print_htlc_onion.py: Got onion')
assert "'type': 'tlv'" in line
assert "'forward_amount': '499msat'" in line or "'forward_amount': '501msat'" in line
assert "'forward_msat': '499msat'" in line or "'forward_msat': '501msat'" in line
assert "'total_msat': '1000msat'" in line
assert "'payment_secret': '{}'".format(paysecret) in line

View File

@@ -626,7 +626,7 @@ def test_openchannel_hook(node_factory, bitcoind):
# Make sure plugin got all the vars we expect
expected = {
'channel_flags': '1',
'dust_limit_satoshis': '546000msat',
'dust_limit_msat': '546000msat',
'htlc_minimum_msat': '0msat',
'id': l1.info['id'],
'max_accepted_htlcs': '483',
@@ -643,14 +643,14 @@ def test_openchannel_hook(node_factory, bitcoind):
'feerate_our_max': '150000',
'feerate_our_min': '1875',
'locktime': '.*',
'their_funding': '100000000msat',
'their_funding_msat': '100000000msat',
'channel_max_msat': '16777215000msat',
})
else:
expected.update({
'channel_reserve_satoshis': '1000000msat',
'channel_reserve_msat': '1000000msat',
'feerate_per_kw': '7500',
'funding_satoshis': '100000000msat',
'funding_msat': '100000000msat',
'push_msat': '0msat',
})
@@ -1148,7 +1148,7 @@ def test_htlc_accepted_hook_forward_restart(node_factory, executor):
assert onion['type'] == 'tlv'
assert re.match(r'^11020203e80401..0608................$', onion['payload'])
assert len(onion['shared_secret']) == 64
assert onion['forward_amount'] == '1000msat'
assert onion['forward_msat'] == '1000msat'
assert len(onion['next_onion']) == 2 * (1300 + 32 + 33 + 1)
f1.result()

View File

@@ -952,7 +952,7 @@ def test_transaction_annotations(node_factory, bitcoind):
assert(len(txs) == 1)
tx = txs[0]
output = tx['outputs'][idx]
assert(output['type'] == 'deposit' and output['msat'] == Millisatoshi(1000000000))
assert(output['type'] == 'deposit' and output['amount_msat'] == Millisatoshi(1000000000))
# ... and all other output should be change, and have no annotations
types = []

View File

@@ -189,7 +189,7 @@ def extract_utxos(moves):
for ev in evs:
if ev[0]['vout'] == m['vout']:
ev[1] = m
assert ev[0]['output_value'] == m['output_value']
assert ev[0]['output_msat'] == m['output_msat']
break
return utxos

View File

@@ -413,7 +413,7 @@ fee_calc:
json_add_psbt(response, "psbt", psbt);
json_add_num(response, "feerate_per_kw", feerate_per_kw);
json_add_num(response, "estimated_final_weight", weight);
json_add_amount_sat_only(response, "excess_msat", excess);
json_add_amount_sat_msat(response, "excess_msat", excess);
if (excess_as_change)
json_add_num(response, "change_outnum", change_outnum);
if (reserve)

View File

@@ -302,12 +302,12 @@ void json_add_amount_sat_compat(struct json_stream *result UNNEEDED,
const char *msatfieldname)
{ fprintf(stderr, "json_add_amount_sat_compat called!\n"); abort(); }
/* Generated stub for json_add_amount_sat_only */
void json_add_amount_sat_only(struct json_stream *result UNNEEDED,
const char *msatfieldname UNNEEDED,
struct amount_sat sat)
/* Generated stub for json_add_amount_sat_msat */
void json_add_amount_sat_msat(struct json_stream *result UNNEEDED,
const char *msatfieldname UNNEEDED,
struct amount_sat sat)
{ fprintf(stderr, "json_add_amount_sat_only called!\n"); abort(); }
{ fprintf(stderr, "json_add_amount_sat_msat called!\n"); abort(); }
/* Generated stub for json_add_bool */
void json_add_bool(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
bool value UNNEEDED)
@@ -356,7 +356,7 @@ void json_add_short_channel_id(struct json_stream *response UNNEEDED,
const struct short_channel_id *id UNNEEDED)
{ fprintf(stderr, "json_add_short_channel_id called!\n"); abort(); }
/* Generated stub for json_add_string */
void json_add_string(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, const char *value UNNEEDED)
void json_add_string(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, const char *value TAKES UNNEEDED)
{ fprintf(stderr, "json_add_string called!\n"); abort(); }
/* Generated stub for json_add_timeabs */
void json_add_timeabs(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,

View File

@@ -558,7 +558,7 @@ static void json_transaction_details(struct json_stream *response,
json_object_start(response, NULL);
json_add_u32(response, "index", i);
json_add_amount_sat_only(response, "msat", sat);
json_add_amount_sats_deprecated(response, "msat", "amount_msat", sat);
#if EXPERIMENTAL_FEATURES
struct tx_annotation *ann = &tx->output_annotations[i];