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());
}
}
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;
}
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;
}
}
Aggregations