Skip to content
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

style(dapi): better api for identities balances #2122

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions packages/dapi-grpc/protos/platform/v0/platform.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,11 @@ use dpp::version::PlatformVersion;
impl<C> Platform<C> {
pub(super) fn query_identities_balances_v0(
&self,
GetIdentitiesBalancesRequestV0 {
identities_ids,
prove,
}: GetIdentitiesBalancesRequestV0,
GetIdentitiesBalancesRequestV0 { ids, prove }: GetIdentitiesBalancesRequestV0,
platform_state: &PlatformState,
platform_version: &PlatformVersion,
) -> Result<QueryValidationResult<GetIdentitiesBalancesResponseV0>, 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(|_| {
Expand Down
9 changes: 1 addition & 8 deletions packages/rs-drive-proof-verifier/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,17 +676,10 @@ impl FromProof<platform::GetIdentitiesBalancesRequest> 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)
Expand Down
11 changes: 3 additions & 8 deletions packages/rs-sdk/src/platform/types/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -153,16 +153,11 @@ impl Query<GetIdentitiesBalancesRequest> for Vec<dpp::prelude::Identifier> {
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 },
)),
};

Expand Down
Loading