/api/health/fix

GET

Automatically heals fracked coins using a two-phase RAIDA ticket-based authentication system to repair partial authentication failures.

Description

The /api/health/fix endpoint implements an automatic healing workflow for coins in the Fracked folder. Fracked coins are those that have 13-24 successful authentications (out of 25 RAIDA servers), meaning they're authentic but have some failing RAIDAs. The Fix operation uses a ticket-based authentication protocol to convert failing RAIDAs to passing status.

The healing process uses two RAIDA commands executed in sequence:

  • Get Ticket (0x0228): Collects authentication tickets from passing RAIDAs
  • Fix (0x0250): Presents tickets to failing RAIDAs to update their databases
How It Works

The Fix protocol works on a simple principle: RAIDAs that have successfully authenticated a coin can vouch for it by providing tickets. Failing RAIDAs accept these tickets as proof of authenticity and update their databases accordingly.

Requirements:

  • Coins must already have some 'p' (pass) status RAIDAs to provide tickets
  • At least 13 tickets are needed to fix a failing RAIDA
  • Tickets are valid for only 1 minute
  • The process runs iteratively up to 10 rounds for maximum healing

Two-Phase RAIDA Protocol

Phase 1: Get Ticket (0x0228)

For each coin in the Fracked folder, the system identifies all RAIDAs with 'p' (pass) status and requests authentication tickets.

Get Ticket Request Format:
Challenge(16 bytes)
+ [DN(1) + SN(4) + AN(16)] × N coins
+ 3E3E (2-byte terminator)

Get Ticket Response Format:
- ALL_PASS (241): Ticket(4) + 3E3E(2)
- ALL_FAIL (242): 3E3E(2)
- MIXED (243): Bitfield(N) + Ticket(4) + 3E3E(2)

Ticket Characteristics:

  • 4-byte random token generated by passing RAIDAs
  • Valid for 1 minute from generation
  • Each passing RAIDA provides one ticket per coin
  • Up to 24 tickets can be collected per coin (one per passing RAIDA)

Phase 2: Fix (0x0250)

Collected tickets are sent to failing RAIDAs for verification and database updates.

Fix Request Format:
Challenge(16 bytes)
+ [DN(1) + SN(4) + Ticket(4)] × N coins
+ 3E3E (2-byte terminator)

Fix Response Format:
- ALL_PASS (241): 3E3E(2) - All coins fixed
- ALL_FAIL (242): 3E3E(2) - All coins rejected
- MIXED (243): Bitfield(N) + 3E3E(2) - Some fixed

Fix Process:

  1. Failing RAIDA receives tickets from passing RAIDAs
  2. RAIDA verifies tickets with issuing RAIDAs (cross-validation)
  3. If 13+ valid tickets received: RAIDA updates its database and returns 'p'
  4. If fewer than 13 tickets or verification fails: Returns error or 'f'

Iterative Healing Workflow

The Fix operation runs iteratively to maximize healing success:

Healing Workflow:
1. Read all coins from Fracked folder
2. For each round (max 10):
   a. Identify RAIDAs needing fixing (non-'p' status)
   b. Identify RAIDAs that can provide tickets ('p' status)
   c. Execute Phase 1: Get Ticket (parallel on all 25 RAIDAs)
   d. Collect tickets (require 13+ per coin)
   e. Execute Phase 2: Fix (parallel on all 25 RAIDAs)
   f. Update POWN strings based on results
   g. If no changes from previous round: Stop
3. Run Grade command to sort coins to Bank/Fracked/Counterfeit
4. Generate receipt file
Why Multiple Rounds?

Each Fix round may heal some RAIDAs, which can then provide tickets in the next round. This cascading effect allows progressively more RAIDAs to be fixed:

  • Round 1: 15 'p' RAIDAs provide 15 tickets → Fix 2 more RAIDAs → 17 'p' total
  • Round 2: 17 'p' RAIDAs provide 17 tickets → Fix 3 more RAIDAs → 20 'p' total
  • Round 3: 20 'p' RAIDAs provide 20 tickets → Fix 5 more RAIDAs → 25 'p' total

The process stops automatically when no changes occur between rounds or all coins are fully healed.

Parameters

Parameter Type Required Description
wallet_path string Yes The file system path to the wallet directory to fix fracked coins in (e.g., C:/Wallets/MyWallet or /home/user/CloudCoin/Wallets/MyWallet).

Response

Returns a JSON object with the healing operation results.

Response Properties

status string
Always "success" when the operation completes.
operation string
Always "coins-fix".
message string
Human-readable message describing the operation result.
wallet string
Name of the wallet where coins were healed.
wallet_path string
The wallet path used for the fix operation.
note string
Additional information about the healing process.

Success Response

{
  "status": "success",
  "operation": "coins-fix",
  "message": "Fix operation completed",
  "wallet": "Default",
  "note": "Fracked coins healed using Get Ticket + Fix protocol"
}

Error Response - Fix Operation Failed

{
  "error": "Fix operation failed",
  "status": 500
}

Healing Success Criteria

After healing completes, coins are automatically sorted to the appropriate folder based on their final POWN status:

POWN String Grading:
- 25 'p' (perfect)   → Bank (fully authenticated)
- 13-24 'p'          → Fracked (partial authentication)
- 0-12 'p'           → Counterfeit (failed authentication)

Healing Outcomes:
- Success: 13 'p' → 25 'p' (Fracked → Bank)
- Partial: 13 'p' → 20 'p' (Fracked → Fracked, improved)
- Failure: 13 'p' → 10 'p' (Fracked → Counterfeit, degraded)
POWN String Updates

The Fix operation updates POWN strings character-by-character based on Fix results:

  • 'p': RAIDA passed (successfully fixed or already passing)
  • 'f': RAIDA failed (counterfeit or rejected tickets)
  • 'e': RAIDA error (network issue or server error)
  • 'n': No reply (timeout)

Each Fix round attempts to convert 'f', 'n', 'e' status to 'p' status using tickets.

Receipt File Generation

The Fix operation generates a detailed receipt file in the wallet's Receipts folder.

Receipt Format: YYYY-MM-DD_HH-MM-SS.fix.txt

=== Receipt ===
Type: Fix Fracked Coins
Date: 2025-01-31 15:30:45
Task ID: Jan-31-25_03-30-45-PM

Summary:
- Total coins processed: 5
- Fully healed (25/25): 3
- Partially healed (13-24/25): 1
- Failed healing (0-12/25): 1

Coin Results:
SN 12345 (250): ppppppppppppppppppppppppp (25/25 Pass - Moved to Bank)
SN 67890 (100): pppppppppppppppppnnnpppppp (20/25 Pass - Still Fracked)
SN 54321 (25):  ppppppppppffffff (8/25 Pass - Moved to Counterfeit)
...

Examples

JavaScript (fetch)

const API_HOST = 'http://localhost:8080';

// Fix fracked coins in specified wallet
async function fixFrackedCoins(walletPath) {
    try {
        console.log(`Starting Fix operation on wallet: ${walletPath}`);
        const encodedPath = encodeURIComponent(walletPath);
        const response = await fetch(`${API_HOST}/api/health/fix?wallet_path=${encodedPath}`);
        const result = await response.json();

        if (result.status === 'success') {
            console.log('Fix completed successfully');
            console.log(`Wallet: ${result.wallet}`);
            console.log(`Path: ${result.wallet_path}`);
            console.log(`Note: ${result.note}`);
        } else {
            console.error('Fix failed:', result.error);
        }
    } catch (error) {
        console.error('Error during Fix operation:', error);
    }
}

// Usage
fixFrackedCoins('C:/CloudCoin/Wallets/Default');

cURL

# Fix all fracked coins in specified wallet
curl -X GET "http://localhost:8080/api/health/fix?wallet_path=C%3A%5CCloudCoin%5CWallets%5CDefault"

# Fix fracked coins in another wallet
curl -X GET "http://localhost:8080/api/health/fix?wallet_path=D%3A%5CCloudCoin%5CWallets%5CMyWallet"

# Fix fracked coins with pretty-printed output
curl -X GET "http://localhost:8080/api/health/fix?wallet_path=C%3A%5CCloudCoin%5CWallets%5CDefault" | json_pp

# Unix path example
curl -X GET "http://localhost:8080/api/health/fix?wallet_path=/home/user/CloudCoin/Wallets/Default"

Go

package main

import (
    "encoding/json"
    "fmt"
    "io/ioutil"
    "net/http"
    "net/url"
)

const ApiHost = "http://localhost:8080"

type FixResponse struct {
    Status    string `json:"status"`
    Operation string `json:"operation"`
    Message   string `json:"message"`
    Wallet    string `json:"wallet"`
    Note      string `json:"note"`
}

// Fix fracked coins in specified wallet
func fixFrackedCoins(walletPath string) error {
    fmt.Printf("Starting Fix operation on wallet: %s\n", walletPath)

    params := url.Values{}
    params.Add("wallet_path", walletPath)

    uri := fmt.Sprintf("%s/api/health/fix?%s", ApiHost, params.Encode())
    resp, err := http.Get(uri)
    if err != nil {
        return fmt.Errorf("request failed: %v", err)
    }
    defer resp.Body.Close()

    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        return fmt.Errorf("failed to read response: %v", err)
    }

    var result FixResponse
    if err := json.Unmarshal(body, &result); err != nil {
        return fmt.Errorf("failed to parse response: %v", err)
    }

    if result.Status == "success" {
        fmt.Println("Fix completed successfully")
        fmt.Printf("Wallet: %s\n", result.Wallet)
        fmt.Printf("Path: %s\n", result.WalletPath)
        fmt.Printf("Note: %s\n", result.Note)
        return nil
    }

    return fmt.Errorf("fix failed: %s", result.Message)
}

func main() {
    // Fix fracked coins in specified wallet
    if err := fixFrackedCoins("C:/CloudCoin/Wallets/Default"); err != nil {
        panic(err)
    }
}

Important Considerations

Prerequisites

Coins must have existing 'p' (pass) status on some RAIDAs to provide tickets:

  • Coins with 0 'p' status cannot be healed (no ticket sources)
  • Run /api/health/authenticate first if coins have no 'p' status
  • Minimum 1 passing RAIDA required; 13+ recommended for best results
Ticket Validity

Tickets have a 1-minute expiration time:

  • Get Ticket and Fix operations run back-to-back automatically
  • All 25 RAIDAs execute in parallel (~1-2 seconds per phase)
  • No user action needed - timing is handled automatically
Parallel RAIDA Execution

Both Get Ticket and Fix requests execute on all 25 RAIDAs simultaneously:

  • Sequential execution: ~50 seconds (2 seconds × 25 RAIDAs)
  • Parallel execution: ~2 seconds (network RTT + processing)
  • 20-25x performance improvement
  • Default timeout: 10 seconds per RAIDA operation

Related Endpoints

/api/wallet/show-coins

View all coins in the wallet including those in the Fracked folder before and after healing.

/api/coins/grade

Manually grade and sort coins to Bank/Fracked/Counterfeit folders based on POWN status.

/api/health/authenticate

Re-authenticate coins with RAIDA servers. Use this first if coins have no 'p' status.

Troubleshooting

No Tickets Available

If the Fix operation reports "No ticket sources available":

  • Check that coins have at least one 'p' (pass) status RAIDA
  • Run /api/health/authenticate to re-authenticate coins
  • Verify RAIDA network connectivity with /api/program/echo

Coins Still Fracked After Fix

Some coins may remain fracked after healing:

  • Insufficient tickets collected (fewer than 13 per failing RAIDA)
  • Network issues preventing ticket verification
  • Some RAIDAs may be offline or unreachable
  • Run Fix operation again - may heal more coins in subsequent rounds

Coins Moved to Counterfeit

If coins move from Fracked to Counterfeit folder:

  • Coins fell below 13 'p' status during Fix operation
  • Likely genuine coins with severe network issues
  • Try authenticating again during better network conditions
  • Contact RAIDA administrators if persistent