Search in sources :

Example 1 with ContractAccount

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

the class ContractStateUpdateOperationHandle method doProcess.

@Override
protected void doProcess(ContractStateUpdateOperation op, LedgerTransactionContext transactionContext, TransactionRequestExtension requestContext, LedgerQuery ledger, OperationHandleContext handleContext, EventManager manager) {
    // 权限校验;
    SecurityPolicy securityPolicy = SecurityContext.getContextUsersPolicy();
    securityPolicy.checkEndpointPermission(LedgerPermission.UPDATE_CONTRACT_STATE, MultiIDsPolicy.AT_LEAST_ONE);
    ContractAccount contract = transactionContext.getDataset().getContractAccountSet().getAccount(op.getContractAddress());
    if (null == contract) {
        throw new ContractDoesNotExistException(String.format("Contract doesn't exist! --[Address=%s]", op.getContractAddress()));
    }
    // REVOKE 状态不可再恢复
    if (contract.getState() == AccountState.REVOKE) {
        throw new IllegalAccountStateException(String.format("Can not change contract in REVOKE state! --[Address=%s]", op.getContractAddress()));
    }
    // 操作账本;
    ((ContractAccountSetEditor) (transactionContext.getDataset().getContractAccountSet())).setState(op.getContractAddress(), op.getState());
}
Also used : ContractAccount(com.jd.blockchain.ledger.core.ContractAccount) ContractAccountSetEditor(com.jd.blockchain.ledger.core.ContractAccountSetEditor) SecurityPolicy(com.jd.blockchain.ledger.SecurityPolicy) IllegalAccountStateException(com.jd.blockchain.ledger.IllegalAccountStateException) ContractDoesNotExistException(com.jd.blockchain.ledger.ContractDoesNotExistException)

Aggregations

ContractDoesNotExistException (com.jd.blockchain.ledger.ContractDoesNotExistException)1 IllegalAccountStateException (com.jd.blockchain.ledger.IllegalAccountStateException)1 SecurityPolicy (com.jd.blockchain.ledger.SecurityPolicy)1 ContractAccount (com.jd.blockchain.ledger.core.ContractAccount)1 ContractAccountSetEditor (com.jd.blockchain.ledger.core.ContractAccountSetEditor)1