尝试在Playground / Explorer中用一项交易更新两项资产

时间:2019-05-02 19:46:09

标签: hyperledger-fabric hyperledger hyperledger-composer hyperledger-explorer

我无法更新asset2标志值。 Asset1事务成功,资产2事务被忽略。我在Playground开发。有什么想法吗?

我尝试将asset2的第二个更新编写为子例程。没有引发错误,事务执行资产1更新,并且忽略对资产2更新的调用。这在Playground和Composer Rest Server Explorer中都会发生。

/*
* @param {************.asset1Update} transact
* @transaction 
*/
async function asset1Update(transact) {

    const asset1Reg = await getAssetRegistry('com.saberdata.printChain.Order'); const userReg = await getParticipantRegistry('com.saberdata.printChain.User'); const fileReg = await getAssetRegistry('com.saberdata.printChain.StoredFile'); const asset2Reg = await getAssetRegistry('com.saberdata.printChain.Project');

    try { // Verify asset1Id provided exists.

        const asset1Exists = await asset1Reg.exists(transact.asset1Id);
        if (!asset1Exists) {
            let errmes = 'asset1Id ' + transact.asset1Id + ' not found.';
            throw ('Error : ' + errmes);
        }

        const asset2Exists = await asset2Reg.exists(transact.asset2);
        if (!asset2Exists) {
            let errmes = 'asset2 ' + transact.asset2 + ' not found.';
            throw ('Error : ' + errmes);
        }

        const userExists = await userReg.exists(transact.projectCreator);
        if (!userExists) {
            let errmes = 'projectCreator ' + transact.projectCreator + ' not found.';
            throw ('Error : ' + errmes);
        }

        const fileExists = await fileReg.exists(transact.file);
        if (!fileExists) {
            let errmes = 'file ' + transact.file + ' not found.';
            throw ('Error : ' + errmes);
        }



        //these cannot be changed
        if (transact.asset1Id.length) {
            let errmes = 'Some fields may not be updated';
            throw ('Error : ' + errmes);
        }
    } catch (err) {
        throw new Error('From CRS -- asset1Update: ' + err);
    }
    // Update asset1 

    let asset1Old = await asset1Reg.get(transact.asset1Id);

    asset1Old.orderStatus = transact.orderStatus;
    asset1Old.orderName = transact.orderName;
    asset1Old.fileName = transact.fileName;
    asset1Old.creationTime = transact.creationTime;
    asset1Old.orderQuantity = transact.orderQuantity;
    asset1Old.completedCount = transact.completedCount;
    asset1Old.materialType = transact.materialType;
    asset1Old.materialAmtReqd = transact.materialAmtReqd; asset1Old.estCompletionTime = transact.estCompletionTime;

    const currentPart = getCurrentParticipant();

    try {

        let origasset2 = await asset2Reg.get(transact.project)
        origasset2.flag = false;
        origasset2.changedBy = currentPart;
        origasset2.changedDate = new Date(Date.now());
    } catch (e) {

        throw new Error('From Revoke(): ' + e);
    }

    await asset2Reg.update(origAsset2);

    return await asset1Reg.update(asset1Old);
}

0 个答案:

没有答案