-
Notifications
You must be signed in to change notification settings - Fork 19
add ability to query specific txn types in /v1/chain/history #361
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
Open
neocybereth
wants to merge
6
commits into
main
Choose a base branch
from
feat/add-transsaction-history-types
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d110847
add ability to query specific txns in history
neocybereth 70c24d8
fix: lint
neocybereth 7d5912b
fix: remove whitespace
neocybereth 3cc2d44
fix: format
neocybereth 388b4ed
fix: formatting
neocybereth 66a3f6e
minors
Fraccaman 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
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 |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| use orm::transactions::WrapperTransactionDb; | ||
| use std::collections::HashSet; | ||
|
|
||
| use orm::transactions::{TransactionKindDb, WrapperTransactionDb}; | ||
|
|
||
| use crate::appstate::AppState; | ||
| use crate::error::transaction::TransactionError; | ||
|
|
@@ -75,14 +77,80 @@ impl TransactionService { | |
| Ok(inner_txs.into_iter().map(InnerTransaction::from).collect()) | ||
| } | ||
|
|
||
| // Helper function to parse transaction types from comma-separated string | ||
| fn parse_transaction_types( | ||
| transaction_types: HashSet<String>, | ||
| ) -> HashSet<TransactionKindDb> { | ||
| transaction_types | ||
| .iter() | ||
| .filter_map(|type_str| { | ||
| let type_str = type_str.trim(); | ||
| match type_str { | ||
| "transparentTransfer" => { | ||
| Some(TransactionKindDb::TransparentTransfer) | ||
| } | ||
| "shieldedTransfer" => { | ||
| Some(TransactionKindDb::ShieldedTransfer) | ||
| } | ||
| "shieldingTransfer" => { | ||
| Some(TransactionKindDb::ShieldingTransfer) | ||
| } | ||
| "unshieldingTransfer" => { | ||
| Some(TransactionKindDb::UnshieldingTransfer) | ||
| } | ||
| "mixedTransfer" => Some(TransactionKindDb::MixedTransfer), | ||
| "ibcMsgTransfer" => Some(TransactionKindDb::IbcMsgTransfer), | ||
| "ibcTransparentTransfer" => { | ||
| Some(TransactionKindDb::IbcTransparentTransfer) | ||
| } | ||
| "ibcShieldingTransfer" => { | ||
| Some(TransactionKindDb::IbcShieldingTransfer) | ||
| } | ||
| "ibcUnshieldingTransfer" => { | ||
| Some(TransactionKindDb::IbcUnshieldingTransfer) | ||
| } | ||
| "bond" => Some(TransactionKindDb::Bond), | ||
| "redelegation" => Some(TransactionKindDb::Redelegation), | ||
| "unbond" => Some(TransactionKindDb::Unbond), | ||
| "withdraw" => Some(TransactionKindDb::Withdraw), | ||
| "claimRewards" => Some(TransactionKindDb::ClaimRewards), | ||
| "voteProposal" => Some(TransactionKindDb::VoteProposal), | ||
| "initProposal" => Some(TransactionKindDb::InitProposal), | ||
| "changeMetadata" => Some(TransactionKindDb::ChangeMetadata), | ||
| "changeCommission" => { | ||
| Some(TransactionKindDb::ChangeCommission) | ||
| } | ||
| "revealPk" => Some(TransactionKindDb::RevealPk), | ||
| "becomeValidator" => { | ||
| Some(TransactionKindDb::BecomeValidator) | ||
| } | ||
| "reactivateValidator" => { | ||
| Some(TransactionKindDb::ReactivateValidator) | ||
| } | ||
| "deactivateValidator" => { | ||
| Some(TransactionKindDb::DeactivateValidator) | ||
| } | ||
| "unjailValidator" => { | ||
| Some(TransactionKindDb::UnjailValidator) | ||
| } | ||
| _ => None, // Skip invalid types | ||
|
Contributor
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. Better to return an error maybe? To avoid typos going unnoticed |
||
| } | ||
| }) | ||
| .collect::<HashSet<_>>() | ||
| } | ||
|
|
||
| pub async fn get_addresses_history( | ||
| &self, | ||
| addresses: Vec<String>, | ||
| page: u64, | ||
| transaction_types: Option<HashSet<String>>, | ||
| ) -> Result<(Vec<TransactionHistory>, u64, u64), TransactionError> { | ||
| let transaction_types = | ||
| transaction_types.map(Self::parse_transaction_types); | ||
|
|
||
| let (txs, total_pages, total_items) = self | ||
| .transaction_repo | ||
| .find_addresses_history(addresses, page as i64) | ||
| .find_addresses_history(addresses, page as i64, transaction_types) | ||
| .await | ||
| .map_err(TransactionError::Database)?; | ||
|
|
||
|
|
||
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.
We could also just have an empty set without the need for an
Option