use of com.jd.blockchain.ledger.DataAccountKVSetOperation.KVWriteEntry in project jdchain-core by blockchain-jd-com.
the class DataAccountKVSetOperationHandle method doProcess.
@Override
protected void doProcess(DataAccountKVSetOperation kvWriteOp, LedgerTransactionContext transactionContext, TransactionRequestExtension requestContext, LedgerQuery ledger, OperationHandleContext handleContext, EventManager manager) {
// 权限校验;
SecurityPolicy securityPolicy = SecurityContext.getContextUsersPolicy();
securityPolicy.checkEndpointPermission(LedgerPermission.WRITE_DATA_ACCOUNT, MultiIDsPolicy.AT_LEAST_ONE);
// 操作账本;
DataAccount account = transactionContext.getDataset().getDataAccountSet().getAccount(kvWriteOp.getAccountAddress());
if (account == null) {
throw new DataAccountDoesNotExistException(String.format("Data account doesn't exist! --[Address=%s]", kvWriteOp.getAccountAddress()));
}
// 写权限校验
securityPolicy.checkDataPermission(account.getPermission(), DataPermissionType.WRITE);
KVWriteEntry[] writeSet = kvWriteOp.getWriteSet();
long v = -1L;
for (KVWriteEntry kvw : writeSet) {
v = account.getDataset().setValue(kvw.getKey(), TypedValue.wrap(kvw.getValue()), kvw.getExpectedVersion());
if (v < 0) {
throw new DataVersionConflictException();
}
}
}
Aggregations