daml_grpc/service/
daml_version_service.rs1use tonic::transport::Channel;
2use tracing::{instrument, trace};
3
4use crate::data::{DamlFeaturesDescriptor, DamlResult};
5use crate::grpc_protobuf::com::daml::ledger::api::v1::version_service_client::VersionServiceClient;
6use crate::grpc_protobuf::com::daml::ledger::api::v1::GetLedgerApiVersionRequest;
7use crate::service::common::make_request;
8
9#[derive(Debug)]
11pub struct DamlVersionService<'a> {
12 channel: Channel,
13 ledger_id: &'a str,
14 auth_token: Option<&'a str>,
15}
16
17impl<'a> DamlVersionService<'a> {
18 pub fn new(channel: Channel, ledger_id: &'a str, auth_token: Option<&'a str>) -> Self {
19 Self {
20 channel,
21 ledger_id,
22 auth_token,
23 }
24 }
25
26 pub fn with_token(self, auth_token: &'a str) -> Self {
28 Self {
29 auth_token: Some(auth_token),
30 ..self
31 }
32 }
33
34 pub fn with_ledger_id(self, ledger_id: &'a str) -> Self {
36 Self {
37 ledger_id,
38 ..self
39 }
40 }
41
42 #[instrument(skip(self))]
44 pub async fn get_ledger_api_version(&self) -> DamlResult<(String, Option<DamlFeaturesDescriptor>)> {
45 let payload = GetLedgerApiVersionRequest {
46 ledger_id: self.ledger_id.to_string(),
47 };
48 trace!(payload = ?payload, token = ?self.auth_token);
49 let response =
50 self.client().get_ledger_api_version(make_request(payload, self.auth_token)?).await?.into_inner();
51 trace!(?response);
52 Ok((response.version, response.features.map(DamlFeaturesDescriptor::from)))
53 }
54
55 fn client(&self) -> VersionServiceClient<Channel> {
56 VersionServiceClient::new(self.channel.clone())
57 }
58}