Search in sources :

Example 6 with RadixEngineException

use of com.radixdlt.engine.RadixEngineException in project radixdlt by radixdlt.

the class WithdrawVoteHandler method handleRequest.

@Override
public UpdateVoteResponse handleRequest(UpdateVoteRequest request) throws CoreApiException {
    coreModelMapper.verifyNetwork(request.getNetworkIdentifier());
    final Txn signedTx;
    try {
        signedTx = radixEngine.constructWithFees(this::buildWithdrawVote, false, REAddr.ofPubKeyAccount(validatorKey), NotEnoughNativeTokensForFeesException::new).signAndBuild(hashSigner::sign);
    } catch (TxBuilderException e) {
        throw CoreApiException.badRequest(coreModelMapper.builderErrorDetails(e));
    }
    try {
        radixEngineStateComputer.addToMempool(signedTx);
        return new UpdateVoteResponse().transactionIdentifier(coreModelMapper.transactionIdentifier(signedTx.getId())).duplicate(false);
    } catch (MempoolDuplicateException e) {
        return new UpdateVoteResponse().transactionIdentifier(coreModelMapper.transactionIdentifier(signedTx.getId())).duplicate(true);
    } catch (MempoolFullException e) {
        throw coreModelMapper.mempoolFullException(e);
    } catch (MempoolRejectedException e) {
        throw coreModelMapper.radixEngineException((RadixEngineException) e.getCause());
    }
}
Also used : MempoolDuplicateException(com.radixdlt.mempool.MempoolDuplicateException) NotEnoughNativeTokensForFeesException(com.radixdlt.api.core.model.NotEnoughNativeTokensForFeesException) MempoolRejectedException(com.radixdlt.mempool.MempoolRejectedException) MempoolFullException(com.radixdlt.mempool.MempoolFullException) RadixEngineException(com.radixdlt.engine.RadixEngineException) Txn(com.radixdlt.atom.Txn) UpdateVoteResponse(com.radixdlt.api.core.openapitools.model.UpdateVoteResponse) TxBuilderException(com.radixdlt.atom.TxBuilderException)

Example 7 with RadixEngineException

use of com.radixdlt.engine.RadixEngineException in project radixdlt by radixdlt.

the class ConstructionParseHandler method handleRequest.

@Override
public ConstructionParseResponse handleRequest(ConstructionParseRequest request) throws CoreApiException {
    modelMapper.verifyNetwork(request.getNetworkIdentifier());
    var txn = modelMapper.bytes(request.getTransaction());
    REProcessedTxn processed;
    try {
        processed = radixEngineStateComputer.test(txn, request.getSigned());
    } catch (RadixEngineException e) {
        throw modelMapper.radixEngineException(e);
    }
    var response = new ConstructionParseResponse();
    var transaction = modelMapper.transaction(processed, this::symbol);
    transaction.getOperationGroups().forEach(response::addOperationGroupsItem);
    response.metadata(new ParsedTransactionMetadata().fee(transaction.getMetadata().getFee()).message(transaction.getMetadata().getMessage()));
    return response;
}
Also used : ConstructionParseResponse(com.radixdlt.api.core.openapitools.model.ConstructionParseResponse) ParsedTransactionMetadata(com.radixdlt.api.core.openapitools.model.ParsedTransactionMetadata) RadixEngineException(com.radixdlt.engine.RadixEngineException) REProcessedTxn(com.radixdlt.constraintmachine.REProcessedTxn)

Example 8 with RadixEngineException

use of com.radixdlt.engine.RadixEngineException in project radixdlt by radixdlt.

the class BerkeleyLedgerEntryStore method transaction.

@Override
public <R> R transaction(TransactionEngineStoreConsumer<LedgerAndBFTProof, R> consumer) throws RadixEngineException {
    var dbTxn = createTransaction();
    try {
        var result = consumer.start(new EngineStoreInTransaction<>() {

            @Override
            public void storeTxn(REProcessedTxn txn) {
                BerkeleyLedgerEntryStore.this.storeTxn(dbTxn, txn);
            }

            @Override
            public void storeMetadata(LedgerAndBFTProof metadata) {
                BerkeleyLedgerEntryStore.this.storeMetadata(dbTxn, metadata);
            }

            @Override
            public ByteBuffer verifyVirtualSubstate(SubstateId substateId) throws VirtualSubstateAlreadyDownException, VirtualParentStateDoesNotExist {
                var parent = substateId.getVirtualParent().orElseThrow();
                var parentState = BerkeleyLedgerEntryStore.this.loadSubstate(dbTxn, parent);
                if (parentState.isEmpty()) {
                    throw new VirtualParentStateDoesNotExist(parent);
                }
                var buf = parentState.get();
                if (buf.get() != SubstateTypeId.VIRTUAL_PARENT.id()) {
                    throw new VirtualParentStateDoesNotExist(parent);
                }
                buf.position(buf.position() - 1);
                if (BerkeleyLedgerEntryStore.this.isVirtualDown(dbTxn, substateId)) {
                    throw new VirtualSubstateAlreadyDownException(substateId);
                }
                return buf;
            }

            @Override
            public Optional<ByteBuffer> loadSubstate(SubstateId substateId) {
                return BerkeleyLedgerEntryStore.this.loadSubstate(dbTxn, substateId);
            }

            @Override
            public CloseableCursor<RawSubstateBytes> openIndexedCursor(SubstateIndex<?> index) {
                return BerkeleyLedgerEntryStore.this.openIndexedCursor(dbTxn, index);
            }

            @Override
            public Optional<ByteBuffer> loadResource(REAddr addr) {
                return BerkeleyLedgerEntryStore.this.loadAddr(dbTxn, addr);
            }
        });
        dbTxn.commit();
        return result;
    } catch (Exception e) {
        dbTxn.abort();
        throw e;
    }
}
Also used : CloseableCursor(com.radixdlt.atom.CloseableCursor) Optional(java.util.Optional) LedgerAndBFTProof(com.radixdlt.statecomputer.LedgerAndBFTProof) REProcessedTxn(com.radixdlt.constraintmachine.REProcessedTxn) ByteBuffer(java.nio.ByteBuffer) RadixEngineException(com.radixdlt.engine.RadixEngineException) VirtualSubstateAlreadyDownException(com.radixdlt.constraintmachine.exceptions.VirtualSubstateAlreadyDownException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) DeserializeException(com.radixdlt.serialization.DeserializeException) VirtualParentStateDoesNotExist(com.radixdlt.constraintmachine.exceptions.VirtualParentStateDoesNotExist) SubstateId(com.radixdlt.atom.SubstateId) VirtualSubstateAlreadyDownException(com.radixdlt.constraintmachine.exceptions.VirtualSubstateAlreadyDownException) REAddr(com.radixdlt.identifiers.REAddr)

Aggregations

RadixEngineException (com.radixdlt.engine.RadixEngineException)8 Inject (com.google.inject.Inject)3 RadixEngine (com.radixdlt.engine.RadixEngine)3 List (java.util.List)3 ImmutableList (com.google.common.collect.ImmutableList)2 HashCode (com.google.common.hash.HashCode)2 AbstractModule (com.google.inject.AbstractModule)2 Guice (com.google.inject.Guice)2 Module (com.google.inject.Module)2 TypeLiteral (com.google.inject.TypeLiteral)2 DefaultSerialization (com.radixdlt.DefaultSerialization)2 NotEnoughNativeTokensForFeesException (com.radixdlt.api.core.model.NotEnoughNativeTokensForFeesException)2 UpdateVoteResponse (com.radixdlt.api.core.openapitools.model.UpdateVoteResponse)2 RoundData (com.radixdlt.application.system.state.RoundData)2 Amount (com.radixdlt.application.tokens.Amount)2 com.radixdlt.atom (com.radixdlt.atom)2 TxAction (com.radixdlt.atom.TxAction)2 TxBuilderException (com.radixdlt.atom.TxBuilderException)2 Txn (com.radixdlt.atom.Txn)2 PermissionLevel (com.radixdlt.constraintmachine.PermissionLevel)2