/globalsync
GET DELETE ASYNCProvides functionality to synchronize or completely reset global objects on the RAIDA network.
GET /api/v1/globalsync
Alias: /sync-global-objects
DELETE /api/v1/globalsync
Alias: /hard-reset-global-objects
GET /globalsync
This endpoint performs a synchronization of global objects for a given denomination. It can be run in a read-only "dry run" mode to see what changes would be made without actually applying them.
Query Parameters
Parameter | Type | Required | Description |
---|---|---|---|
denomination | integer | Yes | The denomination code (e.g., 1 for 1 CC) to synchronize. |
readonly | boolean | No | If this parameter is present (e.g., ?readonly or ?readonly=true ), the operation will be a dry run and no changes will be made. |
DELETE /globalsync
This endpoint performs a hard reset on the global objects, deleting them from the RAIDA network and then recreating them. This is a destructive operation that should be used with caution.
Response (in completed task `data`)
For both `GET` and `DELETE` operations, a successfully completed task will contain the following object in its `data` field.
total_createdinteger
The total number of global objects that were created during the operation.
total_deletedinteger
The total number of global objects that were deleted during the operation.
Examples
JavaScript Examples
const apiHost = 'http://localhost:8006';
async function pollTask(taskId, operation) {
const taskResponse = await fetch(`${apiHost}/api/v1/tasks/${taskId}`);
const taskData = await taskResponse.json();
const task = taskData.payload;
console.log(`[${operation}] Task ${taskId} progress: ${task.progress}% - ${task.message}`);
if (task.status === 'completed') {
console.log(`[${operation}] Task finished successfully!`, task.data);
return true; // Stop polling
} else if (task.status === 'error') {
console.error(`[${operation}] Task failed:`, task.message);
return true; // Stop polling
}
return false; // Continue polling
}
function startPolling(taskId, operation) {
const pollInterval = setInterval(async () => {
const isDone = await pollTask(taskId, operation);
if (isDone) clearInterval(pollInterval);
}, 2000);
}
// GET /globalsync
async function syncGlobal(denomination, isReadOnly) {
let url = `${apiHost}/api/v1/globalsync?denomination=${denomination}`;
if (isReadOnly) {
url += '&readonly';
}
const response = await fetch(url);
const taskInfo = await response.json();
console.log(`[GET] Task created with ID: ${taskInfo.payload.id}`);
startPolling(taskInfo.payload.id, "GET");
}
// DELETE /globalsync
async function deleteGlobal() {
const response = await fetch(`${apiHost}/api/v1/globalsync`, { method: 'DELETE' });
const taskInfo = await response.json();
console.log(`[DELETE] Task created with ID: ${taskInfo.payload.id}`);
startPolling(taskInfo.payload.id, "DELETE");
}
// Example Usage:
// syncGlobal(1, true); // Synchronize denomination 1 in read-only mode
// deleteGlobal();
cURL: Synchronize (GET)
# Step 1: Initiate the sync task
TASK_ID=$(curl -s -X GET "http://localhost:8006/api/v1/globalsync?denomination=1&readonly" | jq -r '.payload.id')
echo "Sync 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
cURL: Delete (DELETE)
# Step 1: Initiate the delete task
TASK_ID=$(curl -s -X DELETE "http://localhost:8006/api/v1/globalsync" | jq -r '.payload.id')
echo "Delete 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 Examples
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, operation 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("[%s] Polling... Status: %s\n", operation, taskResp.Payload.Status)
if taskResp.Payload.Status == "completed" {
fmt.Printf("[%s] Task completed. Result: %+v\n", operation, taskResp.Payload.Data)
return
} else if taskResp.Payload.Status == "error" {
fmt.Printf("[%s] Task failed: %s\n", operation, taskResp.Payload.Message)
return
}
time.Sleep(2 * time.Second)
}
}
func startTask(req *http.Request, operation string) {
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Fatalf("Failed to start %s task: %v", operation, err)
}
defer resp.Body.Close()
var taskResp TaskResponse
if err := json.NewDecoder(resp.Body).Decode(&taskResp); err != nil {
log.Fatalf("Failed to decode initial task response: %v", err)
}
fmt.Printf("[%s] Task created with ID: %s\n", operation, taskResp.Payload.ID)
pollTask(taskResp.Payload.ID, operation)
}
// syncGlobal initiates a GET request to /globalsync
func syncGlobal(denomination int, isReadOnly bool) {
url := fmt.Sprintf("%s/globalsync?denomination=%d", apiHost, denomination)
if isReadOnly {
url += "&readonly"
}
req, _ := http.NewRequest(http.MethodGet, url, nil)
startTask(req, "GET")
}
// deleteGlobal initiates a DELETE request to /globalsync
func deleteGlobal() {
req, _ := http.NewRequest(http.MethodDelete, fmt.Sprintf("%s/globalsync", apiHost), nil)
startTask(req, "DELETE")
}
func main() {
fmt.Println("Running Sync Example:")
syncGlobal(1, true)
fmt.Println("\nRunning Delete Example:")
deleteGlobal()
}