2017-08-01 88 views
0

我可以使用我的作曲家開發環境編寫一些簡單的智能合約,但對何時將資產和參與者保存到註冊表中感到困惑。什麼時候調用getAssetRegistry來更新資產(和參與者相同)

我讀過作曲家runtime.AssetRegistry的文檔和getAssetRegistry函數返回的資產登記對象,並進行更新,但現在還不能明確要更新的資產/ partipants。

下面是一個例子(可以不完全工作):

participant Trader identified by userID { 
    o String userID 
    o String firstName 
    o String lastName 
}  

participant Bank identified by bankID { 
    o String bankID 
    o String description 
    --> BankAccount[] accounts optional 
} 

asset BankAccount identified by accountID { 
    o String accountID 
    o Double balance 
    o AccountTrx[] transactions optional 
    --> Trader owner 
} 

transaction AccountTrx { 
    o Double amount 
    o String operation 
    --> BankAccount account 
    --> Trader party 
} 

如果我寫事務處理器功能以執行賬戶交易(例如提款或存款)如此:

/** 
* Perform a deposit or withdrawal from a bank account 
* @param {org.acme.auctionnetwork.AccountTrx} transaction 
* @transaction 
*/ 

function execTrx(transaction) { 
    // initialize array of transactions if none exist 

    if(transaction.account.transactions == null) { 
     transaction.account.transactions = []; 
    } 

    // determine whether this is a deposit or withdrawal and execute accordingly 

    if(transaction.operation == 'W') { 
     transaction.account.balance -= transaction.amount; 
    } else if(transaction.operation == 'D') { 
     transaction.account.balance += transaction.amount; 
    } 

    // add the current transaction to the bank account's transaction history 

    transaction.account.transactions.push(transaction); 

    // update the registry (but which ones???) 

    return getAssetRegistry('org.acme.auctionnetwork.BankAccount') 
    .then(function(regBankAccount) { 
     return regBankAccount.update(transaction.account); 
    }); 
} 

我是否認爲只有BankAccount資產需要更新? (因爲BankAccount資產中的餘額變量已更新)

我是否還需要更新銀行和交易參與者,因爲交易參與者是交易AccountTrx的一部分,銀行參與者鏈接到BankAccount資產?我沒有看到交易者參與者或BankAccount資產中的任何變化。

回答

0

你應該不需要。資產account有一個關係是,你打電話給正確的AssetRegistry。一個人在使用POST或其他方式調用txn時,首先假設您傳遞的是金額。對於更新資產(BankAccount餘額),您看到了什麼?爲什麼不使用console.log()來檢查..

+0

謝謝,我能夠確認你上面的陳述。我現在已經瞭解瞭如何基於其他實驗工作。 – JesterMania

相關問題