use of com.jd.blockchain.ledger.LedgerException in project jdchain-core by blockchain-jd-com.
the class RolePrivilegeDataset method setRolePrivilege.
/**
* 设置角色权限; <br>
* 如果版本校验不匹配,则返回 -1;
*
* @param roleAuth
* @return
*/
private long setRolePrivilege(RolePrivileges roleAuth) {
if (roleAuth.getRoleName().length() > MAX_ROLE_NAME_LENGTH) {
throw new LedgerException("Too long role name!");
}
Bytes key = encodeKey(roleAuth.getRoleName());
byte[] privilegeBytes = BinaryProtocol.encode(roleAuth, PrivilegeSet.class);
return dataset.setValue(key, privilegeBytes, roleAuth.getVersion());
}
use of com.jd.blockchain.ledger.LedgerException in project jdchain-core by blockchain-jd-com.
the class RolePrivilegeDataset method addRolePrivilege.
/**
* 加入新的角色权限; <br>
*
* 如果指定的角色已经存在,则引发 {@link LedgerException} 异常;
*
* @param roleName 角色名称;不能超过 {@link #MAX_ROLE_NAME_LENGTH} 个 Unicode 字符;
* @param ledgerPrivilege
* @param txPrivilege
*/
public long addRolePrivilege(String roleName, LedgerPrivilegeBitset ledgerPrivilege, TransactionPrivilegeBitset txPrivilege) {
RolePrivileges roleAuth = new RolePrivileges(roleName, -1, ledgerPrivilege, txPrivilege);
long nv = setRolePrivilege(roleAuth);
if (nv < 0) {
throw new LedgerException("Role[" + roleName + "] already exist!");
}
if (ledgerDataStructure.equals(LedgerDataStructure.KV)) {
Bytes index = ROLEPRI_SEQUENCE_KEY_PREFIX.concat(Bytes.fromString(String.valueOf(dataset.getDataCount() + rolepri_index_in_block)));
nv = dataset.setValue(index, Bytes.fromString(roleName).toBytes(), -1);
if (nv < 0) {
throw new LedgerException("Role[" + roleName + "] seq already exist!");
}
rolepri_index_in_block++;
}
return nv;
}
Aggregations