darkfid: support both normal address and base64 encoded mining configurations as miners recipient

This commit is contained in:
skoupidi
2026-01-01 18:17:57 +02:00
parent d56580bd9e
commit 965870ab9b
11 changed files with 48 additions and 39 deletions

View File

@@ -72,11 +72,22 @@ impl MinerRewardsRecipientConfig {
Self { recipient, spend_hook, user_data }
}
pub async fn from_base64(
network: &Network,
encoded_address: &str,
) -> std::result::Result<Self, RpcError> {
let Some(address_bytes) = base64::decode(encoded_address) else {
/// Auxiliary function to convert provided string to its
/// `MinerRewardsRecipientConfig`. Supports parsing both a normal
/// `Address` and a `base64` encoded mining configuration. Also
/// verifies it corresponds to the provided `Network`.
pub async fn from_str(network: &Network, address: &str) -> std::result::Result<Self, RpcError> {
// Try to parse the string as an `Address`
if let Ok(recipient) = Address::from_str(address) {
if recipient.network() != *network {
return Err(RpcError::MinerInvalidRecipientPrefix)
}
return Ok(Self { recipient, spend_hook: None, user_data: None })
}
// Try to parse the string as a `base64` encoded mining
// configuration
let Some(address_bytes) = base64::decode(address) else {
return Err(RpcError::MinerInvalidWalletConfig)
};
let Ok((recipient, spend_hook, user_data)) =

View File

@@ -73,8 +73,8 @@ impl DarkfiNode {
// job.
//
// **Request:**
// * `login` : A base-64 encoded wallet address mining configuration
// * `pass` : Unused client password field. Expects default "x" value.
// * `login` : A wallet address or its base-64 encoded mining configuration
// * `pass` : Unused client password field
// * `agent` : Client agent description
// * `algo` : Client supported mining algorithms
//
@@ -96,7 +96,7 @@ impl DarkfiNode {
// "jsonrpc": "2.0",
// "method": "login",
// "params": {
// "login": "MINING_CONFIG",
// "login": "WALLET_ADDRESS",
// "pass": "x",
// "agent": "XMRig",
// "algo": ["rx/0"]
@@ -131,7 +131,7 @@ impl DarkfiNode {
return JsonError::new(InvalidParams, None, id).into()
};
// Parse login mining configuration
// Parse login
let Some(wallet) = params.get("login") else {
return server_error(RpcError::MinerMissingLogin, id, None)
};
@@ -139,7 +139,7 @@ impl DarkfiNode {
return server_error(RpcError::MinerInvalidLogin, id, None)
};
let config =
match MinerRewardsRecipientConfig::from_base64(&self.registry.network, wallet).await {
match MinerRewardsRecipientConfig::from_str(&self.registry.network, wallet).await {
Ok(c) => c,
Err(e) => return server_error(e, id, None),
};

View File

@@ -132,7 +132,7 @@ impl DarkfiNode {
// merge mining.
//
// **Request:**
// * `address` : A base-64 encoded wallet address mining configuration on the merge mined chain
// * `address` : A wallet address or its base-64 encoded mining configuration on the merge mined chain
// * `aux_hash`: Merge mining job that is currently being polled
// * `height` : Monero height
// * `prev_id` : Hash of the previous Monero block
@@ -189,7 +189,7 @@ impl DarkfiNode {
return JsonResponse::new(JsonValue::from(HashMap::new()), id).into()
}
// Parse address mining configuration
// Parse address
let Some(wallet) = params.get("address") else {
return server_error(RpcError::MinerMissingAddress, id, None)
};
@@ -197,7 +197,7 @@ impl DarkfiNode {
return server_error(RpcError::MinerInvalidAddress, id, None)
};
let config =
match MinerRewardsRecipientConfig::from_base64(&self.registry.network, wallet).await {
match MinerRewardsRecipientConfig::from_str(&self.registry.network, wallet).await {
Ok(c) => c,
Err(e) => return server_error(e, id, None),
};