diff --git a/pkg/fabric-client/channel/block.go b/pkg/fabric-client/channel/block.go index 0ff3e0c517..397e2ba544 100644 --- a/pkg/fabric-client/channel/block.go +++ b/pkg/fabric-client/channel/block.go @@ -13,8 +13,8 @@ import ( fab "github.com/hyperledger/fabric-sdk-go/api/apifabclient" ab "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/protos/orderer" - protos_utils "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/protos/utils" "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common" + protos_utils "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/utils" ccomm "github.com/hyperledger/fabric-sdk-go/pkg/config/comm" "github.com/hyperledger/fabric-sdk-go/pkg/errors" diff --git a/pkg/fabric-client/channel/config.go b/pkg/fabric-client/channel/config.go index d9d7869b80..5f0361294b 100644 --- a/pkg/fabric-client/channel/config.go +++ b/pkg/fabric-client/channel/config.go @@ -10,11 +10,11 @@ import ( "github.com/golang/protobuf/proto" fab "github.com/hyperledger/fabric-sdk-go/api/apifabclient" - protos_utils "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/protos/utils" "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common" mb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/msp" ab "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/orderer" pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer" + protos_utils "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/utils" channelConfig "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/common/channelconfig" "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/msp" diff --git a/pkg/fabric-client/channel/txnproposer.go b/pkg/fabric-client/channel/txnproposer.go index 93da9e39f7..2d700688dc 100644 --- a/pkg/fabric-client/channel/txnproposer.go +++ b/pkg/fabric-client/channel/txnproposer.go @@ -13,9 +13,9 @@ import ( "github.com/golang/protobuf/proto" "github.com/hyperledger/fabric-sdk-go/pkg/errors" - protos_utils "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/protos/utils" "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common" pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer" + protos_utils "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/utils" fab "github.com/hyperledger/fabric-sdk-go/api/apifabclient" "github.com/hyperledger/fabric-sdk-go/api/apitxn" diff --git a/pkg/fabric-client/channel/txnsender.go b/pkg/fabric-client/channel/txnsender.go index e69962ddd7..6a72d69273 100644 --- a/pkg/fabric-client/channel/txnsender.go +++ b/pkg/fabric-client/channel/txnsender.go @@ -18,10 +18,10 @@ import ( "github.com/hyperledger/fabric-sdk-go/pkg/errors" "github.com/hyperledger/fabric-sdk-go/api/apiconfig" - protos_utils "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/protos/utils" "github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/internal/txnproc" "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common" pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer" + protos_utils "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/utils" ) func init() { diff --git a/pkg/fabric-client/client.go b/pkg/fabric-client/client.go index dc7509059b..16c7c655d7 100644 --- a/pkg/fabric-client/client.go +++ b/pkg/fabric-client/client.go @@ -22,7 +22,6 @@ import ( "github.com/hyperledger/fabric-sdk-go/api/apicryptosuite" "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/common/crypto" fcutils "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/common/util" - protos_utils "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/protos/utils" ccomm "github.com/hyperledger/fabric-sdk-go/pkg/config/comm" "github.com/hyperledger/fabric-sdk-go/pkg/errors" channel "github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/channel" @@ -30,6 +29,7 @@ import ( fc "github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/internal" "github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/internal/txnproc" "github.com/hyperledger/fabric-sdk-go/pkg/logging" + protos_utils "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/utils" ) var logger = logging.NewLogger("fabric_sdk_go") diff --git a/pkg/fabric-client/events/eventhub.go b/pkg/fabric-client/events/eventhub.go index 35463d6644..bec2c56df3 100755 --- a/pkg/fabric-client/events/eventhub.go +++ b/pkg/fabric-client/events/eventhub.go @@ -21,12 +21,12 @@ import ( common "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common" pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer" - "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/core/ledger/util" cnsmr "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/events/consumer" - "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/protos/utils" "github.com/hyperledger/fabric-sdk-go/pkg/errors" consumer "github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/events/consumer" "github.com/hyperledger/fabric-sdk-go/pkg/logging" + "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/core/ledger/util" + "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/utils" ) var logger = logging.NewLogger("fabric_sdk_go") diff --git a/pkg/fabric-client/events/eventmocks.go b/pkg/fabric-client/events/eventmocks.go index fdba57b265..c8dc1b7717 100644 --- a/pkg/fabric-client/events/eventmocks.go +++ b/pkg/fabric-client/events/eventmocks.go @@ -16,13 +16,13 @@ import ( "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common" pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer" - ledger_util "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/core/ledger/util" fcConsumer "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/events/consumer" "github.com/hyperledger/fabric-sdk-go/pkg/cryptosuite" "github.com/hyperledger/fabric-sdk-go/pkg/errors" client "github.com/hyperledger/fabric-sdk-go/pkg/fabric-client" internal "github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/internal" "github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/mocks" + ledger_util "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/core/ledger/util" ) type mockEventClientMockEventRegistration struct { diff --git a/pkg/fabric-client/internal/util.go b/pkg/fabric-client/internal/util.go index bcb938621a..56c4a9c9d7 100644 --- a/pkg/fabric-client/internal/util.go +++ b/pkg/fabric-client/internal/util.go @@ -13,8 +13,8 @@ import ( "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common" "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/common/crypto" - protos_utils "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/protos/utils" "github.com/hyperledger/fabric-sdk-go/pkg/errors" + protos_utils "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/utils" ) // CreateSeekGenesisBlockRequest creates a seek request for block 0 on the specified diff --git a/pkg/fabric-client/mocks/mockdata.go b/pkg/fabric-client/mocks/mockdata.go index e3f8f0ef69..365acb885e 100644 --- a/pkg/fabric-client/mocks/mockdata.go +++ b/pkg/fabric-client/mocks/mockdata.go @@ -11,17 +11,17 @@ import ( "github.com/golang/protobuf/ptypes/timestamp" cutil "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/common/util" - "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/protos/utils" "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common" mb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/msp" ab "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/orderer" pp "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer" + "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/utils" "time" channelConfig "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/common/channelconfig" - ledger_util "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/core/ledger/util" "github.com/hyperledger/fabric-sdk-go/pkg/errors" + ledger_util "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/core/ledger/util" ) // NewSimpleMockBlock returns a simple mock block diff --git a/pkg/fabric-client/mocks/mockendorserserver.go b/pkg/fabric-client/mocks/mockendorserserver.go index a9b23c07ed..4aff5ef355 100644 --- a/pkg/fabric-client/mocks/mockendorserserver.go +++ b/pkg/fabric-client/mocks/mockendorserserver.go @@ -10,7 +10,7 @@ import ( "github.com/golang/protobuf/proto" "golang.org/x/net/context" - rwsetutil "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/rwsetutil" + rwsetutil "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/rwsetutil" kvrwset "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/ledger/rwset/kvrwset" "fmt" diff --git a/pkg/fabric-txn/selection/dynamicselection/ccpolicyprovider.go b/pkg/fabric-txn/selection/dynamicselection/ccpolicyprovider.go index b30f0661ba..ddfeeb8566 100644 --- a/pkg/fabric-txn/selection/dynamicselection/ccpolicyprovider.go +++ b/pkg/fabric-txn/selection/dynamicselection/ccpolicyprovider.go @@ -22,7 +22,7 @@ import ( "github.com/hyperledger/fabric-sdk-go/pkg/logging" "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common" - "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/core/common/ccprovider" + "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/core/common/ccprovider" peerImpl "github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/peer" ) diff --git a/pkg/fabric-txn/selection/dynamicselection/dynamicselection_test.go b/pkg/fabric-txn/selection/dynamicselection/dynamicselection_test.go index 47a68d843e..a795419c35 100644 --- a/pkg/fabric-txn/selection/dynamicselection/dynamicselection_test.go +++ b/pkg/fabric-txn/selection/dynamicselection/dynamicselection_test.go @@ -16,11 +16,11 @@ import ( "github.com/hyperledger/fabric-sdk-go/api/apilogging" "github.com/hyperledger/fabric-sdk-go/def/fabapi" "github.com/hyperledger/fabric-sdk-go/def/fabapi/context/defprovider" - "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/core/common/ccprovider" "github.com/hyperledger/fabric-sdk-go/pkg/config" mocks "github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/mocks" "github.com/hyperledger/fabric-sdk-go/pkg/fabric-txn/selection/dynamicselection/pgresolver" "github.com/hyperledger/fabric-sdk-go/pkg/logging" + "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/core/common/ccprovider" "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common" ) diff --git a/scripts/third_party_pins/fabric/apply_fabric_client_utils.sh b/scripts/third_party_pins/fabric/apply_fabric_client_utils.sh index b2eab75dc8..202c02a9da 100755 --- a/scripts/third_party_pins/fabric/apply_fabric_client_utils.sh +++ b/scripts/third_party_pins/fabric/apply_fabric_client_utils.sh @@ -37,9 +37,6 @@ declare -a PKGS=( "sdkpatch/logbridge" "sdkpatch/cryptosuitebridge" - "core/common/ccprovider" - - "core/ledger/kvledger/txmgmt/rwsetutil" "core/ledger/kvledger/txmgmt/version" "core/ledger/util" @@ -108,15 +105,12 @@ declare -a FILES=( "common/channelconfig/organization.go" "common/ledger/ledger_interface.go" - "core/common/ccprovider/ccprovider.go" "sdkpatch/logbridge/logbridge.go" "sdkpatch/cryptosuitebridge/cryptosuitebridge.go" "core/ledger/ledger_interface.go" - "core/ledger/kvledger/txmgmt/rwsetutil/rwset_proto_util.go" "core/ledger/kvledger/txmgmt/version/version.go" - "core/ledger/util/txvalidationflags.go" "events/consumer/adapter.go" @@ -206,23 +200,10 @@ FILTER_FILENAME="common/channelconfig/organization.go" FILTER_FN= gofilter -FILTER_FILENAME="core/ledger/kvledger/txmgmt/rwsetutil/rwset_proto_util.go" -FILTER_FN="NewHeight,ToProtoBytes,toProtoMsg" -gofilter - FILTER_FILENAME="core/ledger/kvledger/txmgmt/version/version.go" FILTER_FN= gofilter -FILTER_FILENAME="core/ledger/util/txvalidationflags.go" -FILTER_FN="IsValid,IsInvalid,Flag,IsSetTo,NewTxValidationFlags" -gofilter - - -FILTER_FILENAME="core/common/ccprovider/ccprovider.go" -FILTER_FN=Reset,String,ProtoMessage -gofilter -sed -i'' -e 's/var ccInfoCache = NewCCInfoCache(ccInfoFSProvider)//g' "${TMP_PROJECT_PATH}/${FILTER_FILENAME}" FILTER_FILENAME="events/consumer/adapter.go" FILTER_FN= diff --git a/scripts/third_party_pins/fabric/apply_fabric_external_utils.sh b/scripts/third_party_pins/fabric/apply_fabric_external_utils.sh index 90a55987f1..f4f53ff2f6 100755 --- a/scripts/third_party_pins/fabric/apply_fabric_external_utils.sh +++ b/scripts/third_party_pins/fabric/apply_fabric_external_utils.sh @@ -14,14 +14,26 @@ set -e IMPORT_SUBSTS=($IMPORT_SUBSTS) GOIMPORTS_CMD=goimports +GOFILTER_CMD="go run scripts/_go/cmd/gofilter/gofilter.go" declare -a PKGS=( "common/cauthdsl" + "protos/utils" + "core/common/ccprovider" + "core/ledger/kvledger/txmgmt/rwsetutil" + "core/ledger/util" ) declare -a FILES=( "common/cauthdsl/cauthdsl_builder.go" "common/cauthdsl/policyparser.go" + "protos/utils/commonutils.go" + "protos/utils/proputils.go" + "protos/utils/txutils.go" + "core/common/ccprovider/ccprovider.go" + "core/common/ccprovider/cdspackage.go" + "core/ledger/kvledger/txmgmt/rwsetutil/rwset_proto_util.go" + "core/ledger/util/txvalidationflags.go" ) echo 'Removing current upstream project from working directory ...' @@ -34,6 +46,55 @@ do mkdir -p $INTERNAL_PATH/${i} done +# Apply fine-grained patching +gofilter() { + echo "Filtering: ${FILTER_FILENAME}" + cp ${TMP_PROJECT_PATH}/${FILTER_FILENAME} ${TMP_PROJECT_PATH}/${FILTER_FILENAME}.bak + $GOFILTER_CMD -filename "${TMP_PROJECT_PATH}/${FILTER_FILENAME}.bak" \ + -filters fn -fn "$FILTER_FN" \ + > "${TMP_PROJECT_PATH}/${FILTER_FILENAME}" +} + +echo "Filtering Go sources for allowed functions ..." +FILTER_FILENAME="protos/utils/commonutils.go" +FILTER_FN="UnmarshalChannelHeader,MarshalOrPanic,UnmarshalChannelHeader,MakeChannelHeader,MakePayloadHeader,ExtractPayload" +FILTER_FN+=",Marshal,ExtractEnvelope,ExtractEnvelopeOrPanic,ExtractPayloadOrPanic" +gofilter + +FILTER_FILENAME="protos/utils/proputils.go" +FILTER_FN="GetHeader,GetChaincodeProposalPayload,GetSignatureHeader,GetChaincodeHeaderExtension,GetBytesChaincodeActionPayload" +FILTER_FN+=",GetBytesTransaction,GetBytesPayload,GetHeader,GetBytesProposalResponsePayload,GetBytesProposal,CreateChaincodeProposal" +FILTER_FN+=",GetBytesChaincodeProposalPayload,CreateChaincodeProposalWithTransient,ComputeProposalTxID" +FILTER_FN+=",CreateChaincodeProposalWithTxIDNonceAndTransient,CreateDeployProposalFromCDS,CreateUpgradeProposalFromCDS" +FILTER_FN+=",createProposalFromCDS,CreateProposalFromCIS,CreateInstallProposalFromCDS,GetTransaction,GetPayload" +FILTER_FN+=",GetChaincodeActionPayload,GetProposalResponsePayload,GetChaincodeAction,GetChaincodeEvents,GetBytesChaincodeEvent,GetBytesEnvelope" +gofilter +sed -i'' -e 's/"github.com\/hyperledger\/fabric\/bccsp\/factory"/factory "github.com\/hyperledger\/fabric-sdk-go\/internal\/github.com\/hyperledger\/fabric\/sdkpatch\/cryptosuitebridge"/g' "${TMP_PROJECT_PATH}/${FILTER_FILENAME}" +sed -i'' -e 's/&bccsp.SHA256Opts{}/factory.GetSHA256Opts()/g' "${TMP_PROJECT_PATH}/${FILTER_FILENAME}" + +FILTER_FILENAME="protos/utils/txutils.go" +FILTER_FN="GetBytesProposalPayloadForTx,GetEnvelopeFromBlock" +gofilter + +FILTER_FILENAME="core/common/ccprovider/ccprovider.go" +FILTER_FN=Reset,String,ProtoMessage +gofilter +sed -i'' -e 's/var ccInfoCache = NewCCInfoCache(ccInfoFSProvider)//g' "${TMP_PROJECT_PATH}/${FILTER_FILENAME}" + +FILTER_FILENAME="core/common/ccprovider/cdspackage.go" +FILTER_FN=Reset,String,ProtoMessage +gofilter +sed -i'' -e 's/var ccInfoCache = NewCCInfoCache(ccInfoFSProvider)//g' "${TMP_PROJECT_PATH}/${FILTER_FILENAME}" + +FILTER_FILENAME="core/ledger/kvledger/txmgmt/rwsetutil/rwset_proto_util.go" +FILTER_FN="NewHeight,ToProtoBytes,FromProtoBytes,toProtoMsg,TxRwSetFromProtoMsg,TxPvtRwSetFromProtoMsg,nsRwSetFromProtoMsg,nsPvtRwSetFromProtoMsg" +FILTER_FN+=",collHashedRwSetFromProtoMsg,collPvtRwSetFromProtoMsg" +gofilter + +FILTER_FILENAME="core/ledger/util/txvalidationflags.go" +FILTER_FN="IsValid,IsInvalid,Flag,IsSetTo,NewTxValidationFlags" +gofilter + # Apply patching echo "Patching import paths on upstream project ..." WORKING_DIR=$TMP_PROJECT_PATH FILES="${FILES[@]}" IMPORT_SUBSTS="${IMPORT_SUBSTS[@]}" scripts/third_party_pins/common/apply_import_patching.sh diff --git a/scripts/third_party_pins/fabric/apply_fabric_protos.sh b/scripts/third_party_pins/fabric/apply_fabric_protos.sh index 5b45390f7b..e4d1b44419 100755 --- a/scripts/third_party_pins/fabric/apply_fabric_protos.sh +++ b/scripts/third_party_pins/fabric/apply_fabric_protos.sh @@ -55,10 +55,6 @@ declare -a FILES=( "protos/orderer/configuration.pb.go" ) -echo 'Removing current upstream project from working directory ...' -rm -Rf "${INTERNAL_PATH}/protos" -mkdir -p "${INTERNAL_PATH}/protos" - # Create directory structure for packages for i in "${PKGS[@]}" do diff --git a/scripts/third_party_pins/fabric/apply_fabric_protos_internal.sh b/scripts/third_party_pins/fabric/apply_fabric_protos_internal.sh index 67b337070c..0d670fdbe6 100755 --- a/scripts/third_party_pins/fabric/apply_fabric_protos_internal.sh +++ b/scripts/third_party_pins/fabric/apply_fabric_protos_internal.sh @@ -23,16 +23,10 @@ declare -a PKGS=( ) declare -a FILES=( - "protos/utils/commonutils.go" - "protos/utils/proputils.go" - "protos/utils/txutils.go" "protos/orderer/ab.pb.go" ) declare -a NPBFILES=( - "protos/utils/commonutils.go" - "protos/utils/proputils.go" - "protos/utils/txutils.go" ) declare -a PBFILES=( @@ -58,27 +52,6 @@ gofilter() { > "${TMP_PROJECT_PATH}/${FILTER_FILENAME}" } -echo "Filtering Go sources for allowed functions ..." -FILTER_FILENAME="protos/utils/commonutils.go" -FILTER_FN="UnmarshalChannelHeader,MarshalOrPanic,UnmarshalChannelHeader,MakeChannelHeader,MakePayloadHeader,ExtractPayload" -FILTER_FN+=",Marshal" -gofilter - -FILTER_FILENAME="protos/utils/proputils.go" -FILTER_FN="GetHeader,GetChaincodeProposalPayload,GetSignatureHeader,GetChaincodeHeaderExtension,GetBytesChaincodeActionPayload" -FILTER_FN+=",GetBytesTransaction,GetBytesPayload,GetHeader,GetBytesProposalResponsePayload,GetBytesProposal,CreateChaincodeProposal" -FILTER_FN+=",GetBytesChaincodeProposalPayload,CreateChaincodeProposalWithTransient,ComputeProposalTxID" -FILTER_FN+=",CreateChaincodeProposalWithTxIDNonceAndTransient,CreateDeployProposalFromCDS,CreateUpgradeProposalFromCDS" -FILTER_FN+=",createProposalFromCDS,CreateProposalFromCIS,CreateInstallProposalFromCDS,GetTransaction,GetPayload" -FILTER_FN+=",GetChaincodeActionPayload,GetProposalResponsePayload,GetChaincodeAction,GetChaincodeEvents,GetBytesChaincodeEvent,GetBytesEnvelope" -gofilter -sed -i'' -e 's/"github.com\/hyperledger\/fabric\/bccsp\/factory"/factory "github.com\/hyperledger\/fabric-sdk-go\/internal\/github.com\/hyperledger\/fabric\/sdkpatch\/cryptosuitebridge"/g' "${TMP_PROJECT_PATH}/${FILTER_FILENAME}" -sed -i'' -e 's/&bccsp.SHA256Opts{}/factory.GetSHA256Opts()/g' "${TMP_PROJECT_PATH}/${FILTER_FILENAME}" - -FILTER_FILENAME="protos/utils/txutils.go" -FILTER_FN="GetBytesProposalPayloadForTx,GetEnvelopeFromBlock" -gofilter - # Apply patching echo "Patching import paths on upstream project ..." WORKING_DIR=$TMP_PROJECT_PATH FILES="${FILES[@]}" IMPORT_SUBSTS="${IMPORT_SUBSTS[@]}" scripts/third_party_pins/common/apply_import_patching.sh diff --git a/scripts/third_party_pins/fabric/apply_upstream.sh b/scripts/third_party_pins/fabric/apply_upstream.sh index 94f2f799e9..491dab30c8 100755 --- a/scripts/third_party_pins/fabric/apply_upstream.sh +++ b/scripts/third_party_pins/fabric/apply_upstream.sh @@ -43,6 +43,10 @@ git am ${CWD}/${PATCHES_PATH}/* cd $CWD +echo 'Removing current upstream project from working directory ...' +rm -Rf "${THIRDPARTY_FABRIC_PATH}/protos" +mkdir -p "${THIRDPARTY_FABRIC_PATH}/protos" + # fabric client utils echo "Pinning and patching fabric client utils..." declare -a CLIENT_UTILS_IMPORT_SUBSTS=( @@ -57,17 +61,24 @@ declare -a CLIENT_UTILS_IMPORT_SUBSTS=( 's/\"github.com\/hyperledger\/fabric\/protos\/msp/\"github.com\/hyperledger\/fabric-sdk-go\/third_party\/github.com\/hyperledger\/fabric\/protos\/msp/g' 's/\"github.com\/hyperledger\/fabric\/protos\/orderer/\"github.com\/hyperledger\/fabric-sdk-go\/third_party\/github.com\/hyperledger\/fabric\/protos\/orderer/g' 's/\"github.com\/hyperledger\/fabric\/protos\/ledger/\"github.com\/hyperledger\/fabric-sdk-go\/third_party\/github.com\/hyperledger\/fabric\/protos\/ledger/g' + 's/\"github.com\/hyperledger\/fabric\/protos\/utils/\"github.com\/hyperledger\/fabric-sdk-go\/third_party\/github.com\/hyperledger\/fabric\/protos\/utils/g' 's/\"github.com\/hyperledger\/fabric\/protos/\"github.com\/hyperledger\/fabric-sdk-go\/internal\/github.com\/hyperledger\/fabric\/protos/g' 's/\"github.com\/hyperledger\/fabric\//\"github.com\/hyperledger\/fabric-sdk-go\/internal\/github.com\/hyperledger\/fabric\//g' ) + eval "INTERNAL_PATH=$THIRDPARTY_INTERNAL_FABRIC_PATH TMP_PROJECT_PATH=$TMP_PROJECT_PATH IMPORT_SUBSTS=\"${CLIENT_UTILS_IMPORT_SUBSTS[*]}\" $SCRIPTS_PATH/apply_fabric_client_utils.sh" # external utils echo "Pinning and patching fabric external utils ..." declare -a EXTERNAL_UTILS_IMPORT_SUBSTS=( 's/\"github.com\/pkg\/errors/\"github.com\/hyperledger\/fabric-sdk-go\/pkg\/errors/g' + 's/\"github.com\/hyperledger\/fabric\/common\/flogging/flogging\"github.com\/hyperledger\/fabric-sdk-go\/internal\/github.com\/hyperledger\/fabric\/sdkpatch\/logbridge/g' + 's/\"github.com\/hyperledger\/fabric\/common\/cauthdsl/\"github.com\/hyperledger\/fabric-sdk-go\/third_party\/github.com\/hyperledger\/fabric\/common\/cauthdsl/g' 's/\"github.com\/hyperledger\/fabric\/protos\/common/\"github.com\/hyperledger\/fabric-sdk-go\/third_party\/github.com\/hyperledger\/fabric\/protos\/common/g' 's/\"github.com\/hyperledger\/fabric\/protos\/msp/\"github.com\/hyperledger\/fabric-sdk-go\/third_party\/github.com\/hyperledger\/fabric\/protos\/msp/g' + 's/\"github.com\/hyperledger\/fabric\/protos\/peer/\"github.com\/hyperledger\/fabric-sdk-go\/third_party\/github.com\/hyperledger\/fabric\/protos\/peer/g' + 's/\"github.com\/hyperledger\/fabric\/protos\/ledger/\"github.com\/hyperledger\/fabric-sdk-go\/third_party\/github.com\/hyperledger\/fabric\/protos\/ledger/g' + 's/\"github.com\/hyperledger\/fabric\/protos\/utils/\"github.com\/hyperledger\/fabric-sdk-go\/third_party\/github.com\/hyperledger\/fabric\/protos\/utils/g' 's/\"github.com\/hyperledger\/fabric\//\"github.com\/hyperledger\/fabric-sdk-go\/internal\/github.com\/hyperledger\/fabric\//g' ) eval "INTERNAL_PATH=$THIRDPARTY_FABRIC_PATH TMP_PROJECT_PATH=$TMP_PROJECT_PATH IMPORT_SUBSTS=\"${EXTERNAL_UTILS_IMPORT_SUBSTS[*]}\" $SCRIPTS_PATH/apply_fabric_external_utils.sh" @@ -78,6 +89,10 @@ declare -a PROTOS_IMPORT_SUBSTS=( 's/\"github.com\/pkg\/errors/\"github.com\/hyperledger\/fabric-sdk-go\/pkg\/errors/g' 's/\"github.com\/hyperledger\/fabric\/common\/flogging/flogging\"github.com\/hyperledger\/fabric-sdk-go\/internal\/github.com\/hyperledger\/fabric\/sdkpatch\/logbridge/g' 's/\"github.com\/hyperledger\/fabric\/bccsp/\"github.com\/hyperledger\/fabric-sdk-go\/internal\/github.com\/hyperledger\/fabric\/bccsp/g' + 's/\"github.com\/hyperledger\/fabric\/common\/cauthdsl/\"github.com\/hyperledger\/fabric-sdk-go\/third_party\/github.com\/hyperledger\/fabric\/common\/cauthdsl/g' + 's/\"github.com\/hyperledger\/fabric\/protos\/peer/\"github.com\/hyperledger\/fabric-sdk-go\/third_party\/github.com\/hyperledger\/fabric\/protos\/peer/g' + 's/\"github.com\/hyperledger\/fabric\/protos\/ledger/\"github.com\/hyperledger\/fabric-sdk-go\/third_party\/github.com\/hyperledger\/fabric\/protos\/ledger/g' + 's/\"github.com\/hyperledger\/fabric\/protos\/utils/\"github.com\/hyperledger\/fabric-sdk-go\/third_party\/github.com\/hyperledger\/fabric\/protos\/utils/g' 's/\"github.com\/hyperledger\/fabric\/protos\//\"github.com\/hyperledger\/fabric-sdk-go\/third_party\/github.com\/hyperledger\/fabric\/protos\//g' 's/\"github.com\/hyperledger\/fabric\//\"github.com\/hyperledger\/fabric-sdk-go\/internal\/github.com\/hyperledger\/fabric\//g' ) @@ -89,11 +104,13 @@ declare -a PROTOS_INTERNAL_IMPORT_SUBSTS=( 's/\"github.com\/pkg\/errors/\"github.com\/hyperledger\/fabric-sdk-go\/pkg\/errors/g' 's/\"github.com\/hyperledger\/fabric\/common\/flogging/factory\"github.com\/hyperledger\/fabric-sdk-go\/internal\/github.com\/hyperledger\/fabric\/sdkpatch\/logbridge/g' 's/\"github.com\/hyperledger\/fabric\/bccsp/\"github.com\/hyperledger\/fabric-sdk-go\/internal\/github.com\/hyperledger\/fabric\/bccsp/g' + 's/\"github.com\/hyperledger\/fabric\/common\/cauthdsl/\"github.com\/hyperledger\/fabric-sdk-go\/third_party\/github.com\/hyperledger\/fabric\/common\/cauthdsl/g' 's/\"github.com\/hyperledger\/fabric\/protos\/common/\"github.com\/hyperledger\/fabric-sdk-go\/third_party\/github.com\/hyperledger\/fabric\/protos\/common/g' 's/\"github.com\/hyperledger\/fabric\/protos\/peer/\"github.com\/hyperledger\/fabric-sdk-go\/third_party\/github.com\/hyperledger\/fabric\/protos\/peer/g' 's/\"github.com\/hyperledger\/fabric\/protos\/msp/\"github.com\/hyperledger\/fabric-sdk-go\/third_party\/github.com\/hyperledger\/fabric\/protos\/msp/g' 's/\"github.com\/hyperledger\/fabric\/protos\/orderer/\"github.com\/hyperledger\/fabric-sdk-go\/third_party\/github.com\/hyperledger\/fabric\/protos\/orderer/g' 's/\"github.com\/hyperledger\/fabric\/protos\/ledger/\"github.com\/hyperledger\/fabric-sdk-go\/third_party\/github.com\/hyperledger\/fabric\/protos\/ledger/g' + 's/\"github.com\/hyperledger\/fabric\/protos\/utils/\"github.com\/hyperledger\/fabric-sdk-go\/third_party\/github.com\/hyperledger\/fabric\/protos\/utils/g' 's/\"github.com\/hyperledger\/fabric\/protos/\"github.com\/hyperledger\/fabric-sdk-go\/internal\/github.com\/hyperledger\/fabric\/protos/g' 's/\"github.com\/hyperledger\/fabric\//\"github.com\/hyperledger\/fabric-sdk-go\/internal\/github.com\/hyperledger\/fabric\//g' ) diff --git a/third_party/github.com/hyperledger/fabric/common/cauthdsl/cauthdsl_builder.go b/third_party/github.com/hyperledger/fabric/common/cauthdsl/cauthdsl_builder.go index f944e15b61..3662515f23 100644 --- a/third_party/github.com/hyperledger/fabric/common/cauthdsl/cauthdsl_builder.go +++ b/third_party/github.com/hyperledger/fabric/common/cauthdsl/cauthdsl_builder.go @@ -27,7 +27,7 @@ import ( "sort" "github.com/golang/protobuf/proto" - "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/protos/utils" + "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/utils" ) // AcceptAllPolicy always evaluates to true diff --git a/third_party/github.com/hyperledger/fabric/common/cauthdsl/policyparser.go b/third_party/github.com/hyperledger/fabric/common/cauthdsl/policyparser.go index 6916588697..8e7d23e717 100644 --- a/third_party/github.com/hyperledger/fabric/common/cauthdsl/policyparser.go +++ b/third_party/github.com/hyperledger/fabric/common/cauthdsl/policyparser.go @@ -27,9 +27,9 @@ import ( "strconv" "github.com/Knetic/govaluate" - "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/protos/utils" "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common" "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/msp" + "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/utils" ) var regex *regexp.Regexp = regexp.MustCompile("^([[:alnum:]]+)([.])(member|admin|client|peer|orderer)$") diff --git a/internal/github.com/hyperledger/fabric/core/common/ccprovider/ccprovider.go b/third_party/github.com/hyperledger/fabric/core/common/ccprovider/ccprovider.go similarity index 100% rename from internal/github.com/hyperledger/fabric/core/common/ccprovider/ccprovider.go rename to third_party/github.com/hyperledger/fabric/core/common/ccprovider/ccprovider.go diff --git a/third_party/github.com/hyperledger/fabric/core/common/ccprovider/cdspackage.go b/third_party/github.com/hyperledger/fabric/core/common/ccprovider/cdspackage.go new file mode 100644 index 0000000000..8c3e7fd517 --- /dev/null +++ b/third_party/github.com/hyperledger/fabric/core/common/ccprovider/cdspackage.go @@ -0,0 +1,62 @@ +/* +Copyright IBM Corp. 2017 All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +/* +Notice: This file has been modified for Hyperledger Fabric SDK Go usage. +Please review third_party pinning scripts and patches for more details. +*/ + +package ccprovider + +import ( + "github.com/golang/protobuf/proto" + + pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer" +) + +//----- CDSData ------ + +//CDSData is data stored in the LSCC on instantiation of a CC +//for CDSPackage. This needs to be serialized for ChaincodeData +//hence the protobuf format +type CDSData struct { + //CodeHash hash of CodePackage from ChaincodeDeploymentSpec + CodeHash []byte `protobuf:"bytes,1,opt,name=codehash,proto3"` + + //MetaDataHash hash of Name and Version from ChaincodeDeploymentSpec + MetaDataHash []byte `protobuf:"bytes,2,opt,name=metadatahash,proto3"` +} + +//----implement functions needed from proto.Message for proto's mar/unmarshal functions + +//Reset resets +func (data *CDSData) Reset() { *data = CDSData{} } + +//String converts to string +func (data *CDSData) String() string { return proto.CompactTextString(data) } + +//ProtoMessage just exists to make proto happy +func (*CDSData) ProtoMessage() {} + +//--------- CDSPackage ------------ + +//CDSPackage encapsulates ChaincodeDeploymentSpec. +type CDSPackage struct { + buf []byte + depSpec *pb.ChaincodeDeploymentSpec + data *CDSData + datab []byte + id []byte +} diff --git a/internal/github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/rwsetutil/rwset_proto_util.go b/third_party/github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/rwsetutil/rwset_proto_util.go similarity index 63% rename from internal/github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/rwsetutil/rwset_proto_util.go rename to third_party/github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/rwsetutil/rwset_proto_util.go index 78bd8a24e6..cdadcbc36b 100644 --- a/internal/github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/rwsetutil/rwset_proto_util.go +++ b/third_party/github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/rwsetutil/rwset_proto_util.go @@ -85,6 +85,21 @@ func (txRwSet *TxRwSet) ToProtoBytes() ([]byte, error) { return proto.Marshal(protoMsg) } +// FromProtoBytes deserializes protobytes into TxReadWriteSet proto message and populates 'TxRwSet' +func (txRwSet *TxRwSet) FromProtoBytes(protoBytes []byte) error { + protoMsg := &rwset.TxReadWriteSet{} + var err error + var txRwSetTemp *TxRwSet + if err = proto.Unmarshal(protoBytes, protoMsg); err != nil { + return err + } + if txRwSetTemp, err = TxRwSetFromProtoMsg(protoMsg); err != nil { + return err + } + txRwSet.NsRwSets = txRwSetTemp.NsRwSets + return nil +} + // ToProtoBytes constructs 'TxPvtReadWriteSet' proto message and serializes using protobuf Marshal func (txPvtRwSet *TxPvtRwSet) ToProtoBytes() ([]byte, error) { var protoMsg *rwset.TxPvtReadWriteSet @@ -95,6 +110,21 @@ func (txPvtRwSet *TxPvtRwSet) ToProtoBytes() ([]byte, error) { return proto.Marshal(protoMsg) } +// FromProtoBytes deserializes protobytes into 'TxPvtReadWriteSet' proto message and populates 'TxPvtRwSet' +func (txPvtRwSet *TxPvtRwSet) FromProtoBytes(protoBytes []byte) error { + protoMsg := &rwset.TxPvtReadWriteSet{} + var err error + var txPvtRwSetTemp *TxPvtRwSet + if err = proto.Unmarshal(protoBytes, protoMsg); err != nil { + return err + } + if txPvtRwSetTemp, err = TxPvtRwSetFromProtoMsg(protoMsg); err != nil { + return err + } + txPvtRwSet.NsPvtRwSet = txPvtRwSetTemp.NsPvtRwSet + return nil +} + func (txRwSet *TxRwSet) toProtoMsg() (*rwset.TxReadWriteSet, error) { protoMsg := &rwset.TxReadWriteSet{DataModel: rwset.TxReadWriteSet_KV} var nsRwSetProtoMsg *rwset.NsReadWriteSet @@ -108,6 +138,19 @@ func (txRwSet *TxRwSet) toProtoMsg() (*rwset.TxReadWriteSet, error) { return protoMsg, nil } +func TxRwSetFromProtoMsg(protoMsg *rwset.TxReadWriteSet) (*TxRwSet, error) { + txRwSet := &TxRwSet{} + var nsRwSet *NsRwSet + var err error + for _, nsRwSetProtoMsg := range protoMsg.NsRwset { + if nsRwSet, err = nsRwSetFromProtoMsg(nsRwSetProtoMsg); err != nil { + return nil, err + } + txRwSet.NsRwSets = append(txRwSet.NsRwSets, nsRwSet) + } + return txRwSet, nil +} + func (nsRwSet *NsRwSet) toProtoMsg() (*rwset.NsReadWriteSet, error) { var err error protoMsg := &rwset.NsReadWriteSet{Namespace: nsRwSet.NameSpace} @@ -125,6 +168,22 @@ func (nsRwSet *NsRwSet) toProtoMsg() (*rwset.NsReadWriteSet, error) { return protoMsg, nil } +func nsRwSetFromProtoMsg(protoMsg *rwset.NsReadWriteSet) (*NsRwSet, error) { + nsRwSet := &NsRwSet{NameSpace: protoMsg.Namespace, KvRwSet: &kvrwset.KVRWSet{}} + if err := proto.Unmarshal(protoMsg.Rwset, nsRwSet.KvRwSet); err != nil { + return nil, err + } + var err error + var collHashedRwSet *CollHashedRwSet + for _, collHashedRwSetProtoMsg := range protoMsg.CollectionHashedRwset { + if collHashedRwSet, err = collHashedRwSetFromProtoMsg(collHashedRwSetProtoMsg); err != nil { + return nil, err + } + nsRwSet.CollHashedRwSets = append(nsRwSet.CollHashedRwSets, collHashedRwSet) + } + return nsRwSet, nil +} + func (collHashedRwSet *CollHashedRwSet) toProtoMsg() (*rwset.CollectionHashedReadWriteSet, error) { var err error protoMsg := &rwset.CollectionHashedReadWriteSet{ @@ -137,6 +196,18 @@ func (collHashedRwSet *CollHashedRwSet) toProtoMsg() (*rwset.CollectionHashedRea return protoMsg, nil } +func collHashedRwSetFromProtoMsg(protoMsg *rwset.CollectionHashedReadWriteSet) (*CollHashedRwSet, error) { + colHashedRwSet := &CollHashedRwSet{ + CollectionName: protoMsg.CollectionName, + PvtRwSetHash: protoMsg.PvtRwsetHash, + HashedRwSet: &kvrwset.HashedRWSet{}, + } + if err := proto.Unmarshal(protoMsg.HashedRwset, colHashedRwSet.HashedRwSet); err != nil { + return nil, err + } + return colHashedRwSet, nil +} + /////////////////////////////////////////////////////////////////////////////// // functions for private read-write set /////////////////////////////////////////////////////////////////////////////// @@ -154,6 +225,19 @@ func (txPvtRwSet *TxPvtRwSet) toProtoMsg() (*rwset.TxPvtReadWriteSet, error) { return protoMsg, nil } +func TxPvtRwSetFromProtoMsg(protoMsg *rwset.TxPvtReadWriteSet) (*TxPvtRwSet, error) { + txPvtRwset := &TxPvtRwSet{} + var nsPvtRwSet *NsPvtRwSet + var err error + for _, nsRwSetProtoMsg := range protoMsg.NsPvtRwset { + if nsPvtRwSet, err = nsPvtRwSetFromProtoMsg(nsRwSetProtoMsg); err != nil { + return nil, err + } + txPvtRwset.NsPvtRwSet = append(txPvtRwset.NsPvtRwSet, nsPvtRwSet) + } + return txPvtRwset, nil +} + func (nsPvtRwSet *NsPvtRwSet) toProtoMsg() (*rwset.NsPvtReadWriteSet, error) { protoMsg := &rwset.NsPvtReadWriteSet{Namespace: nsPvtRwSet.NameSpace} var err error @@ -167,6 +251,19 @@ func (nsPvtRwSet *NsPvtRwSet) toProtoMsg() (*rwset.NsPvtReadWriteSet, error) { return protoMsg, err } +func nsPvtRwSetFromProtoMsg(protoMsg *rwset.NsPvtReadWriteSet) (*NsPvtRwSet, error) { + nsPvtRwSet := &NsPvtRwSet{NameSpace: protoMsg.Namespace} + for _, collPvtRwSetProtoMsg := range protoMsg.CollectionPvtRwset { + var err error + var collPvtRwSet *CollPvtRwSet + if collPvtRwSet, err = collPvtRwSetFromProtoMsg(collPvtRwSetProtoMsg); err != nil { + return nil, err + } + nsPvtRwSet.CollPvtRwSets = append(nsPvtRwSet.CollPvtRwSets, collPvtRwSet) + } + return nsPvtRwSet, nil +} + func (collPvtRwSet *CollPvtRwSet) toProtoMsg() (*rwset.CollectionPvtReadWriteSet, error) { var err error protoMsg := &rwset.CollectionPvtReadWriteSet{CollectionName: collPvtRwSet.CollectionName} @@ -175,3 +272,11 @@ func (collPvtRwSet *CollPvtRwSet) toProtoMsg() (*rwset.CollectionPvtReadWriteSet } return protoMsg, nil } + +func collPvtRwSetFromProtoMsg(protoMsg *rwset.CollectionPvtReadWriteSet) (*CollPvtRwSet, error) { + collPvtRwSet := &CollPvtRwSet{CollectionName: protoMsg.CollectionName, KvRwSet: &kvrwset.KVRWSet{}} + if err := proto.Unmarshal(protoMsg.Rwset, collPvtRwSet.KvRwSet); err != nil { + return nil, err + } + return collPvtRwSet, nil +} diff --git a/internal/github.com/hyperledger/fabric/core/ledger/util/txvalidationflags.go b/third_party/github.com/hyperledger/fabric/core/ledger/util/txvalidationflags.go similarity index 100% rename from internal/github.com/hyperledger/fabric/core/ledger/util/txvalidationflags.go rename to third_party/github.com/hyperledger/fabric/core/ledger/util/txvalidationflags.go diff --git a/internal/github.com/hyperledger/fabric/protos/utils/commonutils.go b/third_party/github.com/hyperledger/fabric/protos/utils/commonutils.go similarity index 67% rename from internal/github.com/hyperledger/fabric/protos/utils/commonutils.go rename to third_party/github.com/hyperledger/fabric/protos/utils/commonutils.go index 6fcc442044..639731d41d 100644 --- a/internal/github.com/hyperledger/fabric/protos/utils/commonutils.go +++ b/third_party/github.com/hyperledger/fabric/protos/utils/commonutils.go @@ -43,6 +43,42 @@ func Marshal(pb proto.Message) ([]byte, error) { return proto.Marshal(pb) } +// ExtractEnvelopeOrPanic retrieves the requested envelope from a given block and unmarshals it -- it panics if either of these operation fail. +func ExtractEnvelopeOrPanic(block *cb.Block, index int) *cb.Envelope { + envelope, err := ExtractEnvelope(block, index) + if err != nil { + panic(err) + } + return envelope +} + +// ExtractEnvelope retrieves the requested envelope from a given block and unmarshals it. +func ExtractEnvelope(block *cb.Block, index int) (*cb.Envelope, error) { + if block.Data == nil { + return nil, fmt.Errorf("No data in block") + } + + envelopeCount := len(block.Data.Data) + if index < 0 || index >= envelopeCount { + return nil, fmt.Errorf("Envelope index out of bounds") + } + marshaledEnvelope := block.Data.Data[index] + envelope, err := GetEnvelopeFromBlock(marshaledEnvelope) + if err != nil { + return nil, fmt.Errorf("Block data does not carry an envelope at index %d: %s", index, err) + } + return envelope, nil +} + +// ExtractPayloadOrPanic retrieves the payload of a given envelope and unmarshals it -- it panics if either of these operations fail. +func ExtractPayloadOrPanic(envelope *cb.Envelope) *cb.Payload { + payload, err := ExtractPayload(envelope) + if err != nil { + panic(err) + } + return payload +} + // ExtractPayload retrieves the payload of a given envelope and unmarshals it. func ExtractPayload(envelope *cb.Envelope) (*cb.Payload, error) { payload := &cb.Payload{} diff --git a/internal/github.com/hyperledger/fabric/protos/utils/proputils.go b/third_party/github.com/hyperledger/fabric/protos/utils/proputils.go similarity index 100% rename from internal/github.com/hyperledger/fabric/protos/utils/proputils.go rename to third_party/github.com/hyperledger/fabric/protos/utils/proputils.go diff --git a/internal/github.com/hyperledger/fabric/protos/utils/txutils.go b/third_party/github.com/hyperledger/fabric/protos/utils/txutils.go similarity index 100% rename from internal/github.com/hyperledger/fabric/protos/utils/txutils.go rename to third_party/github.com/hyperledger/fabric/protos/utils/txutils.go