fabric-sdk-go icon indicating copy to clipboard operation
fabric-sdk-go copied to clipboard

Add support for go version 1.18+

Open hmoazzem opened this issue 1 year ago • 2 comments

It might be expected because of https://github.com/hyperledger/fabric-sdk-go/blob/main/test/fixtures/config/overrides/local_entity_matchers.yaml, but I haven't figured that out yet. Faced with the same issue https://github.com/hyperledger/fabric-sdk-go/issues/265, I resolved by downgrading golang to version 1.18. Reproducible scenario that works in go v1.18, but not higher.

config.yaml

version: 1.0.0

client:
  tlsEnable: true
  organization: org1
channels:
  channel0:
    orderers:
    - orderer1.orderer
    peers:
      peer0.org1: {}
organizations:
  org1:
    mspid: Org1MSP
    cryptoPath:  /home/fabric/crypto/orgs/org1/msp
    peers:
    - peer0.org1
    certificateAuthorities:
    - ca.org1
    users:
      admin:
        cert:
          path: /home/fabric/crypto/orgs/org1/admin/msp/signcerts/cert.pem
        key:
          path: /home/fabric/crypto/orgs/org1/admin/msp/keystore/key.pem
  orderer:
      mspID: OrdererMSP
      cryptoPath: /home/fabric/crypto/orderers/msp
orderers:
  orderer1.orderer:
    url: orderer1.orderer:7050
    tlsCACerts:
      path: /home/fabric/crypto/orderers/admin/tls/ca.pem
peers:
  peer0.org1:
    url: peer0.org1:7051
    tlsCACerts:
      path: /home/fabric/crypto/orgs/org1/admin/tls/ca.pem
certificateAuthorities:
  ca.org1:
    url: https://ca.org1:7054
    caName: ca.org1
    tlsCACerts:
      path: /home/fabric/crypto/orgs/org1/admin/tls/ca.pem

main.go

package main

import (
	"fmt"

	"github.com/hyperledger/fabric-sdk-go/pkg/client/channel"
	"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
	"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
)

const (
	channelID   = "channel0"
	orgName     = "org1"
	orgAdmin    = "admin"
	chaincodeID = "samplecc"
)

func main() {
	sdk, err := fabsdk.New(config.FromFile("config.yaml"))
	if err != nil {
		fmt.Println(err)
	}
	defer sdk.Close()

	clientChannelContext := sdk.ChannelContext(channelID, fabsdk.WithUser(orgAdmin), fabsdk.WithOrg(orgName))
	client, err := channel.New(clientChannelContext)
	if err != nil {
		fmt.Println(err)
	}

	response, err := client.Execute(channel.Request{ChaincodeID: chaincodeID, Fcn: "YourFunction"})
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(string(response.Payload))
}

hmoazzem avatar Aug 24 '23 17:08 hmoazzem

Same issue https://github.com/hyperledger/fabric-sdk-go/issues/260

hmoazzem avatar Aug 24 '23 17:08 hmoazzem

I've replaced fabric-sdk-go in vendor directory with git clone https://github.com/hyperledger/fabric-sdk-go, and issue was solved.

werniq avatar Oct 19 '23 06:10 werniq