refactor: centralize constants, eliminate unwraps, remove dead code, resolve TODOs

- R13+R16: Replace .expect() with .context()? in main.rs and identity.rs
- R17+R18+R19: Fix unwrap() calls in helpers and js-engine
- R20+R21: Remove #[allow(dead_code)] annotations and delete truly dead code
- R22-R26: Create constants.rs module, replace 21 hardcoded values across 12 files
- R28+R29: LND/DWN timeouts already present — verified
- R30-R33: Remove TODO comments, implement marketplace payment check

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-21 01:54:35 +00:00
parent 5c3a3ffa8e
commit f3976ba03a
22 changed files with 113 additions and 104 deletions

View File

@@ -110,13 +110,15 @@ impl NodeIdentity {
/// DID in did:key format (W3C did:key method, Ed25519).
/// Format: did:key:z&lt;base58btc(multicodec_ed25519_pub + 32-byte pubkey)&gt;
pub fn did_key(&self) -> String {
did_key_from_pubkey_hex(&self.pubkey_hex()).expect("pubkey_hex is valid")
pub fn did_key(&self) -> Result<String> {
did_key_from_pubkey_hex(&self.pubkey_hex())
.map_err(|e| anyhow::anyhow!("Invalid pubkey hex: {}", e))
}
/// Generate a W3C DID Core v1.0 compliant DID Document.
pub fn did_document(&self) -> serde_json::Value {
did_document_from_pubkey_hex(&self.pubkey_hex()).expect("pubkey_hex is valid")
pub fn did_document(&self) -> Result<serde_json::Value> {
did_document_from_pubkey_hex(&self.pubkey_hex())
.map_err(|e| anyhow::anyhow!("Invalid pubkey hex: {}", e))
}
}
@@ -299,7 +301,7 @@ mod tests {
let dir = tempfile::tempdir().unwrap();
let identity = NodeIdentity::load_or_create(&dir.path().join("id")).await.unwrap();
let did = identity.did_key();
let did = identity.did_key().unwrap();
assert!(did.starts_with("did:key:z"));
}
@@ -336,8 +338,8 @@ mod tests {
let dir = tempfile::tempdir().unwrap();
let identity = NodeIdentity::load_or_create(&dir.path().join("id")).await.unwrap();
let doc = identity.did_document();
let did = identity.did_key();
let doc = identity.did_document().unwrap();
let did = identity.did_key().unwrap();
// Verify @context
let context = doc["@context"].as_array().unwrap();