Skip to content

Commit

Permalink
fix(weaver-go-sdk): use updated weaver protobuf for fabric and corda …
Browse files Browse the repository at this point in the history
…view

Signed-off-by: Sandeep Nishad <[email protected]>
  • Loading branch information
sandeepnRES committed May 17, 2024
1 parent 4ec24d2 commit 27225eb
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 9 deletions.
11 changes: 10 additions & 1 deletion sdks/fabric/go-sdk/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ undo-vendor:
build-local: run-vendor build undo-vendor

build:
go build -v .
cd helpers && go build -v .
cd asset-manager && go build -v .
cd interoperablehelper && go build -v .

test-local: run-vendor test undo-vendor

test:
cd helpers && go test -v .
cd asset-manager && go test -v .
cd interoperablehelper && go test -v .

clean:
rm -rf vendor
61 changes: 53 additions & 8 deletions sdks/fabric/go-sdk/interoperablehelper/interoperable-helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@ SPDX-License-Identifier: Apache-2.0
package interoperablehelper

import (
"bytes"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"strings"

"github.com/golang/protobuf/proto"
"github.com/google/uuid"
"github.com/hyperledger-labs/weaver-dlt-interoperability/common/protos-go/common"
"github.com/hyperledger-labs/weaver-dlt-interoperability/common/protos-go/corda"
"github.com/hyperledger-labs/weaver-dlt-interoperability/common/protos-go/fabric"
"github.com/hyperledger-labs/weaver-dlt-interoperability/sdks/fabric/go-sdk/helpers"
"github.com/hyperledger-labs/weaver-dlt-interoperability/sdks/fabric/go-sdk/relay"
"github.com/hyperledger-labs/weaver-dlt-interoperability/sdks/fabric/go-sdk/types"
"github.com/hyperledger/fabric-protos-go/peer"
log "github.com/sirupsen/logrus"
protoV2 "google.golang.org/protobuf/proto"
)
Expand Down Expand Up @@ -220,31 +223,73 @@ func isPatternAndAddressMatch(pattern string, address string) bool {
* Argument is a View protobuf ('statePb.View')
**/
func GetResponseDataFromView(view *common.View) ([]byte, error) {
var interopPayload common.InteropPayload
var viewAddress string
var viewPayload []byte
if view.Meta.Protocol == common.Meta_FABRIC {
var fabricViewData fabric.FabricView
err := protoV2.Unmarshal(view.Data, &fabricViewData)
if err != nil {
return nil, logThenErrorf("fabricView unmarshal error: %s", err.Error())
}
err = protoV2.Unmarshal(fabricViewData.Response.Payload, &interopPayload)
if err != nil {
return nil, logThenErrorf("unable to unmarshal interopPayload: %s", err.Error())
for i := 0; i < len(fabricViewData.EndorsedProposalResponses); i++ {
var ccAction peer.ChaincodeAction
err = proto.Unmarshal(fabricViewData.EndorsedProposalResponses[i].GetPayload().GetExtension(), &ccAction)
if err != nil {
return nil, logThenErrorf("unable to unmarshal chaincodeAction: %s", err.Error())
}
var interopPayload common.InteropPayload
err = protoV2.Unmarshal(ccAction.Response.Payload, &interopPayload)
if err != nil {
return nil, logThenErrorf("unable to unmarshal interopPayload: %s", err.Error())
}
if interopPayload.GetConfidential() {
// TODO Add support for confidential (encrypted) view payloads
return nil, logThenErrorf("Encrypted view payloads not currently supported in Weaver Go SDK")
}
if i == 0 {
viewAddress = interopPayload.GetAddress()
viewPayload = interopPayload.GetPayload()
} else {
if viewAddress != interopPayload.GetAddress() {
return nil, logThenErrorf("Proposal response view addresses mismatch: 0 - %s, %d - %s", viewAddress, i, interopPayload.GetAddress())
}
if bytes.Compare(viewPayload, interopPayload.GetPayload()) != 0 {
return nil, logThenErrorf("Proposal response payloads mismatch: 0 - %s, %d - %s", string(viewPayload), i, string(interopPayload.GetPayload()))
}
}
}
} else if view.Meta.Protocol == common.Meta_CORDA {
var cordaViewData corda.ViewData
err := protoV2.Unmarshal(view.Data, &cordaViewData)
if err != nil {
return nil, fmt.Errorf("cordaView unmarshal error: %s", err.Error())
}
err = protoV2.Unmarshal(cordaViewData.Payload, &interopPayload)
if err != nil {
return nil, fmt.Errorf("unable to unmarshal interopPayload: %s", err.Error())
for i := 0; i < len(cordaViewData.NotarizedPayloads); i++ {
var interopPayload common.InteropPayload
err = protoV2.Unmarshal(cordaViewData.NotarizedPayloads[i].Payload, &interopPayload)
if err != nil {
return nil, fmt.Errorf("unable to unmarshal interopPayload: %s", err.Error())
}
if interopPayload.GetConfidential() {
// TODO Add support for confidential (encrypted) view payloads
return nil, logThenErrorf("Encrypted view payloads not currently supported in Weaver Go SDK")
}
if i == 0 {
viewAddress = interopPayload.GetAddress()
viewPayload = interopPayload.GetPayload()
} else {
if viewAddress != interopPayload.GetAddress() {
return nil, logThenErrorf("Proposal response view addresses mismatch: 0 - %s, %d - %s", viewAddress, i, interopPayload.GetAddress())
}
if bytes.Compare(viewPayload, interopPayload.GetPayload()) != 0 {
return nil, logThenErrorf("Proposal response payloads mismatch: 0 - %s, %d - %s", string(viewPayload), i, string(interopPayload.GetPayload()))
}
}
}
} else {
return nil, logThenErrorf("cannot extract data from view; unsupported DLT type: %+v", view.Meta.Protocol)
}
return interopPayload.Payload, nil
return viewPayload, nil
}

func verifyView(contract GatewayContract, b64ViewProto string, address string) error {
Expand Down

0 comments on commit 27225eb

Please sign in to comment.