exoticPruned function
Returns a ExoticPruned representation of a passed Cell of bits and refs
Implementation
ExoticPruned exoticPruned(BitString bits, List<Cell> refs) {
var reader = BitReader(bits);
var type = reader.loadUint(8);
if (type != 1) {
throw 'Pruned Branch cell must have type 1, got $type';
}
if (refs.isNotEmpty) {
throw 'Pruned Branch cell can not have refs, got ${refs.length}';
}
LevelMask mask;
if (bits.length == 280) {
// Special case for config proof - this test proof is generated in the moment of voting for a slashing.
// It seems that tools generate it incorrectly and therefore doesn't have mask in it, so we need to hardcode it equal to 1
mask = LevelMask(1);
} else {
mask = LevelMask(reader.loadUint(8));
if (mask.level < 1 || mask.level > 3) {
throw 'Pruned Branch cell level must be >= 1 and <= 3, got ${mask.level}/${mask.value}';
}
// 256 Hash + 16 Depth
final size = 8 + 8 + (mask.apply(mask.level - 1).hashCount * (256 + 16));
if (bits.length != size) {
throw 'Pruned Branch cell must have exactly $size bits, got ${bits.length}';
}
}
var pruned = <PrunedCell>[];
var hashes = <Uint8List>[];
var depths = <int>[];
for (var i = 0; i < mask.level; i += 1) {
hashes.add(reader.loadList(32));
}
for (var i = 0; i < mask.level; i += 1) {
depths.add(reader.loadUint(16));
}
for (var i = 0; i < mask.level; i += 1) {
pruned.add(PrunedCell(
depth: depths[i],
hash: hashes[i],
));
}
return ExoticPruned(
mask: mask.value,
pruned: pruned,
);
}