@@ -28,45 +28,63 @@ import (
28
28
29
29
"github.com/golang/protobuf/proto"
30
30
"github.com/hyperledger/fabric/protos/peer"
31
+ logging "github.com/op/go-logging"
31
32
)
32
33
34
+ var logger = logging .MustGetLogger ("common/configtx/test" )
35
+
33
36
const (
34
37
// AcceptAllPolicyKey is the key of the AcceptAllPolicy.
35
38
AcceptAllPolicyKey = "AcceptAllPolicy"
36
39
)
37
40
41
+ const (
42
+ OrdererTemplateName = "orderer.template"
43
+ MSPTemplateName = "msp.template"
44
+ )
45
+
38
46
var ordererTemplate configtx.Template
47
+ var mspTemplate configtx.Template
39
48
40
49
var genesisFactory genesis.Factory
41
50
42
- // XXX This is a hacky singleton, which should go away, but is an artifact of using the existing utils implementation
43
- type MSPTemplate struct {}
44
-
45
- func (msp MSPTemplate ) Items (chainID string ) ([]* cb.SignedConfigurationItem , error ) {
46
- return []* cb.SignedConfigurationItem {utils .EncodeMSP (chainID )}, nil
47
- }
48
-
49
- func init () {
50
-
51
+ func readTemplate (name string ) configtx.Template {
51
52
gopath := os .Getenv ("GOPATH" )
52
- data , err := ioutil .ReadFile (gopath + "/src/github.com/hyperledger/fabric/common/configtx/test/orderer.template" )
53
+ data , err := ioutil .ReadFile (gopath + "/src/github.com/hyperledger/fabric/common/configtx/test/" + name )
53
54
if err != nil {
54
55
peerConfig := os .Getenv ("PEER_CFG_PATH" )
55
- data , err = ioutil .ReadFile (peerConfig + "/common/configtx/test/orderer.template" )
56
+ data , err = ioutil .ReadFile (peerConfig + "/common/configtx/test/" + name )
56
57
if err != nil {
57
58
panic (err )
58
59
}
59
60
}
61
+
60
62
templateProto := & cb.ConfigurationTemplate {}
61
63
err = proto .Unmarshal (data , templateProto )
62
64
if err != nil {
63
65
panic (err )
64
66
}
65
67
66
- ordererTemplate = configtx .NewSimpleTemplate (templateProto .Items ... )
68
+ return configtx .NewSimpleTemplate (templateProto .Items ... )
69
+ }
70
+
71
+ func init () {
72
+ ordererTemplate = readTemplate (OrdererTemplateName )
73
+ mspTemplate = readTemplate (MSPTemplateName )
67
74
anchorPeers := []* peer.AnchorPeer {{Host : "fakehost" , Port : 2000 , Cert : []byte {}}}
68
75
gossTemplate := configtx .NewSimpleTemplate (peersharedconfig .TemplateAnchorPeers (anchorPeers ))
69
- genesisFactory = genesis .NewFactoryImpl (configtx .NewCompositeTemplate (MSPTemplate {}, ordererTemplate , gossTemplate ))
76
+ genesisFactory = genesis .NewFactoryImpl (configtx .NewCompositeTemplate (mspTemplate , ordererTemplate , gossTemplate ))
77
+ }
78
+
79
+ // WriteTemplate takes an output file and set of config items and writes them to that file as a marshaled ConfigurationTemplate
80
+ func WriteTemplate (outputFile string , items ... * cb.ConfigurationItem ) {
81
+ logger .Debugf ("Encoding configuration template" )
82
+ outputData := utils .MarshalOrPanic (& cb.ConfigurationTemplate {
83
+ Items : items ,
84
+ })
85
+
86
+ logger .Debugf ("Writing configuration to disk" )
87
+ ioutil .WriteFile (outputFile , outputData , 0644 )
70
88
}
71
89
72
90
func MakeGenesisBlock (chainID string ) (* cb.Block , error ) {
@@ -77,3 +95,8 @@ func MakeGenesisBlock(chainID string) (*cb.Block, error) {
77
95
func GetOrdererTemplate () configtx.Template {
78
96
return ordererTemplate
79
97
}
98
+
99
+ // GetMSPerTemplate returns the test MSP template
100
+ func GetMSPTemplate () configtx.Template {
101
+ return mspTemplate
102
+ }
0 commit comments