Skip to content

Commit 3637620

Browse files
committed
Add low balance check in claim token api
1 parent 37b05f1 commit 3637620

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

docs/api-documentation.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,14 @@ curl "https://forest-explorer.chainsafe.dev/api/claim_token?faucet_info=MainnetF
140140
```bash
141141
ServerError|I'm a teapot - mainnet tokens are not available.
142142
```
143+
144+
---
145+
146+
## Faucet Top-Up Requests
147+
148+
If you encounter a server error indicating that faucet is exhausted (e.g.,
149+
"ServerError|Faucet is empty, Request top-up"), you can request a refill here:
150+
151+
- [Request Faucet Top-Up](https://github.com/ChainSafe/forest-explorer/discussions/134)
152+
153+
This discussion thread is monitored for top-up requests.

src/faucet/server_api.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,15 @@ pub async fn claim_token(
219219
.map_err(ServerFnError::new)?;
220220

221221
SendWrapper::new(async move {
222+
let faucet_balance = rpc
223+
.wallet_balance(from, &faucet_info.token_type())
224+
.await
225+
.map_err(ServerFnError::new)?;
226+
if faucet_balance < *faucet_info.drip_amount() {
227+
return Err(ServerFnError::ServerError(
228+
"Faucet is empty, Request top-up".to_string(),
229+
));
230+
}
222231
match faucet_info {
223232
FaucetInfo::MainnetFIL => {
224233
set_response_status(StatusCode::IM_A_TEAPOT);

0 commit comments

Comments
 (0)