无法在另一个事务处理器函数

时间:2017-08-09 00:29:56

标签: hyperledger hyperledger-fabric hyperledger-composer

问题:我似乎无法在事务处理器函数中使用Factory调用另一个事务处理器函数。

场景:我有一个事务处理器函数,如下所示:

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

function execTrx(transaction) {   
// do stuff
}

我想在另一个事务处理器函数中调用上面的函数:

/**
 * The buyer pays the listing price agreed to the seller and ownership of the vehicle transfers
 * @param {org.acme.auctionnetwork.PayListing} payment - pay the listing
 * @transaction
 */

function payListing(payment) {

    var factory = getFactory();

    var debitBuyer = factory.newResource('org.acme.auctionnetwork', 'AccountTrx', '##INSERTRANDOMTRXIDHERE##');
        debitBuyer.amount = payment.vehicleListing.buyerPrice;
        debitBuyer.operation = 'W';
        debitBuyer.account = buyerAccount;
        debitBuyer.party = buyerAccount.owner;

    var creditSeller = factory.newResource('org.acme.auctionnetwork', 'AccountTrx', '##INSERTRANDOMTRXIDHERE##');
        creditSeller.amount = payment.vehicleListing.buyerPrice;
        creditSeller.operation = 'D';
        creditSeller.account = sellerAccount;
        creditSeller.party = sellerAccount.owner;

    return getTransactionRegistry('org.acme.auctionnetwork.AccountTrx')
    .then(function(regTransactions) {
        return regTransactions.add(debitBuyer)
        .then(function() {
            return regTransactions.add(creditSeller);
        })
    });
}

但是,上述抱怨没有定义getTransactionRegistry()。我知道你通常创建资产和参与者时,你会调用相应的getAssetRegistry()或getParticipantRegistry()函数,并调用add()函数来更新这些新资产和参与者的注册表。问题是我无法找到如何调用交易。

对于研究,我引用了https://hyperledger.github.io/composer/jsdoc/module-composer-runtime.Factory.html。 newResource()函数声称它适用于资产,参与者和事务,但我无法找到执行事务的示例代码(也可以在默认的Hyperledger Composer演示中查看)。

我也做了一些故障排除,并注意到即使我创建了一个新的AccountTrx事务实例,也没有调用execTrx()函数。

更新:在进一步检查时,似乎有一个详细的TransactionHandler类https://hyperledger.github.io/composer/jsdoc/TransactionHandler.html,但就我而言,我找不到任何关于如何使用的文档它,或示例代码。

1 个答案:

答案 0 :(得分:0)

也许回答这个问题为时已晚,但是现在,我们可以使用getNativeAPI()在作曲家内部使用Hyperledger架构的某些API。我们可以在一个函数中使用该函数来调用相同的网络,但这是另一笔交易。

在以下给定的链接过程中,将链码名称(other-tutorial-network)更改为相同的网络名称以进行自我调用。 https://hyperledger.github.io/composer/v0.19/tutorials/invoke-composer-network

API可以与getNativeAPI()一起使用:https://fabric-shim.github.io/release-1.3/fabric-shim.ChaincodeStub.html?redirect=true