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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
use bee_block as bee;
use inx::proto;
use crate::{maybe_missing, Raw};
#[allow(missing_docs)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct LedgerOutput {
pub output_id: bee::output::OutputId,
pub block_id: bee::BlockId,
pub milestone_index_booked: bee::payload::milestone::MilestoneIndex,
pub milestone_timestamp_booked: u32,
pub output: Raw<bee::output::Output>,
}
#[allow(missing_docs)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct LedgerSpent {
pub output: LedgerOutput,
pub transaction_id_spent: bee::payload::transaction::TransactionId,
pub milestone_index_spent: bee::payload::milestone::MilestoneIndex,
pub milestone_timestamp_spent: u32,
}
#[allow(missing_docs)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct UnspentOutput {
pub ledger_index: bee::payload::milestone::MilestoneIndex,
pub output: LedgerOutput,
}
#[allow(missing_docs)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Marker {
pub milestone_index: bee::payload::milestone::MilestoneIndex,
pub consumed_count: usize,
pub created_count: usize,
}
#[allow(missing_docs)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum LedgerUpdate {
Consumed(LedgerSpent),
Created(LedgerOutput),
Begin(Marker),
End(Marker),
}
impl From<proto::ledger_update::Marker> for Marker {
fn from(value: proto::ledger_update::Marker) -> Self {
Self {
milestone_index: value.milestone_index.into(),
consumed_count: value.consumed_count as usize,
created_count: value.created_count as usize,
}
}
}
impl From<proto::ledger_update::Marker> for LedgerUpdate {
fn from(value: proto::ledger_update::Marker) -> Self {
use proto::ledger_update::marker::MarkerType as proto;
match value.marker_type() {
proto::Begin => Self::Begin(value.into()),
proto::End => Self::End(value.into()),
}
}
}
impl TryFrom<proto::LedgerUpdate> for LedgerUpdate {
type Error = bee::InxError;
fn try_from(value: proto::LedgerUpdate) -> Result<Self, Self::Error> {
use proto::ledger_update::Op as proto;
Ok(match maybe_missing!(value.op) {
proto::BatchMarker(marker) => marker.into(),
proto::Consumed(consumed) => LedgerUpdate::Consumed(consumed.try_into()?),
proto::Created(created) => LedgerUpdate::Created(created.try_into()?),
})
}
}
impl TryFrom<proto::LedgerOutput> for LedgerOutput {
type Error = bee::InxError;
fn try_from(value: proto::LedgerOutput) -> Result<Self, Self::Error> {
Ok(Self {
output_id: maybe_missing!(value.output_id).try_into()?,
block_id: maybe_missing!(value.block_id).try_into()?,
milestone_index_booked: value.milestone_index_booked.into(),
milestone_timestamp_booked: value.milestone_timestamp_booked,
output: maybe_missing!(value.output).into(),
})
}
}
impl TryFrom<proto::LedgerSpent> for LedgerSpent {
type Error = bee::InxError;
fn try_from(value: proto::LedgerSpent) -> Result<Self, Self::Error> {
Ok(Self {
output: maybe_missing!(value.output).try_into()?,
transaction_id_spent: maybe_missing!(value.transaction_id_spent).try_into()?,
milestone_index_spent: value.milestone_index_spent.into(),
milestone_timestamp_spent: value.milestone_timestamp_spent,
})
}
}
impl TryFrom<proto::UnspentOutput> for UnspentOutput {
type Error = bee::InxError;
fn try_from(value: proto::UnspentOutput) -> Result<Self, Self::Error> {
Ok(Self {
ledger_index: value.ledger_index.into(),
output: maybe_missing!(value.output).try_into()?,
})
}
}