-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathtopology.go
266 lines (242 loc) · 8.86 KB
/
topology.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package topology
import (
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/api"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabric"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc/node"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/monitoring"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/orion"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/sdk/tracing"
"github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token"
common2 "github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/common"
fabric2 "github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/fabric"
"github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/generators/dlog"
orion2 "github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/orion"
"github.com/hyperledger-labs/fabric-token-sdk/integration/token/common"
auditor2 "github.com/hyperledger-labs/fabric-token-sdk/integration/token/fungible/sdk/auditor"
"github.com/hyperledger-labs/fabric-token-sdk/integration/token/fungible/sdk/endorser"
issuer2 "github.com/hyperledger-labs/fabric-token-sdk/integration/token/fungible/sdk/issuer"
"github.com/hyperledger-labs/fabric-token-sdk/integration/token/fungible/sdk/party"
)
func Topology(opts common.Opts) []api.Topology {
var backendNetwork api.Topology
backendChannel := ""
switch opts.Backend {
case "fabric":
fabricTopology := fabric.NewDefaultTopology()
fabricTopology.EnableIdemix()
fabricTopology.AddOrganizationsByName("Org1", "Org2")
fabricTopology.SetNamespaceApproverOrgs("Org1")
backendNetwork = fabricTopology
backendChannel = fabricTopology.Channels[0].Name
case "orion":
orionTopology := orion.NewTopology()
backendNetwork = orionTopology
default:
panic("unknown backend: " + opts.Backend)
}
// FSC
fscTopology := fsc.NewTopology()
fscTopology.P2PCommunicationType = opts.CommType
fscTopology.WebEnabled = opts.WebEnabled
if opts.Monitoring {
fscTopology.EnablePrometheusMetrics()
fscTopology.EnableTracing(tracing.File)
}
fscTopology.SetLogging(opts.FSCLogSpec, "")
issuer := fscTopology.AddNodeByName("issuer").AddOptions(
fabric.WithOrganization("Org1"),
fabric.WithAnonymousIdentity(),
orion.WithRole("issuer"),
token.WithDefaultIssuerIdentity(opts.HSM),
token.WithIssuerIdentity("issuer.id1", opts.HSM),
token.WithDefaultOwnerIdentity(),
token.WithOwnerIdentity("issuer.owner"),
)
issuer.AddOptions(opts.ReplicationOpts.For("issuer")...)
newIssuer := fscTopology.AddNodeByName("newIssuer").AddOptions(
fabric.WithOrganization("Org1"),
fabric.WithAnonymousIdentity(),
orion.WithRole("issuer"),
token.WithDefaultIssuerIdentity(opts.HSM),
token.WithIssuerIdentity("newIssuer.id1", opts.HSM),
token.WithDefaultOwnerIdentity(),
token.WithOwnerIdentity("newIssuer.owner"),
)
newIssuer.AddOptions(opts.ReplicationOpts.For("newIssuer")...)
var auditor *node.Node
if opts.AuditorAsIssuer {
issuer.AddOptions(
orion.WithRole("auditor"),
token.WithAuditorIdentity(opts.HSM),
fsc.WithAlias("auditor"),
)
auditor = issuer
newIssuer.AddOptions(
orion.WithRole("auditor"),
token.WithAuditorIdentity(opts.HSM),
fsc.WithAlias("auditor"),
)
} else {
auditor = fscTopology.AddNodeByName("auditor").AddOptions(
fabric.WithOrganization("Org1"),
fabric.WithAnonymousIdentity(),
orion.WithRole("auditor"),
token.WithAuditorIdentity(opts.HSM),
)
auditor.AddOptions(opts.ReplicationOpts.For("auditor")...)
}
newAuditor := fscTopology.AddNodeByName("newAuditor").AddOptions(
fabric.WithOrganization("Org1"),
orion.WithRole("auditor"),
token.WithAuditorIdentity(opts.HSM),
)
newAuditor.AddOptions(opts.ReplicationOpts.For("newAuditor")...)
alice := fscTopology.AddNodeByName("alice").AddOptions(
fabric.WithOrganization("Org2"),
fabric.WithAnonymousIdentity(),
orion.WithRole("alice"),
token.WithOwnerIdentity("alice.id1"),
token.WithRemoteOwnerIdentity("alice_remote"),
token.WithRemoteOwnerIdentity("alice_remote_2"),
)
alice.AddOptions(opts.ReplicationOpts.For("alice")...)
bob := fscTopology.AddNodeByName("bob").AddOptions(
fabric.WithOrganization("Org2"),
fabric.WithAnonymousIdentity(),
orion.WithRole("bob"),
token.WithDefaultOwnerIdentity(),
token.WithOwnerIdentity("bob.id1"),
token.WithRemoteOwnerIdentity("bob_remote"),
)
bob.AddOptions(opts.ReplicationOpts.For("bob")...)
charlie := fscTopology.AddNodeByName("charlie").AddOptions(
fabric.WithOrganization("Org2"),
fabric.WithAnonymousIdentity(),
orion.WithRole("charlie"),
token.WithDefaultOwnerIdentity(),
token.WithOwnerIdentity("charlie.id1"),
)
charlie.AddOptions(opts.ReplicationOpts.For("charlie")...)
manager := fscTopology.AddNodeByName("manager").AddOptions(
fabric.WithOrganization("Org2"),
fabric.WithAnonymousIdentity(),
orion.WithRole("manager"),
token.WithDefaultOwnerIdentity(),
token.WithOwnerIdentity("manager.id1"),
token.WithOwnerIdentity("manager.id2"),
token.WithOwnerIdentity("manager.id3"),
)
manager.AddOptions(opts.ReplicationOpts.For("manager")...)
if opts.FSCBasedEndorsement {
endorserTemplate := fscTopology.NewTemplate("endorser")
endorserTemplate.AddOptions(
fabric.WithOrganization("Org1"),
fabric2.WithEndorserRole(),
)
fscTopology.AddNodeFromTemplate("endorser-1", endorserTemplate)
fscTopology.AddNodeFromTemplate("endorser-2", endorserTemplate)
fscTopology.AddNodeFromTemplate("endorser-3", endorserTemplate)
}
tokenTopology := token.NewTopology()
tokenTopology.TokenSelector = opts.TokenSelector
tms := tokenTopology.AddTMS(fscTopology.ListNodes(), backendNetwork, backendChannel, opts.DefaultTMSOpts.TokenSDKDriver)
tms.SetNamespace("token-chaincode")
common.SetDefaultParams(tms, opts.DefaultTMSOpts)
if !opts.DefaultTMSOpts.Aries {
// Enable Fabric-CA
fabric2.WithFabricCA(tms)
}
if opts.FSCBasedEndorsement {
fabric2.WithFSCEndorsers(tms, "endorser-1", "endorser-2", "endorser-3")
}
fabric2.SetOrgs(tms, "Org1")
var nodeList []*node.Node
if opts.Backend == "orion" {
// we need to define the custodian
custodian := fscTopology.AddNodeByName("custodian")
custodian.AddOptions(orion.WithRole("custodian"))
custodian.AddOptions(opts.ReplicationOpts.For("custodian")...)
orion2.SetCustodian(tms, custodian.Name)
tms.AddNode(custodian)
// Enable orion sdk on each FSC node
orionTopology := backendNetwork.(*orion.Topology)
orionTopology.AddDB(tms.Namespace, "custodian", "issuer", "auditor", "alice", "bob", "charlie", "manager")
fscTopology.SetBootstrapNode(custodian)
nodeList = fscTopology.ListNodes()
} else {
nodeList = fscTopology.ListNodes()
if opts.CommType == fsc.LibP2P {
fscTopology.SetBootstrapNode(fscTopology.AddNodeByName("lib-p2p-bootstrap-node"))
}
}
if !opts.NoAuditor {
tms.AddAuditor(auditor)
}
if opts.OnlyUnity {
common2.WithOnlyUnity(tms)
}
if len(opts.SDKs) > 0 {
// business SDKs
// auditors
for _, node := range fscTopology.ListNodes("auditor", "newAuditor") {
node.AddSDKWithBase(opts.SDKs[0], &auditor2.SDK{})
}
// issuers
for _, node := range fscTopology.ListNodes("issuer", "newIssuer") {
if opts.AuditorAsIssuer {
node.AddSDKWithBase(opts.SDKs[0], &issuer2.SDK{}, &auditor2.SDK{})
} else {
node.AddSDKWithBase(opts.SDKs[0], &issuer2.SDK{})
}
}
// parties
for _, node := range fscTopology.ListNodes("alice", "bob", "charlie", "manager") {
node.AddSDKWithBase(opts.SDKs[0], &party.SDK{})
}
// endorsers
if opts.FSCBasedEndorsement {
for _, node := range fscTopology.ListNodes("endorser-1", "endorser-2", "endorser-3") {
node.AddSDKWithBase(opts.SDKs[0], &endorser.SDK{})
}
}
// additional nodes that are backend specific
if opts.Backend == "orion" {
fscTopology.ListNodes("custodian")[0].AddSDK(opts.SDKs[0])
} else if opts.CommType == fsc.LibP2P {
fscTopology.ListNodes("lib-p2p-bootstrap-node")[0].AddSDK(opts.SDKs[0])
}
// add the rest of the SDKs
for i := 1; i < len(opts.SDKs); i++ {
fscTopology.AddSDK(opts.SDKs[i])
}
}
// any extra TMS
for _, tmsOpts := range opts.ExtraTMSs {
tms := tokenTopology.AddTMS(nodeList, backendNetwork, backendChannel, tmsOpts.TokenSDKDriver)
tms.Alias = tmsOpts.Alias
tms.Namespace = "token-chaincode"
tms.Transient = true
if tmsOpts.Aries {
dlog.WithAries(tms)
}
tms.SetTokenGenPublicParams(tmsOpts.PublicParamsGenArgs...)
if !opts.NoAuditor {
tms.AddAuditor(auditor)
}
}
if opts.Monitoring {
monitoringTopology := monitoring.NewTopology()
// monitoringTopology.EnableHyperledgerExplorer()
monitoringTopology.EnablePrometheusGrafana()
return []api.Topology{
backendNetwork, tokenTopology, fscTopology,
monitoringTopology,
}
}
return []api.Topology{backendNetwork, tokenTopology, fscTopology}
}