{
  "openapi": "3.0.3",
  "info": {
    "title": "EVM Indexing as a Service MVP",
    "version": "0.1.0",
    "description": "已实现的 Indexer 创建、revision 读取和异步校验 API。Fiber v3 + Sonic + MongoDB replica set；完整后续范围见 docs/mvp。"
  },
  "servers": [
    {
      "url": "/",
      "description": "部署时的 API 根地址"
    }
  ],
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "paths": {
    "/v1/indexers": {
      "post": {
        "operationId": "createIndexer",
        "summary": "创建草稿及 revision 1",
        "responses": {
          "201": {
            "description": "成功",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Indexer"
                }
              }
            }
          },
          "400": {
            "description": "参数/游标格式错误",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "未认证",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "权限不足",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "资源不存在；跨租户请求同样返回 404",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "状态、版本、幂等或顺序冲突",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "消息/游标超出逻辑保留期",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "配置、ABI、模式或过滤条件不受支持",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "配额或速率限制",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "暂时不可用",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "description": "只保存配置；创建成功不等于 ABI 已通过真实样本验证。tenant_id 来自认证主体，禁止客户端指定。",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateIndexer"
              },
              "examples": {
                "optimistic": {
                  "summary": "低延迟，接收撤销和最终确认",
                  "value": {
                    "name": "Token Transfer",
                    "config": {
                      "chain_id": "1",
                      "contract_addresses": [
                        "0x1111111111111111111111111111111111111111"
                      ],
                      "abi": [
                        {
                          "type": "event",
                          "name": "Transfer",
                          "anonymous": false,
                          "inputs": [
                            {
                              "name": "from",
                              "type": "address",
                              "indexed": true
                            },
                            {
                              "name": "to",
                              "type": "address",
                              "indexed": true
                            },
                            {
                              "name": "value",
                              "type": "uint256",
                              "indexed": false
                            }
                          ]
                        }
                      ],
                      "event_signatures": [
                        "Transfer(address,address,uint256)"
                      ],
                      "filters": [],
                      "start": {
                        "kind": "block",
                        "block_number": "100000"
                      },
                      "consistency": {
                        "mode": "optimistic",
                        "emit_finalized": true
                      },
                      "destinations": [
                        {
                          "destination_id": "dst_example",
                          "version": 1
                        }
                      ],
                      "retention_days": 90
                    }
                  }
                },
                "finalized": {
                  "summary": "等待最终性后推送",
                  "value": {
                    "name": "Token Transfer",
                    "config": {
                      "chain_id": "1",
                      "contract_addresses": [
                        "0x1111111111111111111111111111111111111111"
                      ],
                      "abi": [
                        {
                          "type": "event",
                          "name": "Transfer",
                          "anonymous": false,
                          "inputs": [
                            {
                              "name": "from",
                              "type": "address",
                              "indexed": true
                            },
                            {
                              "name": "to",
                              "type": "address",
                              "indexed": true
                            },
                            {
                              "name": "value",
                              "type": "uint256",
                              "indexed": false
                            }
                          ]
                        }
                      ],
                      "event_signatures": [
                        "Transfer(address,address,uint256)"
                      ],
                      "filters": [],
                      "start": {
                        "kind": "block",
                        "block_number": "100000"
                      },
                      "consistency": {
                        "mode": "finalized"
                      },
                      "destinations": [
                        {
                          "destination_id": "dst_example",
                          "version": 1
                        }
                      ],
                      "retention_days": 90
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/indexers/{indexer_id}": {
      "get": {
        "operationId": "getIndexer",
        "summary": "查询 Indexer 元数据",
        "responses": {
          "200": {
            "description": "成功",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Indexer"
                }
              }
            },
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                },
                "description": "对应 indexers.version 的并发控制值"
              }
            }
          },
          "400": {
            "description": "参数/游标格式错误",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "未认证",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "权限不足",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "资源不存在；跨租户请求同样返回 404",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "状态、版本、幂等或顺序冲突",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "消息/游标超出逻辑保留期",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "配置、ABI、模式或过滤条件不受支持",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "配额或速率限制",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "暂时不可用",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/indexer_id"
          }
        ]
      }
    },
    "/v1/indexers/{indexer_id}/revisions/{revision}": {
      "get": {
        "operationId": "getRevision",
        "summary": "读取配置版本及 ABI",
        "responses": {
          "200": {
            "description": "成功",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Revision"
                }
              }
            }
          },
          "400": {
            "description": "参数/游标格式错误",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "未认证",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "权限不足",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "资源不存在；跨租户请求同样返回 404",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "状态、版本、幂等或顺序冲突",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "消息/游标超出逻辑保留期",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "配置、ABI、模式或过滤条件不受支持",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "配额或速率限制",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "暂时不可用",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/indexer_id"
          },
          {
            "$ref": "#/components/parameters/revision"
          }
        ]
      }
    },
    "/v1/indexers/{indexer_id}/validations": {
      "post": {
        "operationId": "validateIndexer",
        "summary": "异步校验链上读取与解码",
        "responses": {
          "202": {
            "description": "成功",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AcceptedValidation"
                }
              }
            }
          },
          "400": {
            "description": "参数/游标格式错误",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "未认证",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "权限不足",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "资源不存在；跨租户请求同样返回 404",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "状态、版本、幂等或顺序冲突",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "消息/游标超出逻辑保留期",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "配置、ABI、模式或过滤条件不受支持",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "配额或速率限制",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "暂时不可用",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/indexer_id"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ValidateIndexer"
              }
            }
          }
        }
      }
    },
    "/v1/validations/{validation_id}": {
      "get": {
        "operationId": "getValidation",
        "summary": "读取分阶段校验结果和样本",
        "responses": {
          "200": {
            "description": "成功",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Validation"
                }
              }
            }
          },
          "400": {
            "description": "参数/游标格式错误",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "未认证",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "权限不足",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "资源不存在；跨租户请求同样返回 404",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "状态、版本、幂等或顺序冲突",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "消息/游标超出逻辑保留期",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "配置、ABI、模式或过滤条件不受支持",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "配额或速率限制",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "暂时不可用",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/validation_id"
          }
        ]
      }
    },
    "/healthz": {
      "get": {
        "operationId": "healthz",
        "security": [],
        "responses": {
          "200": {
            "description": "Healthy",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status"
                  ],
                  "properties": {
                    "status": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/readyz": {
      "get": {
        "operationId": "readyz",
        "security": [],
        "responses": {
          "200": {
            "description": "Healthy",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status"
                  ],
                  "properties": {
                    "status": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API token 或 JWT；由服务端解析 tenant_id 和 scopes。"
      }
    },
    "parameters": {
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string",
          "minLength": 8,
          "maxLength": 128
        },
        "description": "24 小时幂等窗口，按 tenant + method/path + key 隔离；请求体不同返回 409。"
      },
      "IfMatch": {
        "name": "If-Match",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string"
        },
        "description": "GET Indexer 返回的 ETag；版本不符返回 412。"
      },
      "Limit": {
        "name": "limit",
        "in": "query",
        "schema": {
          "type": "integer",
          "format": "int32",
          "minimum": 1,
          "maximum": 100,
          "default": 50
        }
      },
      "Cursor": {
        "name": "cursor",
        "in": "query",
        "schema": {
          "type": "string"
        },
        "description": "服务端签名的不透明游标，绑定租户和过滤条件；不采用 offset 深分页。"
      },
      "indexer_id": {
        "name": "indexer_id",
        "in": "path",
        "required": true,
        "schema": {
          "$ref": "#/components/schemas/ID"
        }
      },
      "validation_id": {
        "name": "validation_id",
        "in": "path",
        "required": true,
        "schema": {
          "$ref": "#/components/schemas/ID"
        }
      },
      "destination_id": {
        "name": "destination_id",
        "in": "path",
        "required": true,
        "schema": {
          "$ref": "#/components/schemas/ID"
        }
      },
      "delivery_id": {
        "name": "delivery_id",
        "in": "path",
        "required": true,
        "schema": {
          "$ref": "#/components/schemas/ID"
        }
      },
      "stream_id": {
        "name": "stream_id",
        "in": "path",
        "required": true,
        "schema": {
          "$ref": "#/components/schemas/ID"
        }
      },
      "revision": {
        "name": "revision",
        "in": "path",
        "required": true,
        "schema": {
          "type": "integer",
          "format": "int32",
          "minimum": 1
        }
      }
    },
    "schemas": {
      "ID": {
        "type": "string",
        "minLength": 1,
        "maxLength": 512
      },
      "UIntString": {
        "type": "string",
        "pattern": "^(0|[1-9][0-9]*)$",
        "description": "十进制整数字符串；API 不使用浮点数。MVP 区块/序号限制为非负 int64。"
      },
      "ChainID": {
        "type": "string",
        "pattern": "^[1-9][0-9]*$",
        "example": "1"
      },
      "Hash": {
        "type": "string",
        "pattern": "^0x[0-9a-fA-F]{64}$"
      },
      "Address": {
        "type": "string",
        "pattern": "^0x[0-9a-fA-F]{40}$",
        "description": "接受有效 EVM 地址；存储统一为小写。"
      },
      "Timestamp": {
        "type": "string",
        "format": "date-time",
        "description": "RFC3339 UTC 时间；数据库使用 BSON Date。"
      },
      "ErrorDetail": {
        "type": "object",
        "properties": {
          "field": {
            "type": "string"
          },
          "reason": {
            "type": "string"
          }
        },
        "required": [
          "field",
          "reason"
        ],
        "additionalProperties": false
      },
      "Error": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string",
            "example": "VALIDATION_STALE"
          },
          "message": {
            "type": "string"
          },
          "retryable": {
            "type": "boolean"
          },
          "request_id": {
            "type": "string"
          },
          "details": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ErrorDetail"
            }
          },
          "context": {
            "type": "object",
            "additionalProperties": true,
            "description": "仅返回脱敏上下文。"
          }
        },
        "required": [
          "code",
          "message",
          "retryable",
          "request_id"
        ],
        "additionalProperties": false
      },
      "Consistency": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "mode": {
                "type": "string",
                "enum": [
                  "finalized"
                ]
              }
            },
            "required": [
              "mode"
            ],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "mode": {
                "type": "string",
                "enum": [
                  "optimistic"
                ]
              },
              "emit_finalized": {
                "type": "boolean",
                "default": true
              }
            },
            "required": [
              "mode"
            ],
            "additionalProperties": false
          }
        ],
        "description": "创建时选择。finalized 必须由已验证的链/RPC 最终性能力支持；不静默退化成 N 个确认块。optimistic 在完整区块日志可用后推送，并强制支持 revert。"
      },
      "StartPosition": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "kind": {
                "type": "string",
                "enum": [
                  "block"
                ]
              },
              "block_number": {
                "$ref": "#/components/schemas/UIntString"
              }
            },
            "required": [
              "kind",
              "block_number"
            ],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "kind": {
                "type": "string",
                "enum": [
                  "now"
                ]
              }
            },
            "required": [
              "kind"
            ],
            "additionalProperties": false
          }
        ],
        "description": "now 在第一次 start 时固化为当时观测到的 latest 区块 H 的下一块 H+1；保存 H 的哈希。重启不重新解释 now。"
      },
      "ABI": {
        "type": "array",
        "items": {
          "type": "object",
          "additionalProperties": true
        },
        "minItems": 1,
        "maxItems": 4096,
        "description": "完整 JSON ABI。服务端限制序列化后大小为 256 KiB、嵌套深度和复杂度；首版按事件索引。"
      },
      "Filter": {
        "type": "object",
        "properties": {
          "event_signature": {
            "type": "string"
          },
          "argument_position": {
            "type": "integer",
            "format": "int32",
            "minimum": 0
          },
          "operator": {
            "type": "string",
            "enum": [
              "eq",
              "in"
            ]
          },
          "values": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "minItems": 1,
            "maxItems": 100
          }
        },
        "required": [
          "event_signature",
          "argument_position",
          "operator",
          "values"
        ],
        "additionalProperties": false,
        "description": "同一事件的条件 AND；不同事件分别匹配。eq 恰好一个值。MVP 支持 address、bool、整数、bytesN 等标量的等值/集合过滤；整数用十进制。复杂 indexed 参数只接受原始 topic 哈希。服务端拒绝未支持类型。"
      },
      "DestinationBinding": {
        "type": "object",
        "properties": {
          "destination_id": {
            "$ref": "#/components/schemas/ID"
          },
          "version": {
            "type": "integer",
            "format": "int32",
            "minimum": 1
          }
        },
        "required": [
          "destination_id",
          "version"
        ],
        "additionalProperties": false
      },
      "IndexerConfig": {
        "type": "object",
        "properties": {
          "chain_id": {
            "$ref": "#/components/schemas/ChainID"
          },
          "contract_addresses": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Address"
            },
            "minItems": 1,
            "maxItems": 100,
            "uniqueItems": true
          },
          "abi": {
            "$ref": "#/components/schemas/ABI"
          },
          "event_signatures": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "minItems": 1,
            "maxItems": 256,
            "uniqueItems": true
          },
          "filters": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Filter"
            },
            "maxItems": 100
          },
          "start": {
            "$ref": "#/components/schemas/StartPosition"
          },
          "consistency": {
            "$ref": "#/components/schemas/Consistency"
          },
          "destinations": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DestinationBinding"
            },
            "minItems": 1,
            "maxItems": 10
          },
          "retention_days": {
            "type": "integer",
            "format": "int32",
            "enum": [
              90
            ],
            "default": 90
          }
        },
        "required": [
          "chain_id",
          "contract_addresses",
          "abi",
          "event_signatures",
          "start",
          "consistency",
          "destinations"
        ],
        "additionalProperties": false
      },
      "CreateIndexer": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "config": {
            "$ref": "#/components/schemas/IndexerConfig"
          }
        },
        "required": [
          "name",
          "config"
        ],
        "additionalProperties": false
      },
      "Indexer": {
        "type": "object",
        "properties": {
          "id": {
            "$ref": "#/components/schemas/ID"
          },
          "name": {
            "type": "string"
          },
          "desired_state": {
            "type": "string",
            "enum": [
              "stopped",
              "running",
              "paused"
            ]
          },
          "latest_revision": {
            "type": "integer",
            "format": "int32",
            "minimum": 1
          },
          "active_revision": {
            "type": "integer",
            "format": "int32",
            "minimum": 1
          },
          "version": {
            "$ref": "#/components/schemas/UIntString"
          },
          "ever_started": {
            "type": "boolean"
          },
          "created_at": {
            "$ref": "#/components/schemas/Timestamp"
          }
        },
        "required": [
          "id",
          "name",
          "desired_state",
          "latest_revision",
          "version",
          "ever_started",
          "created_at"
        ],
        "additionalProperties": false
      },
      "Revision": {
        "type": "object",
        "properties": {
          "indexer_id": {
            "$ref": "#/components/schemas/ID"
          },
          "revision": {
            "type": "integer",
            "format": "int32",
            "minimum": 1
          },
          "config_hash": {
            "type": "string"
          },
          "abi_hash": {
            "type": "string"
          },
          "config": {
            "$ref": "#/components/schemas/IndexerConfig"
          },
          "activation_block": {
            "$ref": "#/components/schemas/UIntString"
          },
          "created_at": {
            "$ref": "#/components/schemas/Timestamp"
          }
        },
        "required": [
          "indexer_id",
          "revision",
          "config_hash",
          "abi_hash",
          "config",
          "created_at"
        ],
        "additionalProperties": false
      },
      "ValidateIndexer": {
        "type": "object",
        "properties": {
          "revision": {
            "type": "integer",
            "format": "int32",
            "minimum": 1
          },
          "sample": {
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "kind": {
                    "type": "string",
                    "enum": [
                      "recent"
                    ]
                  },
                  "max_blocks": {
                    "type": "integer",
                    "format": "int32",
                    "minimum": 1,
                    "maximum": 100000,
                    "default": 2000
                  }
                },
                "required": [
                  "kind"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "kind": {
                    "type": "string",
                    "enum": [
                      "range"
                    ]
                  },
                  "from_block": {
                    "$ref": "#/components/schemas/UIntString"
                  },
                  "to_block": {
                    "$ref": "#/components/schemas/UIntString"
                  }
                },
                "required": [
                  "kind",
                  "from_block",
                  "to_block"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "kind": {
                    "type": "string",
                    "enum": [
                      "transaction"
                    ]
                  },
                  "transaction_hash": {
                    "$ref": "#/components/schemas/Hash"
                  }
                },
                "required": [
                  "kind",
                  "transaction_hash"
                ],
                "additionalProperties": false
              }
            ]
          }
        },
        "required": [
          "revision"
        ],
        "additionalProperties": false,
        "description": "样本读取受时间/响应体/区块范围预算限制。仅校验链上数据；不会隐式调用目标 Webhook。"
      },
      "AcceptedValidation": {
        "type": "object",
        "properties": {
          "validation_id": {
            "$ref": "#/components/schemas/ID"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued"
            ]
          },
          "status_url": {
            "type": "string"
          }
        },
        "required": [
          "validation_id",
          "status",
          "status_url"
        ],
        "additionalProperties": false
      },
      "ValidationStep": {
        "type": "object",
        "properties": {
          "stage": {
            "type": "string",
            "enum": [
              "config",
              "rpc",
              "contract",
              "fetch_logs",
              "decode",
              "filter",
              "destination"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "running",
              "passed",
              "warning",
              "failed"
            ]
          },
          "duration_ms": {
            "type": "integer",
            "format": "int32",
            "minimum": 0
          },
          "message": {
            "type": "string"
          },
          "error": {
            "$ref": "#/components/schemas/Error"
          }
        },
        "required": [
          "stage",
          "status"
        ],
        "additionalProperties": false
      },
      "DecodedArgument": {
        "type": "object",
        "properties": {
          "position": {
            "type": "integer",
            "format": "int32",
            "minimum": 0
          },
          "name": {
            "type": "string"
          },
          "type": {
            "type": "string"
          },
          "encoding": {
            "type": "string",
            "enum": [
              "value",
              "indexed_hash"
            ]
          },
          "value": {}
        },
        "required": [
          "position",
          "name",
          "type",
          "encoding",
          "value"
        ],
        "additionalProperties": false,
        "description": "整数为十进制字符串，bytes 为 0x 十六进制。数组/tuple 保持结构；indexed 动态/复杂类型仅返回哈希。"
      },
      "EventPayload": {
        "type": "object",
        "properties": {
          "source_event_id": {
            "$ref": "#/components/schemas/ID"
          },
          "decoded_event_id": {
            "$ref": "#/components/schemas/ID"
          },
          "chain_id": {
            "$ref": "#/components/schemas/ChainID"
          },
          "block_number": {
            "$ref": "#/components/schemas/UIntString"
          },
          "block_hash": {
            "$ref": "#/components/schemas/Hash"
          },
          "block_time": {
            "$ref": "#/components/schemas/Timestamp"
          },
          "transaction_hash": {
            "$ref": "#/components/schemas/Hash"
          },
          "transaction_index": {
            "type": "integer",
            "format": "int32",
            "minimum": 0
          },
          "log_index": {
            "type": "integer",
            "format": "int32",
            "minimum": 0
          },
          "contract_address": {
            "$ref": "#/components/schemas/Address"
          },
          "event_signature": {
            "type": "string"
          },
          "abi_hash": {
            "type": "string"
          },
          "decoder_version": {
            "type": "string"
          },
          "args": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DecodedArgument"
            }
          },
          "raw": {
            "type": "object",
            "properties": {
              "topics": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/Hash"
                },
                "maxItems": 4
              },
              "data": {
                "type": "string",
                "pattern": "^0x([0-9a-fA-F]{2})*$"
              }
            },
            "required": [
              "topics",
              "data"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "source_event_id",
          "decoded_event_id",
          "chain_id",
          "block_number",
          "block_hash",
          "block_time",
          "transaction_hash",
          "transaction_index",
          "log_index",
          "contract_address",
          "event_signature",
          "abi_hash",
          "decoder_version",
          "args"
        ],
        "additionalProperties": false
      },
      "Validation": {
        "type": "object",
        "properties": {
          "id": {
            "$ref": "#/components/schemas/ID"
          },
          "kind": {
            "type": "string",
            "enum": [
              "indexer",
              "destination"
            ]
          },
          "indexer_id": {
            "$ref": "#/components/schemas/ID"
          },
          "revision": {
            "type": "integer",
            "format": "int32",
            "minimum": 1
          },
          "destination_id": {
            "$ref": "#/components/schemas/ID"
          },
          "destination_version": {
            "type": "integer",
            "format": "int32",
            "minimum": 1
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "running",
              "passed",
              "passed_with_warnings",
              "failed",
              "cancelled"
            ]
          },
          "config_hash": {
            "type": "string"
          },
          "steps": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ValidationStep"
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sample_events": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/EventPayload"
            },
            "maxItems": 20
          },
          "valid_until": {
            "$ref": "#/components/schemas/Timestamp"
          },
          "created_at": {
            "$ref": "#/components/schemas/Timestamp"
          }
        },
        "required": [
          "id",
          "kind",
          "status",
          "steps",
          "created_at"
        ],
        "additionalProperties": false
      }
    }
  }
}
