File tree Expand file tree Collapse file tree 8 files changed +112
-13
lines changed Expand file tree Collapse file tree 8 files changed +112
-13
lines changed Original file line number Diff line number Diff line change 14
14
15
15
package alonzo
16
16
17
+ import (
18
+ "encoding/json"
19
+ "io"
20
+ "os"
21
+ )
22
+
17
23
type AlonzoGenesis struct {
18
24
LovelacePerUtxoWord uint64 `json:"lovelacePerUTxOWord"`
19
25
MaxValueSize int
@@ -24,3 +30,22 @@ type AlonzoGenesis struct {
24
30
MaxBlockExUnits map [string ]int
25
31
CostModels map [string ]map [string ]int
26
32
}
33
+
34
+ func NewAlonzoGenesisFromReader (r io.Reader ) (AlonzoGenesis , error ) {
35
+ var ret AlonzoGenesis
36
+ dec := json .NewDecoder (r )
37
+ dec .DisallowUnknownFields ()
38
+ if err := dec .Decode (& ret ); err != nil {
39
+ return ret , err
40
+ }
41
+ return ret , nil
42
+ }
43
+
44
+ func NewAlonzoGenesisFromFile (path string ) (AlonzoGenesis , error ) {
45
+ f , err := os .Open (path )
46
+ if err != nil {
47
+ return AlonzoGenesis {}, err
48
+ }
49
+ defer f .Close ()
50
+ return NewAlonzoGenesisFromReader (f )
51
+ }
Original file line number Diff line number Diff line change 15
15
package alonzo_test
16
16
17
17
import (
18
- "encoding/json"
19
18
"reflect"
19
+ "strings"
20
20
"testing"
21
21
22
22
"github.com/blinklabs-io/gouroboros/ledger/alonzo"
@@ -411,8 +411,8 @@ var expectedGenesisObj = alonzo.AlonzoGenesis{
411
411
}
412
412
413
413
func TestGenesisFromJson (t * testing.T ) {
414
- var tmpGenesis alonzo.AlonzoGenesis
415
- if err := json . Unmarshal ([] byte ( alonzoGenesisConfig ), & tmpGenesis ); err != nil {
414
+ tmpGenesis , err := alonzo .NewAlonzoGenesisFromReader ( strings . NewReader ( alonzoGenesisConfig ))
415
+ if err != nil {
416
416
t .Fatalf ("unexpected error: %s" , err )
417
417
}
418
418
if ! reflect .DeepEqual (tmpGenesis , expectedGenesisObj ) {
Original file line number Diff line number Diff line change 14
14
15
15
package byron
16
16
17
+ import (
18
+ "encoding/json"
19
+ "io"
20
+ "os"
21
+ )
22
+
17
23
type ByronGenesis struct {
18
24
AvvmDistr map [string ]string
19
25
BlockVersionData ByronGenesisBlockVersionData
@@ -74,3 +80,22 @@ type ByronGenesisVssCert struct {
74
80
SigningKey string
75
81
VssKey string
76
82
}
83
+
84
+ func NewByronGenesisFromReader (r io.Reader ) (ByronGenesis , error ) {
85
+ var ret ByronGenesis
86
+ dec := json .NewDecoder (r )
87
+ dec .DisallowUnknownFields ()
88
+ if err := dec .Decode (& ret ); err != nil {
89
+ return ret , err
90
+ }
91
+ return ret , nil
92
+ }
93
+
94
+ func NewByronGenesisFromFile (path string ) (ByronGenesis , error ) {
95
+ f , err := os .Open (path )
96
+ if err != nil {
97
+ return ByronGenesis {}, err
98
+ }
99
+ defer f .Close ()
100
+ return NewByronGenesisFromReader (f )
101
+ }
Original file line number Diff line number Diff line change 15
15
package byron_test
16
16
17
17
import (
18
- "encoding/json"
19
18
"reflect"
19
+ "strings"
20
20
"testing"
21
21
22
22
"github.com/blinklabs-io/gouroboros/ledger/byron"
@@ -236,8 +236,8 @@ var expectedGenesisObj = byron.ByronGenesis{
236
236
}
237
237
238
238
func TestGenesisFromJson (t * testing.T ) {
239
- var tmpGenesis byron.ByronGenesis
240
- if err := json . Unmarshal ([] byte ( byronGenesisConfig ), & tmpGenesis ); err != nil {
239
+ tmpGenesis , err := byron .NewByronGenesisFromReader ( strings . NewReader ( byronGenesisConfig ))
240
+ if err != nil {
241
241
t .Fatalf ("unexpected error: %s" , err )
242
242
}
243
243
if ! reflect .DeepEqual (tmpGenesis , expectedGenesisObj ) {
Original file line number Diff line number Diff line change 14
14
15
15
package conway
16
16
17
+ import (
18
+ "encoding/json"
19
+ "io"
20
+ "os"
21
+ )
22
+
17
23
type ConwayGenesis struct {
18
24
PoolVotingThresholds ConwayGenesisPoolVotingThresholds
19
25
DRepVotingThresholds ConwayGenesisDRepVotingThresholds
@@ -64,3 +70,22 @@ type ConwayGenesisCommittee struct {
64
70
Members map [string ]int
65
71
Threshold map [string ]int
66
72
}
73
+
74
+ func NewConwayGenesisFromReader (r io.Reader ) (ConwayGenesis , error ) {
75
+ var ret ConwayGenesis
76
+ dec := json .NewDecoder (r )
77
+ dec .DisallowUnknownFields ()
78
+ if err := dec .Decode (& ret ); err != nil {
79
+ return ret , err
80
+ }
81
+ return ret , nil
82
+ }
83
+
84
+ func NewConwayGenesisFromFile (path string ) (ConwayGenesis , error ) {
85
+ f , err := os .Open (path )
86
+ if err != nil {
87
+ return ConwayGenesis {}, err
88
+ }
89
+ defer f .Close ()
90
+ return NewConwayGenesisFromReader (f )
91
+ }
Original file line number Diff line number Diff line change 15
15
package conway_test
16
16
17
17
import (
18
- "encoding/json"
19
18
"reflect"
19
+ "strings"
20
20
"testing"
21
21
22
22
"github.com/blinklabs-io/gouroboros/ledger/conway"
@@ -383,8 +383,8 @@ var expectedGenesisObj = conway.ConwayGenesis{
383
383
}
384
384
385
385
func TestGenesisFromJson (t * testing.T ) {
386
- var tmpGenesis conway.ConwayGenesis
387
- if err := json . Unmarshal ([] byte ( conwayGenesisConfig ), & tmpGenesis ); err != nil {
386
+ tmpGenesis , err := conway .NewConwayGenesisFromReader ( strings . NewReader ( conwayGenesisConfig ))
387
+ if err != nil {
388
388
t .Fatalf ("unexpected error: %s" , err )
389
389
}
390
390
if ! reflect .DeepEqual (tmpGenesis , expectedGenesisObj ) {
Original file line number Diff line number Diff line change 14
14
15
15
package shelley
16
16
17
- import "time"
17
+ import (
18
+ "encoding/json"
19
+ "io"
20
+ "os"
21
+ "time"
22
+ )
18
23
19
24
type ShelleyGenesis struct {
20
25
SystemStart time.Time `json:"systemStart"`
@@ -56,3 +61,22 @@ type ShelleyGenesisProtocolParams struct {
56
61
MinUtxoValue uint `json:"minUTxOValue"`
57
62
MinPoolCost uint
58
63
}
64
+
65
+ func NewShelleyGenesisFromReader (r io.Reader ) (ShelleyGenesis , error ) {
66
+ var ret ShelleyGenesis
67
+ dec := json .NewDecoder (r )
68
+ dec .DisallowUnknownFields ()
69
+ if err := dec .Decode (& ret ); err != nil {
70
+ return ret , err
71
+ }
72
+ return ret , nil
73
+ }
74
+
75
+ func NewShelleyGenesisFromFile (path string ) (ShelleyGenesis , error ) {
76
+ f , err := os .Open (path )
77
+ if err != nil {
78
+ return ShelleyGenesis {}, err
79
+ }
80
+ defer f .Close ()
81
+ return NewShelleyGenesisFromReader (f )
82
+ }
Original file line number Diff line number Diff line change 15
15
package shelley_test
16
16
17
17
import (
18
- "encoding/json"
19
18
"reflect"
19
+ "strings"
20
20
"testing"
21
21
"time"
22
22
@@ -167,8 +167,8 @@ var expectedGenesisObj = shelley.ShelleyGenesis{
167
167
}
168
168
169
169
func TestGenesisFromJson (t * testing.T ) {
170
- var tmpGenesis shelley.ShelleyGenesis
171
- if err := json . Unmarshal ([] byte ( shelleyGenesisConfig ), & tmpGenesis ); err != nil {
170
+ tmpGenesis , err := shelley .NewShelleyGenesisFromReader ( strings . NewReader ( shelleyGenesisConfig ))
171
+ if err != nil {
172
172
t .Fatalf ("unexpected error: %s" , err )
173
173
}
174
174
if ! reflect .DeepEqual (tmpGenesis , expectedGenesisObj ) {
You can’t perform that action at this time.
0 commit comments