Skip to content
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ ESPRESSO_NODE_1_API_PORT=24001
ESPRESSO_NODE_2_API_PORT=24002
ESPRESSO_NODE_3_API_PORT=24003
ESPRESSO_NODE_4_API_PORT=24004
ESPRESSO_NODE_0_AXUM_PORT=24100
ESPRESSO_NODE_1_AXUM_PORT=24101
ESPRESSO_NODE_2_AXUM_PORT=24102
ESPRESSO_NODE_3_AXUM_PORT=24103
ESPRESSO_NODE_4_AXUM_PORT=24104
ESPRESSO_NODE_0_TONIC_PORT=24200
ESPRESSO_NODE_1_TONIC_PORT=24201
ESPRESSO_NODE_2_TONIC_PORT=24202
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ edition = "2024"
aide = { version = "0.15.1", features = [
"axum",
"axum-json",
"axum-ws",
"scalar",
"swagger",
"redoc",
Expand Down
3 changes: 2 additions & 1 deletion crates/espresso/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ tokio = { workspace = true }
tonic = { workspace = true }
tonic-prost = { workspace = true }
tonic-reflection = { workspace = true }
tower = { workspace = true }
tower = { workspace = true, features = ["limit", "load-shed", "util"] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
url = { workspace = true }
vbs = { workspace = true }

[build-dependencies]
Expand Down
86 changes: 77 additions & 9 deletions crates/espresso/api/examples/test_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use serde::Serialize;
use serialization_api::ApiSerializations;

/// Port for the test API server
const API_PORT: u16 = 5000;
const API_PORT: u16 = 5001;

/// Test API implementation with hardcoded mock data
#[derive(Clone)]
Expand All @@ -35,6 +35,32 @@ impl v1::RewardApi for TestApi {
type RewardAccountQueryData = (u128, Vec<u8>);
type RewardAmounts = (Vec<(u128, u128)>, u64);
type RewardMerkleTreeData = Vec<u8>;
type RewardAccountQueryDataV1 = (u128, Vec<u8>);
type RewardStatePathV1 = serde_json::Value;
type RewardStatePathV2 = serde_json::Value;

async fn get_reward_state_height(&self) -> Result<u64> {
tracing::info!("v1: get_reward_state_height()");
Ok(42)
}

async fn get_reward_state_v2_height(&self) -> Result<u64> {
tracing::info!("v1: get_reward_state_v2_height()");
Ok(42)
}

async fn get_reward_account_proof_v1(
&self,
height: u64,
address: String,
) -> Result<Self::RewardAccountQueryDataV1> {
tracing::info!(
"v1: get_reward_account_proof_v1(height={}, address={})",
height,
address
);
Ok((500_000_000_000_000_000, vec![0xde, 0xad, 0xbe, 0xef]))
}

async fn get_reward_claim_input(
&self,
Expand Down Expand Up @@ -119,6 +145,22 @@ impl v1::RewardApi for TestApi {
tracing::info!("v1: get_reward_merkle_tree_v2(height={})", height);
Ok(vec![0x00, 0x11, 0x22, 0x33, 0x44, 0x55])
}

async fn get_reward_state_path_v1(
&self,
_snapshot: v1::Snapshot,
_key: String,
) -> Result<Self::RewardStatePathV1> {
Ok(serde_json::Value::Null)
}

async fn get_reward_state_path_v2(
&self,
_snapshot: v1::Snapshot,
_key: String,
) -> Result<Self::RewardStatePathV2> {
Ok(serde_json::Value::Null)
}
}

// Implement v1::AvailabilityApi with test data
Expand All @@ -133,13 +175,13 @@ impl v1::AvailabilityApi for TestApi {
&self,
block_id: v1::availability::BlockId,
namespace: u32,
) -> Result<Option<Self::NamespaceProofQueryData>> {
) -> Result<Self::NamespaceProofQueryData> {
tracing::info!(
"v1: get_namespace_proof(block_id={:?}, namespace={})",
block_id,
namespace
);
Ok(Some((vec![0xaa, 0xbb, 0xcc], Some(vec![0x11, 0x22, 0x33]))))
Ok((vec![0xaa, 0xbb, 0xcc], Some(vec![0x11, 0x22, 0x33])))
}

async fn get_namespace_proof_range(
Expand Down Expand Up @@ -645,6 +687,14 @@ impl v1::LightClientApi for TestApi {
) -> Result<Vec<Self::NamespaceProof>> {
Ok(vec![])
}
async fn get_lc_namespaces_proof_range(
&self,
_start: u64,
_end: u64,
_namespaces: String,
) -> Result<Vec<std::collections::HashMap<u64, Self::NamespaceProof>>> {
Ok(vec![])
}
}

#[async_trait]
Expand Down Expand Up @@ -707,10 +757,15 @@ impl v1::TokenApi for TestApi {
#[async_trait]
impl v1::DatabaseApi for TestApi {
type TableSizes = serde_json::Value;
type MigrationStatus = serde_json::Value;

async fn get_table_sizes(&self) -> Result<Self::TableSizes> {
Ok(serde_json::Value::Null)
}

async fn get_migration_status(&self) -> Result<Self::MigrationStatus> {
Ok(serde_json::Value::Null)
}
}

// Implement v2::RewardApi (simplified API - latest-only for claim/balance/proof)
Expand Down Expand Up @@ -1058,11 +1113,16 @@ async fn main() -> Result<()> {
tracing::info!("Serving API at 127.0.0.1:{}", API_PORT);
tracing::info!("");
tracing::info!("API documentation: http://localhost:{}/", API_PORT);
tracing::info!("Swagger UI: http://localhost:{}/v2", API_PORT);
tracing::info!("Scalar UI: http://localhost:{}/v2/scalar", API_PORT);
tracing::info!("Redoc UI: http://localhost:{}/v2/redoc", API_PORT);
tracing::info!("v1 Swagger UI: http://localhost:{}/v1", API_PORT);
tracing::info!("v1 Scalar UI: http://localhost:{}/v1/scalar", API_PORT);
tracing::info!(
"v1 OpenAPI spec: http://localhost:{}/v1/docs/openapi.json",
API_PORT
);
tracing::info!("v2 Swagger UI: http://localhost:{}/v2", API_PORT);
tracing::info!("v2 Scalar UI: http://localhost:{}/v2/scalar", API_PORT);
tracing::info!(
"OpenAPI spec: http://localhost:{}/v2/docs/openapi.json",
"v2 OpenAPI spec: http://localhost:{}/v2/docs/openapi.json",
API_PORT
);
tracing::info!("");
Expand All @@ -1083,8 +1143,16 @@ async fn main() -> Result<()> {

let state = TestApi;

// Start Axum server with combined v1 and v2 APIs
espresso_api::serve_axum(API_PORT, state).await?;
// Start Axum server with combined v1 and v2 APIs, all optional modules enabled
let modules = espresso_api::OptionalModules {
submit: true,
catchup: true,
config: true,
hotshot_events: true,
explorer: true,
light_client: true,
};
espresso_api::serve_axum(API_PORT, state, modules, None).await?;

Ok(())
}
Loading
Loading