我正在使用Hyperledger Composer开发区块链应用程序。 这是我模型的一部分,即.cto文件:
concept Address{
o String addressId
o String PersonInChargeFullName
o String title
o String address1
o String address2 optional
o String city
o String country
o String zipcode regex=/^\d{5}$/
o String phone regex=/^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*$/
o String email regex=/^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/
o Boolean isActive default=true
}
abstract participant Company identified by companyId{
o String companyId
o String companyName
o Address defaultAddress
}
participant OEM extends Company {
o Address[] plants
}
通过此page,我了解到,如果我们使用 optional 作为字段验证器,则意味着该字段是可选的,而其他字段则不是。我说的对吗?
尽管我没有将 PersonInChargeFullName 设置为可选,但是当我从composer-rest-server API提交数据(例如:"PersonInChargeFullName": "",
)时,交易得到了处理,没有任何处理错误。
请告知。
答案 0 :(得分:0)
这里的选项有点不同,请尝试在没有PersonInChargeFullName
字段的情况下运行代码,而不要像PersonInChargeFullName = ""
那样运行,但是不要将其包含在json输入中,我敢肯定您会出错。