何时调用getAssetRegistry更新资产(和参与者等效) [英] When to call getAssetRegistry to update assets (and the participants equivalent)

查看:89
本文介绍了何时调用getAssetRegistry更新资产(和参与者等效)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用Composer开发环境编写一些简单的智能合约,但对于何时将资产和参与者持久保存到注册表中感到困惑.

I'm able to write some simplistic smart contracts using my composer development environment but am confused about when to persist assets and participants into the registry.

我已阅读 composer-runtime.AssetRegistry getAssetRegistry 函数上的文档,以返回资产注册表对象并执行更新,但仍不清楚哪些资产/参与者进行更新.

I've read the docs on composer-runtime.AssetRegistry and the getAssetRegistry function to return an asset registry object and to perform updates but am still not clear which assets/partipants to update.

这是一个示例(可能无法完全正常工作):

Here's an example (may not be fully working):

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
}

如果我编写了交易处理器功能来执行这样的帐户交易(例如提款或存款):

If I write a transaction processor function to perform an account transaction (e.g. a withdrawal or deposit) such as this:

/**
 * 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资产中的余额变量已更新)

Am I right in assuming that only the BankAccount asset needs to be updated? (because the balance variable in the BankAccount asset has been updated)

我是否还需要更新Bank和Trader参与者,因为Trader参与者是交易AccountTrx的一部分,并且Bank参与者与BankAccount资产相关联?我看不到交易者参与者或BankAccount资产中的任何变化.

Would I also need to update the Bank and Trader participants as well, since the Trader participant was part of the transaction AccountTrx and the Bank participant is linked to from the BankAccount asset? I don't see that anything has changed in either the Trader participant or BankAccount asset.

推荐答案

您不需要.资产account与是关系,您正在调用正确的AssetRegistry.有人假设您使用POST或其他方式调用txn时首先要输入一笔金额.对于更新的资产(BankAccount余额),您会看到什么?为什么不使用console.log()进行检查.

you shouldn't need to. The Asset account has a relationship yes, and you're calling the right AssetRegistry. One assumes you're passing in an amount in the first place when calling the txn using POST or otherwise. What do you see for an updated asset (BankAccount balance)? Why not use console.log() to check..

这篇关于何时调用getAssetRegistry更新资产(和参与者等效)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆