-
Notifications
You must be signed in to change notification settings - Fork 550
Expand file tree
/
Copy pathledger_close_meta.go
More file actions
179 lines (162 loc) · 4.65 KB
/
Copy pathledger_close_meta.go
File metadata and controls
179 lines (162 loc) · 4.65 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package xdr
import (
"fmt"
"time"
)
func (l LedgerCloseMeta) LedgerHeaderHistoryEntry() LedgerHeaderHistoryEntry {
switch l.V {
case 0:
return l.MustV0().LedgerHeader
case 1:
return l.MustV1().LedgerHeader
case 2:
return l.MustV2().LedgerHeader
default:
panic(fmt.Sprintf("Unsupported LedgerCloseMeta.V: %d", l.V))
}
}
func (l LedgerCloseMeta) LedgerSequence() uint32 {
return uint32(l.LedgerHeaderHistoryEntry().Header.LedgerSeq)
}
func (l LedgerCloseMeta) LedgerCloseTime() int64 {
return int64(l.LedgerHeaderHistoryEntry().Header.ScpValue.CloseTime)
}
func (l LedgerCloseMeta) ClosedAt() time.Time {
return time.Unix(l.LedgerCloseTime(), 0).UTC()
}
func (l LedgerCloseMeta) LedgerHash() Hash {
return l.LedgerHeaderHistoryEntry().Hash
}
func (l LedgerCloseMeta) PreviousLedgerHash() Hash {
return l.LedgerHeaderHistoryEntry().Header.PreviousLedgerHash
}
func (l LedgerCloseMeta) ProtocolVersion() uint32 {
return uint32(l.LedgerHeaderHistoryEntry().Header.LedgerVersion)
}
func (l LedgerCloseMeta) BucketListHash() Hash {
return l.LedgerHeaderHistoryEntry().Header.BucketListHash
}
func (l LedgerCloseMeta) CountTransactions() int {
switch l.V {
case 0:
return len(l.MustV0().TxProcessing)
case 1:
return len(l.MustV1().TxProcessing)
case 2:
return len(l.MustV2().TxProcessing)
default:
panic(fmt.Sprintf("Unsupported LedgerCloseMeta.V: %d", l.V))
}
}
func (l LedgerCloseMeta) TransactionEnvelopes() []TransactionEnvelope {
var phases []TransactionPhase
switch l.V {
case 0:
return l.MustV0().TxSet.Txs
case 1:
phases = l.MustV1().TxSet.V1TxSet.Phases
case 2:
phases = l.MustV2().TxSet.V1TxSet.Phases
default:
panic(fmt.Sprintf("Unsupported LedgerCloseMeta.V: %d", l.V))
}
envelopes := make([]TransactionEnvelope, 0, l.CountTransactions())
for _, phase := range phases {
switch phase.V {
case 0:
for _, component := range *phase.V0Components {
envelopes = append(envelopes, component.TxsMaybeDiscountedFee.Txs...)
}
case 1:
for _, stage := range phase.ParallelTxsComponent.ExecutionStages {
for _, cluster := range stage {
for _, envelope := range cluster {
envelopes = append(envelopes, envelope)
}
}
}
default:
panic(fmt.Sprintf("Unsupported phase type: %d", phase.V))
}
}
return envelopes
}
// TransactionHash returns Hash for tx at index i in processing order..
func (l LedgerCloseMeta) TransactionHash(i int) Hash {
switch l.V {
case 0:
return l.MustV0().TxProcessing[i].Result.TransactionHash
case 1:
return l.MustV1().TxProcessing[i].Result.TransactionHash
case 2:
return l.MustV2().TxProcessing[i].Result.TransactionHash
default:
panic(fmt.Sprintf("Unsupported LedgerCloseMeta.V: %d", l.V))
}
}
// TransactionResultPair returns TransactionResultPair for tx at index i in processing order.
func (l LedgerCloseMeta) TransactionResultPair(i int) TransactionResultPair {
switch l.V {
case 0:
return l.MustV0().TxProcessing[i].Result
case 1:
return l.MustV1().TxProcessing[i].Result
case 2:
return l.MustV2().TxProcessing[i].Result
default:
panic(fmt.Sprintf("Unsupported LedgerCloseMeta.V: %d", l.V))
}
}
// FeeProcessing returns FeeProcessing for tx at index i in processing order.
func (l LedgerCloseMeta) FeeProcessing(i int) LedgerEntryChanges {
switch l.V {
case 0:
return l.MustV0().TxProcessing[i].FeeProcessing
case 1:
return l.MustV1().TxProcessing[i].FeeProcessing
case 2:
return l.MustV2().TxProcessing[i].FeeProcessing
default:
panic(fmt.Sprintf("Unsupported LedgerCloseMeta.V: %d", l.V))
}
}
// TxApplyProcessing returns TxApplyProcessing for tx at index i in processing order.
func (l LedgerCloseMeta) TxApplyProcessing(i int) TransactionMeta {
switch l.V {
case 0:
return l.MustV0().TxProcessing[i].TxApplyProcessing
case 1:
return l.MustV1().TxProcessing[i].TxApplyProcessing
case 2:
return l.MustV2().TxProcessing[i].TxApplyProcessing
default:
panic(fmt.Sprintf("Unsupported LedgerCloseMeta.V: %d", l.V))
}
}
// UpgradesProcessing returns UpgradesProcessing for ledger.
func (l LedgerCloseMeta) UpgradesProcessing() []UpgradeEntryMeta {
switch l.V {
case 0:
return l.MustV0().UpgradesProcessing
case 1:
return l.MustV1().UpgradesProcessing
case 2:
return l.MustV2().UpgradesProcessing
default:
panic(fmt.Sprintf("Unsupported LedgerCloseMeta.V: %d", l.V))
}
}
// EvictedLedgerKeys returns a slice of ledger keys for entries that have been
// evicted in this ledger.
func (l LedgerCloseMeta) EvictedLedgerKeys() ([]LedgerKey, error) {
switch l.V {
case 0:
return nil, nil
case 1:
return l.MustV1().EvictedKeys, nil
case 2:
return l.MustV2().EvictedKeys, nil
default:
panic(fmt.Sprintf("Unsupported LedgerCloseMeta.V: %d", l.V))
}
}