-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(platform): proof verification for many queries and a few more qu…
…eries (#2431)
- Loading branch information
1 parent
55a1e03
commit 0220302
Showing
48 changed files
with
2,354 additions
and
131 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod total_credits_balance; | ||
|
||
pub mod credits; | ||
pub mod total_single_token_balance; | ||
pub mod total_tokens_balance; |
49 changes: 49 additions & 0 deletions
49
packages/rs-dpp/src/balances/total_single_token_balance/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use crate::balances::credits::SignedTokenAmount; | ||
use crate::ProtocolError; | ||
use std::fmt; | ||
|
||
/// A structure where the token supply and the aggregated token account balances should always be equal | ||
#[derive(Copy, Clone, Debug)] | ||
pub struct TotalSingleTokenBalance { | ||
/// the token supply | ||
pub token_supply: SignedTokenAmount, | ||
/// the sum of all user account balances | ||
pub aggregated_token_account_balances: SignedTokenAmount, | ||
} | ||
|
||
impl fmt::Display for TotalSingleTokenBalance { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
writeln!(f, "TotalSingleTokenBalance {{")?; | ||
writeln!(f, " token_supply: {},", self.token_supply)?; | ||
writeln!( | ||
f, | ||
" aggregated_token_account_balances: {}", | ||
self.aggregated_token_account_balances | ||
)?; | ||
write!(f, "}}") | ||
} | ||
} | ||
impl TotalSingleTokenBalance { | ||
/// Is the outcome okay? basically do the values match up | ||
/// Errors in case of overflow | ||
pub fn ok(&self) -> Result<bool, ProtocolError> { | ||
let TotalSingleTokenBalance { | ||
token_supply, | ||
aggregated_token_account_balances, | ||
} = *self; | ||
|
||
if token_supply < 0 { | ||
return Err(ProtocolError::Generic( | ||
"Token in platform are less than 0".to_string(), | ||
)); | ||
} | ||
|
||
if aggregated_token_account_balances < 0 { | ||
return Err(ProtocolError::Generic( | ||
"Token in aggregated identity balances are less than 0".to_string(), | ||
)); | ||
} | ||
|
||
Ok(token_supply == aggregated_token_account_balances) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
packages/rs-drive-abci/src/query/token_queries/token_total_supply/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use crate::error::query::QueryError; | ||
use crate::error::Error; | ||
use crate::platform_types::platform::Platform; | ||
use crate::platform_types::platform_state::PlatformState; | ||
use crate::query::QueryValidationResult; | ||
use dapi_grpc::platform::v0::get_token_total_supply_request::Version as RequestVersion; | ||
use dapi_grpc::platform::v0::get_token_total_supply_response::Version as ResponseVersion; | ||
use dapi_grpc::platform::v0::{GetTokenTotalSupplyRequest, GetTokenTotalSupplyResponse}; | ||
use dpp::version::PlatformVersion; | ||
mod v0; | ||
|
||
impl<C> Platform<C> { | ||
/// Querying of token total supply | ||
pub fn query_token_total_supply( | ||
&self, | ||
GetTokenTotalSupplyRequest { version }: GetTokenTotalSupplyRequest, | ||
platform_state: &PlatformState, | ||
platform_version: &PlatformVersion, | ||
) -> Result<QueryValidationResult<GetTokenTotalSupplyResponse>, Error> { | ||
let Some(version) = version else { | ||
return Ok(QueryValidationResult::new_with_error( | ||
QueryError::DecodingError( | ||
"could not decode identity token total supply query".to_string(), | ||
), | ||
)); | ||
}; | ||
|
||
let feature_version_bounds = &platform_version | ||
.drive_abci | ||
.query | ||
.token_queries | ||
.token_total_supply; | ||
|
||
let feature_version = match &version { | ||
RequestVersion::V0(_) => 0, | ||
}; | ||
if !feature_version_bounds.check_version(feature_version) { | ||
return Ok(QueryValidationResult::new_with_error( | ||
QueryError::UnsupportedQueryVersion( | ||
"token_total_supply".to_string(), | ||
feature_version_bounds.min_version, | ||
feature_version_bounds.max_version, | ||
platform_version.protocol_version, | ||
feature_version, | ||
), | ||
)); | ||
} | ||
|
||
match version { | ||
RequestVersion::V0(request_v0) => { | ||
let result = | ||
self.query_token_total_supply_v0(request_v0, platform_state, platform_version)?; | ||
Ok(result.map(|response_v0| GetTokenTotalSupplyResponse { | ||
version: Some(ResponseVersion::V0(response_v0)), | ||
})) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.