You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Hyperledger Composer v0.19.4时间参数查询返回空数组问题

Hyperledger Composer v0.19.4: Fixing Empty Results for HistorianRecord Time Range Query

嘿,我看了你遇到的问题,首先得指出一个很容易忽略的逻辑错误——你的时间范围条件写反了!这大概率是返回空数组的首要原因。另外,我再给你明确下Composer v0.19.x里正确的时间戳格式要求:

1. 先修正查询的时间范围逻辑

你当前的条件是_$fromTime>transactionTimestamp AND _$toTime<transactionTimestamp,这意味着要找一个比fromTime早、同时比toTime晚的时间,这根本不可能满足!正确的逻辑应该是让transactionTimestamp落在fromTime和toTime之间:

getTransactionsBetweenIntervalMadeByParticipant{
 description: "Get all transactions made by participant between an interval"
 statement: SELECT org.hyperledger.composer.system.HistorianRecord WHERE ((participantInvoking==_$participantInvoking) AND (transactionTimestamp >= _$fromTime) AND (transactionTimestamp <= _$toTime))
}

如果你的需求是不包含边界值,就用>和<,但一定要保证fromTime早于toTime。

2. 正确的时间戳格式

在Composer v0.19.x中,查询HistorianRecord的transactionTimestamp时,必须使用UTC时区的ISO 8601格式,具体格式是yyyy-MM-ddTHH:mm:ss.SSSZ,比如:2024-05-20T14:30:00.000Z。这里有几个细节要注意:

  • 必须带结尾的Z,表示UTC时区,因为Composer内部存储的时间戳都是UTC格式的,用本地时区的字符串会匹配失败
  • 毫秒部分(.SSS)可以省略,但建议带上以保证精度匹配
  • 不要用Unix时间戳,Composer的查询引擎不支持直接解析这种格式作为时间参数

3. 参数传递示例

调用查询时,参数要传符合格式的字符串,同时participantInvoking必须是完整的资源标识符(包含resource:前缀、类型和ID),比如:

const queryParams = {
  participantInvoking: 'resource:org.yourdomain.Participant#user123',
  fromTime: '2024-01-01T00:00:00.000Z',
  toTime: '2024-05-20T23:59:59.999Z'
};

把这几点都修正后,你的查询应该就能正常返回数据了。

内容的提问来源于stack exchange,提问作者MrL

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:15:40