fabric 超级账本复合密钥

fabric hyperledger composite key

我正在查看高吞吐量链代码示例,并对复合键有疑问。

在代码中,密钥创建如下

compositeIndexName := "varName~op~value~txID"

是否可以通过 'op' 或 'value' 省略或使用一些通配符来查询 'varName'?或者我是否需要为我想查询的每个 ID 创建不同的索引复合键,如 marbles_chaincode 示例中所示?另一种选择是将 couchDB 用于支持更复杂查询的状态数据库?

因为我要将一些 JSON 数据保存到分类帐中,所以我需要通过不同的键来查询(在弹珠示例中,我们说颜色或大小)。

此致问候,节日快乐!

我建议考虑使用 CouchDB 作为状态数据库,因为它为您提供了相当全面的查询功能,这比您在 level db 之上使用复合键可以实现的查询功能更具表现力。如果您以 JSON 格式存储文档,这可能特别有用。无论如何,查看此 CouchDB query syntax 了解更多信息。

// GetQueryResult performs a "rich" query against a state database. It is
// only supported for state databases that support rich query,
// e.g.CouchDB. The query string is in the native syntax
// of the underlying state database. An iterator is returned
// which can be used to iterate (next) over the query result set.
// The query is NOT re-executed during validation phase, phantom reads are
// not detected. That is, other committed transactions may have added,
// updated, or removed keys that impact the result set, and this would not
// be detected at validation/commit time.  Applications susceptible to this
// should therefore not use GetQueryResult as part of transactions that update
// ledger, and should limit use to read-only chaincode operations.
GetQueryResult(query string) (StateQueryIteratorInterface, error)

因此您可以使用以下 API 来检索您的