/
ledger_close_meta.go
158 lines (140 loc) · 4.31 KB
/
ledger_close_meta.go
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
package xdr
import (
"fmt"
)
func (l LedgerCloseMeta) LedgerHeaderHistoryEntry() LedgerHeaderHistoryEntry {
switch l.V {
case 0:
return l.MustV0().LedgerHeader
case 1:
return l.MustV1().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) 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)
default:
panic(fmt.Sprintf("Unsupported LedgerCloseMeta.V: %d", l.V))
}
}
func (l LedgerCloseMeta) TransactionEnvelopes() []TransactionEnvelope {
switch l.V {
case 0:
return l.MustV0().TxSet.Txs
case 1:
var envelopes = make([]TransactionEnvelope, 0, l.CountTransactions())
for _, phase := range l.MustV1().TxSet.V1TxSet.Phases {
for _, component := range *phase.V0Components {
envelopes = append(envelopes, component.TxsMaybeDiscountedFee.Txs...)
}
}
return envelopes
default:
panic(fmt.Sprintf("Unsupported LedgerCloseMeta.V: %d", l.V))
}
}
// 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
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
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
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:
if l.MustV1().TxProcessing[i].TxApplyProcessing.V != 3 {
panic("TransactionResult unavailable because LedgerCloseMeta.V = 1 and TransactionMeta.V != 3")
}
return l.MustV1().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
default:
panic(fmt.Sprintf("Unsupported LedgerCloseMeta.V: %d", l.V))
}
}
// EvictedTemporaryLedgerKeys returns a slice of ledger keys for
// temporary ledger entries that have been evicted in this ledger.
func (l LedgerCloseMeta) EvictedTemporaryLedgerKeys() ([]LedgerKey, error) {
switch l.V {
case 0:
return nil, nil
case 1:
return l.MustV1().EvictedTemporaryLedgerKeys, nil
default:
panic(fmt.Sprintf("Unsupported LedgerCloseMeta.V: %d", l.V))
}
}
// EvictedPersistentLedgerEntries returns the persistent ledger entries
// which have been evicted in this ledger.
func (l LedgerCloseMeta) EvictedPersistentLedgerEntries() ([]LedgerEntry, error) {
switch l.V {
case 0:
return nil, nil
case 1:
return l.MustV1().EvictedPersistentLedgerEntries, nil
default:
panic(fmt.Sprintf("Unsupported LedgerCloseMeta.V: %d", l.V))
}
}