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

feat(sdk): token and group queries #2449

Open
wants to merge 34 commits into
base: v2.0-tokens-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
0d97d80
chore: implement proof verification sugar for new queries
shumkov Jan 28, 2025
474ecfa
chore: add methods for new queries to dapi client
shumkov Jan 28, 2025
f5d1f71
chore: fetch implementation in progress
shumkov Jan 29, 2025
ed9dc9e
chore(sdk): implement queries and fetch methods
shumkov Jan 29, 2025
a23f8d0
Merge branch 'v2.0-tokens-dev' into feat/sdk/queries
shumkov Jan 30, 2025
c2c3c94
fix: fetch implementation for non-optional values
shumkov Jan 30, 2025
9d4920d
fix: fetch objects aren't available from SDK
shumkov Feb 1, 2025
3e571e6
feat(drive): add generate test data logic for init chain
shumkov Feb 3, 2025
bdd7ff8
chore(sdk): improvements and fixes for token queries
shumkov Feb 3, 2025
22212aa
test(sdk): fix SDK test framework
shumkov Feb 3, 2025
21de3a4
test(sdk): add query and group tests
shumkov Feb 3, 2025
27bf8bf
refactor: minor refactorings after PR review
shumkov Feb 3, 2025
9816146
refactor: remove broadcast methods from ST builders
shumkov Feb 3, 2025
42e3e16
fix: some minor fixes
shumkov Feb 3, 2025
1c3ba5e
fix: identity contract nonce
shumkov Feb 3, 2025
e56f057
test: fixtures
shumkov Feb 4, 2025
fdab153
test: more fixtures
shumkov Feb 4, 2025
2351b50
fix: proof result error for credit transfers in sdk
pauldelucia Feb 4, 2025
79f7038
fix: `TokenTransition` has no methods
shumkov Feb 4, 2025
da14f7c
chore: print identity keys
shumkov Feb 4, 2025
21c4d73
Merge remote-tracking branch 'origin/feat/sdk/queries' into feat/sdk/…
shumkov Feb 4, 2025
28727ac
fix: missing methods in token transitions
shumkov Feb 4, 2025
288dca1
chore: add getProof request logging
shumkov Feb 4, 2025
440fc27
fix: more missing methods
shumkov Feb 5, 2025
f173e89
test: fix tests
shumkov Feb 5, 2025
f445d52
fix: invalid GetProof request
shumkov Feb 5, 2025
a52b6bc
fix: cannot read properties of undefined (reading 'dataContract')
shumkov Feb 5, 2025
e317e47
fix: cannot read properties of undefined (reading 'toString')
shumkov Feb 6, 2025
a365cfd
fix: wrong data contract id to verify historical token proof
shumkov Feb 6, 2025
84359ea
fix: the token config is fetched wrong the wrong contract
shumkov Feb 6, 2025
bbadd12
fix: can't create a token contract from buffer
shumkov Feb 6, 2025
a0402cd
set limit to 1 on single key sized query
pauldelucia Feb 7, 2025
3e87933
fix: proofs for historical contracts
shumkov Feb 7, 2025
c809ebd
Merge remote-tracking branch 'origin/feat/sdk/queries' into feat/sdk/…
shumkov Feb 7, 2025
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
16 changes: 14 additions & 2 deletions packages/dapi-grpc/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
// Derive features for versioned messages
//
// "GetConsensusParamsRequest" is excluded as this message does not support proofs
const VERSIONED_REQUESTS: [&str; 34] = [
const VERSIONED_REQUESTS: [&str; 40] = [
"GetDataContractHistoryRequest",
"GetDataContractRequest",
"GetDataContractsRequest",
Expand Down Expand Up @@ -82,14 +82,20 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
"GetIdentitiesTokenBalancesRequest",
"GetIdentityTokenInfosRequest",
"GetIdentitiesTokenInfosRequest",
"GetTokenStatusesRequest",
"GetTokenTotalSupplyRequest",
"GetGroupInfoRequest",
"GetGroupInfosRequest",
"GetGroupActionsRequest",
"GetGroupActionSignersRequest",
];

// The following responses are excluded as they don't support proofs:
// - "GetConsensusParamsResponse"
// - "GetStatusResponse"
//
// "GetEvonodesProposedEpochBlocksResponse" is used for 2 Requests
const VERSIONED_RESPONSES: [&str; 33] = [
const VERSIONED_RESPONSES: [&str; 39] = [
"GetDataContractHistoryResponse",
"GetDataContractResponse",
"GetDataContractsResponse",
Expand Down Expand Up @@ -123,6 +129,12 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
"GetIdentitiesTokenBalancesResponse",
"GetIdentityTokenInfosResponse",
"GetIdentitiesTokenInfosResponse",
"GetTokenStatusesResponse",
"GetTokenTotalSupplyResponse",
"GetGroupInfoResponse",
"GetGroupInfosResponse",
"GetGroupActionsResponse",
"GetGroupActionSignersResponse",
];

check_unique(&VERSIONED_REQUESTS).expect("VERSIONED_REQUESTS");
Expand Down
90 changes: 90 additions & 0 deletions packages/rs-dapi-client/src/transport/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,3 +514,93 @@ impl_transport_request_grpc!(
RequestSettings::default(),
get_status
);

// rpc getIdentityTokenBalances(GetIdentityTokenBalancesRequest) returns (GetIdentityTokenBalancesResponse);
impl_transport_request_grpc!(
platform_proto::GetIdentityTokenBalancesRequest,
platform_proto::GetIdentityTokenBalancesResponse,
PlatformGrpcClient,
RequestSettings::default(),
get_identity_token_balances
);

// rpc getIdentitiesTokenBalances(GetIdentitiesTokenBalancesRequest) returns (GetIdentitiesTokenBalancesResponse);
impl_transport_request_grpc!(
platform_proto::GetIdentitiesTokenBalancesRequest,
platform_proto::GetIdentitiesTokenBalancesResponse,
PlatformGrpcClient,
RequestSettings::default(),
get_identities_token_balances
);

// rpc getIdentityTokenInfos(GetIdentityTokenInfosRequest) returns (GetIdentityTokenInfosResponse);
impl_transport_request_grpc!(
platform_proto::GetIdentityTokenInfosRequest,
platform_proto::GetIdentityTokenInfosResponse,
PlatformGrpcClient,
RequestSettings::default(),
get_identity_token_infos
);

// rpc getIdentitiesTokenInfos(GetIdentitiesTokenInfosRequest) returns (GetIdentitiesTokenInfosResponse);
impl_transport_request_grpc!(
platform_proto::GetIdentitiesTokenInfosRequest,
platform_proto::GetIdentitiesTokenInfosResponse,
PlatformGrpcClient,
RequestSettings::default(),
get_identities_token_infos
);

// rpc getTokenStatuses(GetTokenStatusesRequest) returns (GetTokenStatusesResponse);
impl_transport_request_grpc!(
platform_proto::GetTokenStatusesRequest,
platform_proto::GetTokenStatusesResponse,
PlatformGrpcClient,
RequestSettings::default(),
get_token_statuses
);

// rpc getTokenTotalSupply(GetTokenTotalSupplyRequest) returns (GetTokenTotalSupplyResponse);
impl_transport_request_grpc!(
platform_proto::GetTokenTotalSupplyRequest,
platform_proto::GetTokenTotalSupplyResponse,
PlatformGrpcClient,
RequestSettings::default(),
get_token_total_supply
);

// rpc getGroupInfo(GetGroupInfoRequest) returns (GetGroupInfoResponse);
impl_transport_request_grpc!(
platform_proto::GetGroupInfoRequest,
platform_proto::GetGroupInfoResponse,
PlatformGrpcClient,
RequestSettings::default(),
get_group_info
);

// rpc getGroupInfos(GetGroupInfosRequest) returns (GetGroupInfosResponse);
impl_transport_request_grpc!(
platform_proto::GetGroupInfosRequest,
platform_proto::GetGroupInfosResponse,
PlatformGrpcClient,
RequestSettings::default(),
get_group_infos
);

// rpc getGroupActions(GetGroupActionsRequest) returns (GetGroupActionsResponse);
impl_transport_request_grpc!(
platform_proto::GetGroupActionsRequest,
platform_proto::GetGroupActionsResponse,
PlatformGrpcClient,
RequestSettings::default(),
get_group_actions
);

// rpc getGroupActionSigners(GetGroupActionSignersRequest) returns (GetGroupActionSignersResponse);
impl_transport_request_grpc!(
platform_proto::GetGroupActionSignersRequest,
platform_proto::GetGroupActionSignersResponse,
PlatformGrpcClient,
RequestSettings::default(),
get_group_action_signers
);
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
use crate::balances::credits::SignedTokenAmount;
use crate::ProtocolError;
#[cfg(feature = "fixtures-and-mocks")]
use bincode::Encode;
#[cfg(feature = "fixtures-and-mocks")]
use platform_serialization::de::Decode;
use std::fmt;

/// A structure where the token supply and the aggregated token account balances should always be equal
#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "fixtures-and-mocks", derive(Encode, Decode))]
pub struct TotalSingleTokenBalance {
/// the token supply
pub token_supply: SignedTokenAmount,
Expand Down
3 changes: 3 additions & 0 deletions packages/rs-dpp/src/tokens/info/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use platform_serialization::de::Decode;
use platform_serialization_derive::{PlatformDeserialize, PlatformSerialize};
use platform_version::version::PlatformVersion;
use platform_versioning::PlatformVersioned;
#[cfg(feature = "fixtures-and-mocks")]
use serde::{Deserialize, Serialize};

mod methods;
pub mod v0;
Expand All @@ -22,6 +24,7 @@ pub mod v0;
PartialEq,
)]
#[platform_serialize(unversioned)] //versioned directly, no need to use platform_version
#[cfg_attr(feature = "fixtures-and-mocks", derive(Serialize, Deserialize))]
pub enum IdentityTokenInfo {
V0(IdentityTokenInfoV0),
}
Expand Down
3 changes: 3 additions & 0 deletions packages/rs-dpp/src/tokens/info/v0/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use bincode::{Decode, Encode};
use derive_more::From;
#[cfg(feature = "fixtures-and-mocks")]
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Encode, Decode, From, PartialEq)]
#[cfg_attr(feature = "fixtures-and-mocks", derive(Serialize, Deserialize))]
/// Token information for an identity (version 0).
pub struct IdentityTokenInfoV0 {
pub frozen: bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use dpp::version::PlatformVersion;
use drive::grovedb::TransactionArg;

mod common;
mod test;
pub mod v0;
pub mod v1;

Expand Down Expand Up @@ -42,6 +43,11 @@ impl<C> Platform<C> {
known_versions: vec![0, 1],
received: version,
})),
}
}?;

// UNCOMMENT ONLY TO GENERATE SDK TEST DATA
// self.create_sdk_test_data(&block_info, transaction, platform_version)?;

Ok(())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use crate::error::execution::ExecutionError;
use crate::error::Error;
use crate::platform_types::platform::Platform;
use dpp::block::block_info::BlockInfo;
use dpp::dashcore::Network;
use dpp::version::PlatformVersion;
use drive::grovedb::TransactionArg;

mod tokens;

impl<C> Platform<C> {
/// Creates testing data for SDK functional and e2e tests
///
/// This is function must be used only for testing
/// purposes on local networks and DISABLED BY DEFAULT
#[allow(dead_code)]
pub(super) fn create_sdk_test_data(
&self,
block_info: &BlockInfo,
transaction: TransactionArg,
platform_version: &PlatformVersion,
) -> Result<(), Error> {
if self.config.network != Network::Regtest {
return Err(Error::Execution(ExecutionError::CorruptedCodeExecution(
"create_sdk_test_data must be called only on local network",
)));
}

self.create_data_for_group_token_queries(block_info, transaction, platform_version)?;

Ok(())
}
}
Loading