Composite Key functions in Hyperledger

穿精又带淫゛_ 提交于 2019-12-01 09:40:05

The function simply creates a key by combining the attributes into a single string. Its application is where we need to store multiple instances of one type on the ledger. The keys of those instances will be constructed from a combination of attributes— for example, "Order" + ID, yielding ["Order1","Order2", ...]. This function comes in hand when you intend to search for assets based on components of the key in range queries.

The 'CreateCompositeKey' in SHIM construct a composite key (indeed, a unique key) based on a combination of several attributes.

The inverse function is SplitCompositeKey which splits the compositeKey into attributes.

func SplitCompositeKey(compositeKey string) (string, []string, error)

The 'TestTradeWorkflow_Agreement' function is this code is also useful in understanding the whole process:

In Hyperledger Fabric there are two sample chaincodes which shows how to use composite keys:

  1. Marbles
  2. Map

Basically it almost as you said:

key, err := stub.CreateCompositeKey(index, []string{key1, key2, key3})

// Skiped

stub.PutState(key, value)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!