/crossover/send
POST ASYNCNotifies the system of a cryptocurrency deposit to be converted into CloudCoins.
Description
This endpoint is used to inform the system that you have sent cryptocurrency (e.g., Bitcoin) to a designated address for conversion into CloudCoins. You must provide the transaction ID (hash) and other details. The system will then monitor the blockchain for confirmation. Once confirmed, it will mint the equivalent value in CloudCoins and place them in a new RAIDA locker, returning a `transmit_code` in the completed task.
Asynchronous Operation
This is a long-running, asynchronous operation. It returns a task ID immediately. You must poll the /tasks/{id}
endpoint to monitor its progress as it waits for blockchain confirmation.
Request Body
Parameter | Type | Required | Description |
---|---|---|---|
ticker | string | Yes | The ticker of the source cryptocurrency. Currently, only "BTC" is supported. |
crypto_amount | number | Yes | The exact amount of cryptocurrency that was sent in the transaction. |
txn | string | Yes | The transaction ID (hash) of the payment on its native blockchain. |
tag | string | No | An optional memo or message for the transaction. |
Response (in completed task `data`)
Once the transaction is confirmed and the task is complete, its `data` field will contain a `transmit_code` to access the new CloudCoins.
/locker/{code}
endpoint.Examples
JavaScript: Crossover Send
const apiHost = 'http://localhost:8006';
// Generic function to poll any task
async function pollTask(taskId) {
const taskResponse = await fetch(`${apiHost}/api/v1/tasks/${taskId}`);
const taskData = await taskResponse.json();
const task = taskData.payload;
console.log(`Task ${taskId} progress: ${task.progress}% - ${task.message}`);
if (task.status === 'completed') {
console.log(`Task finished successfully!`, task.data);
return true; // Stop polling
} else if (task.status === 'error') {
console.error(`Task failed:`, task.message);
return true; // Stop polling
}
return false; // Continue polling
}
async function crossoverSend(sendDetails) {
try {
const response = await fetch(`${apiHost}/api/v1/crossover/send`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(sendDetails)
});
const taskInfo = await response.json();
const taskId = taskInfo.payload.id;
console.log(`Crossover send task created with ID: ${taskId}`);
const pollInterval = setInterval(async () => {
const isDone = await pollTask(taskId);
if (isDone) clearInterval(pollInterval);
}, 5000); // Poll every 5 seconds as this can take time
} catch (error) {
console.error('Failed to start send task:', error);
}
}
// Example: Notify system of a BTC deposit
const details = {
ticker: "BTC",
crypto_amount: 0.005,
txn: "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16",
tag: "My first crossover deposit"
};
crossoverSend(details);
cURL: Crossover Send
# Step 1: Initiate the crossover send task
JSON_PAYLOAD='{"ticker":"BTC","crypto_amount":0.005,"txn":"f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16","tag":"My first crossover deposit"}'
TASK_ID=$(curl -s -X POST "http://localhost:8006/api/v1/crossover/send" \
-H "Content-Type: application/json" \
-d "$JSON_PAYLOAD" | jq -r '.payload.id')
echo "Crossover send 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/tasks/$TASK_ID")
STATUS=$(echo $RESPONSE | jq -r '.payload.status')
MESSAGE=$(echo $RESPONSE | jq -r '.payload.message')
echo "Polling task.. Status: $STATUS - $MESSAGE"
if [[ "$STATUS" == "completed" ]] || [[ "$STATUS" == "error" ]]; then
echo "Final Response:"
echo $RESPONSE | jq
break
fi
sleep 5
done
Go: Crossover Send
package main
import (
"bytes"
"encoding/json"
"fmt"
"log"
"net/http"
"time"
)
const apiHost = "http://localhost:8006/api/v1"
// Type for the request
type CrossoverSendRequest struct {
Ticker string `json:"ticker"`
CryptoAmount float64 `json:"crypto_amount"`
Tag string `json:"tag"`
TransactionID string `json:"txn"`
}
// Type for the task response
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"`
}
// pollTask polls a task until it is complete or fails.
func pollTask(taskId 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("Polling... Status: %s, Message: %s\n", taskResp.Payload.Status, taskResp.Payload.Message)
if taskResp.Payload.Status == "completed" {
fmt.Printf("Task completed successfully. Result: %+v\n", taskResp.Payload.Data)
return
} else if taskResp.Payload.Status == "error" {
fmt.Printf("Task failed: %s\n", taskResp.Payload.Message)
return
}
time.Sleep(5 * time.Second)
}
}
// crossoverSend initiates a send operation and polls for the result.
func crossoverSend(details CrossoverSendRequest) {
requestBody, _ := json.Marshal(details)
resp, err := http.Post(fmt.Sprintf("%s/crossover/send", apiHost), "application/json", bytes.NewBuffer(requestBody))
if err != nil {
log.Fatalf("Failed to start send task: %v", err)
}
defer resp.Body.Close()
var taskResp TaskResponse
json.NewDecoder(resp.Body).Decode(&taskResp)
fmt.Printf("Crossover send task created with ID: %s\n", taskResp.Payload.ID)
pollTask(taskResp.Payload.ID)
}
func main() {
details := CrossoverSendRequest{
Ticker: "BTC",
CryptoAmount: 0.005,
TransactionID: "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16",
Tag: "My first crossover deposit",
}
crossoverSend(details)
}