@@ -11,11 +11,13 @@ import (
11
11
12
12
"github.com/hyperledger-labs/weaver-dlt-interoperability/sdks/fabric/go-cli/helpers"
13
13
"github.com/hyperledger-labs/weaver-dlt-interoperability/sdks/fabric/go-cli/helpers/interopsetup"
14
+ "github.com/hyperledger-labs/weaver-dlt-interoperability/sdks/fabric/go-sdk/interoperablehelper"
15
+ "github.com/hyperledger-labs/weaver-dlt-interoperability/sdks/fabric/go-sdk/types"
14
16
)
15
17
16
18
func connectSimpleStateWithSDK () {
17
19
connProfilePath := "../../../tests/network-setups/fabric/shared/network1/peerOrganizations/org1.network1.com/connection-org1.yaml"
18
- contract ,
_ ,
_ := helpers .
FabricHelper (
helpers .
NewGatewayNetworkInterface (),
"mychannel" ,
"simplestate" ,
connProfilePath ,
"network1" ,
"Org1MSP" ,
"[email protected] " )
20
+ _ , contract ,
_ ,
_ := helpers .
FabricHelper (
helpers .
NewGatewayNetworkInterface (),
"mychannel" ,
"simplestate" ,
connProfilePath ,
"network1" ,
"Org1MSP" ,
"[email protected] " )
19
21
20
22
result , err := contract .EvaluateTransaction ("Read" , "a" )
21
23
if err != nil {
@@ -24,6 +26,8 @@ func connectSimpleStateWithSDK() {
24
26
log .Infof ("result of query: %s" , result )
25
27
26
28
result , err = contract .SubmitTransaction ("Create" , "key01" , "value" )
29
+ //valBytes, _ := json.Marshal([]int64{1, 2})
30
+ //result, err = contract.SubmitTransaction("CreateArr", "key01", string(valBytes))
27
31
if err != nil {
28
32
log .Fatalf ("failed Invoke with error: %+v" , err )
29
33
}
@@ -74,7 +78,7 @@ func connectSimpleAssetWithSDK(assetId string) {
74
78
}
75
79
log .Printf ("%s helpers.Invoke %v" , query .CcFunc , string (result ))
76
80
77
- contract ,
_ ,
_ := helpers .
FabricHelper (
helpers .
NewGatewayNetworkInterface (),
"mychannel" ,
"simplestate" ,
connProfilePath ,
"network1" ,
"Org1MSP" ,
"[email protected] " )
81
+ _ , contract ,
_ ,
_ := helpers .
FabricHelper (
helpers .
NewGatewayNetworkInterface (),
"mychannel" ,
"simplestate" ,
connProfilePath ,
"network1" ,
"Org1MSP" ,
"[email protected] " )
78
82
result , err = contract .EvaluateTransaction ("ReadAsset" , "t1" , assetId , "true" )
79
83
if err != nil {
80
84
log .Fatalf ("failed Query with error: %s" , err )
@@ -545,7 +549,7 @@ func fetchAccessControlPolicy(networkId string) {
545
549
ContractName : "interop" ,
546
550
Channel : "mychannel" ,
547
551
CcFunc : "GetAccessControlPolicyBySecurityDomain" ,
548
- Args : []string {"network1" },
552
+ Args : []string {networkId },
549
553
}
550
554
551
555
result , err := helpers .Query (query , connProfilePath , networkId , "Org1MSP" , "" )
@@ -561,7 +565,7 @@ func fetchMembership(networkId string) {
561
565
ContractName : "interop" ,
562
566
Channel : "mychannel" ,
563
567
CcFunc : "GetMembershipBySecurityDomain" ,
564
- Args : []string {"network1" },
568
+ Args : []string {networkId },
565
569
}
566
570
567
571
result , err := helpers .Query (query , connProfilePath , networkId , "Org1MSP" , "" )
@@ -577,7 +581,7 @@ func fetchVerificationPolicy(networkId string) {
577
581
ContractName : "interop" ,
578
582
Channel : "mychannel" ,
579
583
CcFunc : "GetVerificationPolicyBySecurityDomain" ,
580
- Args : []string {"network1" },
584
+ Args : []string {networkId },
581
585
}
582
586
583
587
result , err := helpers .Query (query , connProfilePath , networkId , "Org1MSP" , "" )
@@ -591,14 +595,72 @@ func configureNetwork(networkId string) {
591
595
interopsetup .ConfigureNetwork (networkId )
592
596
}
593
597
598
+ func interop (key string , localNetwork string , requestingOrg string , address string ) {
599
+ relayEnv , err := helpers .GetNetworkConfig (localNetwork )
600
+ if err != nil {
601
+ log .Fatalf ("failed helpers.GetNetworkConfig with error: %+v" , err .Error ())
602
+ }
603
+ log .Debugf ("relayEnv: %+v" , relayEnv )
604
+
605
+ if (relayEnv .RelayEndPoint == "" ) || (relayEnv .ConnProfilePath == "" ) {
606
+ log .Fatalf ("please use a valid --local-network. If valid network please check if your environment variables are configured properly" )
607
+ }
608
+ networkName := localNetwork
609
+ channel := "mychannel"
610
+ contractName := "interop"
611
+ connProfilePath := relayEnv .ConnProfilePath
612
+ mspId := requestingOrg
613
+ username := "User1@org1." + localNetwork + ".com"
614
+
615
+ _ , contract , wallet , err := helpers .FabricHelper (helpers .NewGatewayNetworkInterface (), channel , contractName , connProfilePath ,
616
+ networkName , mspId , username )
617
+ if err != nil {
618
+ log .Fatalf ("failed helpers.FabricHelper with error: %s" , err .Error ())
619
+ }
620
+ keyUser , certUser , err := helpers .GetKeyAndCertForRemoteRequestbyUserName (wallet , username )
621
+ if err != nil {
622
+ log .Fatalf ("failed helpers.GetKeyAndCertForRemoteRequestbyUserName with error: %s" , err .Error ())
623
+ }
624
+ log .Debugf ("keyUser: %s & certUser: %s" , keyUser , certUser )
625
+
626
+ applicationFunction := "Create"
627
+ args := []string {key , "" }
628
+ invokeObject := types.Query {
629
+ ContractName : "simplestate" ,
630
+ Channel : channel ,
631
+ CcFunc : applicationFunction ,
632
+ CcArgs : args ,
633
+ }
634
+ log .Debugf ("invokeObject: %+v" , invokeObject )
635
+
636
+ interopJSON := types.InteropJSON {
637
+ Address : address ,
638
+ ChaincodeFunc : "Read" ,
639
+ ChaincodeId : "simplestate" ,
640
+ ChannelId : channel ,
641
+ RemoteEndPoint : "localhost:9080" ,
642
+ NetworkId : "network1" ,
643
+ Sign : true ,
644
+ CcArgs : []string {"a" },
645
+ }
646
+ log .Debugf ("interopJSON: %+v" , interopJSON )
647
+ interopJSONs := []types.InteropJSON {interopJSON }
648
+
649
+ interopArgIndices := []int {1 }
650
+ interoperablehelper .InteropFlow (contract , networkName , invokeObject , requestingOrg , relayEnv .RelayEndPoint , interopArgIndices , interopJSONs , keyUser , certUser , false )
651
+
652
+ }
653
+
594
654
func main () {
595
655
596
- configureNetwork ("network1" )
597
- fetchAccessControlPolicy ("network1" )
598
- fetchMembership ("network1" )
599
- fetchVerificationPolicy ("network1" )
656
+ interop ("a" , "network1" , "Org1MSP" , "localhost:9080/network1/mychannel:simplestate:Read:a" )
657
+
658
+ //configureNetwork("network1")
659
+ //fetchAccessControlPolicy("network1")
660
+ //fetchMembership("network1")
661
+ //fetchVerificationPolicy("network1")
600
662
601
- //connectSimpleStateWithSDK() // needs the chaincode simplestate on the channel
663
+ //connectSimpleStateWithSDK() // needs the chaincode simplestate on the channel
602
664
//connectSimpleAssetWithSDK("a001") // needs the chaincode simpleasset on the channel
603
665
//testLockAssetAndClaimAssetOfBondAsset("a020") // needs the chaincodes simpleasset and interop on the channel
604
666
//testLockAssetAndUnlockAssetOfBondAsset("a021") // needs the chaincodes simpleasset and interop on the channel
0 commit comments