-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathfungible.go
121 lines (107 loc) · 4.51 KB
/
fungible.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
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package main
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"
api2 "github.com/hyperledger-labs/fabric-smart-client/pkg/api"
"github.com/hyperledger-labs/fabric-token-sdk/cmd/tokengen/cobra/artifactgen"
"github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token"
fabric2 "github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/fabric"
"github.com/hyperledger-labs/fabric-token-sdk/integration/token/fungible/views"
tokensdk "github.com/hyperledger-labs/fabric-token-sdk/token/sdk/dig"
)
func Topology(tokenSDKDriver string, sdks ...api2.SDK) []api.Topology {
// Fabric
fabricTopology := fabric.NewDefaultTopology()
fabricTopology.EnableIdemix()
fabricTopology.AddOrganizationsByName("Org1", "Org2")
fabricTopology.SetNamespaceApproverOrgs("Org1")
fabricTopology.EnableGRPCLogging()
fabricTopology.EnableLogPeersToFile()
fabricTopology.EnableLogOrderersToFile()
fabricTopology.SetLogging("info", "")
// FSC
fscTopology := fsc.NewTopology()
fscTopology.SetLogging("info", "")
fscTopology.EnableLogToFile()
fscTopology.EnablePrometheusMetrics()
// issuer
issuer := fscTopology.AddNodeByName("issuer").AddOptions(
fabric.WithOrganization("Org1"),
fabric.WithAnonymousIdentity(),
token.WithDefaultIssuerIdentity(false),
token.WithIssuerIdentity("issuer.id1", false),
)
issuer.RegisterViewFactory("issue", &views.IssueCashViewFactory{})
issuer.RegisterViewFactory("issued", &views.ListIssuedTokensViewFactory{})
// auditor
auditor := fscTopology.AddNodeByName("auditor").AddOptions(
fabric.WithOrganization("Org1"),
fabric.WithAnonymousIdentity(),
token.WithAuditorIdentity(false),
)
auditor.RegisterViewFactory("registerAuditor", &views.RegisterAuditorViewFactory{})
// alice
alice := fscTopology.AddNodeByName("alice").AddOptions(
fabric.WithOrganization("Org2"),
fabric.WithAnonymousIdentity(),
token.WithDefaultOwnerIdentity(),
token.WithOwnerIdentity("alice.id1"),
)
alice.RegisterResponder(&views.AcceptCashView{}, &views.IssueCashView{})
alice.RegisterResponder(&views.AcceptCashView{}, &views.TransferView{})
alice.RegisterViewFactory("transfer", &views.TransferViewFactory{})
alice.RegisterViewFactory("redeem", &views.RedeemViewFactory{})
alice.RegisterViewFactory("swap", &views.SwapInitiatorViewFactory{})
alice.RegisterViewFactory("unspent", &views.ListUnspentTokensViewFactory{})
// bob
bob := fscTopology.AddNodeByName("bob").AddOptions(
fabric.WithOrganization("Org2"),
fabric.WithAnonymousIdentity(),
token.WithDefaultOwnerIdentity(),
token.WithOwnerIdentity("bob.id1"),
)
bob.RegisterResponder(&views.AcceptCashView{}, &views.IssueCashView{})
bob.RegisterResponder(&views.AcceptCashView{}, &views.TransferView{})
bob.RegisterResponder(&views.SwapResponderView{}, &views.SwapInitiatorView{})
bob.RegisterViewFactory("transfer", &views.TransferViewFactory{})
bob.RegisterViewFactory("redeem", &views.RedeemViewFactory{})
bob.RegisterViewFactory("swap", &views.SwapInitiatorViewFactory{})
bob.RegisterViewFactory("unspent", &views.ListUnspentTokensViewFactory{})
// charlie
charlie := fscTopology.AddNodeByName("charlie").AddOptions(
fabric.WithOrganization("Org2"),
fabric.WithAnonymousIdentity(),
token.WithDefaultOwnerIdentity(),
token.WithOwnerIdentity("charlie.id1"),
)
charlie.RegisterResponder(&views.AcceptCashView{}, &views.IssueCashView{})
charlie.RegisterResponder(&views.AcceptCashView{}, &views.TransferView{})
charlie.RegisterResponder(&views.SwapResponderView{}, &views.SwapInitiatorView{})
charlie.RegisterViewFactory("transfer", &views.TransferViewFactory{})
charlie.RegisterViewFactory("redeem", &views.RedeemViewFactory{})
charlie.RegisterViewFactory("swap", &views.SwapInitiatorViewFactory{})
charlie.RegisterViewFactory("unspent", &views.ListUnspentTokensViewFactory{})
tokenTopology := token.NewTopology()
tms := tokenTopology.AddTMS(fscTopology.ListNodes(), fabricTopology, fabricTopology.Channels[0].Name, tokenSDKDriver)
fabric2.SetOrgs(tms, "Org1")
tms.SetTokenGenPublicParams("16")
tms.AddAuditor(auditor)
for _, sdk := range sdks {
fscTopology.AddSDK(sdk)
}
return []api.Topology{
fabricTopology,
tokenTopology,
fscTopology,
}
}
func main() {
if err := artifactgen.WriteTopologies("fungible.yaml", Topology("dlog", &tokensdk.SDK{}), 0766); err != nil {
panic(err)
}
}