Skip to content

Commit

Permalink
Merge branch 'main' into feature/add-ccapi-for-samples
Browse files Browse the repository at this point in the history
  • Loading branch information
osamamagdy authored Dec 5, 2024
2 parents 2fed06b + 88b7c21 commit efdbe02
Show file tree
Hide file tree
Showing 11 changed files with 611 additions and 8 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
!ecc/ecc
!ecc_go/ecc_go
!ecc_go/enclave.json
!ecc_go/ccToolsDemoEnclave.json
!ecc_enclave/_build/lib/libsgxcc.so
# note: docker seems to have troubles with '+' in filenames in this file, at least in exceptions ..
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ cscope.*
common/protos
internal/protos
coverage.out
vendor
7 changes: 4 additions & 3 deletions ecc_go/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@ HW_EXTENSION=$(shell if [ "${SGX_MODE}" = "HW" ]; then echo "-hw"; fi)
DOCKER_IMAGE ?= fpc/$(CC_NAME)${HW_EXTENSION}
DOCKER_FILE ?= $(FPC_PATH)/ecc_go/Dockerfile
EGO_CONFIG_FILE ?= $(FPC_PATH)/ecc_go/enclave.json
ECC_MAIN_FILES ?= main.go
ECC_BINARY ?= ecc
ECC_BUNDLE ?= $(ECC_BINARY)-bundle

build: ecc docker env

ecc: ecc_dependencies
ego-go build $(GOTAGS) -o $(ECC_BINARY) main.go
cp $(EGO_CONFIG_FILE) .
ego-go build $(GOTAGS) -o $(ECC_BINARY) $(ECC_MAIN_FILES)
cp $(EGO_CONFIG_FILE) ./enclave.json
ego sign
ego uniqueid $(ECC_BINARY) > mrenclave
ego bundle $(ECC_BINARY) $(ECC_BUNDLE)

.PHONY: with_go
with_go: ecc_dependencies
$(GO) build $(GOTAGS) -o $(ECC_BUNDLE) main.go
$(GO) build $(GOTAGS) -o $(ECC_BUNDLE) $(ECC_MAIN_FILES)
echo "fake_mrenclave" > mrenclave

ecc_dependencies:
Expand Down
27 changes: 23 additions & 4 deletions ecc_go/chaincode/enclave_go/shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ SPDX-License-Identifier: Apache-2.0
package enclave_go

import (
"fmt"
//lint:ignore SA1019 the package is needed to unmarshall the header
protoV1 "github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-chaincode-go/shim"
"github.com/hyperledger/fabric-private-chaincode/internal/utils"
common "github.com/hyperledger/fabric-protos-go/common"
pb "github.com/hyperledger/fabric-protos-go/peer"

"google.golang.org/protobuf/proto"
timestamp "google.golang.org/protobuf/types/known/timestamppb"
)

Expand Down Expand Up @@ -177,7 +183,7 @@ func (f *FpcStubInterface) SplitCompositeKey(compositeKey string) (string, []str
}

func (f *FpcStubInterface) GetQueryResult(query string) (shim.StateQueryIteratorInterface, error) {
panic("not implemented") // TODO: Implement
return nil, fmt.Errorf("function not yet supported")
}

func (f *FpcStubInterface) GetQueryResultWithPagination(query string, pageSize int32, bookmark string) (shim.StateQueryIteratorInterface, *pb.QueryResponseMetadata, error) {
Expand Down Expand Up @@ -233,7 +239,7 @@ func (f *FpcStubInterface) GetCreator() ([]byte, error) {
}

func (f *FpcStubInterface) GetTransient() (map[string][]byte, error) {
panic("not implemented") // TODO: Implement
return nil, fmt.Errorf("function not yet supported")
}

func (f *FpcStubInterface) GetBinding() ([]byte, error) {
Expand All @@ -249,9 +255,22 @@ func (f *FpcStubInterface) GetSignedProposal() (*pb.SignedProposal, error) {
}

func (f *FpcStubInterface) GetTxTimestamp() (*timestamp.Timestamp, error) {
panic("not implemented") // TODO: Implement
hdr := &common.Header{}
proposal, Proposalerr := f.GetSignedProposal()
if Proposalerr != nil {
return nil, fmt.Errorf("error retrieving the proposal from the FPC Stub")
}
if err := proto.Unmarshal(proposal.ProposalBytes, protoV1.MessageV2(hdr)); err != nil {
return nil, fmt.Errorf("error unmarshaling Header: %s", err)
}

chdr := &common.ChannelHeader{}
if err := proto.Unmarshal(hdr.ChannelHeader, protoV1.MessageV2(chdr)); err != nil {
return nil, fmt.Errorf("error unmarshaling ChannelHeader: %s", err)
}
return chdr.GetTimestamp(), nil
}

func (f *FpcStubInterface) SetEvent(name string, payload []byte) error {
panic("not implemented") // TODO: Implement
return fmt.Errorf("function not yet supported")
}
Loading

0 comments on commit efdbe02

Please sign in to comment.