From 6be8072d3bb2501e63d45a5a76aefe135db8dc6e Mon Sep 17 00:00:00 2001 From: Quantum Explorer Date: Mon, 16 Sep 2024 05:59:22 +0700 Subject: [PATCH] style(dapi): better api for identities balances --- packages/dapi-grpc/protos/platform/v0/platform.proto | 5 +---- .../query/identity_based_queries/balances/v0/mod.rs | 11 ++--------- packages/rs-drive-proof-verifier/src/proof.rs | 9 +-------- packages/rs-sdk/src/platform/types/identity.rs | 11 +++-------- 4 files changed, 7 insertions(+), 29 deletions(-) diff --git a/packages/dapi-grpc/protos/platform/v0/platform.proto b/packages/dapi-grpc/protos/platform/v0/platform.proto index c884e28c50..b690d3f7cc 100644 --- a/packages/dapi-grpc/protos/platform/v0/platform.proto +++ b/packages/dapi-grpc/protos/platform/v0/platform.proto @@ -362,10 +362,7 @@ message GetEvonodesProposedEpochBlocksByRangeRequest { message GetIdentitiesBalancesRequest { message GetIdentitiesBalancesRequestV0 { - message GetIdentitiesBalancesByKnownIdentityIds { - repeated bytes identities_ids = 1; - } - GetIdentitiesBalancesByKnownIdentityIds identities_ids = 1; + repeated bytes ids = 1; bool prove = 2; } diff --git a/packages/rs-drive-abci/src/query/identity_based_queries/balances/v0/mod.rs b/packages/rs-drive-abci/src/query/identity_based_queries/balances/v0/mod.rs index 3fffc94064..c8d054f888 100644 --- a/packages/rs-drive-abci/src/query/identity_based_queries/balances/v0/mod.rs +++ b/packages/rs-drive-abci/src/query/identity_based_queries/balances/v0/mod.rs @@ -15,18 +15,11 @@ use dpp::version::PlatformVersion; impl Platform { pub(super) fn query_identities_balances_v0( &self, - GetIdentitiesBalancesRequestV0 { - identities_ids, - prove, - }: GetIdentitiesBalancesRequestV0, + GetIdentitiesBalancesRequestV0 { ids, prove }: GetIdentitiesBalancesRequestV0, platform_state: &PlatformState, platform_version: &PlatformVersion, ) -> Result, Error> { - let identities_ids = check_validation_result_with_data!(identities_ids.ok_or( - QueryError::InvalidArgument("identities_ids must be set".to_string()) - )) - .identities_ids; - let identifiers = check_validation_result_with_data!(identities_ids + let identifiers = check_validation_result_with_data!(ids .into_iter() .map(|identity_id| { let identifier: Identifier = identity_id.try_into().map_err(|_| { diff --git a/packages/rs-drive-proof-verifier/src/proof.rs b/packages/rs-drive-proof-verifier/src/proof.rs index a203bb8eec..f3a256e301 100644 --- a/packages/rs-drive-proof-verifier/src/proof.rs +++ b/packages/rs-drive-proof-verifier/src/proof.rs @@ -676,17 +676,10 @@ impl FromProof for IdentityBalances { let mtd = response.metadata().or(Err(Error::EmptyResponseMetadata))?; let identities_ids = match request.version.ok_or(Error::EmptyVersion)? { - get_identities_balances_request::Version::V0(v0) => v0.identities_ids, - }; - - let Some(identities_ids) = identities_ids else { - return Err(Error::RequestError { - error: "expected identity ids".to_string(), - }); + get_identities_balances_request::Version::V0(v0) => v0.ids, }; let identity_ids = identities_ids - .identities_ids .into_iter() .map(|identity_bytes| { Identifier::from_bytes(&identity_bytes) diff --git a/packages/rs-sdk/src/platform/types/identity.rs b/packages/rs-sdk/src/platform/types/identity.rs index d710afd08d..632e3bd5e4 100644 --- a/packages/rs-sdk/src/platform/types/identity.rs +++ b/packages/rs-sdk/src/platform/types/identity.rs @@ -5,7 +5,7 @@ use crate::{ platform::{proto, Query}, Error, }; -use dapi_grpc::platform::v0::get_identities_balances_request::get_identities_balances_request_v0::GetIdentitiesBalancesByKnownIdentityIds; + use dapi_grpc::platform::v0::get_identities_balances_request::GetIdentitiesBalancesRequestV0; use dapi_grpc::platform::v0::get_identity_balance_and_revision_request::GetIdentityBalanceAndRevisionRequestV0; use dapi_grpc::platform::v0::get_identity_balance_request::GetIdentityBalanceRequestV0; @@ -153,16 +153,11 @@ impl Query for Vec { if !prove { unimplemented!("queries without proofs are not supported yet"); } - let identities_ids = self.into_iter().map(|a| a.to_vec()).collect(); + let ids = self.into_iter().map(|a| a.to_vec()).collect(); let request: GetIdentitiesBalancesRequest = GetIdentitiesBalancesRequest { version: Some(get_identities_balances_request::Version::V0( - GetIdentitiesBalancesRequestV0 { - identities_ids: Some(GetIdentitiesBalancesByKnownIdentityIds { - identities_ids, - }), - prove, - }, + GetIdentitiesBalancesRequestV0 { ids, prove }, )), };