Search in sources :

Example 1 with KVWriteEntry

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();
        }
    }
}
Also used : DataAccount(com.jd.blockchain.ledger.core.DataAccount) DataAccountDoesNotExistException(com.jd.blockchain.ledger.DataAccountDoesNotExistException) SecurityPolicy(com.jd.blockchain.ledger.SecurityPolicy) KVWriteEntry(com.jd.blockchain.ledger.DataAccountKVSetOperation.KVWriteEntry) DataVersionConflictException(com.jd.blockchain.ledger.DataVersionConflictException)

Aggregations

DataAccountDoesNotExistException (com.jd.blockchain.ledger.DataAccountDoesNotExistException)1 KVWriteEntry (com.jd.blockchain.ledger.DataAccountKVSetOperation.KVWriteEntry)1 DataVersionConflictException (com.jd.blockchain.ledger.DataVersionConflictException)1 SecurityPolicy (com.jd.blockchain.ledger.SecurityPolicy)1 DataAccount (com.jd.blockchain.ledger.core.DataAccount)1