2016-09-30 31 views
3

我試圖用以下步驟在Hyperledger Fabric區塊鏈上開發一個非常簡單的示例: INIT:設置一個包含給定資產「A」數量的表,由一個帳戶號碼 INVOKE:目前沒有任何內容 QUERY:如果您擁有該帳戶或者您具有允許您觀看所有帳戶的特定角色,則會打印給定帳戶的資產餘額。Hyperledger:在鏈式代碼中登錄用戶tcert屬性

所以,在我membersrvc.yaml,我添加的成員,和屬性是這樣的:

eca: 
     affiliations: 
      banks_and_institutions: 
       banks: 
        - bank_a 
        - bank_b 
        - bank_c 
     users: 
       # Users for usecase1 
       client1: 1 client1 bank_a 
       client2: 1 client2 bank_b 
       client3: 1 client3 bank_c 
       back_office: 1 back_office bank_c 
       regulator: 1 regulator bank_c 

    aca: 
       # User attributes for usercase1 
       attribute-entry-1: client1;bank_a;role;client;2015-01-01T00:00:00-03:00;; 
       attribute-entry-2: client1;bank_a;account;client1;2015-01-01T00:00:00-03:00;; 
       attribute-entry-3: client2;bank_b;role;client;2015-01-01T00:00:00-03:00;; 
       attribute-entry-4: client2;bank_b;account;client2;2015-01-01T00:00:00-03:00;; 
       attribute-entry-5: client3;bank_c;role;client;2015-01-01T00:00:00-03:00;; 
       attribute-entry-6: client3;bank_c;account;client3;2015-01-01T00:00:00-03:00;; 
       attribute-entry-7: back_office;bank_c;role;back_office;2015-01-01T00:00:00-03:00;; 
       attribute-entry-8: back_office;bank_c;account;back_office;2015-01-01T00:00:00-03:00;; 
       attribute-entry-9: regulator;bank_c;role;regulator;2015-01-01T00:00:00-03:00;; 
       attribute-entry-10: regulator;bank_c;account;regulator;2015-01-01T00:00:00-03:00;; 

      address: localhost:7054 
      server-name: acap 
      enabled: true 

但我的問題是:

我怎樣才能在我的查詢功能,查詢這些信息的鏈碼?

我的意思是,在啓用安全性和命令發佈給定用戶:

peer network login client1 -p client1 

peer chaincode query -u client1 -n usecase1 -c '{"Function":"assets", "Args": ["some_username"]}' 

能夠獲得客戶端1角色&帳戶,並將我的規則。

謝謝!

回答

1

如何與屬性的工作的一個例子可以在這裏找到:

github.com/hyperledger/fabric/examples/chaincode/go/asset_management_with_roles 

查詢,您可以使用墊片的方法ReadCertAttribute:

callerRole, err := stub.ReadCertAttribute("role") 
if err != nil { 
    fmt.Printf("Error reading attribute 'role' [%v] \n", err) 
    return nil, fmt.Errorf("Failed fetching caller role. Error was [%v]", err) 
} 

請記住,屬性名應當明確宣佈部署/查詢/調用命令(「屬性」:[「role」,「account」]):

Deploy的示例:

curl -XPOST -d '{"jsonrpc": "2.0", "method": "deploy", "params": {"type": 1,"chaincodeID": {"path": "github.com/PATH/TO/YOUR/CHAINCODE","language": "GOLANG"}, "ctorMsg": {"Function":"init", "args": ["some_args"] },"secureContext": "client1", "attributes": ["role", "account"]},"id": 0}' http://localhost:7050/chaincode 

用於查詢的示例:

curl -XPOST -d '{"jsonrpc": "2.0", "method": "query", "params": {"type": 1, "chaincodeID": {"name": "!!CHAINCODE_ID!!"}, "ctorMsg": {"Function":"assets", "args": ["some_username"]}, "secureContext": "client1", "attributes": ["role", "account"]}, "id": 1}' http://localhost:7050/chaincode 
相關問題