diff --git a/Cargo.lock b/Cargo.lock index 129b340..8e5bb68 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1235,6 +1235,7 @@ dependencies = [ "hex", "hex-literal", "indexmap", + "monero-address", "monero-serai", "paste", "pin-project", diff --git a/Cargo.toml b/Cargo.toml index bd1c6f9..1d8875e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -132,6 +132,7 @@ futures = { version = "0.3", default-features = false } hex = { version = "0.4", default-features = false } hex-literal = { version = "0.4", default-features = false } indexmap = { version = "2", default-features = false } +monero-address = { git = "https://github.com/Cuprate/serai.git", rev = "d5205ce", default-features = false } monero-serai = { git = "https://github.com/Cuprate/serai.git", rev = "d5205ce", default-features = false } paste = { version = "1", default-features = false } pin-project = { version = "1", default-features = false } diff --git a/binaries/cuprated/Cargo.toml b/binaries/cuprated/Cargo.toml index 24e824b..ac9e412 100644 --- a/binaries/cuprated/Cargo.toml +++ b/binaries/cuprated/Cargo.toml @@ -58,6 +58,7 @@ futures = { workspace = true } hex = { workspace = true } hex-literal = { workspace = true } indexmap = { workspace = true } +monero-address = { workspace = true } monero-serai = { workspace = true } paste = { workspace = true } pin-project = { workspace = true } diff --git a/binaries/cuprated/src/rpc/handlers/json_rpc.rs b/binaries/cuprated/src/rpc/handlers/json_rpc.rs index 4f7f00c..1e4c10f 100644 --- a/binaries/cuprated/src/rpc/handlers/json_rpc.rs +++ b/binaries/cuprated/src/rpc/handlers/json_rpc.rs @@ -147,22 +147,16 @@ async fn get_block_template( return Err(anyhow!("Too big extra_nonce size")); } - // TODO: this is hardcoded for the current address scheme + mainnet, - // create/use a more well-defined wallet lib. - let parse_wallet_address = || { - if request.wallet_address.len() == 95 { - Ok(()) - } else { - Err(()) - } + // TODO: This should be `cuprated`'s active network. + let network = match Network::Mainnet { + Network::Mainnet => monero_address::Network::Mainnet, + Network::Stagenet => monero_address::Network::Stagenet, + Network::Testnet => monero_address::Network::Testnet, }; - let is_correct_address_type = || !request.wallet_address.starts_with("4"); - if parse_wallet_address().is_err() { - return Err(anyhow!("Failed to parse wallet address")); - } + let address = monero_address::MoneroAddress::from_str(network, &request.wallet_address)?; - if is_correct_address_type() { + if *address.kind() != monero_address::AddressType::Legacy { return Err(anyhow!("Incorrect address type")); }