Skip to content

Commit

Permalink
feat: implemented endpoint for fetching proxy contract ID
Browse files Browse the repository at this point in the history
  • Loading branch information
alenmestrov committed Dec 26, 2024
1 parent 95d0d1d commit 5fb103d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
11 changes: 11 additions & 0 deletions crates/context/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1421,4 +1421,15 @@ impl ContextManager {
.map_err(|err| eyre::eyre!("Failed to fetch context storage entries: {}", err))?;
Ok(response)
}

pub async fn get_proxy_id(&self, context_id: ContextId) -> EyreResult<String> {
let handle = self.store.handle();
let Some(context_config) = handle.get(&ContextConfigKey::new(context_id))? else {
bail!("Context not found");
};

let proxy_contract = context_config.proxy_contract.as_ref().into();

Ok(proxy_contract)
}
}
21 changes: 21 additions & 0 deletions crates/server/src/admin/handlers/proposals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ pub struct GetProposalResponse {
pub data: ProposalConfig,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GetProxyContractResponse {
pub data: String,
}

#[derive(Copy, Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GetProposalsRequest {
Expand Down Expand Up @@ -181,6 +187,21 @@ pub async fn get_proposal_handler(
}
}

pub async fn get_proxy_contract_handler(
Path(context_id): Path<ContextId>,
Extension(state): Extension<Arc<AdminState>>,
) -> impl IntoResponse {
match state.ctx_manager.get_proxy_id(context_id).await {
Ok(proxy_contract) => ApiResponse {
payload: GetProxyContractResponse {
data: proxy_contract,
},
}
.into_response(),
Err(err) => parse_api_error(err).into_response(),
}
}

pub async fn get_context_value_handler(
Path(context_id): Path<ContextId>,
Extension(state): Extension<Arc<AdminState>>,
Expand Down
6 changes: 5 additions & 1 deletion crates/server/src/admin/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use super::handlers::did::delete_did_handler;
use super::handlers::proposals::{
get_context_storage_entries_handler, get_context_value_handler,
get_number_of_active_proposals_handler, get_number_of_proposal_approvals_handler,
get_proposal_approvers_handler, get_proposal_handler, get_proposals_handler,
get_proposal_approvers_handler, get_proposal_handler, get_proposals_handler, get_proxy_contract_handler,
};
use super::storage::ssl::get_ssl;
use crate::admin::handlers::add_client_key::{
Expand Down Expand Up @@ -173,6 +173,10 @@ pub(crate) fn setup(
.route(
"/contexts/:context_id/proposals/context-storage-entries",
post(get_context_storage_entries_handler),
)
.route(
"/contexts/:context_id/proxy-contract",
get(get_proxy_contract_handler),
);

let dev_router = Router::new()
Expand Down

0 comments on commit 5fb103d

Please sign in to comment.