{
identities: [
// 以下几项自动编号为[0,1,2]
{ role: { name: "member", mspId: "peerOrg1" }},
{ role: { name: "member", mspId: "peerOrg2" }},
{ role: { name: "admin", mspId: "ordererOrg" }}
],
policy: {
// n-of 指定需要组内多少个进行签名, 1-of 等价于 OR, max-of 等价于AND,此处2与后面的组相同,因此是AND
"2-of": [
// 对应编号2的身份
{ "signed-by": 2},
// 嵌套
{ "1-of": [{ "signed-by": 0 }, { "signed-by": 1 }]}
]
}
}
Java中创建如下 .yaml
文件,并调用 ChaincodeEndorsementPolicy.fromYamlFile()
进行解析即可。示例策略对应命令行的 :
OR(OR('Org1MSP.member', 'Org1MSP.admin'), OR('Org2MSP.member', 'Org2MSP.admin'))
指定策略中会用到的角色
identities:
# Org1MSP 中的 member
user1: {"role": {"name": "member", "mspId": "Org1MSP"}}
# Org2MSP 中的 member
user2: {"role": {"name": "member", "mspId": "Org2MSP"}}
# Org1MSP 中的 admin
admin1: {"role": {"name": "admin", "mspId": "Org1MSP"}}
# Org2MSP 中的 admin
admin2: {"role": {"name": "admin", "mspId": "Org2MSP"}}
policy:
# n-of 指定需要组内多少个进行签名, 1-of 等价于 OR, max-of 等价于AND
1-of:
# 嵌套
- 1-of:
# user1 即上面角色中的 user1
- signed-by: "user1"
- signed-by: "admin1"
- 1-of:
- signed-by: "user2"
- signed-by: "admin2"