2017-06-26 57 views
0

我正在使用hyperledger composer製作業務模型,其中我有一個作爲參與者的銀行和一個作爲資產的客戶。該行定義如下:參與者沒有對資源的創建訪問權限

participant Bank identified by bankId { 
o String bankId 
o String name 
o String code 
} 

和客戶看起來是這樣的:

asset Customer identified by aadhaarId { 
o String aadhaarId 
o String panId 
o String firstName 
o String lastName 
o String contactNo 
o String residence 
o String accountNumber 
o AccountType accountType 
o String creationDate 
--> Bank bank 
} 

我想,一個參與者(銀行)只能更新屬於它的客戶,我想創建一個交易要做到這一點。所以,我創建了以下交易:

transaction updateCustomer identified by transactionId { 
o String transactionId 
--> Customer customer 
o Customer newDetails 
} 

,並在將.acl文件中定義的規則如下:

rule bankCanUpdateItsCutomersViaTransaction { 
description: "Allow a participant to update it's own resources" 
participant(p): "org.acme.sample.Bank" 
operation: UPDATE 
resource(r): "org.acme.sample.updateCustomer" 
condition: (p.getIdentifier() == r.customer.bank.getIdentifier()) 
action: ALLOW 
} 

爲了測試這一點,我創建了一個參與者(除了已經提供的管理)和創建一個與該參與者相關聯的客戶。我有一個交易處理器功能,它只是更新客戶資產註冊表。 但是當我嘗試執行updateCustomer事務時,我收到一個錯誤,指出參與者沒有對資源的CREATE訪問權限。即使我將操作更改爲.acl文件中的CREATE,該問題仍然存在。我認爲問題在於條件部分,但我無法糾正它。

我有一個類似的交易,創造顧客如下:

transaction createCustomer identified by transactionId { 
o String transactionId 
o Customer newCustomer 
} 

,併爲它的規則如下:

rule bankCanCreateItsCutomersViaTransaction {  
description: "Allow a participant to create it's own resources" 
participant(p): "org.acme.sample.Bank" 
operation: CREATE 
resource(r): "org.acme.sample.createCustomer" 
condition: (p.getIdentifier() == r.newCustomer.bank.getIdentifier()) 
action: ALLOW 
} 

有這個createCustomer交易背後的一個簡單的事務處理功能只是在客戶資產註冊表中添加newCustomer。這工作完全正常,但updateCustomer事務不起作用。 任何幫助將不勝感激。謝謝:)

回答

0

我採取了一些其他的途徑,而不是檢查客戶是否屬於規則中的那家銀行,我檢查了交易處理器功能。所以,我對updateCustomer規則是這樣的:

rule bankCanInvokeUpdateCustomer { 
description: "Allow a bank to invoke updateCustomer transaction" 
participant: "org.acme.sample.Bank" 
operation: CREATE 
resource: "org.acme.sample.updateCustomer" 
action: ALLOW 
} 

我查銀行如下:

var currentParticipant = getCurrentParticipant(); 
var currentBank = currentParticipant["$identifier"]; 
var actualBank = tx.customer.bank.bankId; 
if(actualBank != currentBank) 
    throw new Error('You can not update someone else\'s customer'); 

上面的代碼使用getCurrentParticipant()函數獲取當前的參與者,那麼銀行相匹配標識符與客戶已註冊的銀行相同。如果它們不相同,則會引發錯誤

0

有了這個規則,你允許銀行更新交易。你應該嘗試由客戶更換的ressource updateCustomer這樣銀行就可以更新資產:

resource(r): "org.acme.sample.Customer" 

而且,很可能需要添加一個規則,爲創造一個updateCustomer交易給銀行的權利:

rule bankCanCreateTransaction { 
    description: "..." 
    participant: "org.acme.sample.Bank" 
    operation: CREATE 
    resource: "org.acme.sample.updateCustomer" 
    action: ALLOW 
} 
+0

您所說的實際上有意義,但createCustomer Transaction正常工作(我只是在問題中更新了它)。如果我將條件更改爲條件:(true),則更新客戶。所以我認爲問題在於我寫作條件的方式。我可以按照規則的方式從updateCustomer交易中訪問客戶嗎? –

相關問題