forked from jl777/SuperNET
-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[r2r] get_current_mtp rpc impl #1340
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
93376eb
implemented get_current_mtp rpc && test
borngraced 178c605
fmt fix
borngraced d1e4f53
fix wasm
borngraced 84808f3
reitration
borngraced a6842ba
better error namings
borngraced 3fe549c
review fixes
borngraced 1b463aa
adjusted get mtp test
borngraced c3e321f
remove test_get_current_mtp from wasm target
borngraced 4a4e917
Improved unit test with Mm2TestConf
borngraced 5c63ae7
Merge branch 'dev' of https://github.com/KomodoPlatform/atomicDEX-API…
borngraced File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use common::{HttpStatusCode, StatusCode}; | ||
use derive_more::Display; | ||
use mm2_core::mm_ctx::MmArc; | ||
use mm2_err_handle::prelude::MmError; | ||
|
||
use crate::{lp_coinfind_or_err, | ||
utxo::{rpc_clients::UtxoRpcError, UtxoCommonOps}, | ||
CoinFindError, MmCoinEnum}; | ||
|
||
pub type GetCurrentMtpRpcResult<T> = Result<T, MmError<GetCurrentMtpError>>; | ||
|
||
#[derive(Deserialize)] | ||
pub struct GetCurrentMtpRequest { | ||
coin: String, | ||
} | ||
|
||
#[derive(Serialize)] | ||
pub struct GetCurrentMtpResponse { | ||
mtp: u32, | ||
} | ||
|
||
#[derive(Serialize, Display, SerializeErrorType)] | ||
#[serde(tag = "error_type", content = "error_data")] | ||
pub enum GetCurrentMtpError { | ||
NoSuchCoin(String), | ||
#[display(fmt = "Requested coin: {}; is not supported for this action.", _0)] | ||
NotSupportedCoin(String), | ||
RpcError(String), | ||
} | ||
|
||
impl HttpStatusCode for GetCurrentMtpError { | ||
fn status_code(&self) -> StatusCode { | ||
match self { | ||
GetCurrentMtpError::NoSuchCoin(_) => StatusCode::PRECONDITION_REQUIRED, | ||
GetCurrentMtpError::NotSupportedCoin(_) => StatusCode::BAD_REQUEST, | ||
GetCurrentMtpError::RpcError(_) => StatusCode::INTERNAL_SERVER_ERROR, | ||
} | ||
} | ||
} | ||
|
||
impl From<UtxoRpcError> for GetCurrentMtpError { | ||
fn from(err: UtxoRpcError) -> Self { Self::RpcError(err.to_string()) } | ||
} | ||
|
||
impl From<CoinFindError> for GetCurrentMtpError { | ||
fn from(err: CoinFindError) -> Self { Self::NoSuchCoin(err.to_string()) } | ||
} | ||
|
||
pub async fn get_current_mtp_rpc( | ||
ctx: MmArc, | ||
req: GetCurrentMtpRequest, | ||
) -> GetCurrentMtpRpcResult<GetCurrentMtpResponse> { | ||
match lp_coinfind_or_err(&ctx, &req.coin).await? { | ||
MmCoinEnum::UtxoCoin(utxo) => Ok(GetCurrentMtpResponse { | ||
mtp: utxo.get_current_mtp().await?, | ||
}), | ||
MmCoinEnum::QtumCoin(qtum) => Ok(GetCurrentMtpResponse { | ||
mtp: qtum.get_current_mtp().await?, | ||
}), | ||
MmCoinEnum::Qrc20Coin(qrc) => Ok(GetCurrentMtpResponse { | ||
mtp: qrc.get_current_mtp().await?, | ||
}), | ||
#[cfg(not(target_arch = "wasm32"))] | ||
MmCoinEnum::ZCoin(zcoin) => Ok(GetCurrentMtpResponse { | ||
mtp: zcoin.get_current_mtp().await?, | ||
}), | ||
MmCoinEnum::Bch(bch) => Ok(GetCurrentMtpResponse { | ||
mtp: bch.get_current_mtp().await?, | ||
}), | ||
_ => Err(MmError::new(GetCurrentMtpError::NotSupportedCoin(req.coin))), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's overhead to run a seednode in this test.
Seednode opens a server socket and listens for incoming P2P connections.
But anyway it's not critical now