Skip to content

Commit faabcd0

Browse files
authored
Merge pull request #4213 from ProvableHQ/feat/solution-limits-rest
[Feat] Add new REST endpoint for solution limits
2 parents 0d2e9b4 + 84a2e99 commit faabcd0

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

node/rest/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ impl<N: Network, C: ConsensusStorage<N>, R: Routing<N>> Rest<N, C, R> {
186186
.route("/transaction/unconfirmed/{id}", get(Self::get_unconfirmed_transaction))
187187
.route("/transaction/broadcast", post(Self::transaction_broadcast))
188188

189-
// POST ../solution/broadcast
189+
// GET and POST ../solution/..
190+
.route("/solution/limits/{prover_address}", get(Self::get_solution_limits_for_prover))
190191
.route("/solution/broadcast", post(Self::solution_broadcast))
191192

192193
// GET ../find/..

node/rest/src/routes.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ use std::{collections::HashMap, fs};
3636

3737
#[cfg(not(feature = "serial"))]
3838
use rayon::prelude::*;
39-
4039
use version::VersionInfo;
4140

4241
#[cfg(feature = "history")]
@@ -1006,6 +1005,19 @@ impl<N: Network, C: ConsensusStorage<N>, R: Routing<N>> Rest<N, C, R> {
10061005
Ok(ret)
10071006
}
10081007

1008+
/// GET /<network>/solution/limits/{prover_address}
1009+
pub(crate) async fn get_solution_limits_for_prover(
1010+
State(rest): State<Self>,
1011+
Path(prover_address): Path<Address<N>>,
1012+
) -> Result<ErasedJson, RestError> {
1013+
Ok(ErasedJson::pretty(json!({
1014+
"is_limit_reached": rest.ledger.is_solution_limit_reached(&prover_address, 0),
1015+
"num_remaining_solutions": rest.ledger.num_remaining_solutions(&prover_address, 0),
1016+
"latest_epoch_hash": rest.ledger.latest_epoch_hash()?,
1017+
"blocks_until_next_epoch": N::NUM_BLOCKS_PER_EPOCH.saturating_sub(rest.ledger.latest_height() % N::NUM_BLOCKS_PER_EPOCH),
1018+
})))
1019+
}
1020+
10091021
/// GET /{network}/program/{id}/mapping/{name}/{key}/history/{height}
10101022
#[cfg(feature = "history")]
10111023
pub(crate) async fn get_history(

0 commit comments

Comments
 (0)