@@ -20,16 +20,22 @@ import (
20
20
"fmt"
21
21
22
22
"github.com/hyperledger/fabric/bccsp/factory"
23
+ "github.com/hyperledger/fabric/common/configtx"
24
+ configtxapi "github.com/hyperledger/fabric/common/configtx/api"
23
25
"github.com/hyperledger/fabric/common/errors"
24
26
"github.com/hyperledger/fabric/common/flogging"
25
27
"github.com/hyperledger/fabric/common/viperutil"
26
28
"github.com/hyperledger/fabric/core/config"
27
29
"github.com/hyperledger/fabric/core/peer"
30
+ "github.com/hyperledger/fabric/core/scc/cscc"
28
31
"github.com/hyperledger/fabric/msp"
29
32
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
33
+ pcommon "github.com/hyperledger/fabric/protos/common"
30
34
pb "github.com/hyperledger/fabric/protos/peer"
35
+ putils "github.com/hyperledger/fabric/protos/utils"
31
36
logging "github.com/op/go-logging"
32
37
"github.com/spf13/viper"
38
+ "golang.org/x/net/context"
33
39
)
34
40
35
41
// UndefinedParamValue defines what undefined parameters in the command line will initialise to
@@ -119,3 +125,66 @@ func GetDefaultSigner() (msp.SigningIdentity, error) {
119
125
120
126
return signer , err
121
127
}
128
+
129
+ // GetOrdererEndpointOfChain returns orderer endpoints of given chain
130
+ func GetOrdererEndpointOfChain (chainID string , signer msp.SigningIdentity , endorserClient pb.EndorserClient ) ([]string , error ) {
131
+
132
+ // query cscc for chain config block
133
+ invocation := & pb.ChaincodeInvocationSpec {
134
+ ChaincodeSpec : & pb.ChaincodeSpec {
135
+ Type : pb .ChaincodeSpec_Type (pb .ChaincodeSpec_Type_value ["GOLANG" ]),
136
+ ChaincodeId : & pb.ChaincodeID {Name : "cscc" },
137
+ Input : & pb.ChaincodeInput {Args : [][]byte {[]byte (cscc .GetConfigBlock ), []byte (chainID )}},
138
+ },
139
+ }
140
+
141
+ creator , err := signer .Serialize ()
142
+ if err != nil {
143
+ return nil , fmt .Errorf ("Error serializing identity for %s: %s" , signer .GetIdentifier (), err )
144
+ }
145
+
146
+ prop , _ , err := putils .CreateProposalFromCIS (pcommon .HeaderType_CONFIG , "" , invocation , creator )
147
+ if err != nil {
148
+ return nil , fmt .Errorf ("Error creating GetConfigBlock proposal: %s" , err )
149
+ }
150
+
151
+ signedProp , err := putils .GetSignedProposal (prop , signer )
152
+ if err != nil {
153
+ return nil , fmt .Errorf ("Error creating signed GetConfigBlock proposal: %s" , err )
154
+ }
155
+
156
+ proposalResp , err := endorserClient .ProcessProposal (context .Background (), signedProp )
157
+ if err != nil {
158
+ return nil , fmt .Errorf ("Error endorsing GetConfigBlock: %s" , err )
159
+ }
160
+
161
+ if proposalResp == nil {
162
+ return nil , fmt .Errorf ("Error nil proposal response: %s" , err )
163
+ }
164
+
165
+ if proposalResp .Response .Status != 0 && proposalResp .Response .Status != 200 {
166
+ return nil , fmt .Errorf ("Error bad proposal response %d" , proposalResp .Response .Status )
167
+ }
168
+
169
+ // parse config block
170
+ block , err := putils .GetBlockFromBlockBytes (proposalResp .Response .Payload )
171
+ if err != nil {
172
+ return nil , fmt .Errorf ("Error unmarshaling config block: %s" , err )
173
+ }
174
+
175
+ envelopeConfig , err := putils .ExtractEnvelope (block , 0 )
176
+ if err != nil {
177
+ return nil , fmt .Errorf ("Error extracting config block envelope: %s" , err )
178
+ }
179
+ configtxInitializer := configtx .NewInitializer ()
180
+ configtxManager , err := configtx .NewManagerImpl (
181
+ envelopeConfig ,
182
+ configtxInitializer ,
183
+ []func (cm configtxapi.Manager ){},
184
+ )
185
+ if err != nil {
186
+ return nil , fmt .Errorf ("Error loadding config block: %s" , err )
187
+ }
188
+
189
+ return configtxManager .ChannelConfig ().OrdererAddresses (), nil
190
+ }
0 commit comments