> ## Documentation Index
> Fetch the complete documentation index at: https://docs.li.fi/llms.txt
> Use this file to discover all available pages before exploring further.

# 跟踪订单状态

> 通过订单服务器 API 或链上事件监控 LI.FI 意图订单。

提交订单后，您可以通过订单服务器 API 或直接监控链上事件来跟踪其进度。

***

## 订单服务器状态

调用 `GET /orders/status`，附带您提交订单时返回的 `onChainOrderId` 或 `catalystOrderId`。

<CodeGroup>
  ```bash curl theme={"system"}
  curl -X GET 'https://order.li.fi/orders/status?catalystOrderId=intent_qVo7_1TkJ7VekL99O7SGS9cRHv0si6'
  ```

  ```ts TypeScript theme={"system"}
  const getOrderStatus = async (orderId: string) => {
    const res = await fetch(
      `https://order.li.fi/orders/status?catalystOrderId=${orderId}`
    );
    return res.json();
  };

  const status = await getOrderStatus('intent_qVo7_1TkJ7VekL99O7SGS9cRHv0si6');
  console.log('Status:', status.meta.orderStatus);
  ```
</CodeGroup>

### 查询参数

| 参数                | 描述                                                        |
| ----------------- | --------------------------------------------------------- |
| `onChainOrderId`  | 在合约事件中发出的链上订单 ID                                          |
| `catalystOrderId` | 从 `POST /orders/submit` 返回的订单服务器 ID（例如 `intent_qVo7_...`） |

至少需要一个参数。

### 响应

响应包含完整的订单、任何关联的报价，以及一个带有状态信息的 `meta` 对象。

```ts theme={"system"}
{
  order: StandardOrder,
  quote: QuoteInfo | null,
  sponsorSignature: string | null,
  allocatorSignature: string | null,
  inputSettler: string,
  meta: {
    submitTime: number,
    orderStatus: "Submitted" | "Open" | "Signed" | "Delivered" | "Settled",
    destinationAddress: string,
    orderIdentifier: string,
    onChainOrderId: string,
    signedAt: string | null,
    deliveredAt: string | null,
    settledAt: string | null,
    expiredAt: string | null,
    orderInitiatedTxHash: string | null,
    orderDeliveredTxHash: string | null,
    orderVerifiedTxHash: string | null,
    orderSettledTxHash: string | null,
    solverAddress: string | null
  }
}
```

### 状态生命周期

| 状态          | 含义                     |
| ----------- | ---------------------- |
| `Submitted` | 订单服务器已收到订单（过渡态）        |
| `Open`      | 订单已在链上注册（过渡态）          |
| `Signed`    | 订单已签名并可供解算器接收          |
| `Delivered` | 解算器已在目标链上交付资产          |
| `Settled`   | 证明已验证，锁定资金释放给解算器。订单完成。 |

大多数集成应将 `Signed`、`Delivered` 和 `Settled` 视为主要的执行状态。`Submitted` 和 `Open` 可能并非在每条路径中都可见。

### 轮询示例

```ts theme={"system"}
const pollUntilDone = async (orderId: string) => {
  let data;
  do {
    data = await getOrderStatus(orderId);
    const { orderStatus } = data.meta;
    console.log(`Status: ${orderStatus}`);

    if (orderStatus === 'Settled') {
      console.log('Complete. Delivery tx:', data.meta.orderDeliveredTxHash);
      return data;
    }

    if (data.meta.expiredAt) {
      console.log('Order expired.');
      return data;
    }

    await new Promise(r => setTimeout(r, 3000));
  } while (true);
};
```

***

## 列出订单

使用 `GET /orders` 通过过滤器查询多个订单。

```bash theme={"system"}
curl -X GET 'https://order.li.fi/orders?user=0xYOUR_ADDRESS&status=Delivered&limit=10'
```

| 参数                | 描述                  |
| ----------------- | ------------------- |
| `user`            | 按发起方地址过滤            |
| `status`          | 按订单状态过滤             |
| `nonce`           | 按 nonce 过滤          |
| `exclusiveFor`    | 按解算器地址过滤            |
| `onChainOrderId`  | 按链上订单 ID 过滤         |
| `catalystOrderId` | 按订单服务器 ID 过滤        |
| `limit`           | 最大结果数（1-50，默认 50）   |
| `offset`          | 跳过的结果数（0-1000，默认 0） |

***

## 链上事件

您也可以直接从合约事件跟踪订单。`orderId` 在所有相关事件上都作为 `topic1` 发出。

### 订单已打开

```solidity theme={"system"}
event Open(bytes32 indexed orderId, StandardOrder order);
```

### 输出已填充（由解算器）

```solidity theme={"system"}
event OutputFilled(
  bytes32 indexed orderId,
  bytes32 solver,
  uint32 timestamp,
  MandateOutput output,
  uint256 finalAmount
);
```

### 订单已终结（结算完成）

```solidity theme={"system"}
event Finalised(
  bytes32 indexed orderId,
  bytes32 solver,
  bytes32 destination
);
```

### 订单已退款

```solidity theme={"system"}
event Refunded(bytes32 indexed orderId);
```

链上 `orderId` 是确定性的，其计算方式为：

```solidity theme={"system"}
function orderIdentifier(StandardOrder calldata order) internal view returns (bytes32) {
  return keccak256(
    abi.encodePacked(
      block.chainid,
      address(this),
      order.user,
      order.nonce,
      order.expires,
      order.fillDeadline,
      order.inputOracle,
      keccak256(abi.encodePacked(order.inputs)),
      abi.encode(order.outputs)
    )
  );
}
```

***

## 后续步骤

<CardGroup cols={2}>
  <Card title="API 概述" icon="code" href="/lifi-intents/intents-api/api-overview">
    完整的端点参考和 Base URL
  </Card>

  <Card title="创建并提交订单" icon="paper-plane" href="/lifi-intents/intents-api/create-and-submit">
    订单构造和提交
  </Card>

  <Card title="结算" icon="lock" href="/lifi-intents/architecture/settlement">
    输入和输出结算的工作原理
  </Card>

  <Card title="系统概述" icon="diagram-project" href="/lifi-intents/architecture/overview">
    Intent/Solver Marketplace 的完整架构
  </Card>
</CardGroup>
