/api/coins/break
GET PARAMETER VALIDATION ONLYBreaks a larger denomination coin into smaller denominations (e.g., break 100 into 4× 25 coins).
This endpoint is NOT fully implemented. Currently only validates the denomination parameter and returns success. The actual coin breaking functionality (cmd_break_coin integration) is pending.
Current behavior:
- ✓ Validates denomination parameter
- ✓ Returns success with denomination and value
- ✗ Does NOT actually break coins
- ✗ Does NOT communicate with RAIDA
- ✗ Does NOT create child coins
Note: Usually called internally by other processes - needs cmd_break_coin() integration to accept denomination parameter.
Description
The `/api/coins/break` endpoint will break a larger denomination coin into smaller denominations. For example, breaking a 100-value coin into four 25-value coins, or a 1000-value coin into ten 100-value coins.
When fully implemented, this endpoint will:
- Select a coin with the specified denomination from the Bank folder
- Request available serial numbers from RAIDA for the child coins
- Send a Break command (0x095c) to all 25 RAIDA servers with:
- Original coin's serial number, denomination, and authenticity numbers
- Target denominations for the child coins
- New serial numbers for the child coins
- RAIDA destroys the original coin and creates the child coins
- Download the child coins with their new authenticity numbers
- Save the child coins to the Bank folder
Breaking coins is useful for:
- Making change for transactions
- Splitting large value into smaller, more usable denominations
- Creating coins of specific denominations for payments
- Optimizing wallet balance distribution
The break operation is atomic across all 25 RAIDA servers:
- All or nothing: All 25 RAIDAs must agree to the break
- Original destroyed: The original coin is permanently destroyed
- New coins created: Child coins receive new serial numbers from RAIDA's pool
- ANs updated: Child coins get new authenticity numbers
Parameters
This endpoint requires one query parameter:
Query Parameters
- 0 = 1
- 1 = 5
- 2 = 25
- 3 = 100
- 4 = 250
- 5 = 1000
- 6 = 5000
- 7 = 25000
- 8 = 100000
- 9 = 250000
- 10 = 1000000
Response
Returns a JSON object indicating the break operation status (currently parameter validation only).
Response Properties
Success Response (Current Implementation)
{
"status": "success",
"operation": "coins-break",
"message": "Break coin endpoint - parameter-based implementation pending",
"wallet": "Default",
"denomination": 3,
"value": 100,
"note": "Usually called internally by other processes - needs cmd_break_coin() integration"
}
Error Response - No Active Wallet
{
"status": "error",
"operation": "coins-break",
"message": "No active wallet. Please load a wallet first using /api/wallet/load"
}
Error Response - Missing Parameter
{
"status": "error",
"operation": "coins-break",
"message": "Missing required parameter: 'denomination'"
}
Error Response - Invalid Denomination
{
"status": "error",
"operation": "coins-break",
"message": "Invalid denomination value. Must be 0-10"
}
Break Examples
Common denomination breaking scenarios:
- 100 (dn=3) → 4× 25 coins (dn=2)
- 250 (dn=4) → 10× 25 coins (dn=2) or 2× 100 + 2× 25
- 1000 (dn=5) → 10× 100 coins (dn=3) or 4× 250 coins (dn=4)
- 5000 (dn=6) → 5× 1000 coins (dn=5) or 20× 250 coins (dn=4)
- 25000 (dn=7) → 5× 5000 coins (dn=6) or 25× 1000 coins (dn=5)
- 100000 (dn=8) → 4× 25000 coins (dn=7) or 100× 1000 coins (dn=5)
Examples
JavaScript (fetch)
const API_HOST = 'http://localhost:8080';
async function breakCoin(denomination) {
try {
const response = await fetch(
`${API_HOST}/api/coins/break?denomination=${denomination}`
);
const result = await response.json();
if (result.status === 'success') {
console.log('Break validated successfully');
console.log(`Denomination: ${result.denomination} (value: ${result.value})`);
console.log(`Wallet: ${result.wallet}`);
console.log(`Note: ${result.note}`);
} else {
console.error('Break failed:', result.message);
}
return result;
} catch (error) {
console.error('Error breaking coin:', error);
throw error;
}
}
// Example: Break a 100-value coin (denomination code 3)
breakCoin(3);
// Example: Break a 1000-value coin (denomination code 5)
breakCoin(5);
cURL
# Break a 100-value coin (denomination code 3)
curl -X GET "http://localhost:8080/api/coins/break?denomination=3"
# Break a 1000-value coin (denomination code 5)
curl -X GET "http://localhost:8080/api/coins/break?denomination=5"
# Break a 250-value coin (denomination code 4)
curl -X GET "http://localhost:8080/api/coins/break?denomination=4"
Go
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
const ApiHost = "http://localhost:8080"
type BreakResponse struct {
Status string `json:"status"`
Operation string `json:"operation"`
Message string `json:"message"`
Wallet string `json:"wallet,omitempty"`
Denomination int `json:"denomination,omitempty"`
Value int `json:"value,omitempty"`
Note string `json:"note,omitempty"`
}
func breakCoin(denomination int) (*BreakResponse, error) {
url := fmt.Sprintf("%s/api/coins/break?denomination=%d", ApiHost, denomination)
resp, err := http.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
var result BreakResponse
if err := json.Unmarshal(body, &result); err != nil {
return nil, err
}
return &result, nil
}
func main() {
// Break a 100-value coin (denomination code 3)
result, err := breakCoin(3)
if err != nil {
panic(err)
}
if result.Status == "success" {
fmt.Printf("Break validated successfully\n")
fmt.Printf("Denomination: %d (value: %d)\n", result.Denomination, result.Value)
fmt.Printf("Wallet: %s\n", result.Wallet)
fmt.Printf("Note: %s\n", result.Note)
} else {
fmt.Printf("Break failed: %s\n", result.Message)
}
}
Denomination Reference
Complete mapping of denomination codes to actual values:
Denomination Codes
Related Endpoints
/api/coins/join
Opposite operation - combine multiple smaller denomination coins into a larger denomination.
/api/wallet/balance
Check available denominations in your wallet before breaking coins.
/api/wallet/show-coins
View all coins in your wallet with their denominations and serial numbers.
Future Implementation
When fully implemented, this endpoint will integrate with cmd_break_coin() to:
- Accept denomination parameter from API request
- Select an appropriate coin from the Bank folder
- Communicate with RAIDA using the Break protocol (0x095c)
- Handle multi-threaded RAIDA requests for 20-25x performance improvement
- Create transaction receipts in the Receipts folder
- Update wallet balance and coin files
- Return detailed results including child coin serial numbers
The C implementation in src/commands.c contains the full cmd_break_coin() logic. The API endpoint needs to be updated to pass the denomination parameter to this function and return the results in JSON format.