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