# Claimed Stacks management

## Claimed Stack Management

**Get All Claimed Stacks**

```
GET /claimed_stacks
```

Returns all claimed stacks for the currently registered node badges.

**Response Status Codes**

* `200 OK`: Successfully retrieved claimed stacks
* `500 Internal Server Error`: Failed to retrieve claimed stacks from state manager

**Response**

```json
[
  {
    "stack_small_id": 1,
    "stack_id": "stack-123",
    "selected_node_id": 123,
    "num_claimed_compute_units": 1000,
    "settlement_time": "2024-03-21T12:00:00Z",
    "attestation_status": "Pending",
    "requested_attestation_nodes": "[456, 789]",
    "received_attestations": 1,
    "required_attestations": 2,
    "settlement_complete": false
  }
]
```

**Response Fields**

* `stack_small_id` (integer): Unique small integer identifier for the stack
* `stack_id` (string): Unique string identifier for the stack
* `selected_node_id` (integer): ID of the node that claimed the stack
* `num_claimed_compute_units` (integer): Number of compute units claimed for settlement
* `settlement_time` (string): ISO timestamp when the settlement was initiated
* `attestation_status` (string): Current status of attestations ("Pending", "Complete", "Failed")
* `requested_attestation_nodes` (string): JSON array of node IDs requested for attestation
* `received_attestations` (integer): Number of attestations received so far
* `required_attestations` (integer): Total number of attestations required
* `settlement_complete` (boolean): Whether the settlement process is complete

**Get Node Claimed Stacks**

```
GET /claimed_stacks/:id
```

Returns all claimed stacks for a specific node identified by its small ID.

**Parameters**

* `id` (path, integer): Node small ID

**Response Status Codes**

* `200 OK`: Successfully retrieved claimed stacks
* `500 Internal Server Error`: Failed to retrieve claimed stacks from state manager

**Response**

Same format as Get All Claimed Stacks, filtered for the specified node.

**Example Error Response**

```json
{
  "error": "Failed to get node claimed stacks"
}
```

**Notes**

* Claimed stacks represent stacks that have entered the settlement process
* The settlement process requires attestations from other nodes
* A stack is considered fully settled when:
  * Required number of attestations is received
  * All attestations are positive
  * No disputes are raised during the settlement period
* The `requested_attestation_nodes` field contains a JSON-encoded array of node IDs
* Settlement status can be determined by comparing `received_attestations` with `required_attestations`
