/stats
GET ASYNCGathers and returns statistics about local wallets and the RAIDA network.
GET /api/v1/stats
Alias: /get-system-statistics
Description
This endpoint initiates a task to collect various statistics, including the number of wallets, the total number of coins, a breakdown of coins by their state (authentic, fracked, limbo), and the current status of the RAIDA network.
Asynchronous Operation
This is an asynchronous operation. It returns a task ID immediately, and you must poll the /tasks/{id}
endpoint to get the final statistics report.
Request Parameters
This endpoint does not require any request parameters.
Response (in completed task `data`)
A successfully completed task will contain the following report in its `data` field.
walletsinteger
The total number of local wallets.
total_coinsinteger
The total number of all coins across all wallets.
coins_authenticinteger
The number of coins in the 'Bank' (authentic) state.
coins_frackedinteger
The number of coins in the 'Fracked' state.
coins_limbointeger
The number of coins in the 'Limbo' state.
raida_online_countinteger
The number of RAIDA servers currently online.
Examples
JavaScript: Get Stats
const apiHost = 'http://localhost:8006';
async function pollTask(taskId) {
const taskResponse = await fetch(`${apiHost}/api/v1/tasks/${taskId}`);
const taskData = await taskResponse.json();
const task = taskData.payload;
console.log(`Task ${taskId} progress: ${task.progress}% - ${task.message}`);
if (task.status === 'completed') {
console.log(`Task finished successfully!`, task.data);
return true; // Stop polling
} else if (task.status === 'error') {
console.error(`Task failed:`, task.message);
return true; // Stop polling
}
return false; // Continue polling
}
async function getStats() {
try {
const response = await fetch(`${apiHost}/api/v1/stats`);
const taskInfo = await response.json();
const taskId = taskInfo.payload.id;
console.log(`Get Stats task created with ID: ${taskId}`);
const pollInterval = setInterval(async () => {
const isDone = await pollTask(taskId);
if (isDone) clearInterval(pollInterval);
}, 2000);
} catch (error) {
console.error('Failed to start stats task:', error);
}
}
getStats();
cURL: Get Stats
# Step 1: Initiate the get-stats task
TASK_ID=$(curl -s -X GET "http://localhost:8006/api/v1/stats" | jq -r '.payload.id')
echo "Get Stats task started with ID: $TASK_ID"
# Step 2: Poll the task endpoint
while true; do
RESPONSE=$(curl -s "http://localhost:8006/api/v1/tasks/$TASK_ID")
STATUS=$(echo $RESPONSE | jq -r '.payload.status')
echo "Polling task.. Status: $STATUS"
if [[ "$STATUS" == "completed" ]] || [[ "$STATUS" == "error" ]]; then
echo "Final Response:"
echo $RESPONSE | jq
break
fi
sleep 2
done
Go: Get Stats
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"time"
)
const apiHost = "http://localhost:8006/api/v1"
type TaskResponse struct {
Payload struct {
ID string `json:"id"`
Status string `json:"status"`
Progress int `json:"progress"`
Message string `json:"message"`
Data interface{} `json:"data"`
} `json:"payload"`
}
func pollTask(taskId string) {
for {
resp, err := http.Get(fmt.Sprintf("%s/tasks/%s", apiHost, taskId))
if err != nil {
log.Printf("Error polling task: %v\n", err)
return
}
var taskResp TaskResponse
json.NewDecoder(resp.Body).Decode(&taskResp)
resp.Body.Close()
fmt.Printf("Polling... Status: %s\n", taskResp.Payload.Status)
if taskResp.Payload.Status == "completed" {
fmt.Printf("Task completed. Result: %+v\n", taskResp.Payload.Data)
return
} else if taskResp.Payload.Status == "error" {
fmt.Printf("Task failed: %s\n", taskResp.Payload.Message)
return
}
time.Sleep(2 * time.Second)
}
}
func getStats() {
resp, err := http.Get(fmt.Sprintf("%s/stats", apiHost))
if err != nil {
log.Fatalf("Failed to start stats task: %v", err)
}
defer resp.Body.Close()
var taskResp TaskResponse
json.NewDecoder(resp.Body).Decode(&taskResp)
fmt.Printf("Get Stats task created with ID: %s\n", taskResp.Payload.ID)
pollTask(taskResp.Payload.ID)
}
func main() {
getStats()
}