-
Notifications
You must be signed in to change notification settings - Fork 1
/
cdstool.go
44 lines (37 loc) · 930 Bytes
/
cdstool.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
package main
import (
"flag"
"fmt"
"io/ioutil"
"github.com/golang/protobuf/proto"
pb "github.com/hyperledger/fabric/protos/peer"
)
var ERRORCOLOR = "\033[1;31m%s\033[0m\n"
func main() {
inputFile := flag.String("input", "", "The CDS package file")
outputFile := flag.String("output", "", "The tarball file to create")
flag.Parse()
if *inputFile == "" || *outputFile == "" {
fmt.Println("CDSTool Command Options:")
flag.PrintDefaults()
return
}
chaincode, err := ioutil.ReadFile(*inputFile)
if err != nil {
fmt.Printf(ERRORCOLOR, err)
return
}
depSpec := &pb.ChaincodeDeploymentSpec{}
err = proto.Unmarshal(chaincode, depSpec)
if err != nil {
fmt.Printf(ERRORCOLOR, err)
return
}
fmt.Printf("Chaincode Information: =%+v\n", depSpec.ChaincodeSpec)
payload := depSpec.CodePackage
err = ioutil.WriteFile(*outputFile, payload, 0644)
if err != nil {
fmt.Printf(ERRORCOLOR, err)
return
}
}