@@ -48,59 +48,70 @@ var peerTemplate configtx.Template
48
48
49
49
var genesisFactory genesis.Factory
50
50
51
- func readTemplate (name string ) configtx.Template {
52
- gopath := os .Getenv ("GOPATH" )
53
- data , err := ioutil .ReadFile (gopath + "/src/github.com/hyperledger/fabric/common/configtx/test/" + name )
51
+ func init () {
52
+ ordererTemplate = readTemplate (OrdererTemplateName )
53
+ mspTemplate = readTemplate (MSPTemplateName )
54
+ peerTemplate = readTemplate (PeerTemplateName )
55
+ genesisFactory = genesis .NewFactoryImpl (configtx .NewCompositeTemplate (mspTemplate , ordererTemplate , peerTemplate ))
56
+ }
57
+
58
+ func resolveName (name string ) (string , []byte ) {
59
+ path := os .Getenv ("GOPATH" ) + "/src/github.com/hyperledger/fabric/common/configtx/test/" + name
60
+ data , err := ioutil .ReadFile (path )
61
+ if err == nil {
62
+ return path , data
63
+ }
64
+
65
+ path = os .Getenv ("PEER_CFG_PATH" ) + "/common/configtx/test/" + name
66
+ data , err = ioutil .ReadFile (path )
54
67
if err != nil {
55
- peerConfig := os .Getenv ("PEER_CFG_PATH" )
56
- data , err = ioutil .ReadFile (peerConfig + "/common/configtx/test/" + name )
57
- if err != nil {
58
- panic (err )
59
- }
68
+ panic (err )
60
69
}
61
70
71
+ return path , data
72
+ }
73
+
74
+ func readTemplate (name string ) configtx.Template {
75
+ _ , data := resolveName (name )
76
+
62
77
templateProto := & cb.ConfigurationTemplate {}
63
- err = proto .Unmarshal (data , templateProto )
78
+ err : = proto .Unmarshal (data , templateProto )
64
79
if err != nil {
65
80
panic (err )
66
81
}
67
82
68
83
return configtx .NewSimpleTemplate (templateProto .Items ... )
69
84
}
70
85
71
- func init () {
72
- ordererTemplate = readTemplate (OrdererTemplateName )
73
- mspTemplate = readTemplate (MSPTemplateName )
74
- peerTemplate = readTemplate (PeerTemplateName )
75
- genesisFactory = genesis .NewFactoryImpl (configtx .NewCompositeTemplate (mspTemplate , ordererTemplate , peerTemplate ))
76
- }
77
-
78
86
// WriteTemplate takes an output file and set of config items and writes them to that file as a marshaled ConfigurationTemplate
79
- func WriteTemplate (outputFile string , items ... * cb.ConfigurationItem ) {
87
+ func WriteTemplate (name string , items ... * cb.ConfigurationItem ) {
88
+ path , _ := resolveName (name )
89
+
80
90
logger .Debugf ("Encoding configuration template" )
81
91
outputData := utils .MarshalOrPanic (& cb.ConfigurationTemplate {
82
92
Items : items ,
83
93
})
84
94
85
- logger .Debugf ("Writing configuration to disk" )
86
- ioutil .WriteFile (outputFile , outputData , 0644 )
95
+ logger .Debugf ("Writing configuration to %s" , path )
96
+ ioutil .WriteFile (path , outputData , 0644 )
87
97
}
88
98
99
+ // MakeGenesisBlock creates a genesis block using the test templates for the given chainID
89
100
func MakeGenesisBlock (chainID string ) (* cb.Block , error ) {
90
101
return genesisFactory .Block (chainID )
91
102
}
92
103
93
- // GetOrderererTemplate returns the test orderer template
94
- func GetOrdererTemplate () configtx.Template {
104
+ // OrderererTemplate returns the test orderer template
105
+ func OrdererTemplate () configtx.Template {
95
106
return ordererTemplate
96
107
}
97
108
98
- // GetMSPerTemplate returns the test MSP template
99
- func GetMSPTemplate () configtx.Template {
109
+ // MSPerTemplate returns the test MSP template
110
+ func MSPTemplate () configtx.Template {
100
111
return mspTemplate
101
112
}
102
113
103
- // GetMSPerTemplate returns the test peer template
104
- func GetPeerTemplate () configtx.Template {
114
+ // MSPerTemplate returns the test peer template
115
+ func PeerTemplate () configtx.Template {
105
116
return peerTemplate
106
117
}
0 commit comments