Skip to content
Open
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
16 changes: 0 additions & 16 deletions packages/rs-context-provider/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,6 @@ pub trait ContextProvider: Send + Sync {
/// * `Ok(CoreBlockHeight)`: On success, returns the platform activation height as defined by mn_rr
/// * `Err(Error)`: On failure, returns an error indicating why the operation failed.
fn get_platform_activation_height(&self) -> Result<CoreBlockHeight, ContextProviderError>;

/// Updates the cached data contract with a fresh version.
///
/// Called when the SDK detects that a cached contract is stale (e.g., after a
/// document deserialization failure due to a contract schema update).
/// The default implementation is a no-op.
fn update_data_contract(&self, _contract: Arc<DataContract>) {}
}

impl<C: AsRef<dyn ContextProvider> + Send + Sync> ContextProvider for C {
Expand Down Expand Up @@ -126,10 +119,6 @@ impl<C: AsRef<dyn ContextProvider> + Send + Sync> ContextProvider for C {
fn get_platform_activation_height(&self) -> Result<CoreBlockHeight, ContextProviderError> {
self.as_ref().get_platform_activation_height()
}

fn update_data_contract(&self, contract: Arc<DataContract>) {
self.as_ref().update_data_contract(contract)
}
}

impl<T: ContextProvider> ContextProvider for std::sync::Mutex<T>
Expand Down Expand Up @@ -167,11 +156,6 @@ where
let lock = self.lock().expect("lock poisoned");
lock.get_platform_activation_height()
}

fn update_data_contract(&self, contract: Arc<DataContract>) {
let lock = self.lock().expect("lock poisoned");
lock.update_data_contract(contract)
}
}

/// A trait that provides a function that can be used to look up a [DataContract] by its [Identifier].
Expand Down
19 changes: 7 additions & 12 deletions packages/rs-drive-proof-verifier/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub enum Error {
},

/// Dash Protocol error
#[error("protocol: {0}")]
ProtocolError(ProtocolError),
#[error("dash protocol: {error}")]
ProtocolError { error: String },

/// Empty response metadata
#[error("empty response metadata")]
Expand Down Expand Up @@ -99,18 +99,17 @@ pub enum Error {

impl From<drive::error::Error> for Error {
fn from(error: drive::error::Error) -> Self {
match error {
drive::error::Error::Protocol(protocol_err) => Self::ProtocolError(*protocol_err),
other => Self::DriveError {
error: other.to_string(),
},
Self::DriveError {
error: error.to_string(),
}
}
}

impl From<ProtocolError> for Error {
fn from(error: ProtocolError) -> Self {
Self::ProtocolError(error)
Self::ProtocolError {
error: error.to_string(),
}
}
}

Expand Down Expand Up @@ -139,10 +138,6 @@ impl<O> MapGroveDbError<O> for Result<O, drive::error::Error> {
})
}

Err(drive::error::Error::Protocol(protocol_err)) => {
Err(Error::ProtocolError(*protocol_err))
}

Err(other) => Err(other.into()),
}
}
Expand Down
72 changes: 48 additions & 24 deletions packages/rs-drive-proof-verifier/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ impl FromProof<platform::GetIdentityRequest> for Identity {

let id = match request.version.ok_or(Error::EmptyVersion)? {
get_identity_request::Version::V0(v0) => {
Identifier::from_bytes(&v0.id).map_err(|e| Error::ProtocolError(e.into()))?
Identifier::from_bytes(&v0.id).map_err(|e| Error::ProtocolError {
error: e.to_string(),
})?
}
};

Expand Down Expand Up @@ -472,7 +474,9 @@ impl FromProof<platform::GetIdentityKeysRequest> for IdentityPublicKeys {
get_identity_keys_request::Version::V0(v0) => {
let request_type = v0.request_type;
let identity_id = Identifier::from_bytes(&v0.identity_id)
.map_err(|e| Error::ProtocolError(e.into()))?
.map_err(|e| Error::ProtocolError {
error: e.to_string(),
})?
.into_buffer();
let limit = v0.limit.map(|i| i as u16);
let offset = v0.offset.map(|i| i as u16);
Expand Down Expand Up @@ -610,12 +614,14 @@ impl FromProof<platform::GetIdentityNonceRequest> for IdentityNonceFetcher {

let mtd = response.metadata().or(Err(Error::EmptyResponseMetadata))?;

let identity_id = match request.version.ok_or(Error::EmptyVersion)? {
get_identity_nonce_request::Version::V0(v0) => Ok::<Identifier, Error>(
Identifier::from_bytes(&v0.identity_id)
.map_err(|e| Error::ProtocolError(e.into()))?,
),
}?;
let identity_id =
match request.version.ok_or(Error::EmptyVersion)? {
get_identity_nonce_request::Version::V0(v0) => Ok::<Identifier, Error>(
Identifier::from_bytes(&v0.identity_id).map_err(|e| Error::ProtocolError {
error: e.to_string(),
})?,
),
}?;

// Extract content from proof and verify Drive/GroveDB proofs
let (root_hash, maybe_nonce) = Drive::verify_identity_nonce(
Expand Down Expand Up @@ -661,10 +667,12 @@ impl FromProof<platform::GetIdentityContractNonceRequest> for IdentityContractNo
let (identity_id, contract_id) = match request.version.ok_or(Error::EmptyVersion)? {
get_identity_contract_nonce_request::Version::V0(v0) => {
Ok::<(Identifier, Identifier), Error>((
Identifier::from_bytes(&v0.identity_id)
.map_err(|e| Error::ProtocolError(e.into()))?,
Identifier::from_bytes(&v0.contract_id)
.map_err(|e| Error::ProtocolError(e.into()))?,
Identifier::from_bytes(&v0.identity_id).map_err(|e| Error::ProtocolError {
error: e.to_string(),
})?,
Identifier::from_bytes(&v0.contract_id).map_err(|e| Error::ProtocolError {
error: e.to_string(),
})?,
))
}
}?;
Expand Down Expand Up @@ -712,9 +720,10 @@ impl FromProof<platform::GetIdentityBalanceRequest> for IdentityBalance {
let mtd = response.metadata().or(Err(Error::EmptyResponseMetadata))?;

let id = match request.version.ok_or(Error::EmptyVersion)? {
get_identity_balance_request::Version::V0(v0) => {
Identifier::from_bytes(&v0.id).map_err(|e| Error::ProtocolError(e.into()))
}
get_identity_balance_request::Version::V0(v0) => Identifier::from_bytes(&v0.id)
.map_err(|e| Error::ProtocolError {
error: e.to_string(),
}),
}?;

// Extract content from proof and verify Drive/GroveDB proofs
Expand Down Expand Up @@ -805,7 +814,9 @@ impl FromProof<platform::GetIdentityBalanceAndRevisionRequest> for IdentityBalan

let id = match request.version.ok_or(Error::EmptyVersion)? {
get_identity_balance_and_revision_request::Version::V0(v0) => {
Identifier::from_bytes(&v0.id).map_err(|e| Error::ProtocolError(e.into()))
Identifier::from_bytes(&v0.id).map_err(|e| Error::ProtocolError {
error: e.to_string(),
})
}
}?;

Expand Down Expand Up @@ -1123,7 +1134,9 @@ impl FromProof<platform::GetDataContractRequest> for DataContract {

let id = match request.version.ok_or(Error::EmptyVersion)? {
get_data_contract_request::Version::V0(v0) => {
Identifier::from_bytes(&v0.id).map_err(|e| Error::ProtocolError(e.into()))
Identifier::from_bytes(&v0.id).map_err(|e| Error::ProtocolError {
error: e.to_string(),
})
}
}?;

Expand Down Expand Up @@ -1168,7 +1181,9 @@ impl FromProof<platform::GetDataContractRequest> for (DataContract, Vec<u8>) {

let id = match request.version.ok_or(Error::EmptyVersion)? {
get_data_contract_request::Version::V0(v0) => {
Identifier::from_bytes(&v0.id).map_err(|e| Error::ProtocolError(e.into()))
Identifier::from_bytes(&v0.id).map_err(|e| Error::ProtocolError {
error: e.to_string(),
})
}
}?;

Expand Down Expand Up @@ -1279,8 +1294,9 @@ impl FromProof<platform::GetDataContractHistoryRequest> for DataContractHistory

let (id, limit, offset, start_at_ms) = match request.version.ok_or(Error::EmptyVersion)? {
get_data_contract_history_request::Version::V0(v0) => {
let id =
Identifier::from_bytes(&v0.id).map_err(|e| Error::ProtocolError(e.into()))?;
let id = Identifier::from_bytes(&v0.id).map_err(|e| Error::ProtocolError {
error: e.to_string(),
})?;
let limit = u32_to_u16_opt(v0.limit.unwrap_or_default())?;
let offset = u32_to_u16_opt(v0.offset.unwrap_or_default())?;
let start_at_ms = v0.start_at_ms;
Expand Down Expand Up @@ -1330,7 +1346,9 @@ impl FromProof<platform::BroadcastStateTransitionRequest> for StateTransitionPro
let proof = response.proof().or(Err(Error::NoProofInResult))?;

let state_transition = StateTransition::deserialize_from_bytes(&request.state_transition)
.map_err(Error::ProtocolError)?;
.map_err(|e| Error::ProtocolError {
error: e.to_string(),
})?;

let mtd = response.metadata().or(Err(Error::EmptyResponseMetadata))?;

Expand Down Expand Up @@ -1755,14 +1773,20 @@ impl FromProof<platform::GetIdentitiesContractKeysRequest> for IdentitiesContrac
Ok(identifier.to_buffer())
})
.collect::<Result<Vec<[u8; 32]>, platform_value::Error>>()
.map_err(|e| Error::ProtocolError(e.into()))?;
.map_err(|e| Error::ProtocolError {
error: e.to_string(),
})?;
let contract_id = Identifier::from_vec(contract_id)
.map_err(|e| Error::ProtocolError(e.into()))?
.map_err(|e| Error::ProtocolError {
error: e.to_string(),
})?
.into_buffer();
let purposes = purposes
.into_iter()
.map(|purpose| {
Purpose::try_from(purpose).map_err(|e| Error::ProtocolError(e.into()))
Purpose::try_from(purpose).map_err(|e| Error::ProtocolError {
error: e.to_string(),
})
})
.collect::<Result<Vec<Purpose>, Error>>()?;
(identifiers, contract_id, document_type_name, purposes)
Expand Down
12 changes: 6 additions & 6 deletions packages/rs-drive-proof-verifier/src/unproved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl FromUnproved<platform::GetCurrentQuorumsInfoRequest> for CurrentQuorumsInfo
.map(|q_hash| {
let mut q_hash_array = [0u8; 32];
if q_hash.len() != 32 {
return Err(Error::ResponseDecodeError {
return Err(Error::ProtocolError {
error: "Invalid quorum_hash length".to_string(),
});
}
Expand All @@ -196,15 +196,15 @@ impl FromUnproved<platform::GetCurrentQuorumsInfoRequest> for CurrentQuorumsInfo
// Extract current quorum hash
let mut current_quorum_hash = [0u8; 32];
if v0.current_quorum_hash.len() != 32 {
return Err(Error::ResponseDecodeError {
return Err(Error::ProtocolError {
error: "Invalid current_quorum_hash length".to_string(),
});
}
current_quorum_hash.copy_from_slice(&v0.current_quorum_hash);

let mut last_block_proposer = [0u8; 32];
if v0.last_block_proposer.len() != 32 {
return Err(Error::ResponseDecodeError {
return Err(Error::ProtocolError {
error: "Invalid last_block_proposer length".to_string(),
});
}
Expand All @@ -225,7 +225,7 @@ impl FromUnproved<platform::GetCurrentQuorumsInfoRequest> for CurrentQuorumsInfo
.into_iter()
.map(|member| {
let pro_tx_hash = ProTxHash::from_slice(&member.pro_tx_hash)
.map_err(|_| Error::ResponseDecodeError {
.map_err(|_| Error::ProtocolError {
error: "Invalid ProTxHash format".to_string(),
})?;
let validator = ValidatorV0 {
Expand All @@ -244,7 +244,7 @@ impl FromUnproved<platform::GetCurrentQuorumsInfoRequest> for CurrentQuorumsInfo

Ok(ValidatorSet::V0(ValidatorSetV0 {
quorum_hash: QuorumHash::from_slice(quorum_hash.as_slice())
.map_err(|_| Error::ResponseDecodeError {
.map_err(|_| Error::ProtocolError {
error: "Invalid Quorum Hash format".to_string(),
})?,
quorum_index: None, // Assuming it's not provided here
Expand All @@ -253,7 +253,7 @@ impl FromUnproved<platform::GetCurrentQuorumsInfoRequest> for CurrentQuorumsInfo
threshold_public_key: BlsPublicKey::try_from(
vs.threshold_public_key.as_slice(),
)
.map_err(|_| Error::ResponseDecodeError {
.map_err(|_| Error::ProtocolError {
error: "Invalid BlsPublicKey format".to_string(),
})?,
}))
Expand Down
4 changes: 0 additions & 4 deletions packages/rs-sdk-trusted-context-provider/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,10 +810,6 @@ impl ContextProvider for TrustedHttpContextProvider {
)),
}
}

fn update_data_contract(&self, contract: Arc<DataContract>) {
self.add_known_contract((*contract).clone());
}
}

#[cfg(test)]
Expand Down
6 changes: 0 additions & 6 deletions packages/rs-sdk/src/mock/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::sync::block_on;
use crate::{Error, Sdk};
use arc_swap::ArcSwapAny;
use dash_context_provider::{ContextProvider, ContextProviderError};
use dpp::data_contract::accessors::v0::DataContractV0Getters;
use dpp::data_contract::TokenConfiguration;
use dpp::prelude::{CoreBlockHeight, DataContract, Identifier};
use dpp::version::PlatformVersion;
Expand Down Expand Up @@ -240,11 +239,6 @@ impl ContextProvider for GrpcContextProvider {
fn get_platform_activation_height(&self) -> Result<CoreBlockHeight, ContextProviderError> {
self.core.get_platform_activation_height()
}

fn update_data_contract(&self, contract: Arc<DataContract>) {
self.data_contracts_cache
.put(contract.id(), (*contract).clone());
}
}

/// Thread-safe cache of various objects inside the SDK.
Expand Down
Loading
Loading