/api/transactions/export
GETExport CloudCoins from the active wallet to a destination folder for sharing or transfer to another wallet.
This endpoint is currently NOT FULLY IMPLEMENTED. It performs parameter validation and returns success, but does not actually export coins from the wallet.
- Current behavior: Validates the
amountparameter and returns success with validated parameters - Missing functionality: Does not read coins from Bank/Fracked folders, does not copy coins to Export folder, does not update transactions.csv
- TODO: Call
cmd_export_coins()and capture actual export results
This documentation describes the intended functionality once fully implemented.
Description
The `/api/transactions/export` endpoint exports CloudCoins from the active wallet's Bank and Fracked folders to a destination folder (typically "Export"). Exported coins can be shared with others or transferred to a different wallet.
The endpoint will select coins from available authenticated (Bank) and partially-authenticated (Fracked) coins to meet the requested amount. Coins are copied, not moved, so they remain in the original folders after export.
This endpoint is useful for:
- Transferring CloudCoins to another user
- Creating backups of specific amounts
- Preparing coins for sending via email or file transfer
- Splitting wallet holdings across multiple locations
- Exported coins are COPIED, not moved - they remain in Bank/Fracked folders
- Amount is specified in whole units (1, 5, 25, 100, 250, etc.), not individual coin serial numbers
- The system will select appropriate denomination coins to meet the requested amount
- Export operations are logged in
transactions.csvfor audit purposes (when fully implemented)
Parameters
All parameters are passed as URL query parameters.
| Parameter | Type | Required | Description |
|---|---|---|---|
amount |
integer | Yes | Number of whole CloudCoin units to export. Must be a positive integer (e.g., 100, 250, 1000). The system will select appropriate denomination coins to meet this amount. |
destination |
string | No | Destination folder name within the wallet directory. Defaults to "Export" if not specified. Common values: "Export", "Shared", "Backup". |
Response
Returns a JSON object with export operation results.
Success Response Properties
Future Implementation Properties
When fully implemented, the response will also include:
Current Example Response (Parameter Validation Only)
{
"status": "success",
"operation": "export",
"amount": 100,
"destination": "Export",
"message": "Export endpoint - implementation pending",
"exported": 0
}
Future Example Response (When Fully Implemented)
{
"status": "success",
"operation": "export",
"amount": 100,
"destination": "Export",
"exported": 2,
"exported_value": 100,
"filename": "export_100cc_2025-01-31_15-30-45.stack",
"file_path": "C:\\MyWallet3\\Default\\Export\\export_100cc_2025-01-31_15-30-45.stack",
"transaction_id": "2025-01-31_15-30-45",
"message": "Successfully exported 100 CloudCoins (2 coins) to Export folder"
}
Error Responses
Returned when the amount parameter is invalid.
{
"status": "error",
"operation": "export",
"error_code": 400,
"message": "Invalid amount parameter"
}
Common causes:
- Missing
amountparameter - Non-numeric
amountvalue - Negative or zero
amount
When fully implemented, may be returned for various operational errors:
- Insufficient balance to export requested amount
- No wallet currently active
- Unable to create destination folder
- File I/O errors during export
- Transaction logging failures
Examples
JavaScript (fetch)
const API_HOST = 'http://localhost:8080';
// Export 100 CloudCoins to default Export folder
async function exportCoins(amount, destination = 'Export') {
try {
const params = new URLSearchParams({
amount: amount,
destination: destination
});
const response = await fetch(`${API_HOST}/api/transactions/export?${params}`);
const result = await response.json();
if (result.status === 'success') {
console.log(`Export initiated: ${result.amount} coins`);
console.log(`Destination: ${result.destination}`);
console.log(`Message: ${result.message}`);
// When fully implemented:
// console.log(`Exported ${result.exported} coins worth ${result.exported_value} units`);
// console.log(`File: ${result.filename}`);
} else {
console.error('Export failed:', result.message);
}
return result;
} catch (error) {
console.error('Error exporting coins:', error);
throw error;
}
}
// Example usage
exportCoins(100, 'Export');
exportCoins(250, 'Backup');
cURL
# Export 100 CloudCoins to default Export folder
curl -X GET "http://localhost:8080/api/transactions/export?amount=100"
# Export 250 CloudCoins to custom destination
curl -X GET "http://localhost:8080/api/transactions/export?amount=250&destination=Backup"
# Export with formatted output
curl -X GET "http://localhost:8080/api/transactions/export?amount=100&destination=Export" | jq .
Go
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/url"
)
const ApiHost = "http://localhost:8080"
type ExportResponse struct {
Status string `json:"status"`
Operation string `json:"operation"`
Amount int `json:"amount"`
Destination string `json:"destination"`
Message string `json:"message"`
Exported int `json:"exported"`
// Future implementation fields
ExportedValue int `json:"exported_value,omitempty"`
Filename string `json:"filename,omitempty"`
FilePath string `json:"file_path,omitempty"`
TransactionID string `json:"transaction_id,omitempty"`
}
func exportCoins(amount int, destination string) (*ExportResponse, error) {
// Build URL with parameters
params := url.Values{}
params.Add("amount", fmt.Sprintf("%d", amount))
params.Add("destination", destination)
url := fmt.Sprintf("%s/api/transactions/export?%s", ApiHost, params.Encode())
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 ExportResponse
if err := json.Unmarshal(body, &result); err != nil {
return nil, err
}
return &result, nil
}
func main() {
// Export 100 coins to Export folder
result, err := exportCoins(100, "Export")
if err != nil {
panic(err)
}
fmt.Printf("Status: %s\n", result.Status)
fmt.Printf("Amount requested: %d\n", result.Amount)
fmt.Printf("Destination: %s\n", result.Destination)
fmt.Printf("Message: %s\n", result.Message)
fmt.Printf("Coins exported: %d\n", result.Exported)
// When fully implemented:
// if result.Filename != "" {
// fmt.Printf("Export file: %s\n", result.Filename)
// fmt.Printf("Transaction ID: %s\n", result.TransactionID)
// }
}
Implementation Details
Current Implementation Status
The endpoint is defined in api_handlers.c (lines 667-690) and currently:
- ✓ Validates the
amountparameter (must be present and numeric) - ✓ Accepts optional
destinationparameter (defaults to "Export") - ✓ Returns structured JSON response
- ✗ Does NOT read coins from Bank/Fracked folders
- ✗ Does NOT select coins to meet requested amount
- ✗ Does NOT copy coins to destination folder
- ✗ Does NOT generate export filenames
- ✗ Does NOT update transactions.csv
Planned Full Implementation
When fully implemented (via cmd_export_coins() in commands.c), the endpoint will:
- Read all coins from the active wallet's Bank and Fracked folders
- Select coins whose total value meets or exceeds the requested amount
- Generate a timestamp-based filename (e.g.,
export_100cc_2025-01-31_15-30-45.stack) - Copy selected coins to the destination folder
- Create binary format (.stack) or JSON format files based on configuration
- Log the transaction in
transactions.csvwith:- Transaction ID (timestamp)
- Operation type ("export")
- Amount requested vs amount exported
- Number of coins exported
- Destination folder path
- Return detailed results including exported coin count and file paths
Coin Selection Algorithm
The system will use a denomination-based selection strategy:
- Prefer larger denominations first to minimize coin count
- Include fracked coins if needed to meet the amount
- May export slightly more than requested if exact change isn't available
Workflow Example
- Check wallet balance:
GET /api/wallet/balance - Verify sufficient funds available
- Export desired amount:
GET /api/transactions/export?amount=100 - Verify export in Export folder
- Share exported file with recipient
- Recipient imports using:
POST /api/transactions/import
Related Endpoints
/api/transactions/import
Import CloudCoins from external files into the active wallet's Import folder for authentication.
/api/wallet/balance
Check current wallet balance before exporting to verify sufficient funds.
/api/coins/export
Alternative export endpoint with additional format options (JSON, PNG, JPEG).
File Format Information
When fully implemented, exported files will use CloudCoin Version 3, File Format 9:
- File extension:
.stack(binary format) or.json(JSON format) - File header: 32 bytes containing format version, coin ID, encryption type, and coin count
- Per-coin data: 407 bytes (7-byte header + 400-byte body with 25 Authenticity Numbers)
- Encryption: Optional AES-128-CTR or AES-256-CTR encryption