Skip to content

Commit

Permalink
fix(sidecar): return version in bolt_metadata endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
thedevbirb committed Jan 21, 2025
1 parent 02ba3b8 commit dc5f3e3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
10 changes: 7 additions & 3 deletions bolt-sidecar/src/api/commitments/firewall/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ use crate::{
api::commitments::{
server::CommitmentEvent,
spec::{
CommitmentError, GET_METADATA_METHOD, GET_VERSION_METHOD, REQUEST_INCLUSION_METHOD,
CommitmentError, MetadataResponse, GET_METADATA_METHOD, GET_VERSION_METHOD,
REQUEST_INCLUSION_METHOD,
},
},
common::BOLT_SIDECAR_VERSION,
Expand Down Expand Up @@ -321,8 +322,11 @@ impl CommitmentRequestProcessor {
self.send_response(response);
}
GET_METADATA_METHOD => {
let response =
JsonRpcSuccessResponse::new(json!(self.state.limits)).with_uuid(id).into();
let metadata = MetadataResponse {
limits: self.state.limits,
version: BOLT_SIDECAR_VERSION.to_string(),
};
let response = JsonRpcSuccessResponse::new(json!(metadata)).with_uuid(id).into();
self.send_response(response);
}
REQUEST_INCLUSION_METHOD => {
Expand Down
17 changes: 2 additions & 15 deletions bolt-sidecar/src/api/commitments/server/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@ use axum::{
Json,
};
use axum_extra::extract::WithRejection;
use serde::{Deserialize, Serialize};
use serde_json::json;
use tracing::{debug, error, info, instrument};

use crate::{
api::commitments::{
server::headers::auth_from_headers,
spec::{
CommitmentError, CommitmentsApi, GET_METADATA_METHOD, GET_VERSION_METHOD,
REQUEST_INCLUSION_METHOD,
CommitmentError, CommitmentsApi, MetadataResponse, GET_METADATA_METHOD,
GET_VERSION_METHOD, REQUEST_INCLUSION_METHOD,
},
},
common::BOLT_SIDECAR_VERSION,
config::limits::LimitsOpts,
primitives::{
jsonrpc::{JsonRpcRequest, JsonRpcResponse, JsonRpcSuccessResponse},
signature::SignatureError,
Expand All @@ -31,17 +29,6 @@ use crate::{

use super::CommitmentsApiInner;

/// Response structure for the metadata endpoint that combines
/// limits configuration with version information in a flat structure
#[derive(Debug, Serialize, Deserialize)]
pub struct MetadataResponse {
/// The operational limits of the sidecar
#[serde(flatten)]
pub limits: LimitsOpts,
/// The version of the Bolt sidecar
pub version: String,
}

/// Handler function for the root JSON-RPC path.
#[instrument(skip_all, name = "POST /rpc", fields(method = %payload.method))]
pub async fn rpc_entrypoint(
Expand Down
4 changes: 2 additions & 2 deletions bolt-sidecar/src/api/commitments/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ fn make_router(state: Arc<CommitmentsApiInner>) -> Router {
#[cfg(test)]
mod test {
use crate::{
api::commitments::spec::SIGNATURE_HEADER, common::BOLT_SIDECAR_VERSION,
api::commitments::spec::{MetadataResponse, SIGNATURE_HEADER},
common::BOLT_SIDECAR_VERSION,
primitives::jsonrpc::JsonRpcError,
};
use alloy::signers::{k256::SecretKey, local::PrivateKeySigner};
use handlers::MetadataResponse;
use serde_json::json;

use crate::{
Expand Down
13 changes: 13 additions & 0 deletions bolt-sidecar/src/api/commitments/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ use axum::{
response::IntoResponse,
Json,
};
use serde::{Deserialize, Serialize};
use thiserror::Error;

use crate::{
config::limits::LimitsOpts,
primitives::{
commitment::InclusionCommitment,
jsonrpc::{JsonRpcError, JsonRpcErrorResponse},
Expand Down Expand Up @@ -124,6 +126,17 @@ impl IntoResponse for CommitmentError {
}
}

/// Response structure for the metadata endpoint that combines
/// limits configuration with version information in a flat structure
#[derive(Debug, Serialize, Deserialize)]
pub struct MetadataResponse {
/// The operational limits of the sidecar
#[serde(flatten)]
pub limits: LimitsOpts,
/// The version of the Bolt sidecar
pub version: String,
}

/// Implements the commitments-API: <https://chainbound.github.io/bolt-docs/api/rpc>
#[async_trait::async_trait]
pub trait CommitmentsApi {
Expand Down

0 comments on commit dc5f3e3

Please sign in to comment.