use capnp::capability::Promise; use capnp::Error; use capnp_rpc::pry; use crate::oid; use crate::utils::oid::ObjectIdentifier; use api::traits::claimable_capnp::trait_claimable; 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; pub const CLAIMABLE_TRAIT_ID: ObjectIdentifier = oid!(1.3.6.1.4.1.61783.612.1.0); pub struct ClaimableServer { } impl ClaimableServer { pub fn insert_into_map(self, mut builder: api_map::Builder) -> 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(()) } }