/fix

POST ASYNC

Launches a process to fix fracked coins and recover limbo coins within a specified wallet.

POST /api/v1/fix
Alias: /repair-wallet-coins

Description

The `/fix` endpoint is a powerful wallet maintenance tool. It initiates a comprehensive process to repair the authenticity of compromised coins by addressing coins with inconsistencies (`fracked`) and attempting to recover those that have failed authenticity checks (`limbo`).

💡 Wallet Maintenance

Running `/fix` periodically is a good practice, especially after large transactions or if a `/health` check reveals issues. It ensures all your coins are valid and spendable.

Asynchronous Workflow

Understanding Asynchronous API Calls

This endpoint is asynchronous, which means:

  1. When you call this endpoint, it immediately returns a task ID.
  2. You then need to periodically check the task status using the /api/v1/task/{task_id} endpoint.
  3. Once the task is complete, the task status endpoint will return the full results in the `data` field.

Request Body

The request must include a JSON body specifying the name of the wallet to fix.

Parameter Type Required Description
name string Yes The name of the wallet containing the coins to be fixed. Ex: "Default".

Example Request Body

{
  "name": "Default"
}

Response

After the asynchronous task finishes, the `data` field of the task status response will contain the `FixResponse` object, which provides a summary of the operation.

Response Properties

total_frackedinteger
The total number of fracked coins identified in the wallet before the fix.
total_limbointeger
The total number of limbo coins identified.
total_fixedinteger
The total number of fracked coins that were successfully repaired.
total_skippedinteger
The total number of coins that were skipped and not processed.
total_errorsinteger
The total number of errors encountered during the process.
total_limbo_recoveredinteger
The total number of limbo coins that were successfully recovered.

Example Response (from task endpoint after completion)

{
  "id": "task_abc123",
  "status": "completed",
  "progress": 100,
  "message": "Fix operation finished.",
  "data": {
    "total_fracked": 7000,
    "total_limbo": 1000,
    "total_fixed": 6000,
    "total_skipped": 1000,
    "total_errors": 0,
    "total_limbo_recovered": 1000
  }
}

Examples

JavaScript (async/await)

const API_HOST = 'http://localhost:8006';
const WALLET_NAME = 'Default';

const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));

async function fixWallet(walletName) {
    try {
        const initialResponse = await fetch(`${API_HOST}/api/v1/fix`, {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ name: walletName })
        });
        if (!initialResponse.ok) throw new Error(`HTTP error! status: ${initialResponse.status}`);
        const task = await initialResponse.json();
        console.log(`Fix task created with ID: ${task.id}`);
        while (true) {
            const statusResponse = await fetch(`${API_HOST}/api/v1/task/${task.id}`);
            const taskStatus = await statusResponse.json();
            console.log(`Task status: ${taskStatus.status}, Progress: ${taskStatus.progress}%`);
            if (taskStatus.status === 'completed' || taskStatus.status === 'error') {
                console.log('Fix operation finished.');
                console.log('Result:', taskStatus.data || taskStatus.message);
                break;
            }
            await sleep(1000);
        }
    } catch (error) {
        console.error('An error occurred:', error);
    }
}
fixWallet(WALLET_NAME);

cURL

# Step 1: Initiate the fix task
TASK_ID=$(curl -s -X POST "http://localhost:8006/api/v1/fix" \
-H "Content-Type: application/json" \
-d '{"name": "Default"}' | jq -r .id)
echo "Task started with ID: $TASK_ID"

# Step 2: Poll the task endpoint until finished
while true; do
  RESPONSE=$(curl -s "http://localhost:8006/api/v1/task/$TASK_ID")
  STATUS=$(echo $RESPONSE | jq -r .status)
  echo "Polling task... Status: $STATUS"
  if [[ "$STATUS" == "completed" || "$STATUS" == "error" ]]; then
    echo "Final Response:"
    echo $RESPONSE | jq
    break
  fi
  sleep 2
done

Go

package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "net/http"
    "time"
)

const ApiHost = "http://localhost:8006"
type FixRequest struct { Name string `json:"name"` }
type TaskResponse struct {
    ID       string          `json:"id"`
    Status   string          `json:"status"`
    Progress int             `json:"progress"`
    Data     json.RawMessage `json:"data,omitempty"`
}

func main() {
    payloadBytes, _ := json.Marshal(FixRequest{Name: "Default"})
    req, _ := http.NewRequest("POST", fmt.Sprintf("%s/api/v1/fix", ApiHost), bytes.NewBuffer(payloadBytes))
    req.Header.Set("Content-Type", "application/json")
    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil { panic(err) }
    defer resp.Body.Close()

    var task TaskResponse
    json.NewDecoder(resp.Body).Decode(&task)
    fmt.Printf("Task created with ID: %s\n", task.ID)
    for {
        taskResp, _ := http.Get(fmt.Sprintf("%s/api/v1/task/%s", ApiHost, task.ID))
        var taskStatus TaskResponse
        json.NewDecoder(taskResp.Body).Decode(&taskStatus)
        taskResp.Body.Close()
        
        fmt.Printf("Task status: %s, Progress: %d%%\n", taskStatus.Status, taskStatus.Progress)
        if taskStatus.Status == "completed" || taskStatus.Status == "error" {
            fmt.Printf("Final result: %s\n", string(taskStatus.Data))
            break
        }
        time.Sleep(1 * time.Second)
    }
}

Related Endpoints

/health

Before fixing, run a health check to identify the number of fracked or counterfeit coins in your wallet.

/task/{task_id}

Poll this endpoint to check the status, progress, and results of any asynchronous operation.