-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Implement `mempool` endpoints - Implement `mempool` tests in Java
- Loading branch information
Showing
36 changed files
with
1,457 additions
and
528 deletions.
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
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
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
62 changes: 62 additions & 0 deletions
62
core-rust/mesh-api-server/src/mesh_api/handlers/mempool.rs
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,62 @@ | ||
use crate::prelude::*; | ||
|
||
pub(crate) async fn handle_mempool( | ||
state: State<MeshApiState>, | ||
Json(request): Json<models::NetworkRequest>, | ||
) -> Result<Json<models::MempoolResponse>, ResponseError> { | ||
assert_matching_network(&request.network_identifier, &state.network)?; | ||
|
||
let mapping_context = MappingContext::new(&state.network); | ||
let mempool = state.state_manager.mempool.read(); | ||
|
||
Ok(Json(models::MempoolResponse::new( | ||
mempool | ||
.all_hashes_iter() | ||
.map(|(intent_hash, _)| { | ||
Ok(models::TransactionIdentifier { | ||
hash: to_api_transaction_hash_bech32m(&mapping_context, intent_hash)?, | ||
}) | ||
}) | ||
.collect::<Result<Vec<_>, MappingError>>()?, | ||
))) | ||
} | ||
|
||
pub(crate) async fn handle_mempool_transaction( | ||
state: State<MeshApiState>, | ||
Json(request): Json<models::MempoolTransactionRequest>, | ||
) -> Result<Json<models::MempoolTransactionResponse>, ResponseError> { | ||
assert_matching_network(&request.network_identifier, &state.network)?; | ||
|
||
let extraction_context = ExtractionContext::new(&state.network); | ||
let mapping_context = MappingContext::new(&state.network); | ||
let mempool = state.state_manager.mempool.read(); | ||
|
||
let intent_hash = extract_transaction_intent_hash( | ||
&extraction_context, | ||
request.transaction_identifier.hash.clone(), | ||
) | ||
.map_err(|err| err.into_response_error("intent_hash"))?; | ||
|
||
if mempool | ||
.get_notarized_transaction_hashes_for_intent(&intent_hash) | ||
.is_empty() | ||
{ | ||
return Err( | ||
ResponseError::from(ApiError::TransactionNotFound).with_details(format!( | ||
"transaction {} not found in mempool transactions", | ||
&request.transaction_identifier.hash | ||
)), | ||
); | ||
} | ||
|
||
// TODO:MESH prepare transaction estimates | ||
let transaction = models::Transaction::new( | ||
models::TransactionIdentifier::new(to_api_transaction_hash_bech32m( | ||
&mapping_context, | ||
&intent_hash, | ||
)?), | ||
vec![], | ||
); | ||
|
||
Ok(Json(models::MempoolTransactionResponse::new(transaction))) | ||
} |
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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
mod account_balance; | ||
mod block; | ||
mod mempool; | ||
mod network_list; | ||
mod network_options; | ||
mod network_status; | ||
|
||
pub(crate) use account_balance::*; | ||
pub(crate) use block::*; | ||
pub(crate) use mempool::*; | ||
pub(crate) use network_list::*; | ||
pub(crate) use network_options::*; | ||
pub(crate) use network_status::*; |
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
Oops, something went wrong.