File tree Expand file tree Collapse file tree 10 files changed +177
-82
lines changed Expand file tree Collapse file tree 10 files changed +177
-82
lines changed Original file line number Diff line number Diff line change @@ -18,14 +18,15 @@ import (
18
18
"encoding/hex"
19
19
"fmt"
20
20
21
- utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
22
-
23
21
"github.com/blinklabs-io/gouroboros/cbor"
24
22
"github.com/blinklabs-io/gouroboros/ledger/common"
23
+
24
+ utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
25
25
)
26
26
27
27
const (
28
- EraIdAllegra = 2
28
+ EraIdAllegra = 2
29
+ EraNameAllegra = "Allegra"
29
30
30
31
BlockTypeAllegra = 3
31
32
@@ -34,6 +35,17 @@ const (
34
35
TxTypeAllegra = 2
35
36
)
36
37
38
+ var (
39
+ EraAllegra = common.Era {
40
+ Id : EraIdAllegra ,
41
+ Name : EraNameAllegra ,
42
+ }
43
+ )
44
+
45
+ func init () {
46
+ common .RegisterEra (EraAllegra )
47
+ }
48
+
37
49
type AllegraBlock struct {
38
50
cbor.StructAsArray
39
51
cbor.DecodeStoreCbor
@@ -68,7 +80,7 @@ func (b *AllegraBlock) BlockBodySize() uint64 {
68
80
}
69
81
70
82
func (b * AllegraBlock ) Era () Era {
71
- return eras [ EraIdAllegra ]
83
+ return EraAllegra
72
84
}
73
85
74
86
func (b * AllegraBlock ) Transactions () []Transaction {
@@ -110,7 +122,7 @@ type AllegraBlockHeader struct {
110
122
}
111
123
112
124
func (h * AllegraBlockHeader ) Era () Era {
113
- return eras [ EraIdAllegra ]
125
+ return EraAllegra
114
126
}
115
127
116
128
type AllegraTransactionBody struct {
Original file line number Diff line number Diff line change @@ -19,14 +19,15 @@ import (
19
19
"encoding/json"
20
20
"fmt"
21
21
22
- utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
23
-
24
22
"github.com/blinklabs-io/gouroboros/cbor"
25
23
"github.com/blinklabs-io/gouroboros/ledger/common"
24
+
25
+ utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
26
26
)
27
27
28
28
const (
29
- EraIdAlonzo = 4
29
+ EraIdAlonzo = 4
30
+ EraNameAlonzo = "Alonzo"
30
31
31
32
BlockTypeAlonzo = 5
32
33
@@ -35,6 +36,17 @@ const (
35
36
TxTypeAlonzo = 4
36
37
)
37
38
39
+ var (
40
+ EraAlonzo = common.Era {
41
+ Id : EraIdAlonzo ,
42
+ Name : EraNameAlonzo ,
43
+ }
44
+ )
45
+
46
+ func init () {
47
+ common .RegisterEra (EraAlonzo )
48
+ }
49
+
38
50
type AlonzoBlock struct {
39
51
cbor.StructAsArray
40
52
cbor.DecodeStoreCbor
@@ -70,7 +82,7 @@ func (b *AlonzoBlock) BlockBodySize() uint64 {
70
82
}
71
83
72
84
func (b * AlonzoBlock ) Era () Era {
73
- return eras [ EraIdAlonzo ]
85
+ return EraAlonzo
74
86
}
75
87
76
88
func (b * AlonzoBlock ) Transactions () []Transaction {
@@ -118,7 +130,7 @@ type AlonzoBlockHeader struct {
118
130
}
119
131
120
132
func (h * AlonzoBlockHeader ) Era () Era {
121
- return eras [ EraIdAlonzo ]
133
+ return EraAlonzo
122
134
}
123
135
124
136
type AlonzoTransactionBody struct {
Original file line number Diff line number Diff line change @@ -19,14 +19,15 @@ import (
19
19
"encoding/json"
20
20
"fmt"
21
21
22
- utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
23
-
24
22
"github.com/blinklabs-io/gouroboros/cbor"
25
23
"github.com/blinklabs-io/gouroboros/ledger/common"
24
+
25
+ utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
26
26
)
27
27
28
28
const (
29
- EraIdBabbage = 5
29
+ EraIdBabbage = 5
30
+ EraNameBabbage = "Babbage"
30
31
31
32
BlockTypeBabbage = 6
32
33
@@ -35,6 +36,17 @@ const (
35
36
TxTypeBabbage = 5
36
37
)
37
38
39
+ var (
40
+ EraBabbage = common.Era {
41
+ Id : EraIdBabbage ,
42
+ Name : EraNameBabbage ,
43
+ }
44
+ )
45
+
46
+ func init () {
47
+ common .RegisterEra (EraBabbage )
48
+ }
49
+
38
50
type BabbageBlock struct {
39
51
cbor.StructAsArray
40
52
cbor.DecodeStoreCbor
@@ -70,7 +82,7 @@ func (b *BabbageBlock) BlockBodySize() uint64 {
70
82
}
71
83
72
84
func (b * BabbageBlock ) Era () Era {
73
- return eras [ EraIdBabbage ]
85
+ return EraBabbage
74
86
}
75
87
76
88
func (b * BabbageBlock ) Transactions () []Transaction {
@@ -171,7 +183,7 @@ func (h *BabbageBlockHeader) BlockBodySize() uint64 {
171
183
}
172
184
173
185
func (h * BabbageBlockHeader ) Era () Era {
174
- return eras [ EraIdBabbage ]
186
+ return EraBabbage
175
187
}
176
188
177
189
type BabbageTransactionBody struct {
Original file line number Diff line number Diff line change @@ -18,14 +18,15 @@ import (
18
18
"encoding/hex"
19
19
"fmt"
20
20
21
- utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
22
-
23
21
"github.com/blinklabs-io/gouroboros/cbor"
24
22
"github.com/blinklabs-io/gouroboros/ledger/common"
23
+
24
+ utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
25
25
)
26
26
27
27
const (
28
- EraIdByron = 0
28
+ EraIdByron = 0
29
+ EraNameByron = "Byron"
29
30
30
31
BlockTypeByronEbb = 0
31
32
BlockTypeByronMain = 1
@@ -37,6 +38,17 @@ const (
37
38
ByronSlotsPerEpoch = 21600
38
39
)
39
40
41
+ var (
42
+ EraByron = common.Era {
43
+ Id : EraIdByron ,
44
+ Name : EraNameByron ,
45
+ }
46
+ )
47
+
48
+ func init () {
49
+ common .RegisterEra (EraByron )
50
+ }
51
+
40
52
type ByronMainBlockHeader struct {
41
53
cbor.StructAsArray
42
54
cbor.DecodeStoreCbor
@@ -119,7 +131,7 @@ func (h *ByronMainBlockHeader) BlockBodySize() uint64 {
119
131
}
120
132
121
133
func (h * ByronMainBlockHeader ) Era () Era {
122
- return eras [ EraIdByron ]
134
+ return EraByron
123
135
}
124
136
125
137
type ByronTransaction struct {
@@ -481,7 +493,7 @@ func (h *ByronEpochBoundaryBlockHeader) BlockBodySize() uint64 {
481
493
}
482
494
483
495
func (h * ByronEpochBoundaryBlockHeader ) Era () Era {
484
- return eras [ EraIdByron ]
496
+ return EraByron
485
497
}
486
498
487
499
type ByronMainBlock struct {
Original file line number Diff line number Diff line change
1
+ // Copyright 2024 Blink Labs Software
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ package common
16
+
17
+ type Era struct {
18
+ Id uint8
19
+ Name string
20
+ }
21
+
22
+ var EraInvalid = Era {
23
+ Id : 0 ,
24
+ Name : "invalid" ,
25
+ }
26
+
27
+ var eras map [uint8 ]Era
28
+
29
+ func RegisterEra (era Era ) {
30
+ if eras == nil {
31
+ eras = make (map [uint8 ]Era )
32
+ }
33
+ eras [era .Id ] = era
34
+ }
35
+
36
+ func EraById (eraId uint8 ) Era {
37
+ era , ok := eras [eraId ]
38
+ if ! ok {
39
+ return EraInvalid
40
+ }
41
+ return era
42
+ }
Original file line number Diff line number Diff line change 1
- // Copyright 2023 Blink Labs Software
1
+ // Copyright 2024 Blink Labs Software
2
2
//
3
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
4
// you may not use this file except in compliance with the License.
12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
- package ledger_test
15
+ package common_test
16
16
17
17
import (
18
- "github.com/blinklabs-io/gouroboros/ledger"
19
18
"testing"
19
+
20
+ _ "github.com/blinklabs-io/gouroboros/ledger" // This is needed to get the eras registered
21
+ "github.com/blinklabs-io/gouroboros/ledger/common"
20
22
)
21
23
22
24
type getEraByIdTestDefinition struct {
@@ -49,6 +51,10 @@ var getEraByIdTests = []getEraByIdTestDefinition{
49
51
Id : 5 ,
50
52
Name : "Babbage" ,
51
53
},
54
+ {
55
+ Id : 6 ,
56
+ Name : "Conway" ,
57
+ },
52
58
{
53
59
Id : 99 ,
54
60
Name : "invalid" ,
@@ -57,8 +63,8 @@ var getEraByIdTests = []getEraByIdTestDefinition{
57
63
58
64
func TestGetEraById (t * testing.T ) {
59
65
for _ , test := range getEraByIdTests {
60
- era := ledger . GetEraById (test .Id )
61
- if era == ledger .EraInvalid {
66
+ era := common . EraById (test .Id )
67
+ if era == common .EraInvalid {
62
68
if test .Name != "invalid" {
63
69
t .Fatalf ("got unexpected EraInvalid, wanted %s" , test .Name )
64
70
}
Original file line number Diff line number Diff line change @@ -18,14 +18,15 @@ import (
18
18
"encoding/hex"
19
19
"fmt"
20
20
21
- utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
22
-
23
21
"github.com/blinklabs-io/gouroboros/cbor"
24
22
"github.com/blinklabs-io/gouroboros/ledger/common"
23
+
24
+ utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
25
25
)
26
26
27
27
const (
28
- EraIdConway = 6
28
+ EraIdConway = 6
29
+ EraNameConway = "Conway"
29
30
30
31
BlockTypeConway = 7
31
32
@@ -34,6 +35,17 @@ const (
34
35
TxTypeConway = 6
35
36
)
36
37
38
+ var (
39
+ EraConway = common.Era {
40
+ Id : EraIdConway ,
41
+ Name : EraNameConway ,
42
+ }
43
+ )
44
+
45
+ func init () {
46
+ common .RegisterEra (EraConway )
47
+ }
48
+
37
49
type ConwayBlock struct {
38
50
cbor.StructAsArray
39
51
cbor.DecodeStoreCbor
@@ -69,7 +81,7 @@ func (b *ConwayBlock) BlockBodySize() uint64 {
69
81
}
70
82
71
83
func (b * ConwayBlock ) Era () Era {
72
- return eras [ EraIdConway ]
84
+ return EraConway
73
85
}
74
86
75
87
func (b * ConwayBlock ) Transactions () []Transaction {
@@ -117,7 +129,7 @@ type ConwayBlockHeader struct {
117
129
}
118
130
119
131
func (h * ConwayBlockHeader ) Era () Era {
120
- return eras [ EraIdConway ]
132
+ return EraConway
121
133
}
122
134
123
135
type ConwayRedeemerKey struct {
You can’t perform that action at this time.
0 commit comments