交易不起作用。 Hyperledger Composer

时间:2018-06-06 09:45:42

标签: javascript hyperledger hyperledger-composer

当我尝试通过REST API服务器提交事务时,它返回500错误。 更新到0.19.7 Hyperledger Composer版本后,我开始收到此错误。

该事务和模型的BNA已经在Hyperledger Composer游乐场进行了测试,并且运行良好。

这是我得到的回复错误

{"error":{"statusCode":500,"name":"Error","message":"Error trying invoke business network. Error: No valid responses from any peers.\nResponse from attempted peer comms was an error: Error: 2 UNKNOWN: error executing chaincode: transaction returned with failure: Error: Generated invalid JSON: ...
at _initializeChannel.then.then.then.then.catch (/home/composer/.npm-global/lib/node_modules/composer-rest-server/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:980:34)\n    at <anonymous>"}}

这是来自其他服务器的日志

Response from attempted peer comms was an error: Error: 2 UNKNOWN: error executing chaincode: transaction returned with failure: Error: Generated invalid JSON: ...
at _initializeChannel.then.then.then.then.catch (/home/composer/.npm-global/lib/node_modules/composer-rest-server/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:980:34)
at <anonymous>

以下是提交错误的交易:

/**
 * @param 
{com.iba.linux.chainnetwork.contract.transaction.ResponseConfiguration} responseConfiguration
 * @transaction
 */
function responseConfiguration(responseConfiguration) {
    var subOrder = responseConfiguration.subOrder;
    subOrder.productionTime = responseConfiguration.productionTime;
    return updateSubOrder(subOrder, 'approvedConfig');
}

function updateSubOrder(subOrder, state) {
    var order = subOrder.order;
    subOrder.state = state;
    return updateAssetInRegistry(subOrder).then(function () {
        return updateOrderIfSubOrdersStateEquals(order, state, subOrder);
    }).then(function (order) {
        return updateAssetInRegistry(order);
    });
}

function updateAssetInRegistry(asset) {
    return getAssetRegistry(asset.getFullyQualifiedType())
        .then(function updTheReg(registry) {
            return registry.update(asset);
        });
}

function updateOrderIfSubOrdersStateEquals(order, state, modifiableSubOrder) {
    var shouldBeUpdated = 0;
    return Promise.all(order.subOrders.map(function (subOrder) {
        return getAssetFromRegistry(subOrder)
            .then(function (subOrder) {
                if (state === subOrder.state || modifiableSubOrder.getIdentifier() === subOrder.getIdentifier()) {
                    shouldBeUpdated++;
                }
                return subOrder;
            });
    })).then(function () {
        if (shouldBeUpdated === order.subOrders.length) {
            order.state = state;
        }
        return order;
    });
}

型号:

contract_transactions.cto

namespace com.iba.linux.chainnetwork.contract.transaction

import com.iba.linux.chainnetwork.contract.SubOrder
import com.iba.linux.chainnetwork.contract.Order

transaction ResponseConfiguration {
    --> SubOrder subOrder
    o Integer productionTime
} 

contract.cto

namespace com.iba.linux.chainnetwork.contract

import com.iba.linux.chainnetwork.asset.definition.AssetDetails
import com.iba.linux.chainnetwork.asset.entity.SimpleAsset
import com.iba.linux.chainnetwork.partner.PrivateOwner

enum OrderState {
    o createdConfig
    o approvedConfig
    o acceptedByClient
    o rejectedByClient
    o manufacturing
    o readyForDeliver
    o delivering
    o delivered
}

asset SubOrder identified by subOrderId {
    o String subOrderId
    --> AssetDetails assetDetails
    --> Order order
    o String note optional
    o Integer productionTime optional 
    --> SimpleAsset orderedAsset optional
    o String clientSign optional
    o OrderState state
    --> Invoice invoice optional 
}

asset Order identified by orderId {
    o String orderId
    --> PrivateOwner client
    --> SubOrder[] subOrders
    o OrderState state
    --> PrivateOwner courier
}

asset Invoice identified by invoiceId {
  o String invoiceId
}

partners.cto

namespace com.iba.linux.chainnetwork.partner

abstract participant Person identified by email {
    o String email
}

enum Role {
    o Client
    o Seller
    o Courier
}

participant PrivateOwner extends Person {
    o Role businessRole
}

有什么问题?

1 个答案:

答案 0 :(得分:0)

我没有看到交易模型,但您的有效JSON可能是

{ 
"$class": "com.iba.linux.chainnetwork.contract.transaction.ResponseConfiguration", 
"productionTime": "0", 
"subOrder": "resource:com.iba.linux.chainnetwork.contract.SubOrder#-707019134" 
} 

resource:前缀 - 请参阅本教程第六步中的一些示例 - 具体说明如何在JSON构造中指定关系标识符here