1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use std::convert::TryFrom;
use std::fmt::Debug;
use chrono::{DateTime, Utc};
use tonic::transport::Channel;
use tracing::{instrument, trace};
use crate::data::DamlResult;
use crate::data::DamlTimeModel;
use crate::grpc_protobuf::com::daml::ledger::api::v1::admin::config_management_service_client::ConfigManagementServiceClient;
use crate::grpc_protobuf::com::daml::ledger::api::v1::admin::{GetTimeModelRequest, SetTimeModelRequest, TimeModel};
use crate::service::common::make_request;
use crate::util::{to_grpc_timestamp, Required};
#[derive(Debug)]
pub struct DamlConfigManagementService<'a> {
channel: Channel,
auth_token: Option<&'a str>,
}
impl<'a> DamlConfigManagementService<'a> {
pub fn new(channel: Channel, auth_token: Option<&'a str>) -> Self {
Self {
channel,
auth_token,
}
}
pub fn with_token(self, auth_token: &'a str) -> Self {
Self {
auth_token: Some(auth_token),
..self
}
}
#[instrument(skip(self))]
pub async fn get_time_model(&self) -> DamlResult<(i64, DamlTimeModel)> {
let payload = GetTimeModelRequest {};
trace!(payload = ?payload, token = ?self.auth_token);
let response = self.client().get_time_model(make_request(payload, self.auth_token)?).await?.into_inner();
trace!(?response);
Ok((response.configuration_generation, DamlTimeModel::try_from(response.time_model.req()?)?))
}
#[instrument(skip(self))]
pub async fn set_time_model(
&self,
submission_id: impl Into<String> + Debug,
maximum_record_time: impl Into<DateTime<Utc>> + Debug,
configuration_generation: i64,
new_time_model: impl Into<DamlTimeModel> + Debug,
) -> DamlResult<i64> {
let payload = SetTimeModelRequest {
submission_id: submission_id.into(),
maximum_record_time: Some(to_grpc_timestamp(maximum_record_time.into())?),
configuration_generation,
new_time_model: Some(TimeModel::try_from(new_time_model.into())?),
};
trace!(payload = ?payload, token = ?self.auth_token);
let response = self.client().set_time_model(make_request(payload, self.auth_token)?).await?.into_inner();
trace!(?response);
Ok(response.configuration_generation)
}
fn client(&self) -> ConfigManagementServiceClient<Channel> {
ConfigManagementServiceClient::new(self.channel.clone())
}
}