blockchain - How is data store in Hyperledger Fabric when using CouchDB as the Ledger State database? -


i'm running code in chaincode developers tutorial, run basic sample chaincode create assets (key-value pairs) on ledger.

i'm able invoke chaincode using cli

peer chaincode invoke -n mycc -c '{"args":["set", "a", "20"]}' -c myc 

and run queries

peer chaincode query -n mycc -c '{"args":["query","a"]}' -c myc 

now want see how key value pair gets stored in couchdb. changed environment variables below in fabric-samples/chaincode-docker-devmode/docker-compose-simple.yaml

core_ledger_state_statedatabase=couchdb core_ledger_state_couchdbconfig_couchdbaddress=couchdb0:5984 

i see documents created below in couchdb ui (http://localhost:5984/myc/_all_docs) when run set.

{   "total_rows": 3,   "offset": 0,   "rows": [{       "id": "lscc\u0000mycc",       "key": "lscc\u0000mycc",       "value": {         "rev": "1-dc6dc8ff92efd35358cf5b89e7949c25"       }     },     {       "id": "mycc\u0000a",       "key": "mycc\u0000a",       "value": {         "rev": "3-7ad1349ec711a99a2a2f1dd1c8b08a20"       }     },     {       "id": "statedb_savepoint",       "key": "statedb_savepoint",       "value": {         "rev": "6-2c3d131fc75772cc9e70311998bdde9d"       }     }   ] } 

how/where value key stored , retrieved? seen below, when checking document in db, retrieved when running chaincode query.

"value": {   "rev": "3-7ad1349ec711a99a2a2f1dd1c8b08a20" } 

when

while key persisted db prefixed name of chaincode, in example it's mycc , separator used []byte{0x00} value. therefore see in example, following output:

{   "id": "mycc\u0000a",   "key": "mycc\u0000a",   "value": {     "rev": "3-7ad1349ec711a99a2a2f1dd1c8b08a20"   } }, 

which stands key a of chaincode mycc. value of key can run curl command following adding query parameter attachements=true, example:

curl -x "http://localhost:5984/mychannel/mycc%00a?attachments=true" 

will result similar this:

--bdb0a91d2e233fdc193f2359e6a50472 content-type: application/json  {"_id":"mycc\u0000a","_rev":"2-2af72e502c2b43c73064728852103fbf","chaincodeid":"mycc","version":"4:0","_attachments":{"valuebytes":{"content_type":"application/octet-stream","revpos":2,"digest":"md5-qpvq4/jgmcgu7wtvfu5zbg==","length":2,"follows":true,"encoding":"gzip","encoded_length":22}}} --bdb0a91d2e233fdc193f2359e6a50472 content-disposition: attachment; filename="valuebytes" content-type: application/octet-stream content-length: 22 content-encoding: gzip  4鯄i --bdb0a91d2e233fdc193f2359e6a50472--% 

for more information how read data couchdb might find following tutorial useful.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -