fabaccess-bffh/bffhd/capnp/traits/claimable.rs

40 lines
1.4 KiB
Rust
Raw Permalink Normal View History

2024-06-10 12:58:50 +02:00
use capnp::capability::Promise;
use capnp::Error;
use capnp_rpc::pry;
2024-05-24 12:48:58 +02:00
use crate::oid;
use crate::utils::oid::ObjectIdentifier;
use api::traits::claimable_capnp::trait_claimable;
2024-06-10 12:58:50 +02:00
use api::traits::claimable_capnp::trait_claimable::{GetStateParams, GetStateResults};
use api::traits_capnp::trait_super::{GetNameParams, GetNameResults, Server};
use api::schema::utils_capnp::map::entry as api_map;
2024-05-24 12:48:58 +02:00
pub const CLAIMABLE_TRAIT_ID: ObjectIdentifier = oid!(1.3.6.1.4.1.61783.612.1.0);
2024-06-10 12:58:50 +02:00
pub struct ClaimableServer {
2024-05-24 12:48:58 +02:00
2024-06-10 12:58:50 +02:00
}
impl ClaimableServer {
pub fn insert_into_map(self, mut builder: api_map::Builder<capnp::data::Owned, capnp::any_pointer::Owned>) -> Result<(), capnp::Error> {
builder.set_key(CLAIMABLE_TRAIT_ID.as_bytes())?;
let client: trait_claimable::Client = capnp_rpc::new_client(self);
let mut cap_builder = builder.init_value();
cap_builder.set_as_capability(client.client.hook);
Ok(())
}
}
impl Server for ClaimableServer {
fn get_name(&mut self, _: GetNameParams, mut result: GetNameResults) -> Promise<(), Error> {
result.get().set_name("Claimable");
Promise::ok(())
}
}
impl trait_claimable::Server for ClaimableServer {
fn get_state(&mut self, _: GetStateParams, mut results: GetStateResults) -> Promise<(), Error> {
let mut builder = pry!(results.get().get_claims());
Promise::ok(())
}
}