Skip to content

Commit

Permalink
feat: versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
lklimek committed Oct 30, 2023
1 parent 4e9a307 commit b7de7ef
Show file tree
Hide file tree
Showing 26 changed files with 575 additions and 340 deletions.
78 changes: 45 additions & 33 deletions 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 @@ -2,6 +2,7 @@

members = [
"packages/dapi-grpc",
"packages/rs-dapi-grpc-macros",
"packages/rs-dpp",
"packages/rs-drive",
"packages/rs-platform-value",
Expand Down
2 changes: 2 additions & 0 deletions packages/dapi-grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ tonic = { version = "0.9.2", features = [
serde = { version = "1.0.171", optional = true, features = ["derive"] }
serde_bytes = { version = "0.11.12", optional = true }
tenderdash-proto = { git = "https://github.com/dashpay/rs-tenderdash-abci" }
dapi-grpc-macros = { path = "../rs-dapi-grpc-macros" }
platform-version = { path = "../rs-platform-version" }

[build-dependencies]
tonic-build = { version = "0.9.2" }
Expand Down
54 changes: 53 additions & 1 deletion packages/dapi-grpc/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,56 @@ pub fn generate() -> Result<(), std::io::Error> {
);
core.generate().unwrap();

let platform = MappingConfig::new(
let mut platform = MappingConfig::new(
PathBuf::from("protos/platform/v0/platform.proto"),
PathBuf::from("src/platform/proto"),
);
// Derive features for versioned messages
//
// "GetConsensusParamsRequest" is excluded as this message does not support proofs
const VERSIONED_REQUESTS: [&str; 13] = [
"GetDataContractHistoryRequest",
"GetDataContractRequest",
"GetDataContractsRequest",
"GetDocumentsRequest",
"GetIdentitiesByPublicKeyHashesRequest",
"GetIdentitiesRequest",
"GetIdentityBalanceAndRevisionRequest",
"GetIdentityBalanceRequest",
"GetIdentityByPublicKeyHashRequest",
"GetIdentityKeysRequest",
"GetIdentityRequest",
"GetProofsRequest",
"WaitForStateTransitionResultRequest",
];

// "GetConsensusParamsResponse" is excluded as this message does not support proofs
const VERSIONED_RESPONSES: [&str; 13] = [
"GetDataContractHistoryResponse",
"GetDataContractResponse",
"GetDataContractsResponse",
"GetDocumentsResponse",
"GetIdentitiesByPublicKeyHashesResponse",
"GetIdentitiesResponse",
"GetIdentityBalanceAndRevisionResponse",
"GetIdentityBalanceResponse",
"GetIdentityByPublicKeyHashResponse",
"GetIdentityKeysResponse",
"GetIdentityResponse",
"GetProofsResponse",
"WaitForStateTransitionResultResponse",
];
for msg in [VERSIONED_REQUESTS, VERSIONED_RESPONSES].concat() {
platform =
platform.message_attribute(msg, r#"#[derive(::dapi_grpc_macros::GrpcMessageV0)]"#);
}

for msg in VERSIONED_RESPONSES {
platform = platform.message_attribute(
msg,
r#"#[derive(::dapi_grpc_macros::VersionedGrpcResponse)]"#,
);
}

#[cfg(feature = "serde")]
let platform = platform
Expand Down Expand Up @@ -111,6 +157,12 @@ impl MappingConfig {
self
}

#[allow(unused)]
fn message_attribute(mut self, path: &str, attribute: &str) -> Self {
self.builder = self.builder.message_attribute(path, attribute);
self
}

/// Run single generation process.
fn generate(self) -> Result<(), std::io::Error> {
// Remove old compiled files; ignore errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use prost::Message;
fn main() {
let request = platform::GetConsensusParamsRequest {
version: Some(platform::get_consensus_params_request::Version::V0(
GetConsensusParamsRequestV0 { height: 123 },
GetConsensusParamsRequestV0 {
prove: true,
height: 123,
},
)),
};

Expand Down
Loading

0 comments on commit b7de7ef

Please sign in to comment.