MCPcopy Create free account
hub / github.com/ElementsProject/lightning / generate_random_id

Function generate_random_id

plugins/lsps-plugin/src/proto/jsonrpc.rs:44–57  ·  view source on GitHub ↗

Generates a random ID for JSON-RPC requests. Uses a secure random number generator to create a hex-encoded ID. Falls back to a timestamp-based ID if random generation fails.

()

Source from the content-addressed store, hash-verified

42/// Uses a secure random number generator to create a hex-encoded ID. Falls back
43/// to a timestamp-based ID if random generation fails.
44fn generate_random_id() -> String {
45 let mut bytes = [0u8; 10];
46 match SysRng.try_fill_bytes(&mut bytes) {
47 Ok(_) => hex::encode(bytes),
48 Err(_) => {
49 // Fallback to a timestamp-based ID if random generation fails
50 let timestamp = std::time::SystemTime::now()
51 .duration_since(std::time::UNIX_EPOCH)
52 .unwrap_or_default()
53 .as_nanos();
54 format!("fallback-{}", timestamp)
55 }
56 }
57}
58
59/// # RequestObject
60///

Callers 1

into_requestMethod · 0.85

Calls 1

encodeFunction · 0.50

Tested by

no test coverage detected