use monero_address

This commit is contained in:
hinto.janai 2025-01-16 19:22:48 -05:00
parent 13f5ed9dd0
commit 1d3c807b98
No known key found for this signature in database
GPG key ID: D47CE05FA175A499
4 changed files with 10 additions and 13 deletions

1
Cargo.lock generated
View file

@ -1235,6 +1235,7 @@ dependencies = [
"hex",
"hex-literal",
"indexmap",
"monero-address",
"monero-serai",
"paste",
"pin-project",

View file

@ -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 }

View file

@ -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 }

View file

@ -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"));
}