Skip to content
Merged
2 changes: 1 addition & 1 deletion mm2src/coins/hd_wallet/withdraw_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type HDCoinPubKey<T> =
<<<<T as HDWalletCoinOps>::HDWallet as HDWalletOps>::HDAccount as HDAccountOps>::HDAddress as HDAddressOps>::Pubkey;

/// Represents the source of the funds for a withdrawal operation.
#[derive(Clone, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(untagged)]
pub enum WithdrawFrom {
/// The address id of the sender address which is specified by the account id, chain, and address id.
Expand Down
30 changes: 20 additions & 10 deletions mm2src/coins/lp_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2135,6 +2135,7 @@ pub struct WithdrawRequest {
#[serde(tag = "type")]
pub enum StakingDetails {
Qtum(QtumDelegationRequest),
Cosmos(Box<rpc_command::tendermint::staking::DelegatePayload>),
}

#[allow(dead_code)]
Expand Down Expand Up @@ -4878,17 +4879,26 @@ pub async fn get_staking_infos(ctx: MmArc, req: GetStakingInfosRequest) -> Staki

pub async fn add_delegation(ctx: MmArc, req: AddDelegateRequest) -> DelegationResult {
let coin = lp_coinfind_or_err(&ctx, &req.coin).await?;
// Need to find a way to do a proper dispatch
let coin_concrete = match coin {
MmCoinEnum::QtumCoin(qtum) => qtum,
_ => {
return MmError::err(DelegationError::CoinDoesntSupportDelegation {
coin: coin.ticker().to_string(),
})
},
};

match req.staking_details {
StakingDetails::Qtum(qtum_staking) => coin_concrete.add_delegation(qtum_staking).compat().await,
StakingDetails::Qtum(req) => {
let MmCoinEnum::QtumCoin(qtum) = coin else {
return MmError::err(DelegationError::CoinDoesntSupportDelegation {
coin: coin.ticker().to_string(),
});
};

qtum.add_delegation(req).compat().await
},
StakingDetails::Cosmos(req) => {
let MmCoinEnum::Tendermint(tendermint) = coin else {
return MmError::err(DelegationError::CoinDoesntSupportDelegation {
coin: coin.ticker().to_string(),
});
};

tendermint.add_delegate(*req).await
},
}
}

Expand Down
16 changes: 15 additions & 1 deletion mm2src/coins/rpc_command/tendermint/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use common::{HttpStatusCode, PagingOptions, StatusCode};
use cosmrs::staking::{Commission, Description, Validator};
use mm2_core::mm_ctx::MmArc;
use mm2_err_handle::prelude::MmError;
use mm2_number::BigDecimal;

use crate::{lp_coinfind_or_err, tendermint::TendermintCoinRpcError, MmCoinEnum};
use crate::{hd_wallet::WithdrawFrom, lp_coinfind_or_err, tendermint::TendermintCoinRpcError, MmCoinEnum, WithdrawFee};

/// Represents current status of the validator.
#[derive(Default, Deserialize)]
Expand Down Expand Up @@ -148,3 +149,16 @@ pub async fn validators_rpc(
validators: validators.into_iter().map(jsonize_validator).collect(),
})
}

#[derive(Clone, Debug, Deserialize)]
pub struct DelegatePayload {
pub validator_address: String,
pub fee: Option<WithdrawFee>,
Comment thread
shamardy marked this conversation as resolved.
pub withdraw_from: Option<WithdrawFrom>,
#[serde(default)]
pub memo: String,
#[serde(default)]
pub amount: BigDecimal,
#[serde(default)]
pub max: bool,
}
Loading