mirror of
https://github.com/daywalker90/cln-nip47.git
synced 2026-08-13 12:33:43 +02:00
misc: fix log levels, substraction overflow, invoice valid check
This commit is contained in:
parent
b31f42691f
commit
e175198c45
6 changed files with 31 additions and 25 deletions
|
|
@ -89,7 +89,7 @@ async fn main() -> Result<(), anyhow::Error> {
|
|||
unsafe {
|
||||
std::env::set_var(
|
||||
"CLN_PLUGIN_LOG",
|
||||
"cln_plugin=info,cln_rpc=info,cln_nip47=debug,info",
|
||||
"cln_plugin=info,cln_rpc=info,cln_nip47=trace,info",
|
||||
);
|
||||
};
|
||||
log_panics::init();
|
||||
|
|
@ -257,9 +257,7 @@ async fn load_pending_hold_invoices(plugin: Plugin<PluginState>) -> Result<(), a
|
|||
invoice_decoded.invoice_created_at,
|
||||
invoice_decoded.invoice_relative_expiry.map(u64::from),
|
||||
),
|
||||
DecodeType::BOLT11_INVOICE => {
|
||||
(invoice_decoded.created_at, invoice_decoded.expiry)
|
||||
}
|
||||
DecodeType::BOLT11_INVOICE => (invoice_decoded.created_at, invoice_decoded.expiry),
|
||||
_ => continue,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -230,7 +230,7 @@ async fn nwc_request_handler(
|
|||
| ClientNotification::Shutdown => return Ok(()),
|
||||
};
|
||||
|
||||
log::debug!("relay_url:{relay_url} subscription_id:{subscription_id} {event:?}");
|
||||
log::trace!("relay_url:{relay_url} subscription_id:{subscription_id} {event:?}");
|
||||
let mut use_nip44 = check_nip44_support(&event);
|
||||
|
||||
let request = decrypt_request(&event.content, wallet_keys, &client_pubkey, &mut use_nip44)?;
|
||||
|
|
@ -334,7 +334,7 @@ async fn nwc_request_handler(
|
|||
);
|
||||
continue;
|
||||
}
|
||||
log::debug!("SENT RESPONSE {response_event:?}");
|
||||
log::trace!("SENT RESPONSE {response_event:?}");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
@ -394,7 +394,7 @@ fn decrypt_request(
|
|||
}
|
||||
}
|
||||
};
|
||||
log::debug!("Decrypted (nip44_v2:{use_nip44}):{content}");
|
||||
log::trace!("Decrypted (nip44_v2:{use_nip44}):{content}");
|
||||
let request: nip47::Request = match serde_json::from_str(&content) {
|
||||
Ok(o) => o,
|
||||
Err(e) => {
|
||||
|
|
@ -417,7 +417,7 @@ fn encrypt_response_content(
|
|||
return Err(anyhow!("Error serializing response! {e}"));
|
||||
}
|
||||
};
|
||||
log::debug!("RESPONSE:{response_str}");
|
||||
log::trace!("RESPONSE:{response_str}");
|
||||
if use_nip44 {
|
||||
match nip44::encrypt(
|
||||
wallet_keys.secret_key(),
|
||||
|
|
|
|||
|
|
@ -245,6 +245,7 @@ async fn lookup_holdinvoice(
|
|||
})
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
async fn get_and_decode_holdinvoice(
|
||||
rpc: &mut ClnRpc,
|
||||
hold_client: &mut HoldClient<Channel>,
|
||||
|
|
@ -289,6 +290,12 @@ async fn get_and_decode_holdinvoice(
|
|||
code: nip47::ErrorCode::Internal,
|
||||
message: e.to_string(),
|
||||
})?;
|
||||
if !invoice_decoded.valid {
|
||||
return Err(nip47::NIP47Error {
|
||||
code: nip47::ErrorCode::Other,
|
||||
message: "Invalid invoice decoded".to_owned(),
|
||||
});
|
||||
}
|
||||
|
||||
Ok((hold_invoice, invoice_decoded))
|
||||
} else {
|
||||
|
|
@ -301,6 +308,13 @@ async fn get_and_decode_holdinvoice(
|
|||
code: nip47::ErrorCode::Internal,
|
||||
message: e.to_string(),
|
||||
})?;
|
||||
if !invoice_decoded.valid {
|
||||
return Err(nip47::NIP47Error {
|
||||
code: nip47::ErrorCode::Other,
|
||||
message: "Invalid invoice decoded".to_owned(),
|
||||
});
|
||||
}
|
||||
|
||||
let ph = match invoice_decoded.item_type {
|
||||
DecodeType::BOLT12_INVOICE => invoice_decoded.invoice_payment_hash.unwrap(),
|
||||
DecodeType::BOLT11_INVOICE => invoice_decoded.payment_hash.unwrap().to_string(),
|
||||
|
|
@ -351,6 +365,12 @@ async fn get_and_decode_holdinvoice(
|
|||
code: nip47::ErrorCode::Internal,
|
||||
message: e.to_string(),
|
||||
})?;
|
||||
if !invoice_decoded.valid {
|
||||
return Err(nip47::NIP47Error {
|
||||
code: nip47::ErrorCode::Other,
|
||||
message: "Invalid invoice decoded".to_owned(),
|
||||
});
|
||||
}
|
||||
Ok((hold_invoice, invoice_decoded))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -348,7 +348,7 @@ async fn send_notification(
|
|||
notification: &String,
|
||||
wallet_service: &WalletService,
|
||||
) -> Result<(), anyhow::Error> {
|
||||
log::debug!("NOTIFICATION: {notification}");
|
||||
log::trace!("NOTIFICATION: {notification}");
|
||||
let content_encrypted_nip04 = nip04::encrypt(
|
||||
wallet_service.wallet_secret.secret_key(),
|
||||
&wallet_service.client_pubkey,
|
||||
|
|
@ -369,7 +369,7 @@ async fn send_notification(
|
|||
.join(", ")
|
||||
);
|
||||
}
|
||||
log::debug!("NIP04 NOTIFICATION SENT: {event_nip04:?}");
|
||||
log::trace!("NIP04 NOTIFICATION SENT: {event_nip04:?}");
|
||||
|
||||
let content_encrypted_nip44 = nip44::encrypt(
|
||||
wallet_service.wallet_secret.secret_key(),
|
||||
|
|
@ -392,7 +392,7 @@ async fn send_notification(
|
|||
.join(", ")
|
||||
);
|
||||
}
|
||||
log::debug!("NIP44 NOTIFICATION SENT: {event_nip44:?}");
|
||||
log::trace!("NIP44 NOTIFICATION SENT: {event_nip44:?}");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ pub async fn cleanup_event_ids(plugin: Plugin<PluginState>) -> Result<(), anyhow
|
|||
continue;
|
||||
}
|
||||
let timestamp = Timestamp::from_str(&id.string.unwrap())?;
|
||||
if now.as_secs() - timestamp.as_secs() > ID_MAX_AGE {
|
||||
if now.as_secs().saturating_sub(timestamp.as_secs()) > ID_MAX_AGE {
|
||||
rpc.call_typed(&DeldatastoreRequest {
|
||||
generation: None,
|
||||
key: id.key.clone(),
|
||||
|
|
|
|||
|
|
@ -139,7 +139,6 @@ async def test_get_balance(nostr_relay, node_factory, get_plugin): # noqa: F811
|
|||
wait_for_announce=True,
|
||||
opts=[
|
||||
{
|
||||
"log-level": "debug",
|
||||
"plugin": get_plugin,
|
||||
"nip47-relays": url,
|
||||
"broken_log": r"Relay receiver exited with error|Connection failed",
|
||||
|
|
@ -190,7 +189,6 @@ async def test_get_info(nostr_relay, node_factory, get_plugin): # noqa: F811
|
|||
url = nostr_relay
|
||||
l1 = node_factory.get_node(
|
||||
options={
|
||||
"log-level": "debug",
|
||||
"plugin": get_plugin,
|
||||
"nip47-relays": url,
|
||||
},
|
||||
|
|
@ -296,7 +294,6 @@ async def test_make_invoice(nostr_relay, node_factory, get_plugin): # noqa: F81
|
|||
url = nostr_relay
|
||||
l1 = node_factory.get_node(
|
||||
options={
|
||||
"log-level": "debug",
|
||||
"plugin": get_plugin,
|
||||
"nip47-relays": url,
|
||||
},
|
||||
|
|
@ -385,7 +382,6 @@ async def test_pay_keysend(nostr_relay, node_factory, get_plugin): # noqa: F811
|
|||
wait_for_announce=True,
|
||||
opts=[
|
||||
{
|
||||
"log-level": "debug",
|
||||
"plugin": get_plugin,
|
||||
"nip47-relays": url,
|
||||
"broken_log": r"Relay receiver exited with error|Connection failed",
|
||||
|
|
@ -444,7 +440,6 @@ async def test_lookup_invoice(nostr_relay, node_factory, get_plugin): # noqa: F
|
|||
wait_for_announce=True,
|
||||
opts=[
|
||||
{
|
||||
"log-level": "debug",
|
||||
"plugin": get_plugin,
|
||||
"nip47-relays": url,
|
||||
"broken_log": r"Relay receiver exited with error|Connection failed",
|
||||
|
|
@ -671,7 +666,6 @@ async def test_list_transactions(nostr_relay, node_factory, get_plugin): # noqa
|
|||
wait_for_announce=True,
|
||||
opts=[
|
||||
{
|
||||
"log-level": "debug",
|
||||
"plugin": get_plugin,
|
||||
"nip47-relays": url,
|
||||
"broken_log": r"Relay receiver exited with error|Connection failed",
|
||||
|
|
@ -775,13 +769,12 @@ async def test_notifications(nostr_relay, node_factory, get_plugin): # noqa: F8
|
|||
wait_for_announce=True,
|
||||
opts=[
|
||||
{
|
||||
"log-level": "debug",
|
||||
"plugin": get_plugin,
|
||||
"nip47-relays": url,
|
||||
"broken_log": r"Relay receiver exited with error|Connection failed",
|
||||
},
|
||||
{"log-level": "debug"},
|
||||
{"log-level": "debug", "plugin": get_plugin, "nip47-relays": url},
|
||||
{"plugin": get_plugin, "nip47-relays": url},
|
||||
],
|
||||
)
|
||||
uri_res = l1.rpc.call("nip47-create", ["test1"])
|
||||
|
|
@ -949,7 +942,6 @@ async def test_pay_invoice(nostr_relay, node_factory, get_plugin): # noqa: F811
|
|||
wait_for_announce=True,
|
||||
opts=[
|
||||
{
|
||||
"log-level": "debug",
|
||||
"plugin": get_plugin,
|
||||
"nip47-relays": url,
|
||||
"broken_log": r"Relay receiver exited with error|Connection failed",
|
||||
|
|
@ -1001,7 +993,6 @@ async def test_persistency(nostr_relay, node_factory, get_plugin): # noqa: F811
|
|||
wait_for_announce=True,
|
||||
opts=[
|
||||
{
|
||||
"log-level": "debug",
|
||||
"plugin": get_plugin,
|
||||
"nip47-relays": url,
|
||||
"broken_log": r"Relay receiver exited with error|Connection failed",
|
||||
|
|
@ -1160,7 +1151,6 @@ async def test_budget_command(nostr_relay, node_factory, get_plugin): # noqa: F
|
|||
wait_for_announce=True,
|
||||
opts=[
|
||||
{
|
||||
"log-level": "debug",
|
||||
"plugin": get_plugin,
|
||||
"nip47-relays": url,
|
||||
"broken_log": r"Relay receiver exited with error|Connection failed",
|
||||
|
|
@ -1291,7 +1281,6 @@ async def test_hold_invoice(
|
|||
"may_reconnect": True,
|
||||
},
|
||||
{
|
||||
"log-level": "debug",
|
||||
"plugin": get_plugin,
|
||||
"important-plugin": get_hold,
|
||||
"hold-grpc-port": node_factory.get_unused_port(),
|
||||
|
|
@ -1837,7 +1826,6 @@ async def test_hold_invoice_expiry(
|
|||
url = nostr_relay
|
||||
l2 = node_factory.get_node(
|
||||
options={
|
||||
"log-level": "debug",
|
||||
"plugin": get_plugin,
|
||||
"important-plugin": get_hold,
|
||||
"hold-grpc-port": node_factory.get_unused_port(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue