Skip to content

Commit afd2687

Browse files
authored
chore: move each ledger era to separate sub-package (#694)
1 parent 30bba11 commit afd2687

File tree

14 files changed

+606
-399
lines changed

14 files changed

+606
-399
lines changed

ledger/allegra.go renamed to ledger/allegra/allegra.go

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 Blink Labs Software
1+
// Copyright 2024 Blink Labs Software
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -12,14 +12,15 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package ledger
15+
package allegra
1616

1717
import (
1818
"encoding/hex"
1919
"fmt"
2020

2121
"github.com/blinklabs-io/gouroboros/cbor"
2222
"github.com/blinklabs-io/gouroboros/ledger/common"
23+
"github.com/blinklabs-io/gouroboros/ledger/shelley"
2324

2425
utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
2526
)
@@ -51,7 +52,7 @@ type AllegraBlock struct {
5152
cbor.DecodeStoreCbor
5253
Header *AllegraBlockHeader
5354
TransactionBodies []AllegraTransactionBody
54-
TransactionWitnessSets []ShelleyTransactionWitnessSet
55+
TransactionWitnessSets []shelley.ShelleyTransactionWitnessSet
5556
TransactionMetadataSet map[uint]*cbor.LazyValue
5657
}
5758

@@ -71,20 +72,20 @@ func (b *AllegraBlock) SlotNumber() uint64 {
7172
return b.Header.SlotNumber()
7273
}
7374

74-
func (b *AllegraBlock) IssuerVkey() IssuerVkey {
75+
func (b *AllegraBlock) IssuerVkey() common.IssuerVkey {
7576
return b.Header.IssuerVkey()
7677
}
7778

7879
func (b *AllegraBlock) BlockBodySize() uint64 {
7980
return b.Header.BlockBodySize()
8081
}
8182

82-
func (b *AllegraBlock) Era() Era {
83+
func (b *AllegraBlock) Era() common.Era {
8384
return EraAllegra
8485
}
8586

86-
func (b *AllegraBlock) Transactions() []Transaction {
87-
ret := make([]Transaction, len(b.TransactionBodies))
87+
func (b *AllegraBlock) Transactions() []common.Transaction {
88+
ret := make([]common.Transaction, len(b.TransactionBodies))
8889
for idx := range b.TransactionBodies {
8990
ret[idx] = &AllegraTransaction{
9091
Body: b.TransactionBodies[idx],
@@ -118,18 +119,18 @@ func (b *AllegraBlock) Utxorpc() *utxorpc.Block {
118119
}
119120

120121
type AllegraBlockHeader struct {
121-
ShelleyBlockHeader
122+
shelley.ShelleyBlockHeader
122123
}
123124

124-
func (h *AllegraBlockHeader) Era() Era {
125+
func (h *AllegraBlockHeader) Era() common.Era {
125126
return EraAllegra
126127
}
127128

128129
type AllegraTransactionBody struct {
129-
ShelleyTransactionBody
130+
shelley.ShelleyTransactionBody
130131
Update struct {
131132
cbor.StructAsArray
132-
ProtocolParamUpdates map[Blake2b224]AllegraProtocolParameterUpdate
133+
ProtocolParamUpdates map[common.Blake2b224]AllegraProtocolParameterUpdate
133134
Epoch uint64
134135
} `cbor:"6,keyasint,omitempty"`
135136
TxValidityIntervalStart uint64 `cbor:"8,keyasint,omitempty"`
@@ -143,8 +144,8 @@ func (b *AllegraTransactionBody) ValidityIntervalStart() uint64 {
143144
return b.TxValidityIntervalStart
144145
}
145146

146-
func (b *AllegraTransactionBody) ProtocolParametersUpdate() map[Blake2b224]any {
147-
updateMap := make(map[Blake2b224]any)
147+
func (b *AllegraTransactionBody) ProtocolParametersUpdate() map[common.Blake2b224]any {
148+
updateMap := make(map[common.Blake2b224]any)
148149
for k, v := range b.Update.ProtocolParamUpdates {
149150
updateMap[k] = v
150151
}
@@ -155,19 +156,19 @@ type AllegraTransaction struct {
155156
cbor.StructAsArray
156157
cbor.DecodeStoreCbor
157158
Body AllegraTransactionBody
158-
WitnessSet ShelleyTransactionWitnessSet
159+
WitnessSet shelley.ShelleyTransactionWitnessSet
159160
TxMetadata *cbor.LazyValue
160161
}
161162

162163
func (t AllegraTransaction) Hash() string {
163164
return t.Body.Hash()
164165
}
165166

166-
func (t AllegraTransaction) Inputs() []TransactionInput {
167+
func (t AllegraTransaction) Inputs() []common.TransactionInput {
167168
return t.Body.Inputs()
168169
}
169170

170-
func (t AllegraTransaction) Outputs() []TransactionOutput {
171+
func (t AllegraTransaction) Outputs() []common.TransactionOutput {
171172
return t.Body.Outputs()
172173
}
173174

@@ -183,51 +184,51 @@ func (t AllegraTransaction) ValidityIntervalStart() uint64 {
183184
return t.Body.ValidityIntervalStart()
184185
}
185186

186-
func (t AllegraTransaction) ReferenceInputs() []TransactionInput {
187+
func (t AllegraTransaction) ReferenceInputs() []common.TransactionInput {
187188
return t.Body.ReferenceInputs()
188189
}
189190

190-
func (t AllegraTransaction) Collateral() []TransactionInput {
191+
func (t AllegraTransaction) Collateral() []common.TransactionInput {
191192
return t.Body.Collateral()
192193
}
193194

194-
func (t AllegraTransaction) CollateralReturn() TransactionOutput {
195+
func (t AllegraTransaction) CollateralReturn() common.TransactionOutput {
195196
return t.Body.CollateralReturn()
196197
}
197198

198199
func (t AllegraTransaction) TotalCollateral() uint64 {
199200
return t.Body.TotalCollateral()
200201
}
201202

202-
func (t AllegraTransaction) Certificates() []Certificate {
203+
func (t AllegraTransaction) Certificates() []common.Certificate {
203204
return t.Body.Certificates()
204205
}
205206

206-
func (t AllegraTransaction) Withdrawals() map[*Address]uint64 {
207+
func (t AllegraTransaction) Withdrawals() map[*common.Address]uint64 {
207208
return t.Body.Withdrawals()
208209
}
209210

210-
func (t AllegraTransaction) AuxDataHash() *Blake2b256 {
211+
func (t AllegraTransaction) AuxDataHash() *common.Blake2b256 {
211212
return t.Body.AuxDataHash()
212213
}
213214

214-
func (t AllegraTransaction) RequiredSigners() []Blake2b224 {
215+
func (t AllegraTransaction) RequiredSigners() []common.Blake2b224 {
215216
return t.Body.RequiredSigners()
216217
}
217218

218219
func (t AllegraTransaction) AssetMint() *common.MultiAsset[common.MultiAssetTypeMint] {
219220
return t.Body.AssetMint()
220221
}
221222

222-
func (t AllegraTransaction) ScriptDataHash() *Blake2b256 {
223+
func (t AllegraTransaction) ScriptDataHash() *common.Blake2b256 {
223224
return t.Body.ScriptDataHash()
224225
}
225226

226-
func (t AllegraTransaction) VotingProcedures() VotingProcedures {
227+
func (t AllegraTransaction) VotingProcedures() common.VotingProcedures {
227228
return t.Body.VotingProcedures()
228229
}
229230

230-
func (t AllegraTransaction) ProposalProcedures() []ProposalProcedure {
231+
func (t AllegraTransaction) ProposalProcedures() []common.ProposalProcedure {
231232
return t.Body.ProposalProcedures()
232233
}
233234

@@ -251,25 +252,25 @@ func (t AllegraTransaction) IsValid() bool {
251252
return true
252253
}
253254

254-
func (t AllegraTransaction) Consumed() []TransactionInput {
255+
func (t AllegraTransaction) Consumed() []common.TransactionInput {
255256
return t.Inputs()
256257
}
257258

258-
func (t AllegraTransaction) Produced() []Utxo {
259-
var ret []Utxo
259+
func (t AllegraTransaction) Produced() []common.Utxo {
260+
var ret []common.Utxo
260261
for idx, output := range t.Outputs() {
261262
ret = append(
262263
ret,
263-
Utxo{
264-
Id: NewShelleyTransactionInput(t.Hash(), idx),
264+
common.Utxo{
265+
Id: shelley.NewShelleyTransactionInput(t.Hash(), idx),
265266
Output: output,
266267
},
267268
)
268269
}
269270
return ret
270271
}
271272

272-
func (t AllegraTransaction) ProtocolParametersUpdate() map[Blake2b224]any {
273+
func (t AllegraTransaction) ProtocolParametersUpdate() map[common.Blake2b224]any {
273274
return t.Body.ProtocolParametersUpdate()
274275
}
275276

@@ -300,11 +301,11 @@ func (t *AllegraTransaction) Cbor() []byte {
300301
}
301302

302303
type AllegraProtocolParameters struct {
303-
ShelleyProtocolParameters
304+
shelley.ShelleyProtocolParameters
304305
}
305306

306307
type AllegraProtocolParameterUpdate struct {
307-
ShelleyProtocolParameterUpdate
308+
shelley.ShelleyProtocolParameterUpdate
308309
}
309310

310311
func NewAllegraBlockFromCbor(data []byte) (*AllegraBlock, error) {

0 commit comments

Comments
 (0)