diff --git a/Cargo.toml b/Cargo.toml index 1c82514cce..0d2e0ccc18 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,8 +46,8 @@ default-features = false [workspace.dependencies.snarkvm] #path = "../snarkVM" -git = "https://github.com/ProvableHQ/snarkVM.git" -rev = "b176b1409" +git = "https://github.com/ljedrz/snarkVM.git" +branch = "feat/record_queries" #version = "=4.4.0" default-features = false diff --git a/node/rest/src/lib.rs b/node/rest/src/lib.rs index 9b42465b8d..442558f4d2 100644 --- a/node/rest/src/lib.rs +++ b/node/rest/src/lib.rs @@ -177,6 +177,7 @@ impl, R: Routing> Rest { .route("/block/height/latest", get(Self::get_block_height_latest)) .route("/block/hash/latest", get(Self::get_block_hash_latest)) .route("/block/latest", get(Self::get_block_latest)) + .route("/block/{height}/record_count", get(Self::get_number_of_block_records)) .route("/block/{height_or_hash}", get(Self::get_block)) // The path param here is actually only the height, but the name must match the route // above, otherwise there'll be a conflict at runtime. @@ -223,6 +224,7 @@ impl, R: Routing> Rest { // GET misc endpoints. .route("/version", get(Self::get_version)) .route("/blocks", get(Self::get_blocks)) + .route("/record_count", get(Self::get_number_of_records)) .route("/height/{hash}", get(Self::get_height)) .route("/memoryPool/transmissions", get(Self::get_memory_pool_transmissions)) .route("/memoryPool/solutions", get(Self::get_memory_pool_solutions)) diff --git a/node/rest/src/routes.rs b/node/rest/src/routes.rs index 813e19e637..22ecb6dd1c 100644 --- a/node/rest/src/routes.rs +++ b/node/rest/src/routes.rs @@ -936,4 +936,21 @@ impl, R: Routing> Rest { None => Err(RestError::service_unavailable(anyhow!("Route isn't available for this node type"))), } } + + /// GET /{network}/record_count + pub(crate) async fn get_number_of_records(State(rest): State) -> ErasedJson { + let record_counts = rest.ledger.get_record_count(); + ErasedJson::pretty(record_counts) + } + + /// GET /{network}/{block}/record_count + pub(crate) async fn get_number_of_block_records( + State(rest): State, + Path(height): Path, + ) -> Result { + match rest.ledger.get_num_block_records(height) { + Ok(record_counts) => Ok(ErasedJson::pretty(record_counts)), + Err(_) => Err(RestError::not_found(anyhow!("Records for block {height} couldn't be found"))), + } + } }