-
Notifications
You must be signed in to change notification settings - Fork 75
feat: Add delegate filter param's to account_tx RPC #2827
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
base: develop
Are you sure you want to change the base?
Changes from 3 commits
7a58d95
141aa14
18bcdf3
55f5961
300219a
eb83ca3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1567,4 +1567,48 @@ toJsonWithBinaryTx(data::TransactionAndMetadata const& txnPlusMeta, std::uint32_ | |
| return obj; | ||
| } | ||
|
|
||
| std::optional<DelegateFilter::Role> | ||
| parseDelegateType(boost::json::value const& delegateType) | ||
| { | ||
| if (not delegateType.is_string()) | ||
| return {}; | ||
|
|
||
| auto const& type = delegateType.as_string(); | ||
|
|
||
| if (type == "delegator") | ||
|
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. Magic strings everywhere 😃 these should either be JS(...) if possible or some sort of constants 🔢 |
||
| return DelegateFilter::Role::Delegator; | ||
| if (type == "delegatee") | ||
| return DelegateFilter::Role::Delegatee; | ||
|
|
||
| return {}; | ||
| } | ||
|
|
||
| std::optional<DelegateFilter> | ||
| parseDelegateFilter(boost::json::object const& delegateObject) | ||
| { | ||
| DelegateFilter delegate{}; | ||
| if (!delegateObject.contains("delegate_filter")) | ||
| return {}; | ||
|
|
||
| auto const& filterVal = delegateObject.at("delegate_filter"); | ||
| if (!filterVal.is_string()) | ||
| return {}; | ||
|
|
||
| auto const delegateTypeOpt = parseDelegateType(filterVal.as_string()); | ||
| if (!delegateTypeOpt.has_value()) | ||
| return {}; | ||
|
|
||
| delegate.delegateType = *delegateTypeOpt; | ||
| if (delegateObject.contains("counterparty")) { | ||
| auto const& counterpartyVal = delegateObject.at("counterparty"); | ||
|
|
||
| if (!counterpartyVal.is_string()) | ||
| return {}; | ||
|
|
||
| delegate.counterParty = counterpartyVal.as_string(); | ||
| } | ||
|
|
||
| return delegate; | ||
| } | ||
|
|
||
| } // namespace rpc | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,9 +33,9 @@ | |
|
|
||
| #include <cstdint> | ||
| #include <expected> | ||
| #include <optional> | ||
| #include <string> | ||
| #include <utility> | ||
| #include <variant> | ||
|
|
||
| namespace etl { | ||
| class LoadBalancer; | ||
|
|
@@ -194,6 +194,27 @@ struct AccountCursor { | |
| } | ||
| }; | ||
|
|
||
| /** | ||
| * @brief A delegate object used filter account_tx by specific delegate accounts | ||
| */ | ||
| struct DelegateFilter { | ||
| /** | ||
| * @brief A delegate type used in delegate filter | ||
| */ | ||
| enum class Role { | ||
| // This account is the *active* sender, acting on behalf of another party. | ||
|
||
| // e.g., Account A in "A sends payment to B on behalf of C." | ||
| Delegatee, | ||
|
|
||
| // This account is the *passive* party whose funds are being moved from. | ||
| // e.g., Account C in "A sends payment to B on behalf of C." | ||
| Delegator | ||
| }; | ||
|
|
||
| Role delegateType; | ||
| std::optional<std::string> counterParty; | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Convert an empty output to a JSON object | ||
| * | ||
|
|
||
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.
Looks like a good place to try and use ranges? 🙂