/
package.go
41 lines (31 loc) · 924 Bytes
/
package.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
/*
Copyright DTCC 2016 All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package java
import (
"archive/tar"
"fmt"
"strings"
"errors"
"path/filepath"
cutil "github.com/hyperledger/fabric/core/container/util"
pb "github.com/hyperledger/fabric/protos/peer"
)
//tw is expected to have the chaincode in it from GenerateHashcode.
//This method will just package the dockerfile
func writeChaincodePackage(spec *pb.ChaincodeSpec, tw *tar.Writer) error {
urlLocation := spec.ChaincodeId.Path
if urlLocation == "" {
return errors.New("ChaincodeSpec's path/URL cannot be empty")
}
if strings.LastIndex(urlLocation, "/") == len(urlLocation)-1 {
urlLocation = urlLocation[:len(urlLocation)-1]
}
jarname := filepath.Base(urlLocation)
err := cutil.WriteFileToPackage(urlLocation, jarname, tw)
if err != nil {
return fmt.Errorf("Error writing Chaincode package contents: %s", err)
}
return nil
}