Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
dviejokfs committed Feb 1, 2023
1 parent b51cc03 commit bd3bfeb
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 8 deletions.
19 changes: 19 additions & 0 deletions cmd/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ hlf-cc-dev listen --forward-to=%s --tunnelAddress="xxx:8082"
pdcContents = string(pdcContentsBytes)
}
var indices []*models.CouchDBIndex
var pdcIndices []*models.CouchDBIndexPdc
if c.metaInf != "" {
src := c.metaInf
// walk through 3 file in the folder
Expand All @@ -164,20 +165,38 @@ hlf-cc-dev listen --forward-to=%s --tunnelAddress="xxx:8082"
Contents: string(contentBytes),
}
indices = append(indices, index)
log.Infof("found index file: %s - %s", relname, path.Base(relname))
}
if strings.Contains(relname, "statedb/couchdb/collections") && !fi.IsDir() {
contentBytes, err := ioutil.ReadFile(file)
if err != nil {
return err
}
pdcName := path.Base(path.Join(relname, "../../"))
index := &models.CouchDBIndexPdc{
ID: path.Base(relname),
PdcName: pdcName,
Contents: string(contentBytes),
}
pdcIndices = append(pdcIndices, index)
log.Infof("found index for PDC %s file: %s - %s", pdcName, relname, path.Base(relname))
}
return nil
})
if err != nil {
return err
}
}
log.Infof("found %d indexes %v", len(indices), indices)
log.Infof("found %d pdc indexes %v", len(pdcIndices), pdcIndices)
input := models.DeployChaincodeInput{
Channel: &c.channel,
Name: c.chaincode,
ChaincodeAddress: chaincodeAddress,
Pdc: pdcContents,
SignaturePolicy: c.signaturePolicy,
Indexes: indices,
PdcIndexes: pdcIndices,
}
var m struct {
DeployChaincode struct {
Expand Down
79 changes: 79 additions & 0 deletions gql/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions gql/models/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 32 additions & 2 deletions gql/resolvers/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/lithammer/shortuuid/v3"
"github.com/pkg/errors"
"io"
"io/ioutil"
"net"
"strings"
"sync"
Expand Down Expand Up @@ -97,7 +98,14 @@ func getChaincodePackage(label string, codeTarGz []byte) ([]byte, error) {
return buf.Bytes(), nil
}

func getCodeTarGz(address string, rootCert string, clientKey string, clientCert string, couchDBIndices []*models.CouchDBIndex) ([]byte, error) {
func getCodeTarGz(
address string,
rootCert string,
clientKey string,
clientCert string,
couchDBIndices []*models.CouchDBIndex,
couchDBIndicesPDC []*models.CouchDBIndexPdc,
) ([]byte, error) {
var err error
connMap := map[string]interface{}{
"address": address,
Expand Down Expand Up @@ -148,7 +156,24 @@ func getCodeTarGz(address string, rootCert string, clientKey string, clientCert
return nil, err
}
}

}
if len(couchDBIndicesPDC) > 0 {
for _, pdcCouchDBIndex := range couchDBIndicesPDC {
header := new(tar.Header)
contentsBytes := []byte(pdcCouchDBIndex.Contents)
header.Mode = 0755
header.Size = int64(len(contentsBytes))
header.Name = fmt.Sprintf("META-INF/statedb/couchdb/collections/%s/indexes/%s", pdcCouchDBIndex.PdcName, pdcCouchDBIndex.ID)
// write header
if err := tw.WriteHeader(header); err != nil {
return nil, err
}
// if not a dir, write file content
r := bytes.NewReader(contentsBytes)
if _, err := io.Copy(tw, r); err != nil {
return nil, err
}
}
}
err = tw.Close()
if err != nil {
Expand Down Expand Up @@ -229,7 +254,11 @@ func (m mutationResolver) DeployChaincode(ctx context.Context, input models.Depl
privateKey,
certificate,
input.Indexes,
input.PdcIndexes,
)
if err != nil {
return nil, err
}
resClient, err := resmgmt.New(m.SDKContext)
if err != nil {
return nil, err
Expand Down Expand Up @@ -265,6 +294,7 @@ func (m mutationResolver) DeployChaincode(ctx context.Context, input models.Depl
if err != nil {
return nil, err
}
ioutil.WriteFile("chaincode.tar.gz", pkg, 0644)
packageID := lifecycle.ComputePackageID(chaincodeName, pkg)
signaturePolicy := input.SignaturePolicy
sp, err := policydsl.FromString(signaturePolicy)
Expand Down
7 changes: 7 additions & 0 deletions schema/mutation.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,16 @@ input DeployChaincodeInput {
chaincodeAddress: String!
signaturePolicy: String!
indexes: [CouchDBIndex!]
pdcIndexes: [CouchDBIndexPDC!]
channel: String
}
input CouchDBIndex {
id: String!
contents: String!
}

input CouchDBIndexPDC {
id: String!
pdcName: String!
contents: String!
}

0 comments on commit bd3bfeb

Please sign in to comment.