-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from hyperledger-labs/f-34
tokengen: add ability to generate artifacts #34
- Loading branch information
Showing
16 changed files
with
1,545 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package gen | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/hyperledger-labs/fabric-smart-client/integration" | ||
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo" | ||
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabric" | ||
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc" | ||
|
||
"gopkg.in/yaml.v2" | ||
|
||
"github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token" | ||
) | ||
|
||
type Topology struct { | ||
Name string `yaml:"name,omitempty"` | ||
} | ||
|
||
type Topologies struct { | ||
Topologies []Topology `yaml:"topologies,omitempty"` | ||
} | ||
|
||
type T struct { | ||
Topologies []interface{} `yaml:"topologies,omitempty"` | ||
} | ||
|
||
var topologyFile string | ||
var output string | ||
var port int | ||
|
||
// Cmd returns the Cobra Command for Version | ||
func Cmd() *cobra.Command { | ||
// Set the flags on the node start command. | ||
flags := cobraCommand.Flags() | ||
flags.StringVarP(&topologyFile, "topology", "t", "", "topology file in yaml format") | ||
flags.StringVarP(&output, "output", "o", "./testdata", "output folder") | ||
flags.IntVarP(&port, "port", "p", 20000, "host starting port") | ||
|
||
return cobraCommand | ||
} | ||
|
||
var cobraCommand = &cobra.Command{ | ||
Use: "artifacts", | ||
Short: "Gen artifacts.", | ||
Long: `Read topology from file and generates artifacts.`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if len(args) != 0 { | ||
return fmt.Errorf("trailing args detected") | ||
} | ||
// Parsing of the command line is done so silence cmd usage | ||
cmd.SilenceUsage = true | ||
return gen(args) | ||
}, | ||
} | ||
|
||
// gen read topology and generates artifacts | ||
func gen(args []string) error { | ||
if len(topologyFile) == 0 { | ||
return errors.Errorf("expecting topology file path") | ||
} | ||
raw, err := ioutil.ReadFile(topologyFile) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed reading topology file [%s]", topologyFile) | ||
} | ||
names := &Topologies{} | ||
if err := yaml.Unmarshal(raw, names); err != nil { | ||
return errors.Wrapf(err, "failed unmarshalling topology file [%s]", topologyFile) | ||
} | ||
|
||
t := &T{} | ||
if err := yaml.Unmarshal(raw, t); err != nil { | ||
return errors.Wrapf(err, "failed unmarshalling topology file [%s]", topologyFile) | ||
} | ||
t2 := []nwo.Topology{} | ||
for i, topology := range names.Topologies { | ||
switch topology.Name { | ||
case fabric.TopologyName: | ||
top := fabric.NewDefaultTopology() | ||
r, err := yaml.Marshal(t.Topologies[i]) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed remarshalling topology configuration [%s]", topologyFile) | ||
} | ||
if err := yaml.Unmarshal(r, top); err != nil { | ||
return errors.Wrapf(err, "failed unmarshalling topology file [%s]", topologyFile) | ||
} | ||
t2 = append(t2, top) | ||
case fsc.TopologyName: | ||
top := fsc.NewTopology() | ||
r, err := yaml.Marshal(t.Topologies[i]) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed remarshalling topology configuration [%s]", topologyFile) | ||
} | ||
if err := yaml.Unmarshal(r, top); err != nil { | ||
return errors.Wrapf(err, "failed unmarshalling topology file [%s]", topologyFile) | ||
} | ||
t2 = append(t2, top) | ||
case token.TopologyName: | ||
top := token.NewTopology() | ||
r, err := yaml.Marshal(t.Topologies[i]) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed remarshalling topology configuration [%s]", topologyFile) | ||
} | ||
if err := yaml.Unmarshal(r, top); err != nil { | ||
return errors.Wrapf(err, "failed unmarshalling topology file [%s]", topologyFile) | ||
} | ||
t2 = append(t2, top) | ||
} | ||
} | ||
|
||
network, err := integration.New(port, output, t2...) | ||
if err != nil { | ||
return errors.Wrapf(err, "cannot instantate integration infrastructure") | ||
} | ||
network.RegisterPlatformFactory(token.NewPlatformFactory()) | ||
network.Generate() | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
I��t���;8��/�(�~a��[�ْ{݉5�% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
MIGkAgEBBDAEyvf/GdwK5sfxMh9aUkrTYg09Tf1nZqrb+xZDilgJeYgGkwheNAIg | ||
nOkb3ql1WJSgBwYFK4EEACKhZANiAAQNDNd2ntGGMnyeqCH8JZ8Pbm+gB6SI1A4v | ||
UjtpP2AivClqPiOb+6Rpoj+7rTp0uPG5ZYNeJc13J4DwxoD8vN08dKOUu5ZPb5kG | ||
y2J5sMpF1DnU5l+9kqcVS7dOVoJMlAQ= | ||
-----END PRIVATE KEY----- |
Binary file not shown.
5 changes: 5 additions & 0 deletions
5
sampleconfig/crypto/idemixorg.example.com/msp/RevocationPublicKey
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-----BEGIN PUBLIC KEY----- | ||
MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEDQzXdp7RhjJ8nqgh/CWfD25voAekiNQO | ||
L1I7aT9gIrwpaj4jm/ukaaI/u606dLjxuWWDXiXNdyeA8MaA/LzdPHSjlLuWT2+Z | ||
BstiebDKRdQ51OZfvZKnFUu3TlaCTJQE | ||
-----END PUBLIC KEY----- |
Oops, something went wrong.