跳到主要内容

区块与交易

本页是区块 / 交易信封 / 检索 相关接口:JSON-RPC 读方法(getBlock 等)与 历史 REST(/api/v1/blocks/api/v1/envelopes/api/v1/tx/{hash}/api/v1/search)。

getBlock

查询单个块。不传 height 返回最新块。

参数类型必填说明
heightu64块高度,默认 tip

响应 data

字段类型说明
parentHex32父块哈希
heightu64块高度
timestamp_msu64块时间戳(毫秒)
digestHex32块 SHA-256 哈希
envelope_countusize块内交易数
event_countusize块内事件数
state_rootHex32状态根哈希
envelopesBlockEnvelopeView[]交易列表

BlockEnvelopeView:

字段类型说明
tx_hashTxHash交易哈希(0x hex)
envelope_idxu32块内序号
signerAddress20签名者地址
nonceu64账户 nonce
actionValueAction JSON
statusTxStatus"accepted" · "kept-reject"
reasonRejectReason?仅 kept-reject 时出现

响应示例:

{
"jsonrpc": "2.0", "id": 1,
"result": {
"height": 12345,
"data": {
"parent": "0xabc...def",
"height": 12345,
"timestamp_ms": 1717200000000,
"digest": "0x123...789",
"envelope_count": 15,
"event_count": 42,
"state_root": "0xdef...abc",
"envelopes": [{
"tx_hash": "0xa1b2...c3d4",
"envelope_idx": 0,
"signer": "0x1111222233334444555566667777888899990000",
"nonce": 42,
"action": { "PlaceOrder": { ... } },
"status": "accepted"
}]
}
}
}

getBlockEvents

按高度查块内事件(分页)。事件格式见 事件投影

参数类型必填说明
heightu64块高度
offsetusize默认 0
limitusize默认 500,最大 2000

请求:

{ "jsonrpc": "2.0", "id": 1, "method": "getBlockEvents", "params": { "height": 12345, "offset": 0, "limit": 10 } }

响应 data EventValue[] — 每项为 {"seq": u64, "block_height": u64, "envelope_idx": u32, "kind": {"DomainTag": {"Variant": {...}}}},数值字段已投影为 decimal string。

响应示例:

{
"jsonrpc": "2.0", "id": 1,
"result": {
"height": 12345,
"data": [{
"seq": 3,
"block_height": 12345,
"envelope_idx": 1,
"kind": {
"Exec": {
"Filled": {
"taker_order_id": 1001,
"maker_order_id": 1002,
"market_id": 1,
"price": "97234.50",
"qty": "0.50000",
"notional": "48617.250000",
"taker_fee": "24.308625",
"maker_fee": "-4.861725",
"aggressor_side": "Bid"
}
}
}
}],
"page": { "offset": 0, "limit": 10, "total": 42 }
}
}

getTx

按交易哈希查回执。

参数类型必填说明
hashTxHash32 字节 hex(0x 前缀)

响应 data

字段类型说明
tx_hashTxHash交易哈希
heightu64所在块高
envelope_idxu32块内序号
signerAddress20签名者地址
nonceu64账户 nonce
actionValueAction JSON
statusTxStatus"accepted" · "kept-reject"
reasonRejectReason?仅 kept-reject 时出现
eventsValue[]本笔交易事件(decimal string 投影)

result.reason vs events[] 与写操作响应相同——reason 内数值为 raw i128events[] 中对应 Rejected 已投影为 decimal string。

请求:

{ "jsonrpc": "2.0", "id": 1, "method": "getTx", "params": { "hash": "0xa1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef123456" } }

响应示例:

{
"jsonrpc": "2.0", "id": 1,
"result": {
"height": 12346,
"data": {
"tx_hash": "0xa1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef123456",
"height": 12346,
"envelope_idx": 3,
"signer": "0x1111222233334444555566667777888899990000",
"nonce": 42,
"action": {
"PlaceOrder": {
"owner": "0x1111222233334444555566667777888899990000",
"symbol": "BTC-USDT",
"side": "Bid",
"limit_price": "97100.00",
"qty": "1.00000",
"tif": "Gtc",
"client_order_id": "my-cloid-1",
"reduce_only": false
}
},
"status": "accepted",
"events": [{
"seq": 0,
"block_height": 12346,
"envelope_idx": 3,
"kind": {
"Exec": {
"OrderAccepted": {
"order_id": 1001,
"market_id": 1,
"owner": "0x1111222233334444555566667777888899990000",
"side": "Bid",
"limit_price": "97100.00",
"qty": "1.00000"
}
}
}
}]
}
}
}

区块(REST)

GET /api/v1/blocks

分页区块头列表,新→旧

Query

ParamDefaultMax
offset0
limit50200

Response 200

{
"data": [
{
"parent": "0x…",
"height": 12345,
"timestamp_ms": 1717000000000,
"digest": "0x…",
"envelope_count": 5,
"event_count": 42,
"state_root": "0x…",
"envelopes": []
}
],
"page": { "offset": 0, "limit": 50, "total": 12346 }
}

列表中 envelopes 恒为空数组。完整列表见 [GET /api/v1/blocks/{id}/envelopes#get-apiv1blocksidenvelopes。


GET /api/v1/blocks/{id}

高度digest 查询单个区块头。

Response 200

{ "data": { /* BlockHeader — 字段同列表项 */ } }

Response 404 — 区块不存在。


GET /api/v1/blocks/{id}/events

区块内链上事件,分页返回。

Path: {id} 必须为数字高度(不支持 digest)。非数字 {id} 返回 404

高度合法但区块尚未 ingest、或区块内无 event 时,返回 200 + 空 data(非 404)。

Query

ParamDefaultMax
offset0
limit5002000

Response 200

{
"data": [
{
"height": 12345,
"seq": 0,
"envelope_idx": 0,
"kind": "Exec",
"sub_kind": "Filled",
"market_id": 1,
"symbol": "BTC-USDT",
"tx_hash": "0x…",
"account": "0x…",
"timestamp_ms": 1717000000000,
"body": { "price": "50000.00", "qty": "1.5" }
}
],
"page": { "offset": 0, "limit": 500, "total": 42 }
}
FieldTypeDescription
kindstring事件大类:ExecCoreOcoLiquidationTriggerBridgeOpsUnknown
sub_kindstring子类型,如 FilledOrderAcceptedOrderRestingPositionUpdatedOrderDone
market_idnumber | nullingest 时提取的市场 ID
symbolstring | null读取时从 market cache 解析
tx_hashstring | null产生该 event 的 L2 交易 hash(见 [事件溯源../system/index.md#事件溯源event-provenance)
timestamp_msnumber区块时间戳(ms)
accountstring | null关联账户(尽力提取)
bodyobject节点原始事件 JSON(decimal 字符串)

GET /api/v1/blocks/{id}/envelopes

区块内全部 envelope(已签名交易)。

Path: {id} 必须为数字高度。非数字 {id} 返回 404

区块不存在或无 envelope 时,返回 200 + 空 data 数组(非 404)。

Response 200

{
"data": [
{
"height": 12345,
"envelope_idx": 0,
"tx_hash": "0x…",
"signer": "0x…",
"nonce": 5,
"status": "accepted",
"action_kind": "PlaceOrder",
"market_id": 1,
"symbol": "BTC-USDT",
"action": { "PlaceOrder": { "market_id": 1, "side": "Bid" } },
"reason": null,
"timestamp_ms": 1717000000000
}
]
}
FieldTypeDescription
statusstring执行结果,如 acceptedkept-reject
action_kindstringaction JSON 顶层 key,如 PlaceOrderAmendOrderAmendTriggerOrderCancelOrder
reasonobject | nullstatus == "kept-reject" 时的拒绝详情
timestamp_msnumber区块时间戳(ms,读取时 join)

交易与信封(REST)

GET /api/v1/envelopes

全局 envelope 索引,支持过滤,新→旧

Query

ParamTypeDefaultMaxDescription
signerstring按签名者过滤
action_kindstring按 action 类型过滤
market_idnumber按市场过滤
from_blocknumber最小区块高度(含)
to_blocknumber最大区块高度(含)
offsetnumber0分页偏移
limitnumber25200页大小

Response 200

{
"data": [ /* EnvelopeView[] */ ],
"page": { "offset": 0, "limit": 25, "total": 1000 }
}

GET /api/v1/tx/{hash}

按 hash 查交易。先查本地索引,未命中则回退链节点 getTx

Path: {hash} — 交易 hash(0x…

Response 200(本地)

{
"data": {
"height": 12345,
"envelope_idx": 0,
"tx_hash": "0x…",
"signer": "0x…",
"nonce": 5,
"status": "accepted",
"action_kind": "PlaceOrder",
"market_id": 1,
"symbol": "BTC-USDT",
"action": { "PlaceOrder": { "market_id": 1, "side": "Bid" } },
"reason": null,
"timestamp_ms": 1717000000000,
"events": [
{
"height": 12345,
"seq": 0,
"envelope_idx": 0,
"kind": "Exec",
"sub_kind": "OrderAccepted",
"market_id": 1,
"symbol": "BTC-USDT",
"tx_hash": "0x…",
"account": "0x…",
"timestamp_ms": 1717000000000,
"body": {}
}
]
},
"source": "local"
}
FieldDescription
source"local" — 本地索引;"node" — 链节点实时查询

source == "node" 时,data 遵循节点 getTx 结构,可能与 EnvelopeView 略有差异。

Response 404 — 本地和节点均未找到。


统一检索(REST)

GET /api/v1/search

一个查询串自动分派到区块 / 交易 / 账户(合并后新增端点)。

Query

ParamTypeRequiredDescription
qstringyes纯数字 → 区块高度;64 hex → 交易 hash(未命中回退区块 digest);40 hex → 账户地址;其它 → type: null

Response 200(区块)

{
"data": { "type": "block", "height": 12345, "digest": "0x…", "found": true },
"query": "12345"
}

Response 200(交易)

{
"data": {
"type": "tx",
"tx_hash": "0xabc…",
"height": 12345,
"envelope_idx": 0,
"found": true
},
"query": "0xabc…"
}

Response 200(账户)

{
"data": { "type": "account", "address": "0x1111222233334444555566667777888899990000" },
"query": "0x1111…"
}

Response 400:缺少 q。未命中时 found: false(非 404)。