engula_cooperator/
cooperator.rs

1// Copyright 2022 The Engula Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use engula_apis::*;
16use engula_supervisor::Supervisor;
17use tonic::Request;
18
19use crate::{apis::cooperator_server::Cooperator as _, Result, Server};
20
21#[derive(Clone)]
22pub struct Cooperator {
23    server: Server,
24}
25
26impl Cooperator {
27    pub fn new(supervisor: Supervisor) -> Self {
28        Self {
29            server: Server::new(supervisor),
30        }
31    }
32
33    pub async fn txn(&self, req: TxnRequest) -> Result<TxnResponse> {
34        let req = Request::new(req);
35        let res = self.server.txn(req).await?;
36        Ok(res.into_inner())
37    }
38}