From 0eb65e4bb5fe575f9c7327ddc05db0757fdd18da Mon Sep 17 00:00:00 2001 From: daywalker90 <8257956+daywalker90@users.noreply.github.com> Date: Fri, 24 May 2024 12:50:20 +0200 Subject: [PATCH] schemas: use sat and sat_or_all again where appropiate Changelog-None --- cln-grpc/src/convert.rs | 48 +++++++++---------- contrib/msggen/msggen/gen/grpc/convert.py | 4 ++ contrib/msggen/msggen/gen/grpc/unconvert.py | 4 ++ contrib/msggen/msggen/gen/grpc/util.py | 2 + contrib/msggen/msggen/gen/grpc2py.py | 5 ++ contrib/msggen/msggen/gen/rpc/rust.py | 2 + contrib/msggen/msggen/model.py | 2 + contrib/msggen/msggen/schema.json | 24 +++++----- contrib/pyln-testing/pyln/testing/fixtures.py | 7 +++ contrib/pyln-testing/pyln/testing/grpc2py.py | 4 ++ doc/rpc-schema-draft.json | 1 + doc/schemas/lightning-addpsbtoutput.json | 2 +- doc/schemas/lightning-fundchannel.json | 4 +- doc/schemas/lightning-fundchannel_start.json | 4 +- doc/schemas/lightning-fundpsbt.json | 2 +- doc/schemas/lightning-multifundchannel.json | 4 +- doc/schemas/lightning-openchannel_bump.json | 2 +- doc/schemas/lightning-openchannel_init.json | 2 +- doc/schemas/lightning-utxopsbt.json | 2 +- doc/schemas/lightning-withdraw.json | 2 +- 20 files changed, 79 insertions(+), 48 deletions(-) diff --git a/cln-grpc/src/convert.rs b/cln-grpc/src/convert.rs index 5806ea854..2e36be3f1 100644 --- a/cln-grpc/src/convert.rs +++ b/cln-grpc/src/convert.rs @@ -4045,7 +4045,7 @@ impl From for pb::AddpsbtoutputRequest { destination: c.destination, // Rule #2 for type string? initialpsbt: c.initialpsbt, // Rule #2 for type string? locktime: c.locktime, // Rule #2 for type u32? - satoshi: Some(c.satoshi.into()), // Rule #2 for type msat + satoshi: Some(c.satoshi.into()), // Rule #2 for type sat } } } @@ -4455,7 +4455,7 @@ impl From for pb::WithdrawRequest { destination: c.destination, // Rule #2 for type string feerate: c.feerate.map(|o|o.into()), // Rule #2 for type feerate? minconf: c.minconf.map(|v| v.into()), // Rule #2 for type u16? - satoshi: Some(c.satoshi.into()), // Rule #2 for type msat_or_all + satoshi: Some(c.satoshi.into()), // Rule #2 for type sat_or_all // Field: Withdraw.utxos[] utxos: c.utxos.map(|arr| arr.into_iter().map(|i| i.into()).collect()).unwrap_or(vec![]), // Rule #3 } @@ -4491,7 +4491,7 @@ impl From for pb::FundpsbtRequest { nonwrapped: c.nonwrapped, // Rule #2 for type boolean? opening_anchor_channel: c.opening_anchor_channel, // Rule #2 for type boolean? reserve: c.reserve, // Rule #2 for type u32? - satoshi: Some(c.satoshi.into()), // Rule #2 for type msat_or_all + satoshi: Some(c.satoshi.into()), // Rule #2 for type sat_or_all startweight: c.startweight, // Rule #2 for type u32 } } @@ -4529,7 +4529,7 @@ impl From for pb::UtxopsbtRequest { opening_anchor_channel: c.opening_anchor_channel, // Rule #2 for type boolean? reserve: c.reserve, // Rule #2 for type u32? reservedok: c.reservedok, // Rule #2 for type boolean? - satoshi: Some(c.satoshi.into()), // Rule #2 for type msat_or_all + satoshi: Some(c.satoshi.into()), // Rule #2 for type sat_or_all startweight: c.startweight, // Rule #2 for type u32 // Field: UtxoPsbt.utxos[] utxos: c.utxos.into_iter().map(|i| i.into()).collect(), // Rule #3 for type outpoint @@ -4696,7 +4696,7 @@ impl From for pb::FundchannelCompleteRequ impl From for pb::FundchannelRequest { fn from(c: requests::FundchannelRequest) -> Self { Self { - amount: Some(c.amount.into()), // Rule #2 for type msat_or_all + amount: Some(c.amount.into()), // Rule #2 for type sat_or_all announce: c.announce, // Rule #2 for type boolean? // Field: FundChannel.channel_type[] channel_type: c.channel_type.map(|arr| arr.into_iter().map(|i| i.into()).collect()).unwrap_or(vec![]), // Rule #3 @@ -4708,7 +4708,7 @@ impl From for pb::FundchannelRequest { mindepth: c.mindepth, // Rule #2 for type u32? push_msat: c.push_msat.map(|f| f.into()), // Rule #2 for type msat? request_amt: c.request_amt.map(|f| f.into()), // Rule #2 for type msat? - reserve: c.reserve.map(|f| f.into()), // Rule #2 for type msat? + reserve: c.reserve.map(|f| f.into()), // Rule #2 for type sat? // Field: FundChannel.utxos[] utxos: c.utxos.map(|arr| arr.into_iter().map(|i| i.into()).collect()).unwrap_or(vec![]), // Rule #3 } @@ -4719,7 +4719,7 @@ impl From for pb::FundchannelRequest { impl From for pb::FundchannelStartRequest { fn from(c: requests::Fundchannel_startRequest) -> Self { Self { - amount: Some(c.amount.into()), // Rule #2 for type msat + amount: Some(c.amount.into()), // Rule #2 for type sat announce: c.announce, // Rule #2 for type boolean? // Field: FundChannel_Start.channel_type[] channel_type: c.channel_type.map(|arr| arr.into_iter().map(|i| i.into()).collect()).unwrap_or(vec![]), // Rule #3 @@ -4728,7 +4728,7 @@ impl From for pb::FundchannelStartRequest { id: c.id.serialize().to_vec(), // Rule #2 for type pubkey mindepth: c.mindepth, // Rule #2 for type u32? push_msat: c.push_msat.map(|f| f.into()), // Rule #2 for type msat? - reserve: c.reserve.map(|f| f.into()), // Rule #2 for type msat? + reserve: c.reserve.map(|f| f.into()), // Rule #2 for type sat? } } } @@ -4831,7 +4831,7 @@ impl From for pb::ListhtlcsRequest { impl From for pb::MultifundchannelDestinations { fn from(c: requests::MultifundchannelDestinations) -> Self { Self { - amount: Some(c.amount.into()), // Rule #2 for type msat_or_all + amount: Some(c.amount.into()), // Rule #2 for type sat_or_all announce: c.announce, // Rule #2 for type boolean? close_to: c.close_to, // Rule #2 for type string? compact_lease: c.compact_lease, // Rule #2 for type string? @@ -4839,7 +4839,7 @@ impl From for pb::MultifundchannelDestin mindepth: c.mindepth, // Rule #2 for type u32? push_msat: c.push_msat.map(|f| f.into()), // Rule #2 for type msat? request_amt: c.request_amt.map(|f| f.into()), // Rule #2 for type msat? - reserve: c.reserve.map(|f| f.into()), // Rule #2 for type msat? + reserve: c.reserve.map(|f| f.into()), // Rule #2 for type sat? } } } @@ -4906,7 +4906,7 @@ impl From for pb::OpenchannelAbortRequest { impl From for pb::OpenchannelBumpRequest { fn from(c: requests::Openchannel_bumpRequest) -> Self { Self { - amount: Some(c.amount.into()), // Rule #2 for type msat + amount: Some(c.amount.into()), // Rule #2 for type sat channel_id: >::as_ref(&c.channel_id).to_vec(), // Rule #2 for type hash funding_feerate: c.funding_feerate.map(|o|o.into()), // Rule #2 for type feerate? initialpsbt: c.initialpsbt, // Rule #2 for type string @@ -4918,7 +4918,7 @@ impl From for pb::OpenchannelBumpRequest { impl From for pb::OpenchannelInitRequest { fn from(c: requests::Openchannel_initRequest) -> Self { Self { - amount: Some(c.amount.into()), // Rule #2 for type msat + amount: Some(c.amount.into()), // Rule #2 for type sat announce: c.announce, // Rule #2 for type boolean? // Field: OpenChannel_Init.channel_type[] channel_type: c.channel_type.map(|arr| arr.into_iter().map(|i| i.into()).collect()).unwrap_or(vec![]), // Rule #3 @@ -5469,7 +5469,7 @@ impl From for requests::AddpsbtoutputRequest { destination: c.destination, // Rule #1 for type string? initialpsbt: c.initialpsbt, // Rule #1 for type string? locktime: c.locktime, // Rule #1 for type u32? - satoshi: c.satoshi.unwrap().into(), // Rule #1 for type msat + satoshi: c.satoshi.unwrap().into(), // Rule #1 for type sat } } } @@ -5868,7 +5868,7 @@ impl From for requests::WithdrawRequest { destination: c.destination, // Rule #1 for type string feerate: c.feerate.map(|a| a.into()), // Rule #1 for type feerate? minconf: c.minconf.map(|v| v as u16), // Rule #1 for type u16? - satoshi: c.satoshi.unwrap().into(), // Rule #1 for type msat_or_all + satoshi: c.satoshi.unwrap().into(), // Rule #1 for type sat_or_all utxos: Some(c.utxos.into_iter().map(|s| s.into()).collect()), // Rule #4 } } @@ -5903,7 +5903,7 @@ impl From for requests::FundpsbtRequest { nonwrapped: c.nonwrapped, // Rule #1 for type boolean? opening_anchor_channel: c.opening_anchor_channel, // Rule #1 for type boolean? reserve: c.reserve, // Rule #1 for type u32? - satoshi: c.satoshi.unwrap().into(), // Rule #1 for type msat_or_all + satoshi: c.satoshi.unwrap().into(), // Rule #1 for type sat_or_all startweight: c.startweight, // Rule #1 for type u32 } } @@ -5940,7 +5940,7 @@ impl From for requests::UtxopsbtRequest { opening_anchor_channel: c.opening_anchor_channel, // Rule #1 for type boolean? reserve: c.reserve, // Rule #1 for type u32? reservedok: c.reservedok, // Rule #1 for type boolean? - satoshi: c.satoshi.unwrap().into(), // Rule #1 for type msat_or_all + satoshi: c.satoshi.unwrap().into(), // Rule #1 for type sat_or_all startweight: c.startweight, // Rule #1 for type u32 utxos: c.utxos.into_iter().map(|s| s.into()).collect(), // Rule #4 } @@ -6104,7 +6104,7 @@ impl From for requests::Fundchannel_completeRequ impl From for requests::FundchannelRequest { fn from(c: pb::FundchannelRequest) -> Self { Self { - amount: c.amount.unwrap().into(), // Rule #1 for type msat_or_all + amount: c.amount.unwrap().into(), // Rule #1 for type sat_or_all announce: c.announce, // Rule #1 for type boolean? channel_type: Some(c.channel_type.into_iter().map(|s| s).collect()), // Rule #4 close_to: c.close_to, // Rule #1 for type string? @@ -6115,7 +6115,7 @@ impl From for requests::FundchannelRequest { mindepth: c.mindepth, // Rule #1 for type u32? push_msat: c.push_msat.map(|a| a.into()), // Rule #1 for type msat? request_amt: c.request_amt.map(|a| a.into()), // Rule #1 for type msat? - reserve: c.reserve.map(|a| a.into()), // Rule #1 for type msat? + reserve: c.reserve.map(|a| a.into()), // Rule #1 for type sat? utxos: Some(c.utxos.into_iter().map(|s| s.into()).collect()), // Rule #4 } } @@ -6125,7 +6125,7 @@ impl From for requests::FundchannelRequest { impl From for requests::Fundchannel_startRequest { fn from(c: pb::FundchannelStartRequest) -> Self { Self { - amount: c.amount.unwrap().into(), // Rule #1 for type msat + amount: c.amount.unwrap().into(), // Rule #1 for type sat announce: c.announce, // Rule #1 for type boolean? channel_type: Some(c.channel_type.into_iter().map(|s| s).collect()), // Rule #4 close_to: c.close_to, // Rule #1 for type string? @@ -6133,7 +6133,7 @@ impl From for requests::Fundchannel_startRequest { id: PublicKey::from_slice(&c.id).unwrap(), // Rule #1 for type pubkey mindepth: c.mindepth, // Rule #1 for type u32? push_msat: c.push_msat.map(|a| a.into()), // Rule #1 for type msat? - reserve: c.reserve.map(|a| a.into()), // Rule #1 for type msat? + reserve: c.reserve.map(|a| a.into()), // Rule #1 for type sat? } } } @@ -6235,7 +6235,7 @@ impl From for requests::ListhtlcsRequest { impl From for requests::MultifundchannelDestinations { fn from(c: pb::MultifundchannelDestinations) -> Self { Self { - amount: c.amount.unwrap().into(), // Rule #1 for type msat_or_all + amount: c.amount.unwrap().into(), // Rule #1 for type sat_or_all announce: c.announce, // Rule #1 for type boolean? close_to: c.close_to, // Rule #1 for type string? compact_lease: c.compact_lease, // Rule #1 for type string? @@ -6243,7 +6243,7 @@ impl From for requests::MultifundchannelDestin mindepth: c.mindepth, // Rule #1 for type u32? push_msat: c.push_msat.map(|a| a.into()), // Rule #1 for type msat? request_amt: c.request_amt.map(|a| a.into()), // Rule #1 for type msat? - reserve: c.reserve.map(|a| a.into()), // Rule #1 for type msat? + reserve: c.reserve.map(|a| a.into()), // Rule #1 for type sat? } } } @@ -6306,7 +6306,7 @@ impl From for requests::Openchannel_abortRequest { impl From for requests::Openchannel_bumpRequest { fn from(c: pb::OpenchannelBumpRequest) -> Self { Self { - amount: c.amount.unwrap().into(), // Rule #1 for type msat + amount: c.amount.unwrap().into(), // Rule #1 for type sat channel_id: Sha256::from_slice(&c.channel_id).unwrap(), // Rule #1 for type hash funding_feerate: c.funding_feerate.map(|a| a.into()), // Rule #1 for type feerate? initialpsbt: c.initialpsbt, // Rule #1 for type string @@ -6318,7 +6318,7 @@ impl From for requests::Openchannel_bumpRequest { impl From for requests::Openchannel_initRequest { fn from(c: pb::OpenchannelInitRequest) -> Self { Self { - amount: c.amount.unwrap().into(), // Rule #1 for type msat + amount: c.amount.unwrap().into(), // Rule #1 for type sat announce: c.announce, // Rule #1 for type boolean? channel_type: Some(c.channel_type.into_iter().map(|s| s).collect()), // Rule #4 close_to: c.close_to, // Rule #1 for type string? diff --git a/contrib/msggen/msggen/gen/grpc/convert.py b/contrib/msggen/msggen/gen/grpc/convert.py index 31dd5850b..19bc9c76f 100644 --- a/contrib/msggen/msggen/gen/grpc/convert.py +++ b/contrib/msggen/msggen/gen/grpc/convert.py @@ -100,6 +100,8 @@ class GrpcConverterGenerator(IGenerator): "u16?": f"c.{name}.map(|v| v.into())", "msat": f"Some(c.{name}.into())", "msat?": f"c.{name}.map(|f| f.into())", + "sat": f"Some(c.{name}.into())", + "sat?": f"c.{name}.map(|f| f.into())", "pubkey": f"c.{name}.serialize().to_vec()", "pubkey?": f"c.{name}.map(|v| v.serialize().to_vec())", "hex": f"hex::decode(&c.{name}).unwrap()", @@ -115,6 +117,8 @@ class GrpcConverterGenerator(IGenerator): "msat_or_any": f"Some(c.{name}.into())", "msat_or_all": f"Some(c.{name}.into())", "msat_or_all?": f"c.{name}.map(|o|o.into())", + "sat_or_all": f"Some(c.{name}.into())", + "sat_or_all?": f"c.{name}.map(|o|o.into())", "feerate?": f"c.{name}.map(|o|o.into())", "feerate": f"Some(c.{name}.into())", "outpoint?": f"c.{name}.map(|o|o.into())", diff --git a/contrib/msggen/msggen/gen/grpc/unconvert.py b/contrib/msggen/msggen/gen/grpc/unconvert.py index b84d5bce3..e996d2c87 100644 --- a/contrib/msggen/msggen/gen/grpc/unconvert.py +++ b/contrib/msggen/msggen/gen/grpc/unconvert.py @@ -110,6 +110,10 @@ class GrpcUnconverterGenerator(GrpcConverterGenerator): "msat_or_all?": f"c.{name}.map(|a| a.into())", "msat_or_any": f"c.{name}.unwrap().into()", "msat_or_any?": f"c.{name}.map(|a| a.into())", + "sat": f"c.{name}.unwrap().into()", + "sat?": f"c.{name}.map(|a| a.into())", + "sat_or_all": f"c.{name}.unwrap().into()", + "sat_or_all?": f"c.{name}.map(|a| a.into())", "feerate": f"c.{name}.unwrap().into()", "feerate?": f"c.{name}.map(|a| a.into())", "outpoint?": f"c.{name}.map(|a| a.into())", diff --git a/contrib/msggen/msggen/gen/grpc/util.py b/contrib/msggen/msggen/gen/grpc/util.py index e03d396f0..21ec56714 100644 --- a/contrib/msggen/msggen/gen/grpc/util.py +++ b/contrib/msggen/msggen/gen/grpc/util.py @@ -9,6 +9,8 @@ typemap = { "msat": "Amount", "msat_or_all": "AmountOrAll", "msat_or_any": "AmountOrAny", + "sat": "Amount", + "sat_or_all": "AmountOrAll", "currency": "string", "number": "double", "pubkey": "bytes", diff --git a/contrib/msggen/msggen/gen/grpc2py.py b/contrib/msggen/msggen/gen/grpc2py.py index 388565776..fd8b508db 100644 --- a/contrib/msggen/msggen/gen/grpc2py.py +++ b/contrib/msggen/msggen/gen/grpc2py.py @@ -54,6 +54,7 @@ class Grpc2PyGenerator(IGenerator): "boolean": "m.{name}", "short_channel_id": "m.{name}", "msat": "amount2msat(m.{name})", + "sat": "amount2sat(m.{name})", "currency": "m.{name}", "number": "m.{name}", } @@ -87,6 +88,10 @@ class Grpc2PyGenerator(IGenerator): return a.msat + def amount2sat(a): + return a.msat / 1000 + + def remove_default(d): # grpc is really not good at empty values, they get replaced with the type's default value... return {k: v for k, v in d.items() if v is not None and v != ""} diff --git a/contrib/msggen/msggen/gen/rpc/rust.py b/contrib/msggen/msggen/gen/rpc/rust.py index 6c947f348..6fbc33445 100644 --- a/contrib/msggen/msggen/gen/rpc/rust.py +++ b/contrib/msggen/msggen/gen/rpc/rust.py @@ -27,6 +27,8 @@ typemap = { "msat": "Amount", "msat_or_all": "AmountOrAll", "msat_or_any": "AmountOrAny", + "sat": "Amount", + "sat_or_all": "AmountOrAll", "currency": "String", "number": "f64", "pubkey": "PublicKey", diff --git a/contrib/msggen/msggen/model.py b/contrib/msggen/msggen/model.py index 3bafcf9a4..4ea1a3df8 100644 --- a/contrib/msggen/msggen/model.py +++ b/contrib/msggen/msggen/model.py @@ -415,6 +415,8 @@ class PrimitiveField(Field): "msat", "msat_or_any", "msat_or_all", + "sat", + "sat_or_all", "currency", "hex", "short_channel_id", diff --git a/contrib/msggen/msggen/schema.json b/contrib/msggen/msggen/schema.json index fb446f861..3a2f4bdcb 100644 --- a/contrib/msggen/msggen/schema.json +++ b/contrib/msggen/msggen/schema.json @@ -79,7 +79,7 @@ ], "properties": { "satoshi": { - "type": "msat", + "type": "sat", "description": [ "The satoshi value of the output. It can be a whole number, a whole number ending in *sat*, or a number with 1 to 8 decimal places ending in *btc*." ] @@ -10047,7 +10047,7 @@ ] }, "amount": { - "type": "msat_or_all", + "type": "sat_or_all", "description": [ "The amount in satoshis taken from the internal wallet to fund the channel (but if we have any anchor channels, this will always leave at least `min-emergency- msat` as change). The string *all* can be used to specify all available funds (or 16777215 satoshi if more is available and large channels were not negotiated with the peer). Otherwise, it is in satoshi precision; it can be a whole number, a whole number ending in *sat*, a whole number ending in *000msat*, or a number with 1 to 8 decimal places ending in *btc*. The value cannot be less than the dust limit, currently set to 546, nor more than 16777215 satoshi (unless large channels were negotiated with the peer)." ] @@ -10113,7 +10113,7 @@ "type": "u32" }, "reserve": { - "type": "msat", + "type": "sat", "description": [ "The amount we want the peer to maintain on its side of the channel. It can be a whole number, a whole number ending in *sat*, a whole number ending in *000msat*, or a number with 1 to 8 decimal places ending in *btc*." ], @@ -10544,7 +10544,7 @@ ] }, "amount": { - "type": "msat", + "type": "sat", "description": [ "Satoshi value that the channel will be funded at. This value MUST be accurate, otherwise the negotiated commitment transactions will not encompass the correct channel value." ] @@ -10580,7 +10580,7 @@ ] }, "reserve": { - "type": "msat", + "type": "sat", "description": [ "The amount we want the peer to maintain on its side." ] @@ -11132,7 +11132,7 @@ ], "properties": { "satoshi": { - "type": "msat_or_all", + "type": "sat_or_all", "description": [ "The minimum satoshi value of the output(s) needed (or the string `all` meaning use all unreserved inputs). If a value, it can be a whole number, a whole number ending in *sat*, a whole number ending in *000msat*, or a number with 1 to 8 decimal places ending in *btc*." ] @@ -22271,7 +22271,7 @@ ] }, "amount": { - "type": "msat_or_all", + "type": "sat_or_all", "description": [ "Amount in satoshis taken from the internal wallet to fund the channel (but if we have any anchor channels, this will always leave at least `min-emergency-msat` as change). The string *all* can be used to specify all available funds (or 16,777,215 satoshi if more is available and large channels were not negotiated with the peer). Otherwise it is in satoshi precision; it can be a whole number, a whole number ending in *sat*, a whole number ending in *000msat*, or a number with 1 to 8 decimal places ending in *btc*. The value cannot be less than the dust limit, currently 546 satoshi as of this writing, nor more than 16,777,215 satoshi (unless large channels were negotiated with the peer)." ] @@ -22314,7 +22314,7 @@ ] }, "reserve": { - "type": "msat", + "type": "sat", "description": [ "Amount we want the peer to maintain on its side of the channel. It can be a whole number, a whole number ending in *sat*, a whole number ending in *000msat*, or a number with 1 to 8 decimal places ending in *btc*." ], @@ -23376,7 +23376,7 @@ ] }, "amount": { - "type": "msat", + "type": "sat", "description": [ "Satoshi value that we will contribute to the channel. This value will be _added_ to the provided PSBT in the output which is encumbered by the 2-of-2 script for this channel." ] @@ -23546,7 +23546,7 @@ ] }, "amount": { - "type": "msat", + "type": "sat", "description": [ "Satoshi value that we will contribute to the channel. This value will be _added_ to the provided PSBT in the output which is encumbered by the 2-of-2 script for this channel." ] @@ -29426,7 +29426,7 @@ ], "properties": { "satoshi": { - "type": "msat_or_all", + "type": "sat_or_all", "description": [ "The minimum satoshi value of the output(s) needed (or the string `all` meaning use all unreserved inputs). If a value, it can be a whole number, a whole number ending in *sat*, a whole number ending in *000msat*, or a number with 1 to 8 decimal places ending in *btc*." ] @@ -30953,7 +30953,7 @@ ] }, "satoshi": { - "type": "msat_or_all", + "type": "sat_or_all", "description": [ "The amount to be withdrawn from the internal wallet (expressed, as name suggests, in satoshi). The string *all* can be used to specify withdrawal of all available funds (but if we have any anchor channels, this will always leave at least `min-emergency-msat` as change). Otherwise, it is in satoshi precision; it can be a whole number, a whole number ending in *sat*, a whole number ending in *000msat*, or a number with 1 to 8 decimal places ending in *btc*." ] diff --git a/contrib/pyln-testing/pyln/testing/fixtures.py b/contrib/pyln-testing/pyln/testing/fixtures.py index aa65955af..f446a842d 100644 --- a/contrib/pyln-testing/pyln/testing/fixtures.py +++ b/contrib/pyln-testing/pyln/testing/fixtures.py @@ -392,6 +392,12 @@ def _extra_validator(is_request: bool): return True return is_msat_request(checker, instance) + def is_sat_or_all(checker, instance): + """sat field, or 'all'""" + if instance == "all": + return True + return is_sat(checker, instance) + def is_currency(checker, instance): """currency including currency code""" pattern = re.compile(r'^\d+(\.\d+)?[A-Z][A-Z][A-Z]$') @@ -414,6 +420,7 @@ def _extra_validator(is_request: bool): "u8": is_u8, "pubkey": is_pubkey, "sat": is_sat, + "sat_or_all": is_sat_or_all, "msat": is_msat, "msat_or_all": is_msat_or_all, "msat_or_any": is_msat_or_any, diff --git a/contrib/pyln-testing/pyln/testing/grpc2py.py b/contrib/pyln-testing/pyln/testing/grpc2py.py index 9828a8acc..4f4c961b8 100644 --- a/contrib/pyln-testing/pyln/testing/grpc2py.py +++ b/contrib/pyln-testing/pyln/testing/grpc2py.py @@ -13,6 +13,10 @@ def amount2msat(a): return a.msat +def amount2sat(a): + return a.msat / 1000 + + def remove_default(d): # grpc is really not good at empty values, they get replaced with the type's default value... return {k: v for k, v in d.items() if v is not None and v != ""} diff --git a/doc/rpc-schema-draft.json b/doc/rpc-schema-draft.json index fefa82ba2..f0f37da5b 100644 --- a/doc/rpc-schema-draft.json +++ b/doc/rpc-schema-draft.json @@ -34,6 +34,7 @@ "u8", "pubkey", "sat", + "sat_or_all", "msat", "msat_or_all", "msat_or_any", diff --git a/doc/schemas/lightning-addpsbtoutput.json b/doc/schemas/lightning-addpsbtoutput.json index 64d58db58..84da0a382 100644 --- a/doc/schemas/lightning-addpsbtoutput.json +++ b/doc/schemas/lightning-addpsbtoutput.json @@ -16,7 +16,7 @@ ], "properties": { "satoshi": { - "type": "msat", + "type": "sat", "description": [ "The satoshi value of the output. It can be a whole number, a whole number ending in *sat*, or a number with 1 to 8 decimal places ending in *btc*." ] diff --git a/doc/schemas/lightning-fundchannel.json b/doc/schemas/lightning-fundchannel.json index 6e4a1cb40..17c171413 100644 --- a/doc/schemas/lightning-fundchannel.json +++ b/doc/schemas/lightning-fundchannel.json @@ -26,7 +26,7 @@ ] }, "amount": { - "type": "msat_or_all", + "type": "sat_or_all", "description": [ "The amount in satoshis taken from the internal wallet to fund the channel (but if we have any anchor channels, this will always leave at least `min-emergency- msat` as change). The string *all* can be used to specify all available funds (or 16777215 satoshi if more is available and large channels were not negotiated with the peer). Otherwise, it is in satoshi precision; it can be a whole number, a whole number ending in *sat*, a whole number ending in *000msat*, or a number with 1 to 8 decimal places ending in *btc*. The value cannot be less than the dust limit, currently set to 546, nor more than 16777215 satoshi (unless large channels were negotiated with the peer)." ] @@ -92,7 +92,7 @@ "type": "u32" }, "reserve": { - "type": "msat", + "type": "sat", "description": [ "The amount we want the peer to maintain on its side of the channel. It can be a whole number, a whole number ending in *sat*, a whole number ending in *000msat*, or a number with 1 to 8 decimal places ending in *btc*." ], diff --git a/doc/schemas/lightning-fundchannel_start.json b/doc/schemas/lightning-fundchannel_start.json index 6ef2ef67f..200ae2e82 100644 --- a/doc/schemas/lightning-fundchannel_start.json +++ b/doc/schemas/lightning-fundchannel_start.json @@ -22,7 +22,7 @@ ] }, "amount": { - "type": "msat", + "type": "sat", "description": [ "Satoshi value that the channel will be funded at. This value MUST be accurate, otherwise the negotiated commitment transactions will not encompass the correct channel value." ] @@ -58,7 +58,7 @@ ] }, "reserve": { - "type": "msat", + "type": "sat", "description": [ "The amount we want the peer to maintain on its side." ] diff --git a/doc/schemas/lightning-fundpsbt.json b/doc/schemas/lightning-fundpsbt.json index 6acd81892..d0a93c73f 100644 --- a/doc/schemas/lightning-fundpsbt.json +++ b/doc/schemas/lightning-fundpsbt.json @@ -15,7 +15,7 @@ ], "properties": { "satoshi": { - "type": "msat_or_all", + "type": "sat_or_all", "description": [ "The minimum satoshi value of the output(s) needed (or the string `all` meaning use all unreserved inputs). If a value, it can be a whole number, a whole number ending in *sat*, a whole number ending in *000msat*, or a number with 1 to 8 decimal places ending in *btc*." ] diff --git a/doc/schemas/lightning-multifundchannel.json b/doc/schemas/lightning-multifundchannel.json index 0d943db50..9e2419bdd 100644 --- a/doc/schemas/lightning-multifundchannel.json +++ b/doc/schemas/lightning-multifundchannel.json @@ -36,7 +36,7 @@ ] }, "amount": { - "type": "msat_or_all", + "type": "sat_or_all", "description": [ "Amount in satoshis taken from the internal wallet to fund the channel (but if we have any anchor channels, this will always leave at least `min-emergency-msat` as change). The string *all* can be used to specify all available funds (or 16,777,215 satoshi if more is available and large channels were not negotiated with the peer). Otherwise it is in satoshi precision; it can be a whole number, a whole number ending in *sat*, a whole number ending in *000msat*, or a number with 1 to 8 decimal places ending in *btc*. The value cannot be less than the dust limit, currently 546 satoshi as of this writing, nor more than 16,777,215 satoshi (unless large channels were negotiated with the peer)." ] @@ -79,7 +79,7 @@ ] }, "reserve": { - "type": "msat", + "type": "sat", "description": [ "Amount we want the peer to maintain on its side of the channel. It can be a whole number, a whole number ending in *sat*, a whole number ending in *000msat*, or a number with 1 to 8 decimal places ending in *btc*." ], diff --git a/doc/schemas/lightning-openchannel_bump.json b/doc/schemas/lightning-openchannel_bump.json index 90cabff05..7e712e68c 100644 --- a/doc/schemas/lightning-openchannel_bump.json +++ b/doc/schemas/lightning-openchannel_bump.json @@ -23,7 +23,7 @@ ] }, "amount": { - "type": "msat", + "type": "sat", "description": [ "Satoshi value that we will contribute to the channel. This value will be _added_ to the provided PSBT in the output which is encumbered by the 2-of-2 script for this channel." ] diff --git a/doc/schemas/lightning-openchannel_init.json b/doc/schemas/lightning-openchannel_init.json index e0f12d908..8ab72791e 100644 --- a/doc/schemas/lightning-openchannel_init.json +++ b/doc/schemas/lightning-openchannel_init.json @@ -21,7 +21,7 @@ ] }, "amount": { - "type": "msat", + "type": "sat", "description": [ "Satoshi value that we will contribute to the channel. This value will be _added_ to the provided PSBT in the output which is encumbered by the 2-of-2 script for this channel." ] diff --git a/doc/schemas/lightning-utxopsbt.json b/doc/schemas/lightning-utxopsbt.json index 32f126dd6..39349279a 100644 --- a/doc/schemas/lightning-utxopsbt.json +++ b/doc/schemas/lightning-utxopsbt.json @@ -18,7 +18,7 @@ ], "properties": { "satoshi": { - "type": "msat_or_all", + "type": "sat_or_all", "description": [ "The minimum satoshi value of the output(s) needed (or the string `all` meaning use all unreserved inputs). If a value, it can be a whole number, a whole number ending in *sat*, a whole number ending in *000msat*, or a number with 1 to 8 decimal places ending in *btc*." ] diff --git a/doc/schemas/lightning-withdraw.json b/doc/schemas/lightning-withdraw.json index 36a2e202c..e4b927989 100644 --- a/doc/schemas/lightning-withdraw.json +++ b/doc/schemas/lightning-withdraw.json @@ -20,7 +20,7 @@ ] }, "satoshi": { - "type": "msat_or_all", + "type": "sat_or_all", "description": [ "The amount to be withdrawn from the internal wallet (expressed, as name suggests, in satoshi). The string *all* can be used to specify withdrawal of all available funds (but if we have any anchor channels, this will always leave at least `min-emergency-msat` as change). Otherwise, it is in satoshi precision; it can be a whole number, a whole number ending in *sat*, a whole number ending in *000msat*, or a number with 1 to 8 decimal places ending in *btc*." ]