use of com.radixdlt.constraintmachine.REProcessedTxn 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