@@ -89,15 +89,17 @@ func (ct *compositeTemplate) Items(chainID string) ([]*cb.SignedConfigurationIte
89
89
90
90
type newChainTemplate struct {
91
91
creationPolicy string
92
+ hash func ([]byte ) []byte
92
93
template Template
93
94
}
94
95
95
96
// NewChainCreationTemplate takes a CreationPolicy and a Template to produce a Template which outputs an appropriately
96
97
// constructed list of SignedConfigurationItem including an appropriate digest. Note, using this Template in
97
98
// a CompositeTemplate will invalidate the CreationPolicy
98
- func NewChainCreationTemplate (creationPolicy string , template Template ) Template {
99
+ func NewChainCreationTemplate (creationPolicy string , hash func ([] byte ) [] byte , template Template ) Template {
99
100
return & newChainTemplate {
100
101
creationPolicy : creationPolicy ,
102
+ hash : hash ,
101
103
template : template ,
102
104
}
103
105
}
@@ -116,7 +118,7 @@ func (nct *newChainTemplate) Items(chainID string) ([]*cb.SignedConfigurationIte
116
118
Key : CreationPolicyKey ,
117
119
Value : utils .MarshalOrPanic (& ab.CreationPolicy {
118
120
Policy : nct .creationPolicy ,
119
- Digest : HashItems (items ),
121
+ Digest : HashItems (items , nct . hash ),
120
122
}),
121
123
}),
122
124
}
@@ -126,12 +128,12 @@ func (nct *newChainTemplate) Items(chainID string) ([]*cb.SignedConfigurationIte
126
128
127
129
// HashItems is a utility method for computing the hash of the concatenation of the marshaled ConfigurationItems
128
130
// in a []*cb.SignedConfigurationItem
129
- func HashItems (items []* cb.SignedConfigurationItem ) []byte {
131
+ func HashItems (items []* cb.SignedConfigurationItem , hash func ([] byte ) [] byte ) []byte {
130
132
sourceBytes := make ([][]byte , len (items ))
131
133
for i := range items {
132
134
sourceBytes [i ] = items [i ].ConfigurationItem
133
135
}
134
- return util . ComputeCryptoHash (util .ConcatenateBytes (sourceBytes ... ))
136
+ return hash (util .ConcatenateBytes (sourceBytes ... ))
135
137
}
136
138
137
139
// join takes a number of SignedConfigurationItem slices and produces a single item
@@ -154,7 +156,15 @@ func join(sets ...[]*cb.SignedConfigurationItem) []*cb.SignedConfigurationItem {
154
156
155
157
// MakeChainCreationTransaction is a handy utility function for creating new chain transactions using the underlying Template framework
156
158
func MakeChainCreationTransaction (creationPolicy string , chainID string , signer msp.SigningIdentity , templates ... Template ) (* cb.Envelope , error ) {
157
- newChainTemplate := NewChainCreationTemplate (creationPolicy , NewCompositeTemplate (templates ... ))
159
+ composite := NewCompositeTemplate (templates ... )
160
+ items , err := composite .Items (chainID )
161
+ if err != nil {
162
+ return nil , err
163
+ }
164
+
165
+ manager , err := NewManagerImpl (& cb.ConfigurationEnvelope {Items : items }, NewInitializer ())
166
+
167
+ newChainTemplate := NewChainCreationTemplate (creationPolicy , manager .ChainConfig ().HashingAlgorithm (), composite )
158
168
signedConfigItems , err := newChainTemplate .Items (chainID )
159
169
if err != nil {
160
170
return nil , err
0 commit comments