Search in sources :

Example 1 with IllegalTransactionException

use of com.jd.blockchain.ledger.IllegalTransactionException in project jdchain-core by blockchain-jd-com.

the class UserRegisterOperationHandle method doProcess.

@Override
protected void doProcess(UserRegisterOperation op, LedgerTransactionContext transactionContext, TransactionRequestExtension requestContext, LedgerQuery ledger, OperationHandleContext handleContext, EventManager manager) {
    // 权限校验;
    SecurityPolicy securityPolicy = SecurityContext.getContextUsersPolicy();
    securityPolicy.checkEndpointPermission(LedgerPermission.REGISTER_USER, MultiIDsPolicy.AT_LEAST_ONE);
    // 证书模式下必须传递证书
    if (transactionContext.getDataset().getAdminDataset().getAdminSettings().getMetadata().getIdentityMode() == IdentityMode.CA) {
        if (StringUtils.isEmpty(op.getCertificate())) {
            throw new IllegalTransactionException("User certificate is empty!");
        }
        X509Certificate cert = CertificateUtils.parseCertificate(op.getCertificate());
        CertificateUtils.checkCertificateRolesAny(cert, CertificateRole.PEER, CertificateRole.GW, CertificateRole.USER);
        CertificateUtils.checkValidity(cert);
        X509Certificate[] ledgerCAs = CertificateUtils.parseCertificates(transactionContext.getDataset().getAdminDataset().getAdminSettings().getMetadata().getLedgerCertificates());
        X509Certificate[] issuers = CertificateUtils.findIssuers(cert, ledgerCAs);
        Arrays.stream(issuers).forEach(issuer -> CertificateUtils.checkCACertificate(issuer));
        CertificateUtils.checkValidityAny(issuers);
    }
    // 操作账本;
    BlockchainIdentity bid = op.getUserID();
    Bytes userAddress = bid.getAddress();
    ((UserAccountSetEditor) (transactionContext.getDataset().getUserAccountSet())).register(userAddress, bid.getPubKey(), op.getCertificate());
}
Also used : Bytes(utils.Bytes) IllegalTransactionException(com.jd.blockchain.ledger.IllegalTransactionException) UserAccountSetEditor(com.jd.blockchain.ledger.core.UserAccountSetEditor) SecurityPolicy(com.jd.blockchain.ledger.SecurityPolicy) BlockchainIdentity(com.jd.blockchain.ledger.BlockchainIdentity) X509Certificate(java.security.cert.X509Certificate)

Example 2 with IllegalTransactionException

use of com.jd.blockchain.ledger.IllegalTransactionException in project jdchain-core by blockchain-jd-com.

the class TransactionSetEditor method saveRequest.

private void saveRequest(TransactionRequest txRequest) {
    // 序列化交易内容;
    byte[] txResultBytes = BinaryProtocol.encode(txRequest, TransactionRequest.class);
    Bytes key;
    if (ledgerDataStructure.equals(LedgerDataStructure.MERKLE_TREE)) {
        // 以交易内容的 hash 为 key;
        key = encodeRequestKey(txRequest.getTransactionHash());
    } else {
        key = encodeKvRequestKey(txStateSet.getDataCount() + txIndex);
    }
    // 交易只有唯一的版本;
    long v = txStateSet.setValue(key, txResultBytes);
    if (v < 0) {
        throw new IllegalTransactionException("Repeated transaction request! --[" + key + "]");
    }
}
Also used : Bytes(utils.Bytes) IllegalTransactionException(com.jd.blockchain.ledger.IllegalTransactionException)

Example 3 with IllegalTransactionException

use of com.jd.blockchain.ledger.IllegalTransactionException in project jdchain-core by blockchain-jd-com.

the class TransactionSetEditor method saveTotalByHeight.

// 按照区块高度记录交易总数
private void saveTotalByHeight() {
    // key = keyprefix/T
    Bytes key = encodeTotalNumKey();
    // 交易序号只有唯一的版本;
    long v = txStateSet.setValue(key, BytesUtils.toBytes(getTotalCount()), preBlockHeight);
    if (v < 0) {
        throw new IllegalTransactionException("Repeated transaction request sequence! --[" + key + "]");
    }
}
Also used : Bytes(utils.Bytes) IllegalTransactionException(com.jd.blockchain.ledger.IllegalTransactionException)

Example 4 with IllegalTransactionException

use of com.jd.blockchain.ledger.IllegalTransactionException in project jdchain-core by blockchain-jd-com.

the class TransactionSetEditor method saveSequence.

// 以账本为维度记录交易哈希对应的索引号
private void saveSequence(TransactionRequest txRequest) {
    // key = keyprefix/SQ/txHash
    Bytes key = encodeSeqKey(txRequest.getTransactionHash());
    // 交易序号只有唯一的版本;
    long v = txStateSet.setValue(key, BytesUtils.toBytes(txStateSet.getDataCount() + txIndex));
    if (v < 0) {
        throw new IllegalTransactionException("Repeated transaction request sequence! --[" + key + "]");
    }
    txIndex++;
}
Also used : Bytes(utils.Bytes) IllegalTransactionException(com.jd.blockchain.ledger.IllegalTransactionException)

Example 5 with IllegalTransactionException

use of com.jd.blockchain.ledger.IllegalTransactionException in project jdchain-core by blockchain-jd-com.

the class TransactionSetEditor method saveResult.

private void saveResult(TransactionResult txResult) {
    // 序列化交易内容;
    byte[] txResultBytes = BinaryProtocol.encode(txResult, TransactionResult.class);
    Bytes key;
    if (ledgerDataStructure.equals(LedgerDataStructure.MERKLE_TREE)) {
        // 以交易内容的 hash 为 key;
        key = encodeResultKey(txResult.getTransactionHash());
    } else {
        key = encodeKvResultKey(txStateSet.getDataCount() + txIndex);
    }
    // 交易只有唯一的版本;
    long v = txStateSet.setValue(key, txResultBytes);
    if (v < 0) {
        throw new IllegalTransactionException("Repeated transaction request! --[" + key + "]");
    }
}
Also used : Bytes(utils.Bytes) IllegalTransactionException(com.jd.blockchain.ledger.IllegalTransactionException)

Aggregations

IllegalTransactionException (com.jd.blockchain.ledger.IllegalTransactionException)5 Bytes (utils.Bytes)5 BlockchainIdentity (com.jd.blockchain.ledger.BlockchainIdentity)1 SecurityPolicy (com.jd.blockchain.ledger.SecurityPolicy)1 UserAccountSetEditor (com.jd.blockchain.ledger.core.UserAccountSetEditor)1 X509Certificate (java.security.cert.X509Certificate)1