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
58
59
60
61
62
63
64
65
use std::{iter::IntoIterator, vec::IntoIter};
use casper_types::{
ExecutionEffect as JsonExecutionEffect, Key, TransformEntry as JsonTransformEntry,
};
use crate::shared::transform::Transform;
#[derive(Debug, Default, Clone, Eq, PartialEq)]
pub struct ExecutionJournal(Vec<(Key, Transform)>);
impl ExecutionJournal {
pub fn new(inner: Vec<(Key, Transform)>) -> Self {
ExecutionJournal(inner)
}
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
pub fn len(&self) -> usize {
self.0.len()
}
pub fn push(&mut self, entry: (Key, Transform)) {
self.0.push(entry)
}
}
impl From<&ExecutionJournal> for JsonExecutionEffect {
fn from(execution_journal: &ExecutionJournal) -> Self {
Self::new(
execution_journal
.0
.iter()
.map(|(key, transform)| JsonTransformEntry {
key: key.to_formatted_string(),
transform: transform.into(),
})
.collect(),
)
}
}
impl IntoIterator for ExecutionJournal {
type Item = (Key, Transform);
type IntoIter = IntoIter<Self::Item>;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}
impl Extend<(Key, Transform)> for ExecutionJournal {
fn extend<I: IntoIterator<Item = (Key, Transform)>>(&mut self, iter: I) {
self.0.extend(iter)
}
}