wss 协议而不是 ws。
你可以通过 WebSocket 调用 subscribe RPC 方法,并提供一个有效查询,来订阅上述任意事件。
查询参数与事件类型限制
虽然 CometBFT 对应用程序输出的事件类型没有任何限制,但在查询数值型事件时,仍有几个注意事项需要考虑。- 查询会将所有数值型事件值转换为
math/big提供的big.Float。整数会被转换为精度等于表示该整数所需位数的浮点数。这样做是为了避免在使用默认精度(64)转换大整数时发生精度损失。 - 比较两个值时,如果其中任意一个是浮点数,另一个也会被表示为大浮点数。整数同样会被解析为大浮点数,其精度等于表示该整数所需的位数。
- 与所有浮点比较一样,比较带小数的浮点数可能导致结果不精确。
- 查询中不能包含负数。
v0.38.x 版本之前,查询参数不支持浮点数。
ValidatorSetUpdates
当验证者集合发生变化时,会发布 ValidatorSetUpdates 事件。该事件携带一个公钥/投票权重对列表。这个列表与 CometBFT 从 ABCI 应用程序接收到的内容相同(参见 ABCI 规范中的 EndBlock 部分)。 响应:CometBFT emits different events, which you can subscribe to via Websocket. This can be useful for third-party applications (for analysis) or for inspecting state. List of events To connect to a node via websocket from the CLI, you can use a tool such as wscat and run:
wss instead of ws.
You can subscribe to any of the events above by calling the subscribe RPC
method via Websocket along with a valid query.
Query parameter and event type restrictions
While CometBFT imposes no restrictions on the application with regard to the type of the event output, there are several considerations that need to be taken into account when querying events with numeric values.- Queries convert all numeric event values to
big.Float, provided bymath/big. Integers are converted into a float with a precision equal to the number of bits needed to represent this integer. This is done to avoid precision loss for big integers when they are converted with the default precision (64). - When comparing two values, if either one of them is a float, the other one will be represented as a big float. Integers are again parsed as big floats with a precision equal to the number of bits required to represent them.
- As with all floating point comparisons, comparing floats with decimal values can lead to imprecise results.
- Queries cannot include negative numbers.
v0.38.x, floats were not supported as query parameters.