测试能否执行交易的时候出现了问题。
错误描述
cielo@cielo-ThinkPad-E550:~/cprogrames/HLF-Fabric-API-master$ node bn-factory-submit-txn.js
2. Received Definition from Runtime: csupplychain 0.0.1
{ ValidationException: Model violation in instance org.sc.product.SampleTransaction#change class org.sc.product.SampleAsset has value 00005 expected a Relationship.
at Function.reportNotRelationshipViolation (/home/cielo/cprogrames/HLF-Fabric-API-master/node_modules/composer-common/lib/serializer/resourcevalidator.js:469:15)
at ResourceValidator.checkRelationship (/home/cielo/cprogrames/HLF-Fabric-API-master/node_modules/composer-common/lib/serializer/resourcevalidator.js:389:31)
at ResourceValidator.visitRelationshipDeclaration (/home/cielo/cprogrames/HLF-Fabric-API-master/node_modules/composer-common/lib/serializer/resourcevalidator.js:371:18)
at ResourceValidator.visit (/home/cielo/cprogrames/HLF-Fabric-API-master/node_modules/composer-common/lib/serializer/resourcevalidator.js:76:25)
at RelationshipDeclaration.accept (/home/cielo/cprogrames/HLF-Fabric-API-master/node_modules/composer-common/lib/introspect/decorated.js:65:24)
at ValidatedResource.setPropertyValue (/home/cielo/cprogrames/HLF-Fabric-API-master/node_modules/composer-common/lib/model/validatedresource.js:74:15)
at main (/home/cielo/cprogrames/HLF-Fabric-API-master/bn-factory-submit-txn.js:78:17)
at /home/cielo/cprogrames/HLF-Fabric-API-master/bn-connection-util.js:42:13
at <anonymous> name: 'ValidationException' }
debug后发现错误地方:
transaction的初始化有问题。
// 4. Create an instance of transaction
let options = {
generate: false,
includeOptionalFields: false
}
let assertid = "00005";
let transaction = factory.newTransaction(namespace,transactionType,assertid,options);
// 5. Set up the properties of the transaction object
transaction.setPropertyValue('asset','00005');
transaction.setPropertyValue('newowner', '0002');
transaction.setPropertyValue('newValue' , newValue);
查看newTransaction的定义,首先删去了assertid这一段。
改为:
let options = {
generate: false,
includeOptionalFields: false
}
let transaction = factory.newTransaction(namespace,transactionType,options);
// 5. Set up the properties of the transaction object
transaction.setPropertyValue('asset','00005');
transaction.setPropertyValue('newowner', '0002');
transaction.setPropertyValue('newValue' , newValue);
报错信息:
cielo@cielo-ThinkPad-E550:~/cprogrames/HLF-Fabric-API-master$ node bn-factory-submit-txn.js2. Received Definition from Runtime: csupplychain 0.0.1
Error: Invalid or missing identifier for Type SampleTransaction in namespace org.sc.product
at Factory.newResource (/home/cielo/cprogrames/HLF-Fabric-API-master/node_modules/composer-common/lib/factory.js:88:19)
at Factory.newTransaction (/home/cielo/cprogrames/HLF-Fabric-API-master/node_modules/composer-common/lib/factory.js:227:32)
at main (/home/cielo/cprogrames/HLF-Fabric-API-master/bn-factory-submit-txn.js:74:31)
at /home/cielo/cprogrames/HLF-Fabric-API-master/bn-connection-util.js:42:13
at <anonymous>
改成
var assertid = "00001";
var newuserid = '0002';
let transaction = factory.newTransaction(namespace,transactionType);
// 5. Set up the properties of the transaction object
transaction.newowner=bnDef.getFactory().newRelationship(namespace,'SampleParticipant',newuserid);
transaction.asset=bnDef.getFactory().newRelationship(namespace,'SampleAsset',assertid);
transaction.setPropertyValue('newValue' , 'change');
报错
cielo@cielo-ThinkPad-E550:~/cprogrames/csupplychain/lib$ node bn-factory-submit-txn.js
2. Received Definition from Runtime: csupplychain 0.0.1
Error: Error trying invoke business network with transaction id 8a8cc2881d1c306407eeb426f6136be533c2811894766351b021133564d0e4ad. Error: No valid responses from any peers.
Response from attempted peer comms was an error: Error: transaction returned with failure: ValidationException: Instance org.sc.product.SampleEvent#8a8cc2881d1c306407eeb426f6136be533c2811894766351b021133564d0e4ad#0 missing required field newowner
at HLFConnection.invokeChainCode (/home/cielo/cprogrames/csupplychain/lib/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:1117:30)
at <anonymous>
错误主体
应该是transaction的值的问题。
但是这个应该怎么赋值呢?好像似乎transaction里面不能有asset和participant,但是初始代码里面是有的……别的例子倒是没有……