Skip to content
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
4 changes: 3 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ exclude = ["packages/wasm-sdk"] # This one is experimental and not ready for use
[workspace.package]

rust-version = "1.85"

100 changes: 66 additions & 34 deletions packages/dash-platform-balance-checker/src/main_simple.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use anyhow::Result;
use dapi_grpc::platform::v0::{
GetIdentityBalanceRequest, GetIdentityBalanceResponse, GetIdentityRequest, GetIdentityResponse,
get_identity_balance_request, get_identity_balance_response, get_identity_request,
get_identity_response, GetIdentityBalanceRequest, GetIdentityRequest,
};
use dpp::dashcore::Network;
use dpp::prelude::Identifier;
use rs_dapi_client::{Address, AddressList, DapiClient, RequestSettings};
use rs_dapi_client::{Address, AddressList, DapiClient, DapiRequestExecutor, RequestSettings};
use std::str::FromStr;

#[tokio::main]
Expand Down Expand Up @@ -37,48 +37,80 @@ async fn main() -> Result<()> {

// Create request for identity (proved)
let request = GetIdentityRequest {
version: None,
id: identity_id.to_vec(),
prove: true,
version: Some(get_identity_request::Version::V0(
get_identity_request::GetIdentityRequestV0 {
id: identity_id.to_vec(),
prove: true,
},
)),
};

println!("Fetching identity (proved)...");
match dapi.platform.get_identity(request).await {
match dapi.execute(request, RequestSettings::default()).await {
Ok(response) => {
if let Some(identity_bytes) = response.identity {
println!(
"✓ Identity found! Raw response length: {} bytes",
identity_bytes.len()
);
// Check if we have a response with version
if let Some(version) = response.inner.version {
match version {
get_identity_response::Version::V0(v0) => {
if let Some(result) = v0.result {
match result {
get_identity_response::get_identity_response_v0::Result::Identity(identity_bytes) => {
println!(
"✓ Identity found! Raw response length: {} bytes",
identity_bytes.len()
);

// Now get balance
let balance_request = GetIdentityBalanceRequest {
version: None,
id: identity_id.to_vec(),
prove: true,
};
// Now get balance
let balance_request = GetIdentityBalanceRequest {
version: Some(get_identity_balance_request::Version::V0(
get_identity_balance_request::GetIdentityBalanceRequestV0 {
id: identity_id.to_vec(),
prove: true,
}
)),
};

println!("\nFetching balance...");
match dapi.platform.get_identity_balance(balance_request).await {
Ok(balance_response) => {
if let Some(balance) = balance_response.balance {
let balance_value = balance.balance;
println!("\n✓ Balance found!");
println!(" Balance: {} credits", balance_value);
println!(
" Balance in DASH: {} DASH",
balance_value as f64 / 100_000_000.0
);
println!("\nFetching balance...");
match dapi.execute(balance_request, RequestSettings::default()).await {
Ok(balance_response) => {
if let Some(version) = balance_response.inner.version {
match version {
get_identity_balance_response::Version::V0(v0) => {
if let Some(result) = v0.result {
match result {
get_identity_balance_response::get_identity_balance_response_v0::Result::Balance(balance) => {
println!("\n✓ Balance found!");
println!(" Balance: {} credits", balance);
println!(
" Balance in DASH: {} DASH",
balance as f64 / 100_000_000.0
);
}
_ => println!("✗ Unexpected response type")
}
} else {
println!("✗ No balance data in response");
}
}
}
} else {
println!("✗ No version in balance response");
}
}
Err(e) => {
println!("✗ Error fetching balance: {}", e);
}
}
}
_ => println!("✗ Identity not found or proof returned")
}
} else {
println!("✗ No balance data in response");
println!("✗ No result in response");
}
}
Err(e) => {
println!("✗ Error fetching balance: {}", e);
}
}
} else {
println!("✗ Identity not found");
println!("✗ No version in response");
}
}
Err(e) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-drive-abci/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ hex = "0.4.3"
indexmap = { version = "2.2.6", features = ["serde"] }
dashcore-rpc = { git = "https://github.com/dashpay/rust-dashcore", tag = "v0.39.6" }
dpp = { path = "../rs-dpp", default-features = false, features = ["abci"] }
simple-signer = { path = "../simple-signer" }
simple-signer = { path = "../simple-signer", features = ["state-transitions"] }
rust_decimal = "1.2.5"
rust_decimal_macros = "1.25.0"
mockall = { version = "0.13", optional = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ mod tests {
core_chain_locked_height: 0,
epoch: 0,
time_ms: 0,
protocol_version: 9,
protocol_version: 10,
chain_id: "chain_id".to_string()
}),
result: Some(
Expand Down
73 changes: 73 additions & 0 deletions packages/rs-drive/QUERY_QUICK_REFERENCE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Dash Platform Query Quick Reference

## Can we do multiple ranges on one index?

**YES, with limitations:**
- ✅ **2 range clauses on SAME field** → Combined into Between operator
- ❌ **Range clauses on DIFFERENT fields** → Not supported
- ❌ **More than 2 range clauses** → Not supported

### Valid Example:
```json
{
"where": [
["age", ">", 18],
["age", "<=", 65]
]
}
```
→ Internally becomes: `age BetweenExcludeLeft [18, 65]`

### Invalid Example:
```json
{
"where": [
["age", ">", 18],
["salary", "<", 100000]
]
}
```
→ Error: Range clauses must be on same field

## Compound Index Queries

For index [A, B, C], ranges can be on ANY property BUT:
- Range on A: No requirements
- Range on B: MUST have `A == value`
- Range on C: MUST have `A == value` AND `B == value`

### Examples:
```json
// ✅ Valid: Range on B with equality on A
{
"where": [
["A", "==", 5],
["B", ">", 10]
]
}

// ❌ Invalid: Range on B without equality on A
{
"where": [
["B", ">", 10] // Error: Missing A
]
}
```

## Key Query Rules

1. **Fields MUST be indexed** (no queries on non-indexed fields)
2. **One IN clause per query** (max 100 values)
3. **One range clause per query** (can be combined from 2 on same field)
4. **Limits**: Default 100, Max 100 (configurable)
5. **Special queryable fields**: `$id`, `$ownerId`, `$createdAt`, `$updatedAt`, `$revision`

## ProveOptions Warning

When using proof generation with GroveDB:
```rust
ProveOptions {
decrease_limit_on_empty_sub_query_result: true, // ALWAYS use true in production
}
```
Setting to `false` can cause memory exhaustion if query matches many empty subtrees!
Loading
Loading