Search in sources :

Example 1 with ResourceData

use of com.radixdlt.application.tokens.state.ResourceData in project radixdlt by radixdlt.

the class BerkeleyLedgerEntryStore method executeStateUpdate.

private void executeStateUpdate(com.sleepycat.je.Transaction txn, REStateUpdate stateUpdate) {
    if (stateUpdate.isBootUp()) {
        var buf = stateUpdate.getStateBuf();
        upParticle(txn, buf, stateUpdate.getId());
        // FIXME: Superhack
        if (stateUpdate.getParsed() instanceof TokenResource) {
            var p = (TokenResource) stateUpdate.getParsed();
            var addr = p.addr();
            var buf2 = stateUpdate.getStateBuf();
            var value = new DatabaseEntry(buf2.array(), buf2.position(), buf2.remaining());
            resourceDatabase.putNoOverwrite(txn, new DatabaseEntry(addr.getBytes()), value);
        }
        // TODO: and stateful reads, move this into a separate store at some point.
        if (stateUpdate.getParsed() instanceof VirtualParent) {
            var p = (VirtualParent) stateUpdate.getParsed();
            var typeByte = p.data()[0];
            var mapKey = SystemMapKey.ofSystem(typeByte);
            insertIntoMapDatabaseOrFail(txn, mapKey, stateUpdate.getId());
        } else if (stateUpdate.getParsed() instanceof ResourceData) {
            var p = (ResourceData) stateUpdate.getParsed();
            var mapKey = SystemMapKey.ofResourceData(p.addr(), stateUpdate.typeByte());
            insertIntoMapDatabaseOrFail(txn, mapKey, stateUpdate.getId());
        } else if (stateUpdate.getParsed() instanceof ValidatorData) {
            var p = (ValidatorData) stateUpdate.getParsed();
            var mapKey = SystemMapKey.ofSystem(stateUpdate.typeByte(), p.validatorKey().getCompressedBytes());
            insertIntoMapDatabaseOrFail(txn, mapKey, stateUpdate.getId());
        } else if (stateUpdate.getParsed() instanceof SystemData) {
            var mapKey = SystemMapKey.ofSystem(stateUpdate.typeByte());
            insertIntoMapDatabaseOrFail(txn, mapKey, stateUpdate.getId());
        }
    } else if (stateUpdate.isShutDown()) {
        if (stateUpdate.getId().isVirtual()) {
            downVirtualSubstate(txn, stateUpdate.getId());
        } else {
            downSubstate(txn, stateUpdate.getId());
            if (stateUpdate.getParsed() instanceof ResourceData) {
                var p = (ResourceData) stateUpdate.getParsed();
                var mapKey = SystemMapKey.ofResourceData(p.addr(), stateUpdate.typeByte());
                deleteFromMapDatabaseOrFail(txn, mapKey);
            } else if (stateUpdate.getParsed() instanceof ValidatorData) {
                var p = (ValidatorData) stateUpdate.getParsed();
                var mapKey = SystemMapKey.ofSystem(stateUpdate.typeByte(), p.validatorKey().getCompressedBytes());
                deleteFromMapDatabaseOrFail(txn, mapKey);
            } else if (stateUpdate.getParsed() instanceof SystemData) {
                var mapKey = SystemMapKey.ofSystem(stateUpdate.typeByte());
                deleteFromMapDatabaseOrFail(txn, mapKey);
            }
        }
    } else {
        throw new IllegalStateException("Must bootup or shutdown to update particle: " + stateUpdate);
    }
}
Also used : ResourceData(com.radixdlt.application.tokens.state.ResourceData) ValidatorData(com.radixdlt.application.validators.state.ValidatorData) TokenResource(com.radixdlt.application.tokens.state.TokenResource) SystemData(com.radixdlt.application.system.state.SystemData) DatabaseEntry(com.sleepycat.je.DatabaseEntry) VirtualParent(com.radixdlt.application.system.state.VirtualParent)

Aggregations

SystemData (com.radixdlt.application.system.state.SystemData)1 VirtualParent (com.radixdlt.application.system.state.VirtualParent)1 ResourceData (com.radixdlt.application.tokens.state.ResourceData)1 TokenResource (com.radixdlt.application.tokens.state.TokenResource)1 ValidatorData (com.radixdlt.application.validators.state.ValidatorData)1 DatabaseEntry (com.sleepycat.je.DatabaseEntry)1