当我尝试更新与同一资产相关的两个资产时,我遇到了错误。从HL Composer v0.18.1升级到v0.19.4后,我收到错误。
这里的模型:
asset Order identified by pullID {
o String pullID
--> PackCase caseNumber optional
}
asset PackCase identified by caseNumber{
o String caseNumber
--> Order[] orders optional
}
我想将Order1和Order2关联到Packcase1。为此,我在事务处理器中使用此方法,它将顺序插入到packcase.orders数组中并同时更新order.casenumber的引用:
function AssociatePackCaseToOrder(tx){
tx.order.caseNumber = tx.packCase;
tx.packCase.orders.push(tx.order);
return getAssetRegistry(namespaceAsset+'.Order')
.then(function(ordersRegistry){
return ordersRegistry.update(tx.order)
.then(function(){
console.info("Order Updated");
return getAssetRegistry(namespaceAsset+'.PackCase')
.then(function(packCaseRegistry){
return packCaseRegistry.update(tx.packCase)
.then(function(){
console.info("PackCase Updated");
})
})
})
})
}
但是当我尝试按顺序调用此方法两次时,我收到此错误:
Error trying invoke business network. Error: No valid responses from any peers.\nResponse from attempted peer comms was an error:
Error: 8 RESOURCE_EXHAUSTED: received trailing metadata size exceeds limit",
"stack":"Error: Error trying invoke business network. Error: No valid responses from any peers.
Response from attempted peer comms was an error: Error: 8 RESOURCE_EXHAUSTED: received trailing metadata size exceeds limit
at _initializeChannel.then.then.then.then.catch (/usr/lib/node_modules/composer-rest-server/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:967:34)
at <anonymous>
有谁知道错误的原因是什么?
答案 0 :(得分:3)
I think there's a problem in your code, and RESOURCE_EXHAUSTED (which is likely to come from grpc message size limits) - possibly the first line where you're assigning an object to a String.
Currently (though you've not posted the transaction model) you're trying to associate an Order (or collection of) with a PackCase - your code shows its one transaction at a time (you update the registry per resource). The code shown below, adds the casenumber reference to the Order and pushes the Order ID (FQ identifier) into the array on PackCase.
So with a model like this:
asset Order identified by pullID {
o String pullID
o String caseNumber optional
--> PackCase packcase optional // this would make more sense naming-wise
}
asset PackCase identified by caseNumber {
o String caseNumber
--> Order[] orders optional
// o Order[] orders optional // alternative, see below.
}
transaction acpto {
--> Order order
--> PackCase packCase
}
your transaction code is like this:
/**
* Associate the Packcase to order
* @param {org.acme.mynetwork.acpto} tx - the tx to be processed
* @transaction
**/
function AssociatePackCaseToOrder(tx){
var namespaceAsset = 'org.acme.mynetwork';
tx.order.caseNumber = tx.packCase.getIdentifier(); // eg. '1'
console.log(" case ref is " + tx.packCase.getIdentifier() );
console.log(" order ref is " + tx.order.getIdentifier() );
// tx.order.pullID = tx.order.getIdentifier(); // because its a relationship, will still have the FQ identifer hence commented out FYI
if(tx.packCase.orders == null) {
tx.packCase.orders = []; // initialise
}
tx.packCase.orders.push(tx.order);
return getAssetRegistry(namespaceAsset+'.Order')
.then(function(ordersRegistry){
return ordersRegistry.update(tx.order)
.then(function(){
console.info("Order Updated");
return getAssetRegistry(namespaceAsset+'.PackCase')
.then(function(packCaseRegistry){
return packCaseRegistry.update(tx.packCase)
.then(function(){
console.info("PackCase Updated");
})
})
})
})
}
Your method: --> Order[] orders optional
{
"$class": "org.acme.mynetwork.PackCase",
"caseNumber": "5",
"orders": [
"resource:org.acme.mynetwork.Order#1",
"resource:org.acme.mynetwork.Order#2",
"resource:org.acme.mynetwork.Order#3"
]
}
alternative Order[] orders optional
:
after submitting 3 transactions for Order 1, Order 2 and Order 3, you get this in the PackCase asset:
{
"$class": "org.acme.mynetwork.PackCase",
"caseNumber": "3",
"orders": [
{
"$class": "org.acme.mynetwork.Order",
"pullID": "1",
"caseNumber": "3"
},
{
"$class": "org.acme.mynetwork.Order",
"pullID": "2",
"caseNumber": "3"
}
{
"$class": "org.acme.mynetwork.Order",
"pullID": "3",
"caseNumber": "3"
}
]
}
Suffice to say, the Order casenumber is updated with the case reference number from PackCase
.