Search in sources :

Example 1 with BiMapper

use of net.sergeych.biserializer.BiMapper in project universa by UniversaBlockchain.

the class ContractDelta method check.

// todo: need to test this synchronized attribute, should not affects overall node's concurrency
public synchronized void check() throws Quantiser.QuantiserException {
    try {
        BiMapper mapper = BossBiMapper.getInstance();
        MapDelta rootDelta = Delta.between(mapper.serialize(existing), mapper.serialize(changed));
        MapDelta definitionDelta = (MapDelta) rootDelta.getChange("definition");
        stateDelta = (MapDelta) rootDelta.getChange("state");
        if (definitionDelta != null) {
            addError(ILLEGAL_CHANGE, "definition", "definition must not be changed");
        }
        // check immutable root area
        // should be only one change here: state
        int allowedRootChanges = 1;
        Delta ch = rootDelta.getChange("api_level");
        if (ch != null) {
            allowedRootChanges++;
        }
        // or can be changed section "transactional"
        Delta transactionalDelta = rootDelta.getChange("transactional");
        if (transactionalDelta != null) {
            allowedRootChanges++;
        }
        if (rootDelta.getChanges().size() > allowedRootChanges)
            addError(ILLEGAL_CHANGE, "root", "root level changes are forbidden except the state");
        // check only permitted changes in data
        checkStateChange();
    } catch (ClassCastException e) {
        e.printStackTrace();
        addError(FAILED_CHECK, "", "failed to compare, structure is broken or not supported");
    }
}
Also used : BossBiMapper(net.sergeych.biserializer.BossBiMapper) BiMapper(net.sergeych.biserializer.BiMapper) Delta(net.sergeych.diff.Delta) MapDelta(net.sergeych.diff.MapDelta) MapDelta(net.sergeych.diff.MapDelta)

Aggregations

BiMapper (net.sergeych.biserializer.BiMapper)1 BossBiMapper (net.sergeych.biserializer.BossBiMapper)1 Delta (net.sergeych.diff.Delta)1 MapDelta (net.sergeych.diff.MapDelta)1