-
Notifications
You must be signed in to change notification settings - Fork 5
feat: address totals REST endpoint #356
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f979bf3
fix: merge volatile totals for deltas of the same tx to avoid overcou…
whankinsiv 2f254c0
feat: account totals endpoint handler
whankinsiv 62b90dd
feat: address totals endpoint handler
whankinsiv f035970
test: add tests for summing same tx totals and preventing duplicate t…
whankinsiv f78f709
add temporary HashMap for deduplicating transactions in address state
whankinsiv 1b3cbb1
fix: defer marking tx as seen until after totals and txs are both pro…
whankinsiv 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -3,8 +3,8 @@ use std::sync::Arc; | |
|
|
||
| use crate::handlers_config::HandlersConfig; | ||
| use crate::types::{ | ||
| AccountAddressREST, AccountRewardREST, AccountUTxOREST, AccountWithdrawalREST, AmountList, | ||
| DelegationUpdateREST, RegistrationUpdateREST, | ||
| AccountAddressREST, AccountRewardREST, AccountTotalsREST, AccountUTxOREST, | ||
| AccountWithdrawalREST, AmountList, DelegationUpdateREST, RegistrationUpdateREST, | ||
| }; | ||
| use acropolis_common::messages::{Message, RESTResponse, StateQuery, StateQueryResponse}; | ||
| use acropolis_common::queries::accounts::{AccountsStateQuery, AccountsStateQueryResponse}; | ||
|
|
@@ -563,7 +563,7 @@ pub async fn handle_account_assets_blockfrost( | |
| .await?; | ||
|
|
||
| let Some(addresses) = addresses else { | ||
| return Ok(RESTResponse::with_text(404, "Account not found")); | ||
| return Err(RESTError::not_found("Account not found")); | ||
| }; | ||
|
|
||
| // Get utxos from address state | ||
|
|
@@ -621,11 +621,78 @@ pub async fn handle_account_assets_blockfrost( | |
|
|
||
| /// Handle `/accounts/{stake_address}/addresses/total` Blockfrost-compatible endpoint | ||
| pub async fn handle_account_totals_blockfrost( | ||
| _context: Arc<Context<Message>>, | ||
| _params: Vec<String>, | ||
| _handlers_config: Arc<HandlersConfig>, | ||
| context: Arc<Context<Message>>, | ||
| params: Vec<String>, | ||
| handlers_config: Arc<HandlersConfig>, | ||
| ) -> Result<RESTResponse, RESTError> { | ||
| Err(RESTError::not_implemented("Account totals not implemented")) | ||
| let account = parse_stake_address(¶ms)?; | ||
|
|
||
| // Get addresses from historical accounts state | ||
| let msg = Arc::new(Message::StateQuery(StateQuery::Accounts( | ||
| AccountsStateQuery::GetAccountAssociatedAddresses { | ||
| account: account.clone(), | ||
| }, | ||
| ))); | ||
| let addresses = query_state( | ||
| &context, | ||
| &handlers_config.historical_accounts_query_topic, | ||
| msg, | ||
| |message| match message { | ||
| Message::StateQueryResponse(StateQueryResponse::Accounts( | ||
| AccountsStateQueryResponse::AccountAssociatedAddresses(addresses), | ||
| )) => Ok(Some(addresses)), | ||
| Message::StateQueryResponse(StateQueryResponse::Accounts( | ||
| AccountsStateQueryResponse::Error(QueryError::NotFound { .. }), | ||
| )) => Ok(None), | ||
| Message::StateQueryResponse(StateQueryResponse::Addresses( | ||
| AddressStateQueryResponse::Error(e), | ||
| )) => Err(e), | ||
| _ => Err(QueryError::internal_error( | ||
| "Unexpected message type while retrieving account addresses", | ||
| )), | ||
| }, | ||
| ) | ||
| .await?; | ||
|
|
||
| let Some(addresses) = addresses else { | ||
| return Err(RESTError::not_found("Account not found")); | ||
| }; | ||
|
|
||
| // Get totals from address state | ||
| let msg = Arc::new(Message::StateQuery(StateQuery::Addresses( | ||
| AddressStateQuery::GetAddressesTotals { addresses }, | ||
| ))); | ||
| let totals = query_state( | ||
| &context, | ||
| &handlers_config.addresses_query_topic, | ||
| msg, | ||
| |message| match message { | ||
| Message::StateQueryResponse(StateQueryResponse::Addresses( | ||
| AddressStateQueryResponse::AddressesTotals(totals), | ||
| )) => Ok(totals), | ||
| Message::StateQueryResponse(StateQueryResponse::Addresses( | ||
| AddressStateQueryResponse::Error(e), | ||
| )) => Err(e), | ||
| _ => Err(QueryError::internal_error( | ||
| "Unexpected message type while retrieving account totals", | ||
| )), | ||
| }, | ||
| ) | ||
| .await?; | ||
|
|
||
| // TODO: Query historical accounts state to retrieve account tx count instead of | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good TODO / comment here. |
||
| // using the addresses totals as the addresses totals does not deduplicate | ||
| // for multi-address transactions, overstating count | ||
|
|
||
| let rest_response = AccountTotalsREST { | ||
| stake_address: account.to_string()?, | ||
| received_sum: totals.received.into(), | ||
| sent_sum: totals.sent.into(), | ||
| tx_count: totals.tx_count, | ||
| }; | ||
|
|
||
| let json = serde_json::to_string_pretty(&rest_response)?; | ||
| Ok(RESTResponse::with_json(200, &json)) | ||
| } | ||
|
|
||
| /// Handle `/accounts/{stake_address}/utxos` Blockfrost-compatible endpoint | ||
|
|
@@ -659,7 +726,7 @@ pub async fn handle_account_utxos_blockfrost( | |
| .await?; | ||
|
|
||
| let Some(addresses) = addresses else { | ||
| return Ok(RESTResponse::with_text(404, "Account not found")); | ||
| return Err(RESTError::not_found("Account not found")); | ||
| }; | ||
|
|
||
| // Get utxos from address state | ||
|
|
||
Oops, something went wrong.
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.
Nice tests