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

refactor(sdk): contested resource as struct type #2225

Merged
merged 14 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
13 changes: 13 additions & 0 deletions Cargo.lock

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

5 changes: 2 additions & 3 deletions packages/rs-dapi-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition = "2021"

[features]
default = ["mocks", "offline-testing"]
tokio-sleep = ["backon/tokio-sleep"]
mocks = [
"dep:sha2",
"dep:hex",
Expand All @@ -19,9 +20,7 @@ dump = ["mocks"]
offline-testing = []

[dependencies]
backon = { version = "1.2", default-features = false, features = [
"tokio-sleep",
] }
backon = { version = "1.2"}
dapi-grpc = { path = "../dapi-grpc", features = [
"core",
"platform",
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-drive-proof-verifier/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1379,7 +1379,7 @@ impl FromProof<platform::GetContestedResourcesRequest> for ContestedResources {
verify_tenderdash_proof(proof, mtd, &root_hash, provider)?;

let resources: ContestedResources =
items.into_iter().map(ContestedResource::Value).collect();
items.into_iter().map(|v| ContestedResource(v)).collect();

Ok((resources.into_option(), mtd.clone(), proof.clone()))
}
Expand Down
23 changes: 7 additions & 16 deletions packages/rs-drive-proof-verifier/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,8 @@ pub struct ElementFetchRequestItem(pub Element);
pub type IdentityBalanceAndRevision = (u64, Revision);

/// Contested resource values.
#[derive(Debug, derive_more::From, Clone, PartialEq)]
pub enum ContestedResource {
/// Generic [Value]
Value(Value),
}
#[derive(Debug, Clone, PartialEq)]
pub struct ContestedResource(pub Value);

impl ContestedResource {
/// Get the value.
Expand All @@ -244,13 +241,9 @@ impl ContestedResource {
}
}

impl TryInto<Value> for ContestedResource {
type Error = crate::Error;

fn try_into(self) -> Result<Value, Self::Error> {
match self {
ContestedResource::Value(value) => Ok(value),
}
impl Into<Value> for ContestedResource {
fn into(self) -> Value {
self.0
}
}

Expand All @@ -261,9 +254,7 @@ impl PlatformVersionEncode for ContestedResource {
encoder: &mut E,
_platform_version: &platform_version::PlatformVersion,
) -> Result<(), bincode::error::EncodeError> {
match self {
ContestedResource::Value(value) => value.encode(encoder),
}
self.0.encode(encoder)
}
}

Expand All @@ -273,7 +264,7 @@ impl PlatformVersionedDecode for ContestedResource {
decoder: &mut D,
_platform_version: &platform_version::PlatformVersion,
) -> Result<Self, bincode::error::DecodeError> {
Ok(ContestedResource::Value(Value::decode(decoder)?))
Ok(ContestedResource(Value::decode(decoder)?))
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/rs-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ test-case = { version = "3.3.1" }

[features]
default = ["mocks", "offline-testing"]
tokio-sleep = ["rs-dapi-client/tokio-sleep"]
lklimek marked this conversation as resolved.
Show resolved Hide resolved

mocks = [
"dep:serde",
Expand Down
1 change: 1 addition & 0 deletions packages/rs-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub use sdk::{RequestSettings, Sdk, SdkBuilder};
pub use dashcore_rpc;
pub use dpp;
pub use drive;
pub use drive_proof_verifier::types as query_types;
pub use rs_dapi_client as dapi_client;

/// Version of the SDK
Expand Down
4 changes: 2 additions & 2 deletions packages/rs-sdk/tests/fetch/contested_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async fn contested_resources_start_at_value() {
for inclusive in [true, false] {
// when I set start_at_value to some value,
for (i, start) in all.0.iter().enumerate() {
let ContestedResource::Value(start_value) = start.clone();
let ContestedResource(start_value) = start.clone();

let query = VotePollsByDocumentTypeQuery {
start_at_value: Some((start_value, inclusive)),
Expand Down Expand Up @@ -217,7 +217,7 @@ async fn contested_resources_limit_PLAN_656() {
);
}

let ContestedResource::Value(last) =
let ContestedResource(last) =
rss.0.into_iter().last().expect("last contested resource");
start_at_value = Some((last, false));

Expand Down
Loading