我可以使用我的作曲家开发环境编写一些简单的智能合约,但对何时将资产和参与者保存到注册表中感到困惑。什么时候调用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资产中的任何变化。
谢谢,我能够确认你上面的陈述。我现在已经了解了如何基于其他实验工作。 – JesterMania