创建资产时出现错误“ ValidationException:org.hyperledger.composer.system.AddAsset类型的意外属性:registryType,registryId”

时间:2019-05-21 10:30:47

标签: hyperledger hyperledger-composer

我是Hyperledger Composer的新手。我正在关注如何与其他业务网络进行交互的作曲家教程 hyperledger_composer_tutorial

我已遵循本教程中提到的步骤1,2,3。当我尝试执行步骤4:创建资产

我能够在业务网络A中创建参与者。 在业务网络A中创建资产时遇到错误

ValidationException: Unexpected properties for type org.hyperledger.composer.system.AddAsset: registryType, registryId

error image

这是我的代码

网络A

/**
 * My commodity trading network
 */
namespace org.example.mynetwork
asset Commodity identified by tradingSymbol {
    o String tradingSymbol
    o String description
    o String mainExchange
    o Double quantity
    --> Trader owner
}
participant Trader identified by tradeId {
    o String tradeId
    o String firstName
    o String lastName
}
transaction Trade {
    --> Commodity commodity
    --> Trader newOwner
}

2) logic.js

        /**
         * Track the trade of a commodity from one trader to another
         * @param {org.example.mynetwork.Trade} trade - the trade to be processed
         * @transaction
         */
        async function tradeCommodity(trade) {
            trade.commodity.owner = trade.newOwner;

            const otherNetworkData = await getNativeAPI().invokeChaincode('other-tutorial-network', ['getResourceInRegistry', 'Asset', 'org.example.mynetwork.Commodity', trade.commodity.tradingSymbol], 'composerchannel');                    
            const stringAsset = new Buffer(otherNetworkData.payload.toArrayBuffer()).toString('utf8');
            const asset = getSerializer().fromJSON(JSON.parse(stringAsset));

            trade.commodity.quantity = asset.quantity;

            const assetRegistry = await getAssetRegistry('org.example.mynetwork.Commodity');
            await assetRegistry.update(trade.commodity);
        }

网络B

/**
 * My commodity trading network
 */
namespace org.example.mynetwork
asset Commodity identified by tradingSymbol {
    o String tradingSymbol
    o String description
    o String mainExchange
    o Double quantity
    --> Trader owner
}
participant Trader identified by tradeId {
    o String tradeId
    o String firstName
    o String lastName
}
transaction Trade {
    --> Commodity commodity
    --> Trader newOwner
}
2) logic.js

/**
 * Track the trade of a commodity from one trader to another
 * @param {org.example.mynetwork.Trade} trade - the trade to be processed
 * @transaction
 */
async function tradeCommodity(trade) {
    trade.commodity.owner = trade.newOwner;
    let assetRegistry = await getAssetRegistry('org.example.mynetwork.Commodity');
    await assetRegistry.update(trade.commodity);
}

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我相信您在命令行中作为输入提供的JSON可能是错误的,因为您要添加商品类型的资产。

请改用此命令

composer transaction submit --card networkA -d '{"$class": "org.example.mynetwork.Commodity","tradingSymbol": "Ag","owner": "resource: org.example.mynetwork.Trader#bob@example.com","description": "Some", "mainExchange": "exhange","quantity": 25}'