1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use std::collections::BTreeMap;
use codec::{Encode, Decode};
use fork_tree::ForkTree;
use sp_runtime::traits::{Block as BlockT, NumberFor};
use crate::{Epoch, EpochChanges, PersistedEpoch, PersistedEpochHeader};
#[derive(Clone, Encode, Decode)]
pub struct EpochChangesV0<Hash, Number, E: Epoch> {
inner: ForkTree<Hash, Number, PersistedEpoch<E>>,
}
pub type EpochChangesForV0<Block, Epoch> = EpochChangesV0<<Block as BlockT>::Hash, NumberFor<Block>, Epoch>;
impl<Hash, Number, E: Epoch> EpochChangesV0<Hash, Number, E> where
Hash: PartialEq + Ord + Copy,
Number: Ord + Copy,
{
pub fn from_raw(inner: ForkTree<Hash, Number, PersistedEpoch<E>>) -> Self {
Self { inner }
}
pub fn migrate(self) -> EpochChanges<Hash, Number, E> {
let mut epochs = BTreeMap::new();
let inner = self.inner.map(&mut |hash, number, data| {
let header = PersistedEpochHeader::from(&data);
epochs.insert((*hash, *number), data);
header
});
EpochChanges { inner, epochs }
}
}