├── .codecov.yaml
├── .github
├── settings.yml
└── stale.yml
├── .gitignore
├── CHANGELOG.md
├── CODEOWNERS
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── MAINTAINERS.md
├── Makefile
├── README.md
├── SECURITY.md
├── ci.properties
├── ci
├── azure-pipelines.yml
└── install_deps.yml
├── doc.go
├── go.mod
├── go.sum
├── golangci.yml
├── internal
└── github.com
│ └── hyperledger
│ ├── fabric-ca
│ ├── lib
│ │ ├── attrmgr
│ │ │ └── attrmgr.go
│ │ ├── client.go
│ │ ├── client
│ │ │ └── credential
│ │ │ │ ├── credential.go
│ │ │ │ └── x509
│ │ │ │ ├── credential.go
│ │ │ │ └── signer.go
│ │ ├── clientconfig.go
│ │ ├── identity.go
│ │ ├── sdkpatch_serverstruct.go
│ │ ├── serverrevoke.go
│ │ ├── streamer
│ │ │ └── jsonstreamer.go
│ │ ├── tls
│ │ │ └── tls.go
│ │ └── util.go
│ ├── sdkinternal
│ │ └── pkg
│ │ │ ├── api
│ │ │ ├── client.go
│ │ │ ├── net.go
│ │ │ └── serverresponses.go
│ │ │ └── util
│ │ │ ├── csp.go
│ │ │ └── util.go
│ └── sdkpatch
│ │ ├── cryptosuitebridge
│ │ └── cryptosuitebridge.go
│ │ ├── keyutil
│ │ └── keys.go
│ │ └── logbridge
│ │ ├── logbridge.go
│ │ └── syslogwriter.go
│ └── fabric
│ ├── bccsp
│ ├── aesopts.go
│ ├── bccsp.go
│ ├── ecdsaopts.go
│ ├── factory
│ │ ├── pkcs11
│ │ │ └── pkcs11factory.go
│ │ └── sw
│ │ │ └── swfactory.go
│ ├── hashopts.go
│ ├── keystore.go
│ ├── opts.go
│ ├── pkcs11
│ │ ├── conf.go
│ │ ├── ecdsa.go
│ │ ├── ecdsakey.go
│ │ ├── impl.go
│ │ └── pkcs11.go
│ ├── signer
│ │ └── signer.go
│ ├── sw
│ │ ├── aes.go
│ │ ├── aeskey.go
│ │ ├── conf.go
│ │ ├── dummyks.go
│ │ ├── ecdsa.go
│ │ ├── ecdsakey.go
│ │ ├── fileks.go
│ │ ├── hash.go
│ │ ├── impl.go
│ │ ├── inmemoryks.go
│ │ ├── internals.go
│ │ ├── keyderiv.go
│ │ ├── keygen.go
│ │ ├── keyimport.go
│ │ ├── keys.go
│ │ └── new.go
│ └── utils
│ │ └── ecdsa.go
│ ├── common
│ ├── capabilities
│ │ ├── application.go
│ │ ├── capabilities.go
│ │ ├── channel.go
│ │ └── orderer.go
│ ├── channelconfig
│ │ ├── acls.go
│ │ ├── api.go
│ │ ├── application.go
│ │ ├── applicationorg.go
│ │ ├── bundle.go
│ │ ├── channel.go
│ │ ├── consortium.go
│ │ ├── consortiums.go
│ │ ├── msp.go
│ │ ├── orderer.go
│ │ ├── organization.go
│ │ ├── standardvalues.go
│ │ └── util.go
│ ├── configtx
│ │ └── configtx.go
│ ├── crypto
│ │ └── random.go
│ ├── genesis
│ │ └── genesis.go
│ ├── ledger
│ │ └── ledger_interface.go
│ ├── metrics
│ │ ├── disabled
│ │ │ └── provider.go
│ │ ├── internal
│ │ │ └── namer
│ │ │ │ └── namer.go
│ │ ├── prometheus
│ │ │ └── provider.go
│ │ ├── provider.go
│ │ └── statsd
│ │ │ ├── goruntime
│ │ │ ├── collector.go
│ │ │ └── metrics.go
│ │ │ └── provider.go
│ ├── policies
│ │ ├── implicitmetaparser.go
│ │ ├── policy.go
│ │ └── util.go
│ ├── policydsl
│ │ ├── policydsl_builder.go
│ │ └── policyparser.go
│ └── util
│ │ └── utils.go
│ ├── core
│ ├── chaincode
│ │ ├── persistence
│ │ │ ├── chaincode_package.go
│ │ │ └── persistence.go
│ │ └── platforms
│ │ │ ├── golang
│ │ │ ├── list.go
│ │ │ └── platform.go
│ │ │ ├── java
│ │ │ └── platform.go
│ │ │ ├── node
│ │ │ └── platform.go
│ │ │ ├── platforms.go
│ │ │ └── util
│ │ │ └── writer.go
│ ├── common
│ │ └── ccprovider
│ │ │ ├── ccprovider.go
│ │ │ └── cdspackage.go
│ ├── ledger
│ │ └── kvledger
│ │ │ └── txmgmt
│ │ │ └── rwsetutil
│ │ │ └── rwset_proto_util.go
│ ├── middleware
│ │ ├── chain.go
│ │ ├── request_id.go
│ │ └── require_cert.go
│ └── operations
│ │ ├── metrics.go
│ │ ├── system.go
│ │ └── tls.go
│ ├── discovery
│ ├── client
│ │ ├── api.go
│ │ ├── client.go
│ │ ├── selection.go
│ │ └── signer.go
│ └── protoext
│ │ ├── querytype.go
│ │ └── response.go
│ ├── gossip
│ ├── protoext
│ │ ├── message.go
│ │ ├── signing.go
│ │ └── stringers.go
│ └── util
│ │ └── misc.go
│ ├── msp
│ ├── cache
│ │ ├── cache.go
│ │ └── second_chance.go
│ ├── cert.go
│ ├── configbuilder.go
│ ├── factory.go
│ ├── identities.go
│ ├── msp.go
│ ├── mspimpl.go
│ ├── mspimplsetup.go
│ ├── mspimplvalidate.go
│ └── mspmgrimpl.go
│ ├── protoutil
│ ├── blockutils.go
│ ├── commonutils.go
│ ├── configtxutils.go
│ ├── proputils.go
│ ├── signeddata.go
│ ├── txutils.go
│ └── unmarshalers.go
│ ├── sdkinternal
│ ├── ccmetadata
│ │ └── validators.go
│ ├── configtxgen
│ │ ├── encoder
│ │ │ └── encoder.go
│ │ └── genesisconfig
│ │ │ └── config.go
│ ├── configtxlator
│ │ └── update
│ │ │ └── update.go
│ ├── peer
│ │ └── packaging
│ │ │ └── platforms.go
│ └── pkg
│ │ ├── comm
│ │ └── config.go
│ │ ├── identity
│ │ └── identity.go
│ │ └── txflags
│ │ └── validation_flags.go
│ └── sdkpatch
│ ├── cachebridge
│ └── cache.go
│ ├── cryptosuitebridge
│ └── cryptosuitebridge.go
│ ├── keyutil
│ └── keys.go
│ └── logbridge
│ ├── httpadmin
│ └── spec.go
│ └── logbridge.go
├── pkg
├── client
│ ├── channel
│ │ ├── api.go
│ │ ├── api_test.go
│ │ ├── chclient.go
│ │ ├── chclient_test.go
│ │ ├── chclientrun.go
│ │ ├── chclientrun_perf.go
│ │ ├── chclientrun_std.go
│ │ ├── example_test.go
│ │ └── invoke
│ │ │ ├── api.go
│ │ │ ├── selectendorsehandler.go
│ │ │ ├── signature.go
│ │ │ ├── signature_test.go
│ │ │ ├── txnhandler.go
│ │ │ └── txnhandler_test.go
│ ├── common
│ │ ├── discovery
│ │ │ ├── discoveryfilter.go
│ │ │ ├── discoveryfilter_test.go
│ │ │ ├── dynamicdiscovery
│ │ │ │ ├── chservice.go
│ │ │ │ ├── chservice_test.go
│ │ │ │ ├── chservice_test_env.go
│ │ │ │ ├── errors.go
│ │ │ │ ├── localprovider.go
│ │ │ │ ├── localprovider_test.go
│ │ │ │ ├── localservice.go
│ │ │ │ ├── localservice_test.go
│ │ │ │ ├── opts.go
│ │ │ │ ├── service.go
│ │ │ │ └── service_test.go
│ │ │ ├── greylist
│ │ │ │ ├── greylist.go
│ │ │ │ └── greylist_test.go
│ │ │ └── staticdiscovery
│ │ │ │ ├── localprovider.go
│ │ │ │ ├── localservice.go
│ │ │ │ ├── service.go
│ │ │ │ └── staticdiscovery_test.go
│ │ ├── filter
│ │ │ ├── endpoint.go
│ │ │ └── endpoint_test.go
│ │ ├── mocks
│ │ │ ├── mockdiscovery.go
│ │ │ ├── mockselection.go
│ │ │ └── mocktransactor.go
│ │ ├── random
│ │ │ ├── random.go
│ │ │ └── random_test.go
│ │ ├── selection
│ │ │ ├── balancer
│ │ │ │ └── balancer.go
│ │ │ ├── dynamicselection
│ │ │ │ ├── ccpolicyprovider.go
│ │ │ │ ├── ccpolicyprovider_test.go
│ │ │ │ ├── dynamicselection.go
│ │ │ │ ├── dynamicselection_test.go
│ │ │ │ └── pgresolver
│ │ │ │ │ ├── groups.go
│ │ │ │ │ ├── groups_test.go
│ │ │ │ │ ├── groupsimpl.go
│ │ │ │ │ ├── lbpolicyimpl.go
│ │ │ │ │ ├── mocks.go
│ │ │ │ │ ├── pgresolver.go
│ │ │ │ │ ├── pgresolver_test.go
│ │ │ │ │ └── pgresolverimpl.go
│ │ │ ├── fabricselection
│ │ │ │ ├── cachekey.go
│ │ │ │ ├── fabricselection.go
│ │ │ │ ├── opts.go
│ │ │ │ ├── selection_test.go
│ │ │ │ ├── selection_test_env.go
│ │ │ │ ├── selectionfilter.go
│ │ │ │ └── selectionfilter_test.go
│ │ │ ├── options
│ │ │ │ └── opts.go
│ │ │ ├── sorter
│ │ │ │ ├── balancedsorter
│ │ │ │ │ ├── balancedsorter.go
│ │ │ │ │ ├── balancedsorter_test.go
│ │ │ │ │ └── opts.go
│ │ │ │ └── blockheightsorter
│ │ │ │ │ ├── blockheightsorter.go
│ │ │ │ │ ├── blockheightsorter_test.go
│ │ │ │ │ └── opts.go
│ │ │ └── staticselection
│ │ │ │ ├── staticselection.go
│ │ │ │ └── staticselection_test.go
│ │ └── verifier
│ │ │ └── signature.go
│ ├── event
│ │ ├── event.go
│ │ ├── event_test.go
│ │ ├── example_test.go
│ │ └── opts.go
│ ├── ledger
│ │ ├── example_test.go
│ │ ├── ledger.go
│ │ ├── ledger_test.go
│ │ ├── opts.go
│ │ └── opts_test.go
│ ├── msp
│ │ ├── ca.go
│ │ ├── client.go
│ │ ├── client_test.go
│ │ ├── example_test.go
│ │ ├── identity.go
│ │ └── options.go
│ └── resmgmt
│ │ ├── example_test.go
│ │ ├── lifecycleclient.go
│ │ ├── lifecycleclient_test.go
│ │ ├── lifecycleprocessor.go
│ │ ├── lifecycleprocessor_test.go
│ │ ├── lscc.go
│ │ ├── mockchannelprovider.gen.go
│ │ ├── mockchannelservice.gen.go
│ │ ├── mocklifecycleresource.gen.go
│ │ ├── mocktransactor.gen.go
│ │ ├── opts.go
│ │ ├── opts_test.go
│ │ ├── resmgmt.go
│ │ ├── resmgmt_test.go
│ │ └── testdata
│ │ ├── config.block
│ │ ├── extractcherr.tx
│ │ ├── signcherr.tx
│ │ └── test.tx
├── common
│ ├── errors
│ │ ├── multi
│ │ │ ├── example_test.go
│ │ │ ├── multi.go
│ │ │ └── multi_test.go
│ │ ├── retry
│ │ │ ├── defaults.go
│ │ │ ├── invoker.go
│ │ │ ├── invoker_test.go
│ │ │ ├── retry.go
│ │ │ └── retry_test.go
│ │ └── status
│ │ │ ├── codes.go
│ │ │ ├── example_test.go
│ │ │ ├── status.go
│ │ │ └── status_test.go
│ ├── logging
│ │ ├── example_test.go
│ │ ├── logger.go
│ │ ├── logger_test.go
│ │ └── logger_testing_env.go
│ ├── options
│ │ └── options.go
│ └── providers
│ │ ├── context
│ │ └── context.go
│ │ ├── core
│ │ ├── cryptosuite.go
│ │ ├── kvstore.go
│ │ ├── provider.go
│ │ └── signingmgr.go
│ │ ├── fab
│ │ ├── channel.go
│ │ ├── context.go
│ │ ├── eventservice.go
│ │ ├── network.go
│ │ ├── orderer.go
│ │ ├── peer.go
│ │ ├── proposer.go
│ │ ├── provider.go
│ │ └── sender.go
│ │ ├── msp
│ │ ├── identity.go
│ │ ├── provider.go
│ │ └── store.go
│ │ └── test
│ │ ├── mockcontext
│ │ └── mockcontext.gen.go
│ │ ├── mockcore
│ │ └── mockcore.gen.go
│ │ ├── mockfab
│ │ ├── mockconfig.go
│ │ └── mockfab.gen.go
│ │ └── mockmsp
│ │ └── mockmsp.gen.go
├── context
│ └── context.go
├── core
│ ├── config
│ │ ├── comm
│ │ │ ├── comm.go
│ │ │ ├── comm_test.go
│ │ │ ├── testdata
│ │ │ │ ├── server.crt
│ │ │ │ └── server.key
│ │ │ └── tls
│ │ │ │ ├── certpool.go
│ │ │ │ └── certpool_test.go
│ │ ├── config.go
│ │ ├── config_test.go
│ │ ├── cryptoutil
│ │ │ ├── cryptoutils.go
│ │ │ └── cryptoutils_test.go
│ │ ├── defbackend.go
│ │ ├── endpoint
│ │ │ ├── endpoint.go
│ │ │ └── endpoint_test.go
│ │ ├── lookup
│ │ │ ├── lookup.go
│ │ │ └── lookup_test.go
│ │ └── testdata
│ │ │ ├── certs
│ │ │ ├── ca.crt
│ │ │ ├── client_sdk_go-key.pem
│ │ │ └── client_sdk_go.pem
│ │ │ ├── config_test.yaml
│ │ │ ├── config_test_embedded_pems.yaml
│ │ │ ├── config_test_entity_matchers.yaml
│ │ │ ├── config_test_msp_only.yaml
│ │ │ ├── config_test_no_server_certs.yaml
│ │ │ ├── config_test_pem.yaml
│ │ │ ├── matcher-samples
│ │ │ ├── matchers_sample1.yaml
│ │ │ ├── matchers_sample2.yaml
│ │ │ ├── matchers_sample3.yaml
│ │ │ ├── matchers_sample4.yaml
│ │ │ ├── matchers_sample5.yaml
│ │ │ └── matchers_sample6.yaml
│ │ │ ├── template
│ │ │ └── config.yaml
│ │ │ └── viper-test.yaml
│ ├── cryptosuite
│ │ ├── bccsp
│ │ │ ├── multisuite
│ │ │ │ ├── cryptosuiteimpl.go
│ │ │ │ └── cryptosuiteimpl_test.go
│ │ │ ├── pkcs11
│ │ │ │ ├── cryptosuiteimpl.go
│ │ │ │ └── cryptosuiteimpl_test.go
│ │ │ ├── sw
│ │ │ │ ├── cryptosuiteimpl.go
│ │ │ │ └── cryptosuiteimpl_test.go
│ │ │ └── wrapper
│ │ │ │ ├── cryptosuiteimpl.go
│ │ │ │ ├── cryptosuiteimpl_test.go
│ │ │ │ └── mocksuite_test.go
│ │ ├── common
│ │ │ └── pkcs11
│ │ │ │ ├── contextHandle.go
│ │ │ │ ├── contextHandle_test.go
│ │ │ │ └── opts.go
│ │ ├── cryptoconfig.go
│ │ ├── cryptoconfig_test.go
│ │ ├── cryptosuite.go
│ │ ├── cryptosuite_test.go
│ │ ├── opts.go
│ │ └── opts_test.go
│ ├── logging
│ │ ├── api
│ │ │ └── logger.go
│ │ ├── metadata
│ │ │ ├── callerInfo.go
│ │ │ ├── callerInfo_test.go
│ │ │ ├── level.go
│ │ │ ├── level_test.go
│ │ │ └── utils.go
│ │ ├── modlog
│ │ │ ├── modlog.go
│ │ │ ├── modlog_test.go
│ │ │ └── testVerifyUtils.go
│ │ └── testdata
│ │ │ └── sampleloggingprovider.go
│ └── mocks
│ │ ├── mockconfigbackend.go
│ │ ├── mockconfigbackend_test.go
│ │ ├── mockcorecontext.go
│ │ └── mocksigningmgr.go
├── fab
│ ├── api.go
│ ├── ccpackager
│ │ ├── gopackager
│ │ │ ├── packager.go
│ │ │ ├── packager_test.go
│ │ │ └── testdata
│ │ │ │ └── src
│ │ │ │ └── github.com
│ │ │ │ ├── events_cc
│ │ │ │ ├── META-INF
│ │ │ │ │ └── sample-json
│ │ │ │ │ │ └── event.json
│ │ │ │ └── events_cc.go
│ │ │ │ ├── example_cc
│ │ │ │ └── example_cc.go
│ │ │ │ └── example_cc1
│ │ │ │ ├── META-INF-foo
│ │ │ │ └── example1-foo.json
│ │ │ │ ├── META-INF
│ │ │ │ └── example1.json
│ │ │ │ ├── example_cc1.go
│ │ │ │ └── foo-META-INF
│ │ │ │ └── foo-example.json
│ │ ├── javapackager
│ │ │ ├── packager.go
│ │ │ ├── packager_test.go
│ │ │ └── testdata
│ │ │ │ ├── events_cc
│ │ │ │ ├── META-INF
│ │ │ │ │ └── sample-json
│ │ │ │ │ │ └── event.json
│ │ │ │ ├── build.gradle
│ │ │ │ ├── settings.gradle
│ │ │ │ └── src
│ │ │ │ │ └── main
│ │ │ │ │ └── java
│ │ │ │ │ └── org
│ │ │ │ │ └── hyperledger
│ │ │ │ │ └── fabric
│ │ │ │ │ └── example
│ │ │ │ │ └── events_cc.java
│ │ │ │ ├── example_cc
│ │ │ │ ├── build.gradle
│ │ │ │ ├── settings.gradle
│ │ │ │ └── src
│ │ │ │ │ └── main
│ │ │ │ │ └── java
│ │ │ │ │ └── org
│ │ │ │ │ └── hyperledger
│ │ │ │ │ └── fabric
│ │ │ │ │ └── example
│ │ │ │ │ └── SimpleChaincode.java
│ │ │ │ └── example_cc1
│ │ │ │ ├── META-INF-foo
│ │ │ │ └── example1-foo.json
│ │ │ │ ├── META-INF
│ │ │ │ └── example1.json
│ │ │ │ ├── build.gradle
│ │ │ │ ├── foo-META-INF
│ │ │ │ └── foo-example.json
│ │ │ │ ├── settings.gradle
│ │ │ │ └── src
│ │ │ │ └── main
│ │ │ │ └── java
│ │ │ │ └── org
│ │ │ │ └── hyperledger
│ │ │ │ └── fabric
│ │ │ │ └── example
│ │ │ │ └── SimpleChaincode.java
│ │ ├── lifecycle
│ │ │ ├── packager.go
│ │ │ ├── packager_test.go
│ │ │ └── testdata
│ │ │ │ └── golang_cc
│ │ │ │ ├── go.mod
│ │ │ │ ├── go.sum
│ │ │ │ └── golang_cc.go
│ │ └── nodepackager
│ │ │ ├── packager.go
│ │ │ ├── packager_test.go
│ │ │ └── testdata
│ │ │ ├── event_cc
│ │ │ ├── META-INF
│ │ │ │ └── sample-json
│ │ │ │ │ └── event.json
│ │ │ ├── chaincode_example02.js
│ │ │ └── package.json
│ │ │ ├── example_cc
│ │ │ ├── chaincode_example02.js
│ │ │ └── package.json
│ │ │ └── example_cc1
│ │ │ ├── META-INF-foo
│ │ │ └── example1-foo.json
│ │ │ ├── META-INF
│ │ │ └── example1.json
│ │ │ ├── chaincode_example02.js
│ │ │ ├── foo-META-INF
│ │ │ └── foo-example.json
│ │ │ └── package.json
│ ├── channel
│ │ ├── cscc.go
│ │ ├── ledger.go
│ │ ├── ledger_test.go
│ │ ├── membership
│ │ │ ├── cache.go
│ │ │ ├── cache_test.go
│ │ │ ├── membership.go
│ │ │ ├── membership_test.go
│ │ │ └── reference.go
│ │ ├── qscc.go
│ │ ├── responsevalidator.go
│ │ ├── transactor.go
│ │ └── transactor_test.go
│ ├── chconfig
│ │ ├── cache.go
│ │ ├── cache_test.go
│ │ ├── chconfig.go
│ │ ├── chconfig_test.go
│ │ ├── opts.go
│ │ └── reference.go
│ ├── comm
│ │ ├── comm_test.go
│ │ ├── connection.go
│ │ ├── connection_test.go
│ │ ├── connectionopts.go
│ │ ├── connector.go
│ │ ├── connector_test.go
│ │ ├── mocks.go
│ │ ├── network.go
│ │ ├── network_test.go
│ │ ├── streamconnection.go
│ │ └── streamconnection_test.go
│ ├── default_channel_test.go
│ ├── discovery
│ │ ├── discovery.go
│ │ ├── discovery_test.go
│ │ ├── mockdiscoveryclient.go
│ │ ├── mocks
│ │ │ └── mockdiscoveryserver.go
│ │ ├── request.go
│ │ ├── util.go
│ │ └── util_test.go
│ ├── endpointconfig.go
│ ├── endpointconfig_test.go
│ ├── events
│ │ ├── api
│ │ │ ├── connection.go
│ │ │ └── endpoint.go
│ │ ├── client
│ │ │ ├── client.go
│ │ │ ├── client_test.go
│ │ │ ├── dispatcher
│ │ │ │ ├── dispatcher.go
│ │ │ │ ├── dispatcher_test.go
│ │ │ │ ├── events.go
│ │ │ │ ├── opts.go
│ │ │ │ └── registrations.go
│ │ │ ├── lbp
│ │ │ │ ├── lbp.go
│ │ │ │ ├── lbp_test.go
│ │ │ │ ├── random.go
│ │ │ │ └── roundrobin.go
│ │ │ ├── mocks
│ │ │ │ ├── mockconnection.go
│ │ │ │ ├── mockdiscovery.go
│ │ │ │ ├── mockdispatcher.go
│ │ │ │ ├── mockpeer.go
│ │ │ │ ├── numevents.go
│ │ │ │ └── util.go
│ │ │ ├── opts.go
│ │ │ └── peerresolver
│ │ │ │ ├── balanced
│ │ │ │ ├── balanced.go
│ │ │ │ ├── balanced_test.go
│ │ │ │ └── opts.go
│ │ │ │ ├── config.go
│ │ │ │ ├── minblockheight
│ │ │ │ ├── minblockheight.go
│ │ │ │ ├── minblockheight_test.go
│ │ │ │ └── opts.go
│ │ │ │ ├── peerresolver.go
│ │ │ │ ├── preferorg
│ │ │ │ ├── opts.go
│ │ │ │ ├── preferorg.go
│ │ │ │ └── preferorg_test.go
│ │ │ │ └── preferpeer
│ │ │ │ ├── opts.go
│ │ │ │ ├── preferpeer.go
│ │ │ │ └── preferpeer_test.go
│ │ ├── deliverclient
│ │ │ ├── connection
│ │ │ │ ├── connection.go
│ │ │ │ └── connection_test.go
│ │ │ ├── deliverclient.go
│ │ │ ├── deliverclient_test.go
│ │ │ ├── dispatcher
│ │ │ │ ├── dispatcher.go
│ │ │ │ ├── dispatcher_test.go
│ │ │ │ └── events.go
│ │ │ ├── mocks
│ │ │ │ ├── mockconnection.go
│ │ │ │ └── mockevents.go
│ │ │ ├── opts.go
│ │ │ └── seek
│ │ │ │ └── seek.go
│ │ ├── endpoint
│ │ │ ├── endpoint.go
│ │ │ ├── endpoint_test.go
│ │ │ └── endpointdiscovery.go
│ │ ├── mocks
│ │ │ └── mockdelserver.go
│ │ └── service
│ │ │ ├── blockfilter
│ │ │ ├── acceptanyfilter.go
│ │ │ └── headertypefilter
│ │ │ │ ├── headertypefilter.go
│ │ │ │ └── headertypefilter_test.go
│ │ │ ├── dispatcher
│ │ │ ├── dispatcher.go
│ │ │ ├── dispatcher_test.go
│ │ │ ├── events.go
│ │ │ ├── opts.go
│ │ │ └── registrations.go
│ │ │ ├── mocks
│ │ │ ├── blockproducer.go
│ │ │ ├── blockwrapper.go
│ │ │ ├── fblockwrapper.go
│ │ │ ├── mockevents.go
│ │ │ ├── mockledger.go
│ │ │ └── mockproducer.go
│ │ │ ├── opts.go
│ │ │ ├── service.go
│ │ │ └── service_test.go
│ ├── keyvaluestore
│ │ ├── filekeyvaluestore.go
│ │ └── filekeyvaluestore_test.go
│ ├── matchers_test.go
│ ├── mocks
│ │ ├── mockbroadcastserver.go
│ │ ├── mockcaclient.go
│ │ ├── mockchannel.go
│ │ ├── mockchconfig.go
│ │ ├── mockchprovider.go
│ │ ├── mockconfig.go
│ │ ├── mockcontext.go
│ │ ├── mockcryptosuite.go
│ │ ├── mockdata.go
│ │ ├── mockdiscovery.go
│ │ ├── mockendorserserver.go
│ │ ├── mockeventservice.go
│ │ ├── mockfabricprovider.go
│ │ ├── mockidentity.go
│ │ ├── mockidentitymgr.go
│ │ ├── mocklocal.go
│ │ ├── mockmembership.go
│ │ ├── mockmsp.go
│ │ ├── mockmspmanager.go
│ │ ├── mockorderer.go
│ │ ├── mockpeer.go
│ │ ├── mockselection.go
│ │ └── mocktransactor.go
│ ├── opts.go
│ ├── opts_test.go
│ ├── orderer
│ │ ├── orderer.go
│ │ ├── orderer_test.go
│ │ └── testdata
│ │ │ └── ca.crt
│ ├── peer
│ │ ├── peer.go
│ │ ├── peer_test.go
│ │ ├── peerendorser.go
│ │ └── peerendorser_test.go
│ ├── resource
│ │ ├── api.go
│ │ ├── block.go
│ │ ├── config.go
│ │ ├── config_test.go
│ │ ├── configtx.go
│ │ ├── configtx_test.go
│ │ ├── configtxmsp.go
│ │ ├── configtxmsp_test.go
│ │ ├── cscc.go
│ │ ├── genesisconfig
│ │ │ └── config.go
│ │ ├── lifecycle.go
│ │ ├── lifecycle_test.go
│ │ ├── lscc.go
│ │ ├── lscc_test.go
│ │ ├── resource.go
│ │ └── resource_test.go
│ ├── signingmgr
│ │ ├── signingmgr.go
│ │ └── signingmgr_test.go
│ └── txn
│ │ ├── env.go
│ │ ├── proposal.go
│ │ ├── proposal_test.go
│ │ ├── txn.go
│ │ └── txn_test.go
├── fabsdk
│ ├── api
│ │ └── factory.go
│ ├── context.go
│ ├── context_test.go
│ ├── defpkgsuite.go
│ ├── defpkgsuite_test.go
│ ├── fabsdk.go
│ ├── fabsdk_chconfig_test.go
│ ├── fabsdk_perf.go
│ ├── fabsdk_std.go
│ ├── fabsdk_test.go
│ ├── factory.go
│ ├── factory
│ │ ├── defcore
│ │ │ ├── corefactory.go
│ │ │ └── corefactory_test.go
│ │ ├── defmsp
│ │ │ ├── mspfactory.go
│ │ │ └── mspfactory_test.go
│ │ └── defsvc
│ │ │ ├── svcfactory.go
│ │ │ └── svcfactory_test.go
│ ├── metrics
│ │ ├── cfg
│ │ │ ├── config.go
│ │ │ ├── opts.go
│ │ │ └── opts_test.go
│ │ └── metrics.go
│ ├── mocks_test.go
│ ├── provider
│ │ ├── chpvdr
│ │ │ ├── cachekey.go
│ │ │ ├── chprovider.go
│ │ │ ├── chprovider_test.go
│ │ │ ├── contextcache.go
│ │ │ ├── eventserviceref.go
│ │ │ └── fabprovider_testing_env.go
│ │ ├── fabpvdr
│ │ │ ├── fabpvdr.go
│ │ │ └── fabpvdr_test.go
│ │ └── msppvdr
│ │ │ ├── msppvdr.go
│ │ │ └── msppvdr_test.go
│ ├── singleton_test.go
│ └── test
│ │ └── mocksdkapi
│ │ └── mocksdkapi.gen.go
├── gateway
│ ├── contract.go
│ ├── contract_test.go
│ ├── example_test.go
│ ├── filesystemwallet.go
│ ├── filesystemwallet_test.go
│ ├── gateway.go
│ ├── gateway_test.go
│ ├── identity.go
│ ├── inmemorywallet.go
│ ├── inmemorywallet_test.go
│ ├── network.go
│ ├── network_test.go
│ ├── spi.go
│ ├── testdata
│ │ ├── connection-discovery.json
│ │ ├── connection-tls.json
│ │ ├── connection.json
│ │ └── wallet
│ │ │ ├── invalid1.id
│ │ │ ├── invalid2.id
│ │ │ ├── invalid3.id
│ │ │ ├── invalid4.id
│ │ │ └── x509-v1.id
│ ├── transaction.go
│ ├── transaction_test.go
│ ├── wallet.go
│ ├── wallet_test.go
│ └── x509identity.go
├── msp
│ ├── api
│ │ └── api.go
│ ├── caclient.go
│ ├── caclient_test.go
│ ├── certfileuserstore.go
│ ├── certfileuserstore_test.go
│ ├── enrollment_test.go
│ ├── fabcaadapter.go
│ ├── filecertstore.go
│ ├── filekeystore.go
│ ├── filekeystore_test.go
│ ├── getsigid.go
│ ├── getsigid_test.go
│ ├── identityconfig.go
│ ├── identityconfig_test.go
│ ├── identitymgr.go
│ ├── identitymgr_test.go
│ ├── main_test.go
│ ├── matchers_test.go
│ ├── memory_key_store.go
│ ├── memory_user_store.go
│ ├── opts.go
│ ├── opts_test.go
│ ├── test
│ │ ├── mockmsp
│ │ │ ├── mockfabriccaserver.go
│ │ │ ├── mockkey.go
│ │ │ ├── mockuser.go
│ │ │ └── mockuserstore.go
│ │ └── mockmspapi
│ │ │ └── mockmspapi.gen.go
│ ├── testdata
│ │ ├── cryptoconfig
│ │ │ ├── v1
│ │ │ │ └── user
│ │ │ │ │ └── keystore
│ │ │ │ │ └── 0001_sk
│ │ │ └── v2
│ │ │ │ └── user
│ │ │ │ └── keystore
│ │ │ │ └── priv_sk
│ │ └── root.pem
│ ├── user.go
│ └── user_test.go
└── util
│ ├── concurrent
│ ├── futurevalue
│ │ ├── futurevalue.go
│ │ └── futurevalue_test.go
│ ├── lazycache
│ │ ├── keys.go
│ │ ├── lazycache.go
│ │ ├── lazycache_test.go
│ │ └── refoptcheck.go
│ ├── lazyref
│ │ ├── expiration.go
│ │ ├── lazyref.go
│ │ ├── lazyref_test.go
│ │ └── options.go
│ └── rollingcounter
│ │ ├── rollingcounter.go
│ │ └── rollingcounter_test.go
│ ├── pathvar
│ ├── subst.go
│ └── subst_test.go
│ └── test
│ ├── test.go
│ └── util.go
├── scripts
├── _go
│ └── src
│ │ ├── chaincoded
│ │ ├── cmd
│ │ │ └── chaincoded
│ │ │ │ ├── chaincoded.go
│ │ │ │ └── log.go
│ │ └── go.mod
│ │ ├── gofilter
│ │ ├── cmd
│ │ │ └── gofilter
│ │ │ │ └── gofilter.go
│ │ └── go.mod
│ │ └── pkcs11helper
│ │ ├── cmd
│ │ └── pkcs11helper
│ │ │ ├── .gitignore
│ │ │ ├── README.md
│ │ │ ├── main.go
│ │ │ └── testdata
│ │ │ └── key.ec.pem
│ │ ├── go.mod
│ │ ├── go.sum
│ │ └── pkg
│ │ └── pkcs11wrapper
│ │ ├── ecdsa.go
│ │ └── pkcs11.go
├── changelog.sh
└── third_party_pins
│ ├── README.md
│ ├── apply_thirdparty_pins.sh
│ ├── common
│ ├── apply_header_notice.sh
│ └── insert_header_notice.sh
│ ├── fabric-ca
│ ├── apply_fabric_ca_client_utils.sh
│ └── apply_upstream.sh
│ └── fabric
│ ├── apply_fabric_client_utils.sh
│ ├── apply_fabric_common_utils.sh
│ ├── apply_fabric_external_utils.sh
│ └── apply_upstream.sh
├── test
├── fixtures
│ ├── config
│ │ ├── config_e2e.yaml
│ │ ├── config_e2e_multiorg_bootstrap.yaml
│ │ ├── config_e2e_no_orderer.yaml
│ │ ├── config_e2e_pkcs11.yaml
│ │ ├── config_e2e_single_org.yaml
│ │ ├── config_test.yaml
│ │ ├── config_test_crypto_bccsp.yaml
│ │ ├── config_test_endpoints.yaml
│ │ ├── config_test_without_orderer.yaml
│ │ └── overrides
│ │ │ └── local_entity_matchers.yaml
│ ├── dockerenv
│ │ ├── .env
│ │ ├── devstable-env.sh
│ │ ├── docker-compose-chaincoded.yaml
│ │ ├── docker-compose-negative.yaml
│ │ ├── docker-compose-nopkcs11-test.yaml
│ │ ├── docker-compose-pkcs11-test.yaml
│ │ ├── docker-compose-std.yaml
│ │ ├── docker-compose.yaml
│ │ ├── latest-env.sh
│ │ ├── nomutualtls-env.sh
│ │ ├── prerelease-env.sh
│ │ ├── prev-env.sh
│ │ └── stable-env.sh
│ ├── fabric
│ │ ├── v1.4
│ │ │ └── config
│ │ │ │ └── configtx.yaml
│ │ ├── v1
│ │ │ └── config
│ │ │ │ └── cryptogen.yaml
│ │ └── v2.2
│ │ │ └── config
│ │ │ └── configtx.yaml
│ ├── softhsm2
│ │ ├── Dockerfile
│ │ ├── install-softhsm2.sh
│ │ └── install_go.sh
│ └── testdata
│ │ ├── go
│ │ └── src
│ │ │ └── github.com
│ │ │ ├── example_cc
│ │ │ ├── example_cc.go
│ │ │ ├── go.mod
│ │ │ └── go.sum
│ │ │ └── example_pvt_cc
│ │ │ ├── example_pvt_cc.go
│ │ │ ├── go.mod
│ │ │ └── go.sum
│ │ ├── java
│ │ └── example_cc
│ │ │ ├── build.gradle
│ │ │ ├── settings.gradle
│ │ │ └── src
│ │ │ └── main
│ │ │ └── java
│ │ │ └── org
│ │ │ └── hyperledger
│ │ │ └── fabric
│ │ │ └── example
│ │ │ └── SimpleChaincode.java
│ │ └── node
│ │ └── example_cc
│ │ ├── chaincode_example02.js
│ │ └── package.json
├── integration
│ ├── base_test_setup.go
│ ├── e2e
│ │ ├── configless
│ │ │ ├── cryptoconfig_override_test.go
│ │ │ ├── end_to_end_test.go
│ │ │ ├── endpointconfig_override_test.go
│ │ │ ├── identityconfig_override_test.go
│ │ │ └── metricconfig_override_test.go
│ │ ├── end_to_end.go
│ │ ├── end_to_end_test.go
│ │ ├── no_orderer_config_test.go
│ │ ├── orgs
│ │ │ ├── multi_orgs_ch_update_signatures_test.go
│ │ │ ├── multi_orgs_singleorgconfig.go
│ │ │ ├── multi_orgs_singleorgconfig_prev.go
│ │ │ ├── multiple_orgs_minconfig_test.go
│ │ │ ├── multiple_orgs_test.go
│ │ │ └── scripts
│ │ │ │ └── generate_signature.sh
│ │ └── pkcs11
│ │ │ └── e2e_test.go
│ ├── env.go
│ ├── go.mod
│ ├── go.sum
│ ├── negative
│ │ ├── expiredorderer
│ │ │ └── expired_certificate_test.go
│ │ ├── expiredpeer
│ │ │ └── expired_certificate_test.go
│ │ ├── revoked
│ │ │ └── revoked_test.go
│ │ └── testdata
│ │ │ ├── ordererOrganizations
│ │ │ └── example.com
│ │ │ │ └── expiredtlsca
│ │ │ │ └── expired.pem
│ │ │ └── peerOrganizations
│ │ │ └── org1.example.com
│ │ │ └── expiredtlsca
│ │ │ └── expired.pem
│ ├── pkg
│ │ ├── client
│ │ │ ├── channel
│ │ │ │ ├── channel_client_javacc_test.go
│ │ │ │ ├── channel_client_nodecc_test.go
│ │ │ │ ├── channel_client_pvt_test.go
│ │ │ │ ├── channel_client_test.go
│ │ │ │ └── main_test.go
│ │ │ ├── common
│ │ │ │ ├── discovery
│ │ │ │ │ ├── discoveryclient_test.go
│ │ │ │ │ └── main_test.go
│ │ │ │ └── selection
│ │ │ │ │ ├── fabricselection_test.go
│ │ │ │ │ └── main_test.go
│ │ │ ├── event
│ │ │ │ ├── events_client_test.go
│ │ │ │ └── main_test.go
│ │ │ ├── ledger
│ │ │ │ ├── channel_ledger_test.go
│ │ │ │ ├── ledger_queries_test.go
│ │ │ │ └── main_test.go
│ │ │ ├── msp
│ │ │ │ ├── affiliations_test.go
│ │ │ │ ├── cainfo_test.go
│ │ │ │ ├── check_cert_attributes.go
│ │ │ │ ├── custom_core_factory.go
│ │ │ │ ├── custom_msp_factory.go
│ │ │ │ ├── enrollment_test.go
│ │ │ │ ├── identity_test.go
│ │ │ │ └── user_data_mgmt_test.go
│ │ │ └── resmgmt
│ │ │ │ ├── main_test.go
│ │ │ │ ├── resmgmt_queries_pvt_test.go
│ │ │ │ └── resmgmt_queries_test.go
│ │ ├── context
│ │ │ ├── main_test.go
│ │ │ └── sdk_parent_context_test.go
│ │ ├── fab
│ │ │ ├── eventclient_test.go
│ │ │ ├── install_chaincode_test.go
│ │ │ ├── main_test.go
│ │ │ ├── resource_queries_test.go
│ │ │ └── transient_data_test.go
│ │ ├── fabsdk
│ │ │ └── provider
│ │ │ │ ├── channel_config_test.go
│ │ │ │ ├── custom_cryptosuite_test.go
│ │ │ │ ├── main_test.go
│ │ │ │ ├── sdk_dyndiscovery_test.go
│ │ │ │ └── sdk_provider_test.go
│ │ └── gateway
│ │ │ ├── gateway.go
│ │ │ └── gateway_test.go
│ ├── prepare.go
│ ├── util
│ │ └── runner
│ │ │ └── runner.go
│ └── utils.go
├── metadata
│ ├── metadata.go
│ └── path.go
├── performance
│ ├── go.mod
│ ├── go.sum
│ ├── pkg
│ │ └── client
│ │ │ └── channel
│ │ │ ├── README.md
│ │ │ ├── chclient_fixture_test.go
│ │ │ ├── chclient_test.go
│ │ │ └── mockendorserserver.go
│ └── prometheus
│ │ ├── docker-compose.yaml
│ │ └── prometheus.yml
└── scripts
│ ├── chaincoded.sh
│ ├── check_license.sh
│ ├── check_lint.sh
│ ├── check_status.sh
│ ├── check_version.sh
│ ├── clean_integration.sh
│ ├── dependencies.sh
│ ├── fabric_test_commitlevel.sh
│ ├── generate_channeltx.sh
│ ├── generate_crypto.sh
│ ├── integration-pkcs11.sh
│ ├── integration.sh
│ ├── lib
│ ├── docker.sh
│ ├── find_packages.sh
│ └── linter.sh
│ ├── negative.sh
│ ├── populate-fixtures.sh
│ ├── unit-pkcs11.sh
│ └── unit.sh
└── third_party
└── github.com
└── hyperledger
└── fabric
├── common
└── policydsl
│ ├── policydsl_builder.go
│ └── policyparser.go
└── core
├── common
└── ccprovider
│ ├── ccprovider.go
│ └── cdspackage.go
└── ledger
├── kvledger
└── txmgmt
│ └── rwsetutil
│ └── rwset_proto_util.go
└── util
└── txvalidationflags.go
/.codecov.yaml:
--------------------------------------------------------------------------------
1 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
2 | #
3 | # SPDX-License-Identifier: Apache-2.0
4 |
5 | coverage:
6 | status:
7 | project:
8 | default:
9 | # this project is not currently at the desired target of 85%
10 | # target: 85%
11 | target: 73%
12 | patch:
13 | default:
14 | target: 85%
15 | only_pulls: true
16 |
17 | ignore:
18 | - "test/integration/**/*"
19 | - ./**/*.gen.go
20 |
--------------------------------------------------------------------------------
/.github/settings.yml:
--------------------------------------------------------------------------------
1 | #
2 | # SPDX-License-Identifier: Apache-2.0
3 | #
4 |
5 | repository:
6 | name: fabric-sdk-go
7 | description: null
8 | homepage: https://wiki.hyperledger.org/display/fabric
9 | default_branch: main
10 | has_downloads: true
11 | has_issues: false
12 | has_projects: false
13 | has_wiki: false
14 | archived: true
15 | private: false
16 | allow_squash_merge: true
17 | allow_merge_commit: false
18 | allow_rebase_merge: true
19 |
--------------------------------------------------------------------------------
/.github/stale.yml:
--------------------------------------------------------------------------------
1 | # SPDX-License-Identifier: Apache-2.0
2 | # Number of days of inactivity before an issue becomes stale
3 | daysUntilStale: 14
4 | # Number of days of inactivity before a stale issue is closed
5 | daysUntilClose: 14
6 | # Issues with these labels will never be considered stale
7 | # CAUTION: These issues are likely to get _less_ attention since stale bot
8 | # will never nag anyone about them. Stale bot just reflects the community's
9 | # actual priorities and adding labels to this list will not change that.
10 | # If issues you care about are going stale, you need to work with the
11 | # community to raise their profile, e.g. add more information, reach out on
12 | # Rocket.Chat, join a community call, etc.
13 | # WARNING: Please do not change these labels without seeking community
14 | # consensus first!
15 | # Label to use when marking an issue as stale
16 | staleLabel: stale
17 | only: pulls
18 | # Comment to post when marking an issue as stale. Set to `false` to disable
19 | markComment: >
20 | This issue has been automatically marked as stale because it has not had
21 | recent activity. It will be closed if no further activity occurs. Thank you
22 | for your contributions.
23 | # Comment to post when closing a stale issue. Set to `false` to disable
24 | closeComment: false
25 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
3 | #
4 | # SPDX-License-Identifier: Apache-2.0
5 | #
6 | *.db
7 | *report.xml
8 | .DS_Store
9 | .vscode
10 | debug.test
11 | coverage.txt
12 | vendor/
13 | scripts/_go/pkg/
14 | scripts/_go/bin/
15 | .idea/
16 | test/fixtures/fabric/*/crypto-config/
17 | test/fixtures/fabric/*/channel/
--------------------------------------------------------------------------------
/CODEOWNERS:
--------------------------------------------------------------------------------
1 | # SPDX-License-Identifier: Apache-2.0
2 |
3 | # Fabric SDK Go maintainers
4 | * @hyperledger/fabric-sdk-go-maintainers
5 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | Code of Conduct Guidelines
2 | ==========================
3 |
4 | Please review the Hyperledger [Code of
5 | Conduct](https://hyperledger.github.io/tsc/code-of-conduct.html)
6 | before participating. It is important that we keep things civil.
7 |
8 | 
This work is licensed under a Creative Commons Attribution 4.0 International License.
9 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | ## Contributing
2 |
3 | We welcome contributions to the Hyperledger Fabric Project in many forms, and
4 | there's always plenty to do!
5 |
6 | Please visit the
7 | [contributors guide](http://hyperledger-fabric.readthedocs.io/en/latest/CONTRIBUTING.html) in the
8 | docs to learn how to make contributions to this exciting project.
9 |
10 | 
This work is licensed under a Creative Commons Attribution 4.0 International License.
11 | s
12 |
--------------------------------------------------------------------------------
/MAINTAINERS.md:
--------------------------------------------------------------------------------
1 | ## Maintainers
2 |
3 | ### Active Maintainers
4 |
5 | | Name | GitHub | email |
6 | |---|---|---|
7 | | Andrew Coleman | andrew-coleman | andrew_coleman@uk.ibm.com |
8 | | Bob Stasyszyn | bstasyszyn | bob.stasyszyn@securekey.com |
9 | | Troy Ronda | troyronda | troy@troyronda.com |
10 |
11 | ### Retired Maintainers
12 |
13 | | Name | GitHub | email |
14 | |---|---|---|
15 | | Aleksandar Likic | alikic | aleksandar.likic@securekey.com |
16 | | Firas.Qutishat | fqutishat | firas.qutishat@securekey.com |
17 | | Gari Singh | mastersingh24 | gari.r.singh@gmail.com |
18 | | Jim Zhang | jimthematrix | jim_the_matrix@hotmail.com |
19 |
20 | 
This work is licensed under a Creative Commons Attribution 4.0 International License
21 |
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 | # Hyperledger Security Policy
2 |
3 | ## Reporting a Security Bug
4 |
5 | If you think you have discovered a security issue in any of the Hyperledger projects, we'd love to hear from you. We will take all security bugs seriously and if confirmed upon investigation we will patch it within a reasonable amount of time and release a public security bulletin discussing the impact and credit the discoverer.
6 |
7 | There are two ways to report a security bug. The easiest is to email a description of the flaw and any related information (e.g. reproduction steps, version) to [security at hyperledger dot org](mailto:security@hyperledger.org).
8 |
9 | The other way is to file a confidential security bug in our [JIRA bug tracking system](https://jira.hyperledger.org). Be sure to set the “Security Level” to “Security issue”.
10 |
11 | The process by which the Hyperledger Security Team handles security bugs is documented further in our [Defect Response page](https://wiki.hyperledger.org/display/HYP/Defect+Response) on our [wiki](https://wiki.hyperledger.org).
12 |
13 |
--------------------------------------------------------------------------------
/ci.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
3 | #
4 | # SPDX-License-Identifier: Apache-2.0
5 | #
6 |
7 | GO_MIN_VER=1.14.0
8 | GO_MAX_VER=1.16.99
9 |
--------------------------------------------------------------------------------
/ci/azure-pipelines.yml:
--------------------------------------------------------------------------------
1 | # Copyright the Hyperledger Fabric contributors. All rights reserved.
2 | #
3 | # SPDX-License-Identifier: Apache-2.0
4 |
5 | name: $(SourceBranchName)-$(Date:yyyyMMdd)$(Rev:.rrr)
6 | trigger:
7 | - main
8 | pr:
9 | - main
10 |
11 | variables:
12 | GOPATH: $(Agent.BuildDirectory)/go
13 | PATH: $(Agent.BuildDirectory)/go/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
14 | GOVER: 1.14
15 |
16 | jobs:
17 | - job: UnitTest
18 | pool:
19 | vmImage: ubuntu-18.04
20 | dependsOn: []
21 | timeoutInMinutes: 60
22 | steps:
23 | - template: install_deps.yml
24 | - checkout: self
25 | # TODO: seperate unit-test and checks.
26 | # TODO: resolve dependencies between dependencies.sh and install_deps.yml
27 | - script: make unit-test
28 | displayName: Run checks and unit test
29 | - script: bash <(curl https://codecov.io/bash) -t $CODECOV_UPLOAD_TOKEN
30 | env:
31 | CODECOV_UPLOAD_TOKEN: $(CODECOV_UPLOAD_TOKEN)
32 | displayName: Upload coverage to Codecov
33 |
34 | - job: IntegrationTest
35 | pool:
36 | vmImage: ubuntu-18.04
37 | dependsOn: []
38 | timeoutInMinutes: 60
39 | steps:
40 | - template: install_deps.yml
41 | - checkout: self
42 | - script: make integration-test
43 | displayName: Run integration test
44 | env:
45 | # TODO: update this variable name in the Makefile
46 | JENKINS_URL: true
--------------------------------------------------------------------------------
/ci/install_deps.yml:
--------------------------------------------------------------------------------
1 | # Copyright the Hyperledger Fabric contributors. All rights reserved.
2 | #
3 | # SPDX-License-Identifier: Apache-2.0
4 |
5 | steps:
6 | - script: sudo apt-get clean
7 | displayName: Run apt clean
8 | - script: sudo apt-get update
9 | displayName: Run apt update
10 | - script: sudo apt-get install -y gcc haveged libtool make
11 | displayName: Install dependencies
12 | - task: GoTool@0
13 | inputs:
14 | version: $(GOVER)
15 | goPath: $(GOPATH)
16 | displayName: Install Go $(GOVER)
17 | - script: GO111MODULE=off go get -u github.com/myitcv/gobin
18 | displayName: Install gobin
--------------------------------------------------------------------------------
/go.mod:
--------------------------------------------------------------------------------
1 | // Copyright SecureKey Technologies Inc. All Rights Reserved.
2 | //
3 | // SPDX-License-Identifier: Apache-2.0
4 |
5 | module github.com/hyperledger/fabric-sdk-go
6 |
7 | require (
8 | github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible
9 | github.com/cloudflare/cfssl v1.4.1
10 | github.com/go-kit/kit v0.10.0
11 | github.com/golang/mock v1.4.3
12 | github.com/golang/protobuf v1.3.3
13 | github.com/hashicorp/hcl v1.0.0 // indirect
14 | github.com/hyperledger/fabric-config v0.0.5
15 | github.com/hyperledger/fabric-lib-go v1.0.0
16 | github.com/hyperledger/fabric-protos-go v0.0.0-20211118165945-23d738fc3553
17 | github.com/magiconair/properties v1.8.5 // indirect
18 | github.com/miekg/pkcs11 v1.0.3
19 | github.com/mitchellh/mapstructure v1.3.2
20 | github.com/pelletier/go-toml v1.9.4 // indirect
21 | github.com/pkg/errors v0.8.1
22 | github.com/prometheus/client_golang v1.3.0
23 | github.com/spf13/afero v1.6.0 // indirect
24 | github.com/spf13/cast v1.3.1
25 | github.com/spf13/jwalterweatherman v1.1.0 // indirect
26 | github.com/spf13/viper v1.1.1
27 | github.com/stretchr/testify v1.5.1
28 | golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d
29 | golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7
30 | google.golang.org/grpc v1.29.1
31 | gopkg.in/yaml.v2 v2.3.0
32 | )
33 |
34 | go 1.14
35 |
--------------------------------------------------------------------------------
/internal/github.com/hyperledger/fabric-ca/lib/sdkpatch_serverstruct.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | /*
7 | Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
8 | Please review third_party pinning scripts and patches for more details.
9 | */
10 |
11 | package lib
12 |
13 | // CAConfig ...
14 | type CAConfig struct {
15 | }
16 |
17 | // ServerConfig ...
18 | type ServerConfig struct {
19 | CAcfg CAConfig `skip:"true"`
20 | }
21 |
22 | type serverInfoResponseNet struct {
23 | // CAName is a unique name associated with fabric-ca-server's CA
24 | CAName string
25 | // Base64 encoding of PEM-encoded certificate chain
26 | CAChain string
27 | // Base64 encoding of idemix issuer public key
28 | IssuerPublicKey string
29 | // Version of the server
30 | Version string
31 | }
32 |
33 | type enrollmentResponseNet struct {
34 | // Base64 encoded PEM-encoded ECert
35 | Cert string
36 | // The server information
37 | ServerInfo serverInfoResponseNet
38 | }
39 |
--------------------------------------------------------------------------------
/internal/github.com/hyperledger/fabric-ca/lib/serverrevoke.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | /*
7 | Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
8 | Please review third_party pinning scripts and patches for more details.
9 | */
10 |
11 | package lib
12 |
13 | import (
14 | "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/sdkinternal/pkg/api"
15 | )
16 |
17 | type revocationResponseNet struct {
18 | RevokedCerts []api.RevokedCert
19 | CRL string
20 | }
21 |
22 | // CertificateStatus represents status of an enrollment certificate
23 | type CertificateStatus string
24 |
25 | const (
26 | // Revoked is the status of a revoked certificate
27 | Revoked CertificateStatus = "revoked"
28 | // Good is the status of a active certificate
29 | Good = "good"
30 | )
31 |
--------------------------------------------------------------------------------
/internal/github.com/hyperledger/fabric-ca/sdkpatch/logbridge/logbridge.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | /*
7 | Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
8 | Please review third_party pinning scripts and patches for more details.
9 | */
10 |
11 | package logbridge
12 |
13 | import (
14 | clog "github.com/cloudflare/cfssl/log"
15 | "github.com/hyperledger/fabric-sdk-go/pkg/common/logging"
16 | )
17 |
18 | var logger *logging.Logger
19 | var cfLogBridge *cLogger
20 |
21 | func init() {
22 | logger = logging.NewLogger("fabsdk/fab")
23 | cfLogBridge = &cLogger{}
24 | clog.SetLogger(cfLogBridge)
25 | }
26 |
27 | // Debug bridges calls to the Go SDK logger's Debug.
28 | func Debug(args ...interface{}) {
29 | logger.Debug(args...)
30 | }
31 |
32 | // Debugf bridges calls to the Go SDK logger's Debugf.
33 | func Debugf(format string, args ...interface{}) {
34 | logger.Debugf(format, args)
35 | }
36 |
37 | // Info bridges calls to the Go SDK logger's Info.
38 | func Info(args ...interface{}) {
39 | logger.Info(args...)
40 | }
41 |
42 | // Infof bridges calls to the Go SDK logger's Debugf.
43 | func Infof(format string, args ...interface{}) {
44 | logger.Infof(format, args...)
45 | }
46 |
47 | // Warning bridges calls to the Go SDK logger's Warn.
48 | func Warning(args ...interface{}) {
49 | logger.Warn(args...)
50 | }
51 |
52 | // Fatalf bridges calls to the Go SDK logger's Debugf.
53 | func Fatalf(format string, args ...interface{}) {
54 | logger.Fatalf(format, args...)
55 | }
56 |
--------------------------------------------------------------------------------
/internal/github.com/hyperledger/fabric-ca/sdkpatch/logbridge/syslogwriter.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | /*
7 | Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
8 | Please review third_party pinning scripts and patches for more details.
9 | */
10 |
11 | package logbridge
12 |
13 | // cLogger implements CFSSL's SyslogWriter interface
14 | type cLogger struct {
15 | }
16 |
17 | // Debug bridges calls to the Go SDK logger's Debug.
18 | func (log *cLogger) Debug(s string) {
19 | logger.Debug(s)
20 | }
21 |
22 | // Info bridges calls to the Go SDK logger's Info.
23 | func (log *cLogger) Info(s string) {
24 | logger.Info(s)
25 | }
26 |
27 | // Warning bridges calls to the Go SDK logger's Warn.
28 | func (log *cLogger) Warning(s string) {
29 | logger.Warn(s)
30 | }
31 |
32 | // Err bridges calls to the Go SDK logger's Error.
33 | func (log *cLogger) Err(s string) {
34 | logger.Error(s)
35 | }
36 |
37 | // Crit bridges calls to the Go SDK logger's Error.
38 | func (log *cLogger) Crit(s string) {
39 | logger.Error(s)
40 | }
41 |
42 | // Emerg bridges calls to the Go SDK logger's Error.
43 | func (log *cLogger) Emerg(s string) {
44 | logger.Error(s)
45 | }
46 |
--------------------------------------------------------------------------------
/internal/github.com/hyperledger/fabric/bccsp/factory/pkcs11/pkcs11factory.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | /*
7 | Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
8 | Please review third_party pinning scripts and patches for more details.
9 | */
10 | package pkcs11
11 |
12 | import (
13 | "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/bccsp"
14 | "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/bccsp/pkcs11"
15 | "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/bccsp/sw"
16 | "github.com/pkg/errors"
17 | )
18 |
19 | const (
20 | // PKCS11BasedFactoryName is the name of the factory of the hsm-based BCCSP implementation
21 | PKCS11BasedFactoryName = "PKCS11"
22 | )
23 |
24 | // PKCS11Factory is the factory of the HSM-based BCCSP.
25 | type PKCS11Factory struct{}
26 |
27 | // Name returns the name of this factory
28 | func (f *PKCS11Factory) Name() string {
29 | return PKCS11BasedFactoryName
30 | }
31 |
32 | // Get returns an instance of BCCSP using Opts.
33 | func (f *PKCS11Factory) Get(p11Opts *pkcs11.PKCS11Opts) (bccsp.BCCSP, error) {
34 | // Validate arguments
35 | if p11Opts == nil {
36 | return nil, errors.New("Invalid config. It must not be nil.")
37 | }
38 |
39 | ks := sw.NewDummyKeyStore()
40 |
41 | return pkcs11.New(*p11Opts, ks)
42 | }
43 |
--------------------------------------------------------------------------------
/internal/github.com/hyperledger/fabric/bccsp/keystore.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. 2016 All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 | /*
17 | Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
18 | Please review third_party pinning scripts and patches for more details.
19 | */
20 | package bccsp
21 |
22 | // KeyStore represents a storage system for cryptographic keys.
23 | // It allows to store and retrieve bccsp.Key objects.
24 | // The KeyStore can be read only, in that case StoreKey will return
25 | // an error.
26 | type KeyStore interface {
27 |
28 | // ReadOnly returns true if this KeyStore is read only, false otherwise.
29 | // If ReadOnly is true then StoreKey will fail.
30 | ReadOnly() bool
31 |
32 | // GetKey returns a key object whose SKI is the one passed.
33 | GetKey(ski []byte) (k Key, err error)
34 |
35 | // StoreKey stores the key k in this KeyStore.
36 | // If this KeyStore is read only then the method will fail.
37 | StoreKey(k Key) (err error)
38 | }
39 |
--------------------------------------------------------------------------------
/internal/github.com/hyperledger/fabric/bccsp/sw/hash.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. 2017 All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 | /*
17 | Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
18 | Please review third_party pinning scripts and patches for more details.
19 | */
20 |
21 | package sw
22 |
23 | import (
24 | "hash"
25 |
26 | "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/bccsp"
27 | )
28 |
29 | type hasher struct {
30 | hash func() hash.Hash
31 | }
32 |
33 | func (c *hasher) Hash(msg []byte, opts bccsp.HashOpts) ([]byte, error) {
34 | h := c.hash()
35 | h.Write(msg)
36 | return h.Sum(nil), nil
37 | }
38 |
39 | func (c *hasher) GetHash(opts bccsp.HashOpts) (hash.Hash, error) {
40 | return c.hash(), nil
41 | }
42 |
--------------------------------------------------------------------------------
/internal/github.com/hyperledger/fabric/common/channelconfig/acls.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright State Street Corp. 2018 All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | /*
7 | Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
8 | Please review third_party pinning scripts and patches for more details.
9 | */
10 |
11 | package channelconfig
12 |
13 | import (
14 | pb "github.com/hyperledger/fabric-protos-go/peer"
15 | )
16 |
17 | // aclsProvider provides mappings for resource to policy names
18 | type aclsProvider struct {
19 | aclPolicyRefs map[string]string
20 | }
21 |
22 | func (ag *aclsProvider) PolicyRefForAPI(aclName string) string {
23 | return ag.aclPolicyRefs[aclName]
24 | }
25 |
26 | // this translates policies to absolute paths if needed
27 | func newAPIsProvider(acls map[string]*pb.APIResource) *aclsProvider {
28 | aclPolicyRefs := make(map[string]string)
29 |
30 | for key, acl := range acls {
31 | if len(acl.PolicyRef) == 0 {
32 | logger.Warningf("Policy reference for resource '%s' is specified, but empty, falling back to default", key)
33 | continue
34 | }
35 | // If the policy is fully qualified, ie to /Channel/Application/Readers leave it alone
36 | // otherwise, make it fully qualified referring to /Channel/Application/policyName
37 | if acl.PolicyRef[0] != '/' {
38 | aclPolicyRefs[key] = "/" + ChannelGroupKey + "/" + ApplicationGroupKey + "/" + acl.PolicyRef
39 | } else {
40 | aclPolicyRefs[key] = acl.PolicyRef
41 | }
42 | }
43 |
44 | return &aclsProvider{
45 | aclPolicyRefs: aclPolicyRefs,
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/internal/github.com/hyperledger/fabric/common/channelconfig/bundle.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | /*
7 | Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
8 | Please review third_party pinning scripts and patches for more details.
9 | */
10 |
11 | package channelconfig
12 |
13 | import (
14 | flogging "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/sdkpatch/logbridge"
15 | )
16 |
17 | var logger = flogging.MustGetLogger("common.channelconfig")
18 |
19 | // RootGroupKey is the key for namespacing the channel config, especially for
20 | // policy evaluation.
21 | const RootGroupKey = "Channel"
22 |
--------------------------------------------------------------------------------
/internal/github.com/hyperledger/fabric/common/channelconfig/consortiums.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | /*
7 | Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
8 | Please review third_party pinning scripts and patches for more details.
9 | */
10 |
11 | package channelconfig
12 |
13 | import (
14 | cb "github.com/hyperledger/fabric-protos-go/common"
15 | )
16 |
17 | const (
18 | // ConsortiumsGroupKey is the group name for the consortiums config
19 | ConsortiumsGroupKey = "Consortiums"
20 | )
21 |
22 | // ConsortiumsConfig holds the consoritums configuration information
23 | type ConsortiumsConfig struct {
24 | consortiums map[string]Consortium
25 | }
26 |
27 | // NewConsortiumsConfig creates a new instance of the consoritums config
28 | func NewConsortiumsConfig(consortiumsGroup *cb.ConfigGroup, mspConfig *MSPConfigHandler) (*ConsortiumsConfig, error) {
29 | cc := &ConsortiumsConfig{
30 | consortiums: make(map[string]Consortium),
31 | }
32 |
33 | for consortiumName, consortiumGroup := range consortiumsGroup.Groups {
34 | var err error
35 | if cc.consortiums[consortiumName], err = NewConsortiumConfig(consortiumGroup, mspConfig); err != nil {
36 | return nil, err
37 | }
38 | }
39 | return cc, nil
40 | }
41 |
42 | // Consortiums returns a map of the current consortiums
43 | func (cc *ConsortiumsConfig) Consortiums() map[string]Consortium {
44 | return cc.consortiums
45 | }
46 |
--------------------------------------------------------------------------------
/internal/github.com/hyperledger/fabric/common/configtx/configtx.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | /*
7 | Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
8 | Please review third_party pinning scripts and patches for more details.
9 | */
10 |
11 | package configtx
12 |
13 | import (
14 | cb "github.com/hyperledger/fabric-protos-go/common"
15 | )
16 |
17 | // Validator provides a mechanism to propose config updates, see the config update results
18 | // and validate the results of a config update.
19 | type Validator interface {
20 | // Validate attempts to apply a configtx to become the new config
21 | Validate(configEnv *cb.ConfigEnvelope) error
22 |
23 | // Validate attempts to validate a new configtx against the current config state
24 | ProposeConfigUpdate(configtx *cb.Envelope) (*cb.ConfigEnvelope, error)
25 |
26 | // ChannelID retrieves the channel ID associated with this manager
27 | ChannelID() string
28 |
29 | // ConfigProto returns the current config as a proto
30 | ConfigProto() *cb.Config
31 |
32 | // Sequence returns the current sequence number of the config
33 | Sequence() uint64
34 | }
35 |
--------------------------------------------------------------------------------
/internal/github.com/hyperledger/fabric/common/crypto/random.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. 2016 All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 | /*
17 | Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
18 | Please review third_party pinning scripts and patches for more details.
19 | */
20 |
21 | package crypto
22 |
23 | import (
24 | "crypto/rand"
25 |
26 | "github.com/pkg/errors"
27 | )
28 |
29 | const (
30 | // NonceSize is the default NonceSize
31 | NonceSize = 24
32 | )
33 |
34 | // GetRandomBytes returns len random looking bytes
35 | func GetRandomBytes(len int) ([]byte, error) {
36 | key := make([]byte, len)
37 |
38 | // TODO: rand could fill less bytes then len
39 | _, err := rand.Read(key)
40 | if err != nil {
41 | return nil, errors.Wrap(err, "error getting random bytes")
42 | }
43 |
44 | return key, nil
45 | }
46 |
47 | // GetRandomNonce returns a random byte array of length NonceSize
48 | func GetRandomNonce() ([]byte, error) {
49 | return GetRandomBytes(NonceSize)
50 | }
51 |
--------------------------------------------------------------------------------
/internal/github.com/hyperledger/fabric/common/metrics/disabled/provider.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | /*
7 | Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
8 | Please review third_party pinning scripts and patches for more details.
9 | */
10 |
11 | package disabled
12 |
13 | import (
14 | "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/common/metrics"
15 | )
16 |
17 | type Provider struct{}
18 |
19 | func (p *Provider) NewCounter(o metrics.CounterOpts) metrics.Counter { return &Counter{} }
20 | func (p *Provider) NewGauge(o metrics.GaugeOpts) metrics.Gauge { return &Gauge{} }
21 | func (p *Provider) NewHistogram(o metrics.HistogramOpts) metrics.Histogram { return &Histogram{} }
22 |
23 | type Counter struct{}
24 |
25 | func (c *Counter) Add(delta float64) {}
26 | func (c *Counter) With(labelValues ...string) metrics.Counter {
27 | return c
28 | }
29 |
30 | type Gauge struct{}
31 |
32 | func (g *Gauge) Add(delta float64) {}
33 | func (g *Gauge) Set(delta float64) {}
34 | func (g *Gauge) With(labelValues ...string) metrics.Gauge {
35 | return g
36 | }
37 |
38 | type Histogram struct{}
39 |
40 | func (h *Histogram) Observe(value float64) {}
41 | func (h *Histogram) With(labelValues ...string) metrics.Histogram {
42 | return h
43 | }
44 |
--------------------------------------------------------------------------------
/internal/github.com/hyperledger/fabric/common/policies/implicitmetaparser.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | /*
7 | Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
8 | Please review third_party pinning scripts and patches for more details.
9 | */
10 |
11 | package policies
12 |
13 | import (
14 | "strings"
15 |
16 | cb "github.com/hyperledger/fabric-protos-go/common"
17 | "github.com/pkg/errors"
18 | )
19 |
20 | func ImplicitMetaFromString(input string) (*cb.ImplicitMetaPolicy, error) {
21 | args := strings.Split(input, " ")
22 | if len(args) != 2 {
23 | return nil, errors.Errorf("expected two space separated tokens, but got %d", len(args))
24 | }
25 |
26 | res := &cb.ImplicitMetaPolicy{
27 | SubPolicy: args[1],
28 | }
29 |
30 | switch args[0] {
31 | case cb.ImplicitMetaPolicy_ANY.String():
32 | res.Rule = cb.ImplicitMetaPolicy_ANY
33 | case cb.ImplicitMetaPolicy_ALL.String():
34 | res.Rule = cb.ImplicitMetaPolicy_ALL
35 | case cb.ImplicitMetaPolicy_MAJORITY.String():
36 | res.Rule = cb.ImplicitMetaPolicy_MAJORITY
37 | default:
38 | return nil, errors.Errorf("unknown rule type '%s', expected ALL, ANY, or MAJORITY", args[0])
39 | }
40 |
41 | return res, nil
42 | }
43 |
--------------------------------------------------------------------------------
/internal/github.com/hyperledger/fabric/core/chaincode/persistence/chaincode_package.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | /*
7 | Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
8 | Please review third_party pinning scripts and patches for more details.
9 | */
10 |
11 | package persistence
12 |
13 | import (
14 | "regexp"
15 |
16 | "github.com/pkg/errors"
17 | )
18 |
19 | // LabelRegexp is the regular expression controlling the allowed characters
20 | // for the package label.
21 | var LabelRegexp = regexp.MustCompile(`^[[:alnum:]][[:alnum:]_.+-]*$`)
22 |
23 | // ValidateLabel return an error if the provided label contains any invalid
24 | // characters, as determined by LabelRegexp.
25 | func ValidateLabel(label string) error {
26 | if !LabelRegexp.MatchString(label) {
27 | return errors.Errorf("invalid label '%s'. Label must be non-empty, can only consist of alphanumerics, symbols from '.+-_', and can only begin with alphanumerics", label)
28 | }
29 |
30 | return nil
31 | }
32 |
--------------------------------------------------------------------------------
/internal/github.com/hyperledger/fabric/core/middleware/chain.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | /*
7 | Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
8 | Please review third_party pinning scripts and patches for more details.
9 | */
10 |
11 | package middleware
12 |
13 | import (
14 | "net/http"
15 | )
16 |
17 | type Middleware func(http.Handler) http.Handler
18 |
19 | // A Chain is a middleware chain use for http request processing.
20 | type Chain struct {
21 | mw []Middleware
22 | }
23 |
24 | // NewChain creates a new Middleware chain. The chain will call the Middleware
25 | // in the order provided.
26 | func NewChain(middlewares ...Middleware) Chain {
27 | return Chain{
28 | mw: append([]Middleware{}, middlewares...),
29 | }
30 | }
31 |
32 | // Handler returns an http.Handler for this chain.
33 | func (c Chain) Handler(h http.Handler) http.Handler {
34 | if h == nil {
35 | h = http.DefaultServeMux
36 | }
37 |
38 | for i := len(c.mw) - 1; i >= 0; i-- {
39 | h = c.mw[i](h)
40 | }
41 | return h
42 | }
43 |
--------------------------------------------------------------------------------
/internal/github.com/hyperledger/fabric/core/middleware/request_id.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | /*
7 | Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
8 | Please review third_party pinning scripts and patches for more details.
9 | */
10 |
11 | package middleware
12 |
13 | import (
14 | "context"
15 | "net/http"
16 | )
17 |
18 | var requestIDKey = requestIDKeyType{}
19 |
20 | type requestIDKeyType struct{}
21 |
22 | func RequestID(ctx context.Context) string {
23 | if reqID, ok := ctx.Value(requestIDKey).(string); ok {
24 | return reqID
25 | }
26 | return "unknown"
27 | }
28 |
29 | type GenerateIDFunc func() string
30 |
31 | type requestID struct {
32 | generateID GenerateIDFunc
33 | next http.Handler
34 | }
35 |
36 | func WithRequestID(generator GenerateIDFunc) Middleware {
37 | return func(next http.Handler) http.Handler {
38 | return &requestID{next: next, generateID: generator}
39 | }
40 | }
41 |
42 | func (r *requestID) ServeHTTP(w http.ResponseWriter, req *http.Request) {
43 | reqID := req.Header.Get("X-Request-Id")
44 | if reqID == "" {
45 | reqID = r.generateID()
46 | req.Header.Set("X-Request-Id", reqID)
47 | }
48 |
49 | ctx := context.WithValue(req.Context(), requestIDKey, reqID)
50 | req = req.WithContext(ctx)
51 |
52 | w.Header().Add("X-Request-Id", reqID)
53 |
54 | r.next.ServeHTTP(w, req)
55 | }
56 |
--------------------------------------------------------------------------------
/internal/github.com/hyperledger/fabric/core/middleware/require_cert.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | /*
7 | Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
8 | Please review third_party pinning scripts and patches for more details.
9 | */
10 |
11 | package middleware
12 |
13 | import (
14 | "net/http"
15 | )
16 |
17 | type requireCert struct {
18 | next http.Handler
19 | }
20 |
21 | // RequireCert is used to ensure that a verified TLS client certificate was
22 | // used for authentication.
23 | func RequireCert() Middleware {
24 | return func(next http.Handler) http.Handler {
25 | return &requireCert{next: next}
26 | }
27 | }
28 |
29 | func (r *requireCert) ServeHTTP(w http.ResponseWriter, req *http.Request) {
30 | switch {
31 | case req.TLS == nil:
32 | fallthrough
33 | case len(req.TLS.VerifiedChains) == 0:
34 | fallthrough
35 | case len(req.TLS.VerifiedChains[0]) == 0:
36 | w.WriteHeader(http.StatusUnauthorized)
37 | default:
38 | r.next.ServeHTTP(w, req)
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/internal/github.com/hyperledger/fabric/core/operations/metrics.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | /*
7 | Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
8 | Please review third_party pinning scripts and patches for more details.
9 | */
10 |
11 | package operations
12 |
13 | import (
14 | "sync"
15 |
16 | "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/common/metrics"
17 | "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/common/metrics/prometheus"
18 | )
19 |
20 | var (
21 | fabricVersion = metrics.GaugeOpts{
22 | Name: "fabric_version",
23 | Help: "The active version of Fabric.",
24 | LabelNames: []string{"version"},
25 | StatsdFormat: "%{#fqname}.%{version}",
26 | }
27 |
28 | gaugeLock sync.Mutex
29 | promVersionGauge metrics.Gauge
30 | )
31 |
32 | func versionGauge(provider metrics.Provider) metrics.Gauge {
33 | switch provider.(type) {
34 | case *prometheus.Provider:
35 | gaugeLock.Lock()
36 | defer gaugeLock.Unlock()
37 | if promVersionGauge == nil {
38 | promVersionGauge = provider.NewGauge(fabricVersion)
39 | }
40 | return promVersionGauge
41 |
42 | default:
43 | return provider.NewGauge(fabricVersion)
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/internal/github.com/hyperledger/fabric/core/operations/tls.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | /*
7 | Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
8 | Please review third_party pinning scripts and patches for more details.
9 | */
10 |
11 | package operations
12 |
13 | import (
14 | "crypto/tls"
15 | "crypto/x509"
16 | "io/ioutil"
17 |
18 | "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/sdkinternal/pkg/comm"
19 | )
20 |
21 | type TLS struct {
22 | Enabled bool
23 | CertFile string
24 | KeyFile string
25 | ClientCertRequired bool
26 | ClientCACertFiles []string
27 | }
28 |
29 | func (t TLS) Config() (*tls.Config, error) {
30 | var tlsConfig *tls.Config
31 |
32 | if t.Enabled {
33 | cert, err := tls.LoadX509KeyPair(t.CertFile, t.KeyFile)
34 | if err != nil {
35 | return nil, err
36 | }
37 | caCertPool := x509.NewCertPool()
38 | for _, caPath := range t.ClientCACertFiles {
39 | caPem, err := ioutil.ReadFile(caPath)
40 | if err != nil {
41 | return nil, err
42 | }
43 | caCertPool.AppendCertsFromPEM(caPem)
44 | }
45 | tlsConfig = &tls.Config{
46 | Certificates: []tls.Certificate{cert},
47 | CipherSuites: comm.DefaultTLSCipherSuites,
48 | ClientCAs: caCertPool,
49 | }
50 | if t.ClientCertRequired {
51 | tlsConfig.ClientAuth = tls.RequireAndVerifyClientCert
52 | } else {
53 | tlsConfig.ClientAuth = tls.VerifyClientCertIfGiven
54 | }
55 | }
56 |
57 | return tlsConfig, nil
58 | }
59 |
--------------------------------------------------------------------------------
/internal/github.com/hyperledger/fabric/discovery/protoext/querytype.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | /*
7 | Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
8 | Please review third_party pinning scripts and patches for more details.
9 | */
10 |
11 | package protoext
12 |
13 | import "github.com/hyperledger/fabric-protos-go/discovery"
14 |
15 | // QueryType defines the types of service discovery requests
16 | type QueryType uint8
17 |
18 | const (
19 | InvalidQueryType QueryType = iota
20 | ConfigQueryType
21 | PeerMembershipQueryType
22 | ChaincodeQueryType
23 | LocalMembershipQueryType
24 | )
25 |
26 | // GetType returns the type of the request
27 | func GetQueryType(q *discovery.Query) QueryType {
28 | switch {
29 | case q.GetCcQuery() != nil:
30 | return ChaincodeQueryType
31 | case q.GetConfigQuery() != nil:
32 | return ConfigQueryType
33 | case q.GetPeerQuery() != nil:
34 | return PeerMembershipQueryType
35 | case q.GetLocalPeers() != nil:
36 | return LocalMembershipQueryType
37 | default:
38 | return InvalidQueryType
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/internal/github.com/hyperledger/fabric/discovery/protoext/response.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | /*
7 | Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
8 | Please review third_party pinning scripts and patches for more details.
9 | */
10 |
11 | package protoext
12 |
13 | import "github.com/hyperledger/fabric-protos-go/discovery"
14 |
15 | // ResponseConfigAt returns the ConfigResult at a given index in the Response,
16 | // or an Error if present.
17 | func ResponseConfigAt(m *discovery.Response, i int) (*discovery.ConfigResult, *discovery.Error) {
18 | r := m.Results[i]
19 | return r.GetConfigResult(), r.GetError()
20 | }
21 |
22 | // ResponseMembershipAt returns the PeerMembershipResult at a given index in the Response,
23 | // or an Error if present.
24 | func ResponseMembershipAt(m *discovery.Response, i int) (*discovery.PeerMembershipResult, *discovery.Error) {
25 | r := m.Results[i]
26 | return r.GetMembers(), r.GetError()
27 | }
28 |
29 | // ResponseEndorsersAt returns the PeerMembershipResult at a given index in the Response,
30 | // or an Error if present.
31 | func ResponseEndorsersAt(m *discovery.Response, i int) (*discovery.ChaincodeQueryResult, *discovery.Error) {
32 | r := m.Results[i]
33 | return r.GetCcQueryRes(), r.GetError()
34 | }
35 |
--------------------------------------------------------------------------------
/internal/github.com/hyperledger/fabric/protoutil/configtxutils.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | /*
7 | Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
8 | Please review third_party pinning scripts and patches for more details.
9 | */
10 | /*
11 | Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
12 | Please review third_party pinning scripts and patches for more details.
13 | */
14 |
15 | package protoutil
16 |
17 | import "github.com/hyperledger/fabric-protos-go/common"
18 |
19 | func NewConfigGroup() *common.ConfigGroup {
20 | return &common.ConfigGroup{
21 | Groups: make(map[string]*common.ConfigGroup),
22 | Values: make(map[string]*common.ConfigValue),
23 | Policies: make(map[string]*common.ConfigPolicy),
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/internal/github.com/hyperledger/fabric/sdkinternal/pkg/identity/identity.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | /*
7 | Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
8 | Please review third_party pinning scripts and patches for more details.
9 | */
10 |
11 | // Package identity provides a set of interfaces for identity-related operations.
12 |
13 | package identity
14 |
15 | // Signer is an interface which wraps the Sign method.
16 | //
17 | // Sign signs message bytes and returns the signature or an error on failure.
18 | type Signer interface {
19 | Sign(message []byte) ([]byte, error)
20 | }
21 |
22 | // Serializer is an interface which wraps the Serialize function.
23 | //
24 | // Serialize converts an identity to bytes. It returns an error on failure.
25 | type Serializer interface {
26 | Serialize() ([]byte, error)
27 | }
28 |
29 | // SignerSerializer groups the Sign and Serialize methods.
30 | type SignerSerializer interface {
31 | Signer
32 | Serializer
33 | }
34 |
--------------------------------------------------------------------------------
/internal/github.com/hyperledger/fabric/sdkpatch/logbridge/logbridge.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | /*
7 | Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
8 | Please review third_party pinning scripts and patches for more details.
9 | */
10 |
11 | package logbridge
12 |
13 | import (
14 | "github.com/hyperledger/fabric-sdk-go/pkg/common/logging"
15 | )
16 |
17 | // Log levels (from fabric-sdk-go/pkg/logging/level.go).
18 | const (
19 | CRITICAL logging.Level = iota
20 | ERROR
21 | WARNING
22 | INFO
23 | DEBUG
24 | )
25 |
26 | // Logger bridges the SDK's logger struct
27 | type Logger struct {
28 | *logging.Logger
29 | module string
30 | }
31 |
32 | // MustGetLogger bridges calls the Go SDK NewLogger
33 | func MustGetLogger(module string) *Logger {
34 | fabModule := "fabsdk/fab"
35 | logger := logging.NewLogger(fabModule)
36 | return &Logger{
37 | Logger: logger,
38 | module: fabModule,
39 | }
40 | }
41 |
42 | // Warningf bridges calls to the Go SDK logger's Warnf.
43 | func (l *Logger) Warningf(format string, args ...interface{}) {
44 | l.Warnf(format, args...)
45 | }
46 |
47 | // Warning bridges calls to the Go SDK logger's Warn.
48 | func (l *Logger) Warning(args ...interface{}) {
49 | l.Warn(args...)
50 | }
51 |
52 | // IsEnabledFor bridges calls to the Go SDK logger's IsEnabledFor.
53 | func (l *Logger) IsEnabledFor(level logging.Level) bool {
54 | return logging.IsEnabledFor(l.module, level)
55 | }
56 |
--------------------------------------------------------------------------------
/pkg/client/channel/chclientrun.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package channel
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/client/common/discovery/greylist"
11 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/context"
12 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
13 | )
14 |
15 | func newClient(channelContext context.Channel, membership fab.ChannelMembership, eventService fab.EventService, greylistProvider *greylist.Filter) Client {
16 | channelClient := Client{
17 | membership: membership,
18 | eventService: eventService,
19 | greylist: greylistProvider,
20 | context: channelContext,
21 | metrics: channelContext.GetMetrics(),
22 | }
23 | return channelClient
24 | }
25 |
--------------------------------------------------------------------------------
/pkg/client/channel/chclientrun_std.go:
--------------------------------------------------------------------------------
1 | //go:build !pprof
2 | // +build !pprof
3 |
4 | /*
5 | Copyright SecureKey Technologies Inc. All Rights Reserved.
6 |
7 | SPDX-License-Identifier: Apache-2.0
8 | */
9 |
10 | package channel
11 |
12 | import (
13 | "github.com/hyperledger/fabric-sdk-go/pkg/client/channel/invoke"
14 | )
15 |
16 | func callQuery(cc *Client, request Request, options ...RequestOption) (Response, error) {
17 | return cc.InvokeHandler(invoke.NewQueryHandler(), request, options...)
18 | }
19 |
20 | func callExecute(cc *Client, request Request, options ...RequestOption) (Response, error) {
21 | return cc.InvokeHandler(invoke.NewExecuteHandler(), request, options...)
22 | }
23 |
--------------------------------------------------------------------------------
/pkg/client/common/discovery/discoveryfilter.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package discovery
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
11 | )
12 |
13 | // filterService implements discovery service
14 | type filterService struct {
15 | discoveryService fab.DiscoveryService
16 | targetFilter fab.TargetFilter
17 | }
18 |
19 | // NewDiscoveryFilterService return discovery service with filter
20 | func NewDiscoveryFilterService(discoveryService fab.DiscoveryService, targetFilter fab.TargetFilter) fab.DiscoveryService {
21 | return &filterService{discoveryService: discoveryService, targetFilter: targetFilter}
22 | }
23 |
24 | // GetPeers is used to get peers
25 | func (fs *filterService) GetPeers() ([]fab.Peer, error) {
26 | peers, err := fs.discoveryService.GetPeers()
27 | if err != nil {
28 | return nil, err
29 | }
30 | targets := filterTargets(peers, fs.targetFilter)
31 | return targets, nil
32 | }
33 |
34 | // filterTargets is helper method to filter peers
35 | func filterTargets(peers []fab.Peer, filter fab.TargetFilter) []fab.Peer {
36 |
37 | if filter == nil {
38 | return peers
39 | }
40 |
41 | filteredPeers := []fab.Peer{}
42 | for _, peer := range peers {
43 | if filter.Accept(peer) {
44 | filteredPeers = append(filteredPeers, peer)
45 | }
46 | }
47 |
48 | return filteredPeers
49 | }
50 |
--------------------------------------------------------------------------------
/pkg/client/common/discovery/dynamicdiscovery/chservice_test_env.go:
--------------------------------------------------------------------------------
1 | // +build testing
2 |
3 | /*
4 | Copyright SecureKey Technologies Inc. All Rights Reserved.
5 |
6 | SPDX-License-Identifier: Apache-2.0
7 | */
8 |
9 | package dynamicdiscovery
10 |
11 | import (
12 | contextAPI "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/context"
13 | "github.com/hyperledger/fabric-sdk-go/pkg/fab/discovery"
14 | )
15 |
16 | // SetClientProvider overrides the discovery client provider for unit tests
17 | func SetClientProvider(provider func(ctx contextAPI.Client) (discovery.Client, error)) {
18 | clientProvider = provider
19 | }
20 |
--------------------------------------------------------------------------------
/pkg/client/common/discovery/dynamicdiscovery/errors.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package dynamicdiscovery
8 |
9 | import (
10 | "strings"
11 |
12 | "github.com/pkg/errors"
13 | )
14 |
15 | const (
16 | // AccessDenied indicates that the user does not have permission to perform the operation
17 | AccessDenied = "access denied"
18 | )
19 |
20 | // DiscoveryError is an error originating at the Discovery service
21 | type DiscoveryError struct {
22 | error
23 | target string
24 | }
25 |
26 | //Error returns string representation with target
27 | func (e DiscoveryError) Error() string {
28 | return errors.Wrapf(e.error, "target [%s]", e.target).Error()
29 | }
30 |
31 | //Target returns url of the peer
32 | func (e DiscoveryError) Target() string {
33 | return e.target
34 | }
35 |
36 | //IsAccessDenied checks if response contains access denied msg
37 | func (e DiscoveryError) IsAccessDenied() bool {
38 | return strings.Contains(e.Error(), AccessDenied)
39 | }
40 |
41 | func newDiscoveryError(err error, target string) error {
42 | return DiscoveryError{target: target, error: err}
43 | }
44 |
--------------------------------------------------------------------------------
/pkg/client/common/discovery/staticdiscovery/localservice.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package staticdiscovery
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
11 | )
12 |
13 | type localDiscoveryService struct {
14 | config fab.EndpointConfig
15 | peers []fab.Peer
16 | }
17 |
18 | // GetPeers is used to get local peers
19 | func (ds *localDiscoveryService) GetPeers() ([]fab.Peer, error) {
20 | return ds.peers, nil
21 | }
22 |
--------------------------------------------------------------------------------
/pkg/client/common/discovery/staticdiscovery/service.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package staticdiscovery
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
11 | "github.com/pkg/errors"
12 | )
13 |
14 | // DiscoveryService implements a static discovery service
15 | type DiscoveryService struct {
16 | peers []fab.Peer
17 | }
18 |
19 | // NewService creates a static discovery service
20 | func NewService(config fab.EndpointConfig, peerCreator peerCreator, channelID string) (*DiscoveryService, error) {
21 | if channelID == "" {
22 | return nil, errors.New("channel ID must be provided")
23 | }
24 |
25 | // Use configured channel peers
26 | chPeers := config.ChannelPeers(channelID)
27 | if len(chPeers) == 0 {
28 | return nil, errors.Errorf("no channel peers configured for channel [%s]", channelID)
29 | }
30 |
31 | peers := []fab.Peer{}
32 | for _, p := range chPeers {
33 | newPeer, err := peerCreator.CreatePeerFromConfig(&p.NetworkPeer)
34 | if err != nil || newPeer == nil {
35 | return nil, errors.WithMessage(err, "NewPeer failed")
36 | }
37 |
38 | peers = append(peers, newPeer)
39 | }
40 |
41 | return &DiscoveryService{
42 | peers: peers,
43 | }, nil
44 | }
45 |
46 | // GetPeers is used to get peers
47 | func (ds *DiscoveryService) GetPeers() ([]fab.Peer, error) {
48 | return ds.peers, nil
49 | }
50 |
--------------------------------------------------------------------------------
/pkg/client/common/random/random.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package random
8 |
9 | import (
10 | "math/rand"
11 |
12 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
13 | )
14 |
15 | //PickRandomNPeerConfigs picks N random unique peer configs from given channel peer list
16 | func PickRandomNPeerConfigs(chPeers []fab.ChannelPeer, n int) []fab.PeerConfig {
17 |
18 | var result []fab.PeerConfig
19 | for _, index := range rand.Perm(len(chPeers)) {
20 | result = append(result, chPeers[index].PeerConfig)
21 | if len(result) == n {
22 | break
23 | }
24 | }
25 | return result
26 | }
27 |
--------------------------------------------------------------------------------
/pkg/client/common/selection/dynamicselection/pgresolver/pgresolver.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package pgresolver
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
11 | )
12 |
13 | // PeerGroupResolver resolves a group of peers that would (exactly) satisfy
14 | // a chaincode's endorsement policy.
15 | type PeerGroupResolver interface {
16 | // Resolve returns a PeerGroup ensuring that all of the peers in the group are
17 | // in the given set of available peers.
18 | Resolve(peers []fab.Peer) (PeerGroup, error)
19 | }
20 |
21 | // LoadBalancePolicy is used to pick a peer group from a given set of peer groups
22 | type LoadBalancePolicy interface {
23 | // Choose returns one of the peer groups from the given set of peer groups.
24 | // This method should never return nil but may return a PeerGroup that contains no peers.
25 | Choose(peerGroups []PeerGroup) PeerGroup
26 | }
27 |
--------------------------------------------------------------------------------
/pkg/client/common/selection/fabricselection/cachekey.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package fabricselection
8 |
9 | import (
10 | "encoding/json"
11 |
12 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
13 | )
14 |
15 | type cacheKey struct {
16 | chaincodes []*fab.ChaincodeCall
17 | }
18 |
19 | func newCacheKey(chaincodes []*fab.ChaincodeCall) *cacheKey {
20 | return &cacheKey{chaincodes: chaincodes}
21 | }
22 |
23 | func (k *cacheKey) String() string {
24 | bytes, err := json.Marshal(k.chaincodes)
25 | if err != nil {
26 | logger.Errorf("unexpected error marshalling chaincodes: %s", err)
27 | return ""
28 | }
29 | return string(bytes)
30 | }
31 |
--------------------------------------------------------------------------------
/pkg/client/common/selection/fabricselection/selection_test_env.go:
--------------------------------------------------------------------------------
1 | // +build testing
2 |
3 | /*
4 | Copyright SecureKey Technologies Inc. All Rights Reserved.
5 |
6 | SPDX-License-Identifier: Apache-2.0
7 | */
8 |
9 | package fabricselection
10 |
11 | import (
12 | contextAPI "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/context"
13 | )
14 |
15 | // SetClientProvider overrides the discovery client provider for unit tests
16 | func SetClientProvider(provider func(ctx contextAPI.Client) (DiscoveryClient, error)) {
17 | clientProvider = provider
18 | }
19 |
--------------------------------------------------------------------------------
/pkg/client/common/selection/fabricselection/selectionfilter_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package fabricselection
8 |
9 | import (
10 | "context"
11 | "testing"
12 |
13 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
14 | "github.com/stretchr/testify/require"
15 | )
16 |
17 | func TestPeerEndpointValue(t *testing.T) {
18 | const mspID = "org1"
19 | const url = "peer1.org1.com"
20 |
21 | t.Run("Success", func(t *testing.T) {
22 | ep := &peerEndpointValue{
23 | mspID: mspID,
24 | url: url,
25 | properties: fab.Properties{
26 | fab.PropertyLedgerHeight: uint64(1001),
27 | },
28 | }
29 |
30 | require.Equal(t, mspID, ep.MSPID())
31 | require.Equal(t, url, ep.URL())
32 | require.NotEmpty(t, ep.Properties())
33 | require.Equal(t, uint64(1001), ep.Properties()[fab.PropertyLedgerHeight])
34 | require.Equal(t, uint64(1001), ep.BlockHeight())
35 | require.Panics(t, func() {
36 | _, err := ep.ProcessTransactionProposal(context.TODO(), fab.ProcessProposalRequest{})
37 | require.NoError(t, err)
38 | })
39 | })
40 |
41 | t.Run("No ledger height property", func(t *testing.T) {
42 | ep := &peerEndpointValue{
43 | mspID: mspID,
44 | url: url,
45 | properties: fab.Properties{},
46 | }
47 |
48 | require.Equal(t, mspID, ep.MSPID())
49 | require.Equal(t, url, ep.URL())
50 | require.Empty(t, ep.Properties())
51 | require.Equal(t, uint64(0), ep.BlockHeight())
52 | })
53 | }
54 |
--------------------------------------------------------------------------------
/pkg/client/common/selection/sorter/balancedsorter/balancedsorter.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package balancedsorter
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/client/common/selection/options"
11 | "github.com/hyperledger/fabric-sdk-go/pkg/common/logging"
12 | coptions "github.com/hyperledger/fabric-sdk-go/pkg/common/options"
13 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
14 | )
15 |
16 | var logger = logging.NewLogger("fabsdk/client")
17 |
18 | // New returns a peer sorter that chooses a peer according to a provided balancer.
19 | func New(opts ...coptions.Opt) options.PeerSorter {
20 | params := defaultParams()
21 | coptions.Apply(params, opts)
22 |
23 | return func(peers []fab.Peer) []fab.Peer {
24 | return params.balancer(peers)
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/pkg/client/common/selection/sorter/balancedsorter/opts.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package balancedsorter
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/client/common/selection/balancer"
11 | "github.com/hyperledger/fabric-sdk-go/pkg/common/options"
12 | )
13 |
14 | type params struct {
15 | balancer balancer.Balancer
16 | }
17 |
18 | func defaultParams() *params {
19 | return ¶ms{
20 | balancer: balancer.RoundRobin(),
21 | }
22 | }
23 |
24 | // WithBalancer sets the balancing strategy to use to load balance between the peers
25 | func WithBalancer(value balancer.Balancer) options.Opt {
26 | return func(p options.Params) {
27 | if setter, ok := p.(balancerSetter); ok {
28 | setter.SetBalancer(value)
29 | }
30 | }
31 | }
32 |
33 | type balancerSetter interface {
34 | SetBalancer(value balancer.Balancer)
35 | }
36 |
37 | func (p *params) SetBalancer(value balancer.Balancer) {
38 | logger.Debugf("Balancer: %#v", value)
39 | p.balancer = value
40 | }
41 |
--------------------------------------------------------------------------------
/pkg/client/msp/identity.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package msp
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
11 | "github.com/pkg/errors"
12 | )
13 |
14 | var (
15 | // ErrUserNotFound indicates the user was not found
16 | ErrUserNotFound = errors.New("user not found")
17 | )
18 |
19 | // IdentityManager provides management of identities in a Fabric network
20 | type IdentityManager interface {
21 | GetSigningIdentity(name string) (msp.SigningIdentity, error)
22 | CreateSigningIdentity(ops ...msp.SigningIdentityOption) (msp.SigningIdentity, error)
23 | }
24 |
--------------------------------------------------------------------------------
/pkg/client/resmgmt/testdata/config.block:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger/fabric-sdk-go/315f4e0485018a7b2c84f8ac4646bb6834bd9d66/pkg/client/resmgmt/testdata/config.block
--------------------------------------------------------------------------------
/pkg/client/resmgmt/testdata/extractcherr.tx:
--------------------------------------------------------------------------------
1 | ExtractChannelConfigError
--------------------------------------------------------------------------------
/pkg/client/resmgmt/testdata/signcherr.tx:
--------------------------------------------------------------------------------
1 | SignChannelConfigError
--------------------------------------------------------------------------------
/pkg/client/resmgmt/testdata/test.tx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger/fabric-sdk-go/315f4e0485018a7b2c84f8ac4646bb6834bd9d66/pkg/client/resmgmt/testdata/test.tx
--------------------------------------------------------------------------------
/pkg/common/errors/multi/example_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package multi
8 |
9 | import (
10 | "fmt"
11 | )
12 |
13 | func Example() {
14 | errs := Errors{}
15 | errs = append(errs, fmt.Errorf("peer0 failed"))
16 | errs = append(errs, fmt.Errorf("peer1 failed"))
17 |
18 | // Multi errors implement the standard error interface and are returned as regular errors
19 | err := interface{}(errs).(error)
20 |
21 | // We can extract multi errors from a standard error
22 | errs, ok := err.(Errors)
23 | fmt.Println(ok)
24 |
25 | // And handle each error individually
26 | for _, e := range errs {
27 | fmt.Println(e)
28 | }
29 |
30 | // Output:
31 | // true
32 | // peer0 failed
33 | // peer1 failed
34 | }
35 |
--------------------------------------------------------------------------------
/pkg/common/errors/status/example_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package status
8 |
9 | import "fmt"
10 |
11 | func Example() {
12 | // Status errors are returned for certain transient errors by clients in the SDK
13 | statusError := New(ClientStatus, EndorsementMismatch.ToInt32(), "proposal responses do not match", nil)
14 |
15 | // Status errors implement the standard error interface and are returned as regular errors
16 | err := interface{}(statusError).(error)
17 |
18 | // A user can extract status information from a status
19 | status, ok := FromError(err)
20 | fmt.Println(ok)
21 | fmt.Println(status.Group)
22 | fmt.Println(Code(status.Code))
23 | fmt.Println(status.Message)
24 |
25 | // Output:
26 | // true
27 | // Client Status
28 | // ENDORSEMENT_MISMATCH
29 | // proposal responses do not match
30 | }
31 |
--------------------------------------------------------------------------------
/pkg/common/logging/logger_testing_env.go:
--------------------------------------------------------------------------------
1 | // +build testing
2 |
3 | /*
4 | Copyright SecureKey Technologies Inc. All Rights Reserved.
5 |
6 | SPDX-License-Identifier: Apache-2.0
7 | */
8 |
9 | package logging
10 |
11 | import "sync"
12 |
13 | // UnsafeReset allows reinitialization of the logger provider.
14 | // This method is intended to enable tests and should not be called.
15 | func UnsafeReset() {
16 | loggerProviderInstance = nil
17 | loggerProviderOnce = sync.Once{}
18 | }
19 |
--------------------------------------------------------------------------------
/pkg/common/options/options.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package options
8 |
9 | // Params represents a construct that holds
10 | // a set of parameters
11 | type Params interface{}
12 |
13 | // Opt is an option that is applied to Params
14 | type Opt func(opts Params)
15 |
16 | // Apply applies the given options to the given Params
17 | func Apply(params Params, opts []Opt) {
18 | for _, opt := range opts {
19 | opt(params)
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/pkg/common/providers/context/context.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package context
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
11 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
12 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
13 | )
14 |
15 | // Client supplies the configuration and signing identity to client objects.
16 | type Client fab.ClientContext
17 |
18 | // Providers represents the SDK configured providers context.
19 | type Providers interface {
20 | core.Providers
21 | msp.Providers
22 | fab.Providers
23 | }
24 |
25 | // Local supplies the configuration for a local context client
26 | type Local interface {
27 | Client
28 | LocalDiscoveryService() fab.DiscoveryService
29 | }
30 |
31 | // Channel supplies the configuration for channel context client
32 | type Channel interface {
33 | Client
34 | ChannelService() fab.ChannelService
35 | ChannelID() string
36 | }
37 |
38 | // ClientProvider returns client context
39 | type ClientProvider func() (Client, error)
40 |
41 | // LocalProvider returns local client context
42 | type LocalProvider func() (Local, error)
43 |
44 | // ChannelProvider returns channel client context
45 | type ChannelProvider func() (Channel, error)
46 |
--------------------------------------------------------------------------------
/pkg/common/providers/core/kvstore.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package core
8 |
9 | import "github.com/pkg/errors"
10 |
11 | var (
12 | // ErrKeyValueNotFound indicates that a value for the key does not exist
13 | ErrKeyValueNotFound = errors.New("value for key not found")
14 | )
15 |
16 | // KVStore is a generic key-value store interface.
17 | type KVStore interface {
18 |
19 | /**
20 | * Store sets the value for the key.
21 | */
22 | Store(key interface{}, value interface{}) error
23 |
24 | /**
25 | * Load returns the value stored in the store for a key.
26 | * If a value for the key was not found, returns (nil, ErrNotFound)
27 | */
28 | Load(key interface{}) (interface{}, error)
29 |
30 | /**
31 | * Delete deletes the value for a key.
32 | */
33 | Delete(key interface{}) error
34 | }
35 |
--------------------------------------------------------------------------------
/pkg/common/providers/core/provider.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package core
8 |
9 | //CryptoSuiteConfig contains sdk configuration items for cryptosuite.
10 | type CryptoSuiteConfig interface {
11 | IsSecurityEnabled() bool
12 | SecurityAlgorithm() string
13 | SecurityLevel() int
14 | SecurityProvider() string
15 | SoftVerify() bool
16 | SecurityProviderLibPath() string
17 | SecurityProviderPin() string
18 | SecurityProviderLabel() string
19 | KeyStorePath() string
20 | }
21 |
22 | // Providers represents the SDK configured core providers context.
23 | type Providers interface {
24 | CryptoSuite() CryptoSuite
25 | SigningManager() SigningManager
26 | }
27 |
28 | //ConfigProvider provides config backend for SDK
29 | type ConfigProvider func() ([]ConfigBackend, error)
30 |
31 | //ConfigBackend backend for all config types in SDK
32 | type ConfigBackend interface {
33 | Lookup(key string) (interface{}, bool)
34 | }
35 |
--------------------------------------------------------------------------------
/pkg/common/providers/core/signingmgr.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package core
8 |
9 | // SigningManager signs object with provided key
10 | type SigningManager interface {
11 | Sign([]byte, Key) ([]byte, error)
12 | }
13 |
--------------------------------------------------------------------------------
/pkg/common/providers/fab/context.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package fab
8 |
9 | import (
10 | reqContext "context"
11 |
12 | "github.com/hyperledger/fabric-sdk-go/pkg/common/options"
13 | )
14 |
15 | // ChannelService supplies services related to a channel.
16 | type ChannelService interface {
17 | Config() (ChannelConfig, error)
18 | EventService(opts ...options.Opt) (EventService, error)
19 | Membership() (ChannelMembership, error)
20 | ChannelConfig() (ChannelCfg, error)
21 | Transactor(reqCtx reqContext.Context) (Transactor, error)
22 | Discovery() (DiscoveryService, error)
23 | Selection() (SelectionService, error)
24 | }
25 |
26 | // Transactor supplies methods for sending transaction proposals and transactions.
27 | type Transactor interface {
28 | Sender
29 | ProposalSender
30 | }
31 |
32 | // ChannelProvider supplies Channel related-objects for the named channel.
33 | type ChannelProvider interface {
34 | ChannelService(ctx ClientContext, channelID string) (ChannelService, error)
35 | }
36 |
37 | // ErrorHandler is invoked when an error occurs in one of the services
38 | type ErrorHandler func(ctxt ClientContext, channelID string, err error)
39 |
--------------------------------------------------------------------------------
/pkg/common/providers/fab/orderer.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package fab
8 |
9 | import (
10 | reqContext "context"
11 |
12 | "github.com/hyperledger/fabric-protos-go/common"
13 | )
14 |
15 | // Orderer The Orderer class represents a peer in the target blockchain network to which
16 | // HFC sends a block of transactions of endorsed proposals requiring ordering.
17 | type Orderer interface {
18 | URL() string
19 | SendBroadcast(ctx reqContext.Context, envelope *SignedEnvelope) (*common.Status, error)
20 | SendDeliver(ctx reqContext.Context, envelope *SignedEnvelope) (chan *common.Block, chan error)
21 | }
22 |
23 | // A SignedEnvelope can can be sent to an orderer for broadcasting
24 | type SignedEnvelope struct {
25 | Payload []byte
26 | Signature []byte
27 | }
28 |
--------------------------------------------------------------------------------
/pkg/common/providers/fab/peer.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package fab
8 |
9 | // The Peer class represents a peer in the target blockchain network to which
10 | // HFC sends endorsement proposals or query requests.
11 | type Peer interface {
12 | ProposalProcessor
13 | // MSPID gets the Peer mspID.
14 | MSPID() string
15 |
16 | //URL gets the peer address
17 | URL() string
18 |
19 | // Properties returns properties of the peer.
20 | Properties() Properties
21 |
22 | // TODO: Name, EnrollmentCertificate (if needed)
23 | }
24 |
25 | // PeerState provides state information about the Peer
26 | type PeerState interface {
27 | BlockHeight() uint64
28 | }
29 |
30 | // Properties defines the properties of a peer
31 | type Properties map[Property]interface{}
32 |
33 | // Property is the key into the Properties map
34 | type Property = string
35 |
36 | // Following is a well-known list of properties of a peer, although this list may be extended.
37 | const (
38 | // PropertyChaincodes defines the chaincodes that are deployed on the peer. Value type:[]*github.com/hyperledger/fabric-protos-go/gossip.Chaincode
39 | PropertyChaincodes Property = "Chaincodes"
40 | // PropertyLedgerHeight defines the ledger height property. Value type: uint64
41 | PropertyLedgerHeight Property = "LedgerHeight"
42 | // PropertyLeftChannel defines the "left-channel" property which indicates whether the peer left the channel. Value type: bool
43 | PropertyLeftChannel Property = "LeftChannel"
44 | )
45 |
--------------------------------------------------------------------------------
/pkg/common/providers/fab/sender.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package fab
8 |
9 | import (
10 | pb "github.com/hyperledger/fabric-protos-go/peer"
11 | )
12 |
13 | // TransactionRequest holds endorsed Transaction Proposals.
14 | type TransactionRequest struct {
15 | Proposal *TransactionProposal
16 | ProposalResponses []*TransactionProposalResponse
17 | }
18 |
19 | // Sender provides the ability for a transaction to be created and sent.
20 | //
21 | // TODO: CreateTransaction should be refactored as it is actually a factory method.
22 | type Sender interface {
23 | CreateTransaction(request TransactionRequest) (*Transaction, error)
24 | SendTransaction(tx *Transaction) (*TransactionResponse, error)
25 | }
26 |
27 | // The Transaction object created from an endorsed proposal.
28 | type Transaction struct {
29 | Proposal *TransactionProposal
30 | Transaction *pb.Transaction
31 | }
32 |
33 | // TransactionResponse contains information returned by the orderer.
34 | type TransactionResponse struct {
35 | Orderer string
36 | }
37 |
--------------------------------------------------------------------------------
/pkg/common/providers/msp/store.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package msp
8 |
9 | // UserData is the representation of User in UserStore
10 | // PrivateKey is stored separately, in the crypto store
11 | type UserData struct {
12 | ID string
13 | MSPID string
14 | EnrollmentCertificate []byte
15 | }
16 |
17 | // UserStore is responsible for UserData persistence
18 | type UserStore interface {
19 | Store(*UserData) error
20 | Load(IdentityIdentifier) (*UserData, error)
21 | }
22 |
23 | // PrivKeyKey is a composite key for accessing a private key in the key store
24 | type PrivKeyKey struct {
25 | ID string
26 | MSPID string
27 | SKI []byte
28 | }
29 |
--------------------------------------------------------------------------------
/pkg/core/config/comm/testdata/server.crt:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIICZjCCAg2gAwIBAgIQLl+Ug2jLrky26o8cOZE9MjAKBggqhkjOPQQDAjB2MQsw
3 | CQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy
4 | YW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEfMB0GA1UEAxMWdGxz
5 | Y2Eub3JnMS5leGFtcGxlLmNvbTAeFw0xNzA3MjgxNDI3MjBaFw0yNzA3MjYxNDI3
6 | MjBaMFsxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQH
7 | Ew1TYW4gRnJhbmNpc2NvMR8wHQYDVQQDExZwZWVyMC5vcmcxLmV4YW1wbGUuY29t
8 | MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEAhDbBctALpd2ushdz8/cng3hnPE9
9 | YFkZa0QIkhBzuPZE7iH8JpB/e5d1zz6IsN0fY5FsvjZsvWkCj8xrl+eePaOBlzCB
10 | lDAOBgNVHQ8BAf8EBAMCBaAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMC
11 | MAwGA1UdEwEB/wQCMAAwKwYDVR0jBCQwIoAgP2onPvGFmShXzjY5WPEJhhDAKM8h
12 | j7l705FH7ynFXNwwKAYDVR0RBCEwH4IWcGVlcjAub3JnMS5leGFtcGxlLmNvbYIF
13 | cGVlcjAwCgYIKoZIzj0EAwIDRwAwRAIgKvld7K1+MukbhULYuhVRZsy4UqpdZ3Iu
14 | +UEU4Vs/CDwCIEuzQaX2N0gnf4UziPBAlrJGArocYA27CpSQX7ycmzJh
15 | -----END CERTIFICATE-----
16 |
--------------------------------------------------------------------------------
/pkg/core/config/comm/testdata/server.key:
--------------------------------------------------------------------------------
1 | -----BEGIN PRIVATE KEY-----
2 | MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgIHcvk45pDqakyZY6
3 | 81ZlopbYflQUbcnYUvjFJSoRJfShRANCAAQCENsFy0Aul3a6yF3Pz9yeDeGc8T1g
4 | WRlrRAiSEHO49kTuIfwmkH97l3XPPoiw3R9jkWy+Nmy9aQKPzGuX5549
5 | -----END PRIVATE KEY-----
6 |
--------------------------------------------------------------------------------
/pkg/core/config/defbackend.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package config
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/util/pathvar"
11 | "github.com/pkg/errors"
12 | "github.com/spf13/viper"
13 | )
14 |
15 | // defConfigBackend represents the default config backend
16 | type defConfigBackend struct {
17 | configViper *viper.Viper
18 | opts options
19 | }
20 |
21 | // Lookup gets the config item value by Key
22 | func (c *defConfigBackend) Lookup(key string) (interface{}, bool) {
23 | value := c.configViper.Get(key)
24 | if value == nil {
25 | return nil, false
26 | }
27 | return value, true
28 | }
29 |
30 | // load Default config
31 | func (c *defConfigBackend) loadTemplateConfig() error {
32 | // get Environment Default Config Path
33 | templatePath := c.opts.templatePath
34 | if templatePath == "" {
35 | return nil
36 | }
37 |
38 | // if set, use it to load default config
39 | c.configViper.AddConfigPath(pathvar.Subst(templatePath))
40 | err := c.configViper.ReadInConfig() // Find and read the config file
41 | if err != nil { // Handle errors reading the config file
42 | return errors.Wrapf(err, "loading config from template failed: %s", templatePath)
43 | }
44 | return nil
45 | }
46 |
--------------------------------------------------------------------------------
/pkg/core/config/testdata/certs/ca.crt:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIICSjCCAfCgAwIBAgIRANGFNJZxfQhsx/zuXmB8rrYwCgYIKoZIzj0EAwIwdjEL
3 | MAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG
4 | cmFuY2lzY28xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHzAdBgNVBAMTFnRs
5 | c2NhLm9yZzEuZXhhbXBsZS5jb20wHhcNMTgwNzIxMDAzNjMyWhcNMjgwNzE4MDAz
6 | NjMyWjB2MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UE
7 | BxMNU2FuIEZyYW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEfMB0G
8 | A1UEAxMWdGxzY2Eub3JnMS5leGFtcGxlLmNvbTBZMBMGByqGSM49AgEGCCqGSM49
9 | AwEHA0IABMnTyjNlRPNa9hcf2jyzeqkApuhsAhfD/efVr9t6dYhwHt1lnfrwYQPw
10 | lO0yW40L7XwPiAFvILSLi49SvixEbrSjXzBdMA4GA1UdDwEB/wQEAwIBpjAPBgNV
11 | HSUECDAGBgRVHSUAMA8GA1UdEwEB/wQFMAMBAf8wKQYDVR0OBCIEIIz7JQnE5v7m
12 | jOT0RA+iECV1whDUWF1OlKZGPqmhI7lQMAoGCCqGSM49BAMCA0gAMEUCIQCjlvSe
13 | rZgTAWGUQ9Yc2CtXisZRD6gKss8skLX+sKhUyAIgbMUwqhUnEmL3FA9LzglFEFbd
14 | eSlg/uxAuli/QNhBTZA=
15 | -----END CERTIFICATE-----
16 |
--------------------------------------------------------------------------------
/pkg/core/config/testdata/certs/client_sdk_go-key.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN EC PRIVATE KEY-----
2 | MIGkAgEBBDByldj7VTpqTQESGgJpR9PFW9b6YTTde2WN6/IiBo2nW+CIDmwQgmAl
3 | c/EOc9wmgu+gBwYFK4EEACKhZANiAAT6I1CGNrkchIAEmeJGo53XhDsoJwRiohBv
4 | 2PotEEGuO6rMyaOupulj2VOj+YtgWw4ZtU49g4Nv6rq1QlKwRYyMwwRJSAZHIUMh
5 | YZjcDi7YEOZ3Fs1hxKmIxR+TTR2vf9I=
6 | -----END EC PRIVATE KEY-----
7 |
--------------------------------------------------------------------------------
/pkg/core/config/testdata/certs/client_sdk_go.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIC5TCCAkagAwIBAgIUMYhiY5MS3jEmQ7Fz4X/e1Dx33J0wCgYIKoZIzj0EAwQw
3 | gYwxCzAJBgNVBAYTAkNBMRAwDgYDVQQIEwdPbnRhcmlvMRAwDgYDVQQHEwdUb3Jv
4 | bnRvMREwDwYDVQQKEwhsaW51eGN0bDEMMAoGA1UECxMDTGFiMTgwNgYDVQQDEy9s
5 | aW51eGN0bCBFQ0MgUm9vdCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eSAoTGFiKTAe
6 | Fw0xNzEyMDEyMTEzMDBaFw0xODEyMDEyMTEzMDBaMGMxCzAJBgNVBAYTAkNBMRAw
7 | DgYDVQQIEwdPbnRhcmlvMRAwDgYDVQQHEwdUb3JvbnRvMREwDwYDVQQKEwhsaW51
8 | eGN0bDEMMAoGA1UECxMDTGFiMQ8wDQYDVQQDDAZzZGtfZ28wdjAQBgcqhkjOPQIB
9 | BgUrgQQAIgNiAAT6I1CGNrkchIAEmeJGo53XhDsoJwRiohBv2PotEEGuO6rMyaOu
10 | pulj2VOj+YtgWw4ZtU49g4Nv6rq1QlKwRYyMwwRJSAZHIUMhYZjcDi7YEOZ3Fs1h
11 | xKmIxR+TTR2vf9KjgZAwgY0wDgYDVR0PAQH/BAQDAgWgMBMGA1UdJQQMMAoGCCsG
12 | AQUFBwMCMAwGA1UdEwEB/wQCMAAwHQYDVR0OBBYEFDwS3xhpAWs81OVWvZt+iUNL
13 | z26DMB8GA1UdIwQYMBaAFLRasbknomawJKuQGiyKs/RzTCujMBgGA1UdEQQRMA+C
14 | DWZhYnJpY19zZGtfZ28wCgYIKoZIzj0EAwQDgYwAMIGIAkIAk1MxMogtMtNO0rM8
15 | gw2rrxqbW67ulwmMQzp6EJbm/28T2pIoYWWyIwpzrquypI7BOuf8is5b7Jcgn9oz
16 | 7sdMTggCQgF7/8ZFl+wikAAPbciIL1I+LyCXKwXosdFL6KMT6/myYjsGNeeDeMbg
17 | 3YkZ9DhdH1tN4U/h+YulG/CkKOtUATtQxg==
18 | -----END CERTIFICATE-----
19 |
--------------------------------------------------------------------------------
/pkg/core/config/testdata/viper-test.yaml:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
3 | #
4 | # SPDX-License-Identifier: Apache-2.0
5 | #
6 | test:
7 | testkey: testvalue
8 |
--------------------------------------------------------------------------------
/pkg/core/cryptosuite/bccsp/multisuite/cryptosuiteimpl.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package multisuite
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
11 | "github.com/hyperledger/fabric-sdk-go/pkg/core/cryptosuite/bccsp/pkcs11"
12 | "github.com/hyperledger/fabric-sdk-go/pkg/core/cryptosuite/bccsp/sw"
13 | "github.com/pkg/errors"
14 | )
15 |
16 | //GetSuiteByConfig returns cryptosuite adaptor for bccsp loaded according to given config
17 | func GetSuiteByConfig(config core.CryptoSuiteConfig) (core.CryptoSuite, error) {
18 | switch config.SecurityProvider() {
19 | case "sw":
20 | return sw.GetSuiteByConfig(config)
21 | case "pkcs11":
22 | return pkcs11.GetSuiteByConfig(config)
23 | }
24 |
25 | return nil, errors.Errorf("Unsupported security provider requested: %s", config.SecurityProvider())
26 | }
27 |
--------------------------------------------------------------------------------
/pkg/core/cryptosuite/bccsp/wrapper/mocksuite_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package wrapper
8 |
9 | import (
10 | "fmt"
11 |
12 | "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/bccsp"
13 | bccspSw "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/bccsp/factory/sw"
14 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
15 | )
16 |
17 | //getSuiteByConfig returns cryptosuite adaptor for bccsp loaded according to given config
18 | func getSuiteByConfig(config core.CryptoSuiteConfig) (core.CryptoSuite, error) {
19 | opts := getOptsByConfig(config)
20 | bccsp, err := getBCCSPFromOpts(opts)
21 |
22 | if err != nil {
23 | return nil, err
24 | }
25 | return &CryptoSuite{BCCSP: bccsp}, nil
26 | }
27 |
28 | func getBCCSPFromOpts(config *bccspSw.SwOpts) (bccsp.BCCSP, error) {
29 | f := &bccspSw.SWFactory{}
30 |
31 | return f.Get(config)
32 | }
33 |
34 | //getOptsByConfig Returns Factory opts for given SDK config
35 | func getOptsByConfig(c core.CryptoSuiteConfig) *bccspSw.SwOpts {
36 | // TODO: delete this check
37 | if c.SecurityProvider() != "SW" {
38 | panic(fmt.Sprintf("Unsupported BCCSP Provider: %s", c.SecurityProvider()))
39 | }
40 |
41 | opts := &bccspSw.SwOpts{
42 | HashFamily: c.SecurityAlgorithm(),
43 | SecLevel: c.SecurityLevel(),
44 | FileKeystore: &bccspSw.FileKeystoreOpts{
45 | KeyStorePath: c.KeyStorePath(),
46 | },
47 | }
48 |
49 | return opts
50 | }
51 |
--------------------------------------------------------------------------------
/pkg/core/logging/metadata/level.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package metadata
8 |
9 | import "github.com/hyperledger/fabric-sdk-go/pkg/core/logging/api"
10 |
11 | //ModuleLevels maintains log levels based on module
12 | type ModuleLevels struct {
13 | levels map[string]api.Level
14 | }
15 |
16 | // GetLevel returns the log level for the given module.
17 | func (l *ModuleLevels) GetLevel(module string) api.Level {
18 | level, exists := l.levels[module]
19 | if !exists {
20 | level, exists = l.levels[""]
21 | // no configuration exists, default to info
22 | if !exists {
23 | level = api.INFO
24 | }
25 | }
26 | return level
27 | }
28 |
29 | // SetLevel sets the log level for the given module.
30 | func (l *ModuleLevels) SetLevel(module string, level api.Level) {
31 | if l.levels == nil {
32 | l.levels = make(map[string]api.Level)
33 | }
34 | l.levels[module] = level
35 | }
36 |
37 | // IsEnabledFor will return true if logging is enabled for the given module.
38 | func (l *ModuleLevels) IsEnabledFor(module string, level api.Level) bool {
39 | return level <= l.GetLevel(module)
40 | }
41 |
--------------------------------------------------------------------------------
/pkg/core/logging/metadata/utils.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package metadata
8 |
9 | import (
10 | "errors"
11 | "strings"
12 |
13 | "github.com/hyperledger/fabric-sdk-go/pkg/core/logging/api"
14 | )
15 |
16 | //Log level names in string
17 | var levelNames = []string{
18 | "CRITICAL",
19 | "ERROR",
20 | "WARNING",
21 | "INFO",
22 | "DEBUG",
23 | }
24 |
25 | // ParseLevel returns the log level from a string representation.
26 | func ParseLevel(level string) (api.Level, error) {
27 | for i, name := range levelNames {
28 | if strings.EqualFold(name, level) {
29 | return api.Level(i), nil
30 | }
31 | }
32 | return api.ERROR, errors.New("logger: invalid log level")
33 | }
34 |
35 | //ParseString returns String repressentation of given log level
36 | func ParseString(level api.Level) string {
37 | return levelNames[level]
38 | }
39 |
--------------------------------------------------------------------------------
/pkg/core/mocks/mockcorecontext.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package mocks
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
11 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
12 | )
13 |
14 | // MockCoreContext is a mock core context
15 | type MockCoreContext struct {
16 | MockConfig core.CryptoSuiteConfig
17 | MockCryptoSuite core.CryptoSuite
18 | MockUserStore msp.UserStore
19 | MockSigningManager core.SigningManager
20 | MockCryptoSuiteConfig core.CryptoSuiteConfig
21 | }
22 |
23 | // CryptoSuite ...
24 | func (m *MockCoreContext) CryptoSuite() core.CryptoSuite {
25 | return m.MockCryptoSuite
26 | }
27 |
28 | // SigningManager ...
29 | func (m *MockCoreContext) SigningManager() core.SigningManager {
30 | return m.MockSigningManager
31 | }
32 |
33 | //CryptoSuiteConfig ...
34 | func (m *MockCoreContext) CryptoSuiteConfig() core.CryptoSuiteConfig {
35 | return m.MockCryptoSuiteConfig
36 | }
37 |
--------------------------------------------------------------------------------
/pkg/core/mocks/mocksigningmgr.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package mocks
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
11 | )
12 |
13 | // MockSigningManager is mock signing manager
14 | type MockSigningManager struct {
15 | }
16 |
17 | // NewMockSigningManager Constructor for a mock signing manager.
18 | func NewMockSigningManager() core.SigningManager {
19 | return &MockSigningManager{}
20 | }
21 |
22 | // Sign will sign the given object using provided key
23 | func (mgr *MockSigningManager) Sign(object []byte, key core.Key) ([]byte, error) {
24 | return object, nil
25 | }
26 |
--------------------------------------------------------------------------------
/pkg/fab/ccpackager/gopackager/testdata/src/github.com/events_cc/META-INF/sample-json/event.json:
--------------------------------------------------------------------------------
1 | {
2 | "sample": {
3 | "title": "sample-json",
4 | "data": "sample text"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/pkg/fab/ccpackager/gopackager/testdata/src/github.com/example_cc1/META-INF-foo/example1-foo.json:
--------------------------------------------------------------------------------
1 | {
2 | "sample": {
3 | "title": "sample-json",
4 | "data": "sample text"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/pkg/fab/ccpackager/gopackager/testdata/src/github.com/example_cc1/META-INF/example1.json:
--------------------------------------------------------------------------------
1 | {
2 | "sample": {
3 | "title": "sample-json",
4 | "data": "sample text"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/pkg/fab/ccpackager/gopackager/testdata/src/github.com/example_cc1/foo-META-INF/foo-example.json:
--------------------------------------------------------------------------------
1 | {
2 | "sample": {
3 | "title": "sample-json",
4 | "data": "sample text"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/pkg/fab/ccpackager/javapackager/testdata/events_cc/META-INF/sample-json/event.json:
--------------------------------------------------------------------------------
1 | {
2 | "sample": {
3 | "title": "sample-json",
4 | "data": "sample text"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/pkg/fab/ccpackager/javapackager/testdata/events_cc/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright IBM Corp. 2018 All Rights Reserved.
3 | *
4 | * SPDX-License-Identifier: Apache-2.0
5 | */
6 | plugins {
7 | id 'com.github.johnrengelman.shadow' version '2.0.3'
8 | id 'java'
9 | }
10 |
11 | group 'org.hyperledger.fabric-chaincode-java'
12 | version '1.0-SNAPSHOT'
13 |
14 | sourceCompatibility = 1.8
15 |
16 | repositories {
17 | mavenLocal()
18 | mavenCentral()
19 | }
20 |
21 | dependencies {
22 | compile group: 'org.hyperledger.fabric-chaincode-java', name: 'fabric-chaincode-shim', version: '1.+'
23 | testCompile group: 'junit', name: 'junit', version: '4.12'
24 | }
25 |
26 | shadowJar {
27 | baseName = 'chaincode'
28 | version = null
29 | classifier = null
30 |
31 | manifest {
32 | attributes 'Main-Class': 'org.hyperledger.fabric.example.SimpleChaincode'
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/pkg/fab/ccpackager/javapackager/testdata/events_cc/settings.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright IBM Corp. 2017 All Rights Reserved.
3 | *
4 | * SPDX-License-Identifier: Apache-2.0
5 | */
6 | rootProject.name = 'fabric-chaincode-example-gradle'
7 |
8 |
--------------------------------------------------------------------------------
/pkg/fab/ccpackager/javapackager/testdata/example_cc/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright IBM Corp. 2018 All Rights Reserved.
3 | *
4 | * SPDX-License-Identifier: Apache-2.0
5 | */
6 | plugins {
7 | id 'com.github.johnrengelman.shadow' version '2.0.3'
8 | id 'java'
9 | }
10 |
11 | group 'org.hyperledger.fabric-chaincode-java'
12 | version '1.0-SNAPSHOT'
13 |
14 | sourceCompatibility = 1.8
15 |
16 | repositories {
17 | mavenLocal()
18 | mavenCentral()
19 | }
20 |
21 | dependencies {
22 | compile group: 'org.hyperledger.fabric-chaincode-java', name: 'fabric-chaincode-shim', version: '1.+'
23 | testCompile group: 'junit', name: 'junit', version: '4.12'
24 | }
25 |
26 | shadowJar {
27 | baseName = 'chaincode'
28 | version = null
29 | classifier = null
30 |
31 | manifest {
32 | attributes 'Main-Class': 'org.hyperledger.fabric.example.SimpleChaincode'
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/pkg/fab/ccpackager/javapackager/testdata/example_cc/settings.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright IBM Corp. 2017 All Rights Reserved.
3 | *
4 | * SPDX-License-Identifier: Apache-2.0
5 | */
6 | rootProject.name = 'fabric-chaincode-example-gradle'
7 |
8 |
--------------------------------------------------------------------------------
/pkg/fab/ccpackager/javapackager/testdata/example_cc1/META-INF-foo/example1-foo.json:
--------------------------------------------------------------------------------
1 | {
2 | "sample": {
3 | "title": "sample-json",
4 | "data": "sample text"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/pkg/fab/ccpackager/javapackager/testdata/example_cc1/META-INF/example1.json:
--------------------------------------------------------------------------------
1 | {
2 | "sample": {
3 | "title": "sample-json",
4 | "data": "sample text"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/pkg/fab/ccpackager/javapackager/testdata/example_cc1/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright IBM Corp. 2018 All Rights Reserved.
3 | *
4 | * SPDX-License-Identifier: Apache-2.0
5 | */
6 | plugins {
7 | id 'com.github.johnrengelman.shadow' version '2.0.3'
8 | id 'java'
9 | }
10 |
11 | group 'org.hyperledger.fabric-chaincode-java'
12 | version '1.0-SNAPSHOT'
13 |
14 | sourceCompatibility = 1.8
15 |
16 | repositories {
17 | mavenLocal()
18 | mavenCentral()
19 | }
20 |
21 | dependencies {
22 | compile group: 'org.hyperledger.fabric-chaincode-java', name: 'fabric-chaincode-shim', version: '1.+'
23 | testCompile group: 'junit', name: 'junit', version: '4.12'
24 | }
25 |
26 | shadowJar {
27 | baseName = 'chaincode'
28 | version = null
29 | classifier = null
30 |
31 | manifest {
32 | attributes 'Main-Class': 'org.hyperledger.fabric.example.SimpleChaincode'
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/pkg/fab/ccpackager/javapackager/testdata/example_cc1/foo-META-INF/foo-example.json:
--------------------------------------------------------------------------------
1 | {
2 | "sample": {
3 | "title": "sample-json",
4 | "data": "sample text"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/pkg/fab/ccpackager/javapackager/testdata/example_cc1/settings.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright IBM Corp. 2017 All Rights Reserved.
3 | *
4 | * SPDX-License-Identifier: Apache-2.0
5 | */
6 | rootProject.name = 'fabric-chaincode-example-gradle'
7 |
8 |
--------------------------------------------------------------------------------
/pkg/fab/ccpackager/lifecycle/testdata/golang_cc/go.mod:
--------------------------------------------------------------------------------
1 | // Copyright SecureKey Technologies Inc. All Rights Reserved.
2 | //
3 | // SPDX-License-Identifier: Apache-2.0
4 |
5 | module golang_cc
6 |
7 | require (
8 | github.com/hyperledger/fabric-chaincode-go v0.0.0-20200511190512-bcfeb58dd83a
9 | github.com/hyperledger/fabric-protos-go v0.0.0-20200506201313-25f6564b9ac4
10 | google.golang.org/genproto v0.0.0-20190327125643-d831d65fe17d // indirect
11 | )
12 |
13 | go 1.14
14 |
--------------------------------------------------------------------------------
/pkg/fab/ccpackager/lifecycle/testdata/golang_cc/golang_cc.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package main
8 |
9 | import (
10 | "github.com/hyperledger/fabric-chaincode-go/shim"
11 | pb "github.com/hyperledger/fabric-protos-go/peer"
12 | )
13 |
14 | // GolangCC is a sample chaincode written in Go
15 | type GolangCC struct {
16 | }
17 |
18 | // Init initializes the chaincode
19 | func (cc *GolangCC) Init(stub shim.ChaincodeStubInterface) pb.Response {
20 | return shim.Success(nil)
21 | }
22 |
23 | // Invoke invokes the chaincode
24 | func (cc *GolangCC) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
25 | return shim.Success(nil)
26 | }
27 |
28 | func main() {
29 | err := shim.Start(new(GolangCC))
30 | if err != nil {
31 | panic(err)
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/pkg/fab/ccpackager/nodepackager/testdata/event_cc/META-INF/sample-json/event.json:
--------------------------------------------------------------------------------
1 | {
2 | "sample": {
3 | "title": "sample-json",
4 | "data": "sample text"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/pkg/fab/ccpackager/nodepackager/testdata/event_cc/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "chaincode_example02",
3 | "version": "1.0.0",
4 | "description": "chaincode_example02 chaincode implemented in node.js",
5 | "engines": {
6 | "node": ">=8.4.0",
7 | "npm": ">=5.3.0"
8 | },
9 | "scripts": { "start" : "node chaincode_example02.js" },
10 | "engine-strict": true,
11 | "license": "Apache-2.0",
12 | "dependencies": {
13 | "fabric-shim": "~1.4.0"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/pkg/fab/ccpackager/nodepackager/testdata/example_cc/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "chaincode_example02",
3 | "version": "1.0.0",
4 | "description": "chaincode_example02 chaincode implemented in node.js",
5 | "engines": {
6 | "node": ">=8.4.0",
7 | "npm": ">=5.3.0"
8 | },
9 | "scripts": { "start" : "node chaincode_example02.js" },
10 | "engine-strict": true,
11 | "license": "Apache-2.0",
12 | "dependencies": {
13 | "fabric-shim": "~1.4.0"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/pkg/fab/ccpackager/nodepackager/testdata/example_cc1/META-INF-foo/example1-foo.json:
--------------------------------------------------------------------------------
1 | {
2 | "sample": {
3 | "title": "sample-json",
4 | "data": "sample text"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/pkg/fab/ccpackager/nodepackager/testdata/example_cc1/META-INF/example1.json:
--------------------------------------------------------------------------------
1 | {
2 | "sample": {
3 | "title": "sample-json",
4 | "data": "sample text"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/pkg/fab/ccpackager/nodepackager/testdata/example_cc1/foo-META-INF/foo-example.json:
--------------------------------------------------------------------------------
1 | {
2 | "sample": {
3 | "title": "sample-json",
4 | "data": "sample text"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/pkg/fab/ccpackager/nodepackager/testdata/example_cc1/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "chaincode_example02",
3 | "version": "1.0.0",
4 | "description": "chaincode_example02 chaincode implemented in node.js",
5 | "engines": {
6 | "node": ">=8.4.0",
7 | "npm": ">=5.3.0"
8 | },
9 | "scripts": { "start" : "node chaincode_example02.js" },
10 | "engine-strict": true,
11 | "license": "Apache-2.0",
12 | "dependencies": {
13 | "fabric-shim": "~1.4.0"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/pkg/fab/channel/cscc.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package channel
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
11 | )
12 |
13 | const (
14 | cscc = "cscc"
15 | csccConfigBlock = "GetConfigBlock"
16 | )
17 |
18 | func createConfigBlockInvokeRequest(channelID string) fab.ChaincodeInvokeRequest {
19 | cir := fab.ChaincodeInvokeRequest{
20 | ChaincodeID: cscc,
21 | Fcn: csccConfigBlock,
22 | Args: [][]byte{[]byte(channelID)},
23 | }
24 | return cir
25 | }
26 |
--------------------------------------------------------------------------------
/pkg/fab/comm/mocks.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package comm
8 |
9 | import (
10 | "context"
11 |
12 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
13 | fabmocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks"
14 | "google.golang.org/grpc"
15 | )
16 |
17 | // MockCommManager is a non-caching comm manager used
18 | // for unit testing
19 | type MockCommManager struct {
20 | }
21 |
22 | // DialContext creates a connection
23 | func (m *MockCommManager) DialContext(ctx context.Context, target string, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
24 | return grpc.DialContext(ctx, target, opts...)
25 | }
26 |
27 | // ReleaseConn closes the connection
28 | func (m *MockCommManager) ReleaseConn(conn *grpc.ClientConn) {
29 | if err := conn.Close(); err != nil {
30 | logger.Warnf("Error closing connection: %s", err)
31 | }
32 | }
33 |
34 | // MockInfraProvider overrides the comm manager to return
35 | // the MockCommManager
36 | type MockInfraProvider struct {
37 | fabmocks.MockInfraProvider
38 | }
39 |
40 | // NewMockInfraProvider return a new MockInfraProvider
41 | func NewMockInfraProvider() *MockInfraProvider {
42 | return &MockInfraProvider{}
43 | }
44 |
45 | // CommManager returns the MockCommManager
46 | func (f *MockInfraProvider) CommManager() fab.CommManager {
47 | return &MockCommManager{}
48 | }
49 |
--------------------------------------------------------------------------------
/pkg/fab/discovery/util.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package discovery
8 |
9 | import (
10 | "reflect"
11 | "strings"
12 |
13 | discclient "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/discovery/client"
14 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
15 | )
16 |
17 | // GetProperties extracts the properties from the discovered peer.
18 | func GetProperties(endpoint *discclient.Peer) fab.Properties {
19 | if endpoint.StateInfoMessage == nil {
20 | return nil
21 | }
22 |
23 | stateInfo := endpoint.StateInfoMessage.GetStateInfo()
24 | if stateInfo == nil || stateInfo.Properties == nil {
25 | return nil
26 | }
27 |
28 | properties := make(fab.Properties)
29 |
30 | val := reflect.ValueOf(stateInfo.Properties).Elem()
31 |
32 | for i := 0; i < val.NumField(); i++ {
33 | fType := val.Type().Field(i)
34 |
35 | // Exclude protobuf fields
36 | if !strings.HasPrefix(fType.Name, "XXX_") {
37 | properties[fType.Name] = val.Field(i).Interface()
38 | }
39 | }
40 |
41 | return properties
42 | }
43 |
--------------------------------------------------------------------------------
/pkg/fab/events/api/connection.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package api
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/context"
11 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
12 | )
13 |
14 | // Connection defines the functions for an event server connection
15 | type Connection interface {
16 | // Receive sends events to the given channel
17 | Receive(chan<- interface{})
18 | // Close closes the connection
19 | Close()
20 | // Closed return true if the connection is closed
21 | Closed() bool
22 | }
23 |
24 | // ConnectionProvider creates a Connection.
25 | type ConnectionProvider func(context context.Client, chConfig fab.ChannelCfg, peer fab.Peer) (Connection, error)
26 |
--------------------------------------------------------------------------------
/pkg/fab/events/api/endpoint.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package api
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/common/options"
11 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
12 | )
13 |
14 | // EventEndpoint extends a Peer endpoint and provides the
15 | // event URL, which may or may not be the same as the Peer URL
16 | type EventEndpoint interface {
17 | fab.Peer
18 |
19 | // Opts returns additional options for the connection
20 | Opts() []options.Opt
21 | }
22 |
--------------------------------------------------------------------------------
/pkg/fab/events/client/dispatcher/registrations.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package dispatcher
8 |
9 | // ConnectionReg is a connection registration
10 | type ConnectionReg struct {
11 | Eventch chan<- *ConnectionEvent
12 | }
13 |
--------------------------------------------------------------------------------
/pkg/fab/events/client/lbp/lbp.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package lbp
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
11 | )
12 |
13 | // LoadBalancePolicy chooses a peer from a set of peers
14 | type LoadBalancePolicy interface {
15 | Choose(peers []fab.Peer) (fab.Peer, error)
16 | }
17 |
--------------------------------------------------------------------------------
/pkg/fab/events/client/lbp/random.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package lbp
8 |
9 | import (
10 | "math/rand"
11 |
12 | "github.com/hyperledger/fabric-sdk-go/pkg/common/logging"
13 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
14 | )
15 |
16 | var logger = logging.NewLogger("fabsdk/fab")
17 |
18 | // Random implements a random load-balance policy
19 | type Random struct {
20 | }
21 |
22 | // NewRandom returns a new Random load-balance policy
23 | func NewRandom() *Random {
24 | return &Random{}
25 | }
26 |
27 | // Choose randomly chooses a peer from the list of peers
28 | func (lbp *Random) Choose(peers []fab.Peer) (fab.Peer, error) {
29 | if len(peers) == 0 {
30 | logger.Warn("No peers to choose from!")
31 | return nil, nil
32 | }
33 |
34 | index := rand.Intn(len(peers))
35 | logger.Debugf("Choosing peer at index %d", index)
36 | return peers[index], nil
37 | }
38 |
--------------------------------------------------------------------------------
/pkg/fab/events/client/lbp/roundrobin.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package lbp
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/util/concurrent/rollingcounter"
11 |
12 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
13 | )
14 |
15 | // RoundRobin implements a round-robin load-balance policy
16 | type RoundRobin struct {
17 | counter *rollingcounter.Counter
18 | }
19 |
20 | // NewRoundRobin returns a new RoundRobin load-balance policy
21 | func NewRoundRobin() *RoundRobin {
22 | return &RoundRobin{
23 | counter: rollingcounter.New(),
24 | }
25 | }
26 |
27 | // Choose chooses from the list of peers in round-robin fashion
28 | func (lbp *RoundRobin) Choose(peers []fab.Peer) (fab.Peer, error) {
29 | if len(peers) == 0 {
30 | logger.Warn("No peers to choose from!")
31 | return nil, nil
32 | }
33 | return peers[lbp.counter.Next(len(peers))], nil
34 | }
35 |
--------------------------------------------------------------------------------
/pkg/fab/events/client/mocks/mockdiscovery.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package mocks
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
11 | )
12 |
13 | // MockDiscoveryService is a mock discovery service used for event endpoint discovery
14 | type MockDiscoveryService struct {
15 | peers []fab.Peer
16 | }
17 |
18 | // NewDiscoveryService returns a new MockDiscoveryService
19 | func NewDiscoveryService(peers ...fab.Peer) fab.DiscoveryService {
20 | return &MockDiscoveryService{
21 | peers: peers,
22 | }
23 | }
24 |
25 | // GetPeers returns a list of discovered peers
26 | func (s *MockDiscoveryService) GetPeers() ([]fab.Peer, error) {
27 | return s.peers, nil
28 | }
29 |
--------------------------------------------------------------------------------
/pkg/fab/events/client/mocks/mockdispatcher.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package mocks
8 |
9 | // MockDispatcher is a mock Dispatcher
10 | type MockDispatcher struct {
11 | Error error
12 | LastBlock uint64
13 | }
14 |
15 | // Start returns the configured error
16 | func (d *MockDispatcher) Start() error {
17 | return d.Error
18 | }
19 |
20 | // EventCh simply returns the configured error
21 | func (d *MockDispatcher) EventCh() (chan<- interface{}, error) {
22 | return nil, d.Error
23 | }
24 |
25 | // LastBlockNum returns the last block number
26 | func (d *MockDispatcher) LastBlockNum() uint64 {
27 | return d.LastBlock
28 | }
29 |
--------------------------------------------------------------------------------
/pkg/fab/events/client/mocks/util.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package mocks
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
11 | fabmocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks"
12 | )
13 |
14 | // NewMockConfig returns a mock endpoint config with the given event service policy for the given channel
15 | func NewMockConfig(channelID string, policy fab.EventServicePolicy) *fabmocks.MockConfig {
16 | config := &fabmocks.MockConfig{}
17 | config.SetCustomChannelConfig(channelID, &fab.ChannelEndpointConfig{
18 | Policies: fab.ChannelPolicies{
19 | EventService: policy,
20 | },
21 | })
22 | return config
23 | }
24 |
--------------------------------------------------------------------------------
/pkg/fab/events/client/peerresolver/balanced/opts.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package balanced
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/context"
11 | "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/client/lbp"
12 | "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/client/peerresolver"
13 | )
14 |
15 | type params struct {
16 | loadBalancePolicy lbp.LoadBalancePolicy
17 | }
18 |
19 | func defaultParams(context context.Client, channelID string) *params {
20 | return ¶ms{
21 | loadBalancePolicy: peerresolver.GetBalancer(context.EndpointConfig().ChannelConfig(channelID).Policies.EventService),
22 | }
23 | }
24 |
25 | func (p *params) SetLoadBalancePolicy(value lbp.LoadBalancePolicy) {
26 | logger.Debugf("LoadBalancePolicy: %#v", value)
27 | p.loadBalancePolicy = value
28 | }
29 |
--------------------------------------------------------------------------------
/pkg/fab/events/client/peerresolver/config.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package peerresolver
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/common/logging"
11 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
12 | "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/client/lbp"
13 | )
14 |
15 | var logger = logging.NewLogger("fabsdk/fab")
16 |
17 | // GetBalancer returns the configured load balancer
18 | func GetBalancer(policy fab.EventServicePolicy) lbp.LoadBalancePolicy {
19 | switch policy.Balancer {
20 | case fab.RoundRobin:
21 | logger.Debugf("Using round-robin load balancer.")
22 | return lbp.NewRoundRobin()
23 | case fab.Random:
24 | logger.Debugf("Using random load balancer.")
25 | return lbp.NewRandom()
26 | default:
27 | logger.Debugf("Balancer not specified. Using random load balancer.")
28 | return lbp.NewRandom()
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/pkg/fab/events/client/peerresolver/peerresolver.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package peerresolver
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/common/options"
11 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/context"
12 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
13 | "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/service"
14 | )
15 |
16 | // Resolver decided which peer to connect to and when to disconnect from that peer
17 | type Resolver interface {
18 | // Resolve chooses a peer from the given set of peers
19 | Resolve(peers []fab.Peer) (fab.Peer, error)
20 | // ShouldDisconnect returns true to disconnect from the connected peer
21 | ShouldDisconnect(peers []fab.Peer, connectedPeer fab.Peer) bool
22 | }
23 |
24 | // Provider creates a peer Resolver
25 | type Provider func(ed service.Dispatcher, context context.Client, channelID string, opts ...options.Opt) Resolver
26 |
--------------------------------------------------------------------------------
/pkg/fab/events/client/peerresolver/preferorg/opts.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package preferorg
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/context"
11 | "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/client/lbp"
12 | "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/client/peerresolver"
13 | )
14 |
15 | type params struct {
16 | loadBalancePolicy lbp.LoadBalancePolicy
17 | }
18 |
19 | func defaultParams(context context.Client, channelID string) *params {
20 | return ¶ms{
21 | loadBalancePolicy: peerresolver.GetBalancer(context.EndpointConfig().ChannelConfig(channelID).Policies.EventService),
22 | }
23 | }
24 |
25 | func (p *params) SetLoadBalancePolicy(value lbp.LoadBalancePolicy) {
26 | logger.Debugf("LoadBalancePolicy: %#v", value)
27 | p.loadBalancePolicy = value
28 | }
29 |
--------------------------------------------------------------------------------
/pkg/fab/events/client/peerresolver/preferpeer/opts.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package preferpeer
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/context"
11 | "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/client/lbp"
12 | "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/client/peerresolver"
13 | )
14 |
15 | type params struct {
16 | loadBalancePolicy lbp.LoadBalancePolicy
17 | }
18 |
19 | func defaultParams(context context.Client, channelID string) *params {
20 | return ¶ms{
21 | loadBalancePolicy: peerresolver.GetBalancer(context.EndpointConfig().ChannelConfig(channelID).Policies.EventService),
22 | }
23 | }
24 |
25 | func (p *params) SetLoadBalancePolicy(value lbp.LoadBalancePolicy) {
26 | logger.Debugf("LoadBalancePolicy: %#v", value)
27 | p.loadBalancePolicy = value
28 | }
29 |
--------------------------------------------------------------------------------
/pkg/fab/events/deliverclient/dispatcher/events.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package dispatcher
8 |
9 | import (
10 | ab "github.com/hyperledger/fabric-protos-go/orderer"
11 | )
12 |
13 | // SeekEvent is a SeekInfo request to the deliver server
14 | type SeekEvent struct {
15 | SeekInfo *ab.SeekInfo
16 | ErrCh chan<- error
17 | }
18 |
19 | // NewSeekEvent returns a new SeekRequestEvent
20 | func NewSeekEvent(seekInfo *ab.SeekInfo, errch chan<- error) *SeekEvent {
21 | return &SeekEvent{
22 | SeekInfo: seekInfo,
23 | ErrCh: errch,
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/pkg/fab/events/endpoint/endpoint.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package endpoint
8 |
9 | import (
10 | "crypto/x509"
11 |
12 | "github.com/hyperledger/fabric-sdk-go/pkg/common/options"
13 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
14 | "github.com/hyperledger/fabric-sdk-go/pkg/fab/comm"
15 | )
16 |
17 | // EventEndpoint extends a Peer endpoint
18 | type EventEndpoint struct {
19 | Certificate *x509.Certificate
20 | fab.Peer
21 | opts []options.Opt
22 | }
23 |
24 | // Opts returns additional options for the event connection
25 | func (e *EventEndpoint) Opts() []options.Opt {
26 | return e.opts
27 | }
28 |
29 | // BlockHeight returns the block height of the peer. If the peer doesn't contain any state info then 0 is returned.
30 | func (e *EventEndpoint) BlockHeight() uint64 {
31 | peerState, ok := e.Peer.(fab.PeerState)
32 | if !ok {
33 | return 0
34 | }
35 | return peerState.BlockHeight()
36 | }
37 |
38 | // FromPeerConfig creates a new EventEndpoint from the given config
39 | func FromPeerConfig(config fab.EndpointConfig, peer fab.Peer, peerCfg *fab.PeerConfig) *EventEndpoint {
40 | opts := comm.OptsFromPeerConfig(peerCfg)
41 | opts = append(opts, comm.WithConnectTimeout(config.Timeout(fab.PeerConnection)))
42 |
43 | return &EventEndpoint{
44 | Peer: peer,
45 | opts: opts,
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/pkg/fab/events/service/blockfilter/acceptanyfilter.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package blockfilter
8 |
9 | import (
10 | cb "github.com/hyperledger/fabric-protos-go/common"
11 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
12 | )
13 |
14 | // AcceptAny returns a block filter that accepts any block
15 | var AcceptAny fab.BlockFilter = func(block *cb.Block) bool {
16 | return true
17 | }
18 |
--------------------------------------------------------------------------------
/pkg/fab/events/service/blockfilter/headertypefilter/headertypefilter_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package headertypefilter
8 |
9 | import (
10 | "testing"
11 |
12 | servicemocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/service/mocks"
13 | cb "github.com/hyperledger/fabric-protos-go/common"
14 | pb "github.com/hyperledger/fabric-protos-go/peer"
15 | )
16 |
17 | func TestHeaderTypeBlockFilter(t *testing.T) {
18 | filter := New(cb.HeaderType_CONFIG, cb.HeaderType_CONFIG_UPDATE)
19 |
20 | if !filter(servicemocks.NewBlock("somechannel", servicemocks.NewTransaction("txid", pb.TxValidationCode_VALID, cb.HeaderType_CONFIG))) {
21 | t.Fatalf("expecting block filter to accept block with header type %s", cb.HeaderType_CONFIG)
22 | }
23 | if !filter(servicemocks.NewBlock("somechannel", servicemocks.NewTransaction("txid", pb.TxValidationCode_VALID, cb.HeaderType_CONFIG_UPDATE))) {
24 | t.Fatalf("expecting block filter to accept block with header type %s", cb.HeaderType_CONFIG_UPDATE)
25 | }
26 | if filter(servicemocks.NewBlock("somechannel", servicemocks.NewTransaction("txid", pb.TxValidationCode_VALID, cb.HeaderType_MESSAGE))) {
27 | t.Fatalf("expecting block filter to reject block with header type %s", cb.HeaderType_MESSAGE)
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/pkg/fab/events/service/mocks/blockproducer.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package mocks
8 |
9 | import (
10 | "sync/atomic"
11 |
12 | cb "github.com/hyperledger/fabric-protos-go/common"
13 | pb "github.com/hyperledger/fabric-protos-go/peer"
14 | )
15 |
16 | // BlockProducer is a block BlockProducer that ensures the block
17 | // number is set sequencially
18 | type BlockProducer struct {
19 | blockNum uint64
20 | }
21 |
22 | // NewBlockProducer returns a new block producer
23 | func NewBlockProducer() *BlockProducer {
24 | return &BlockProducer{}
25 | }
26 |
27 | // NewBlock returns a new block
28 | func (p *BlockProducer) NewBlock(channelID string, transactions ...*TxInfo) *cb.Block {
29 | block := NewBlock(channelID, transactions...)
30 | block.Header.Number = p.blockNum
31 | atomic.AddUint64(&p.blockNum, 1)
32 | return block
33 | }
34 |
35 | // NewFilteredBlock returns a new filtered block
36 | func (p *BlockProducer) NewFilteredBlock(channelID string, filteredTx ...*pb.FilteredTransaction) *pb.FilteredBlock {
37 | block := NewFilteredBlock(channelID, filteredTx...)
38 | block.Number = p.blockNum
39 | atomic.AddUint64(&p.blockNum, 1)
40 | return block
41 | }
42 |
--------------------------------------------------------------------------------
/pkg/fab/events/service/mocks/blockwrapper.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package mocks
8 |
9 | import (
10 | cb "github.com/hyperledger/fabric-protos-go/common"
11 | )
12 |
13 | // BlockWrapper wraps the Block and conforms to the Block interface
14 | type BlockWrapper struct {
15 | block *cb.Block
16 | }
17 |
18 | // NewBlockWrapper returns a new Block wrapper
19 | func NewBlockWrapper(block *cb.Block) *BlockWrapper {
20 | return &BlockWrapper{block: block}
21 | }
22 |
23 | // Block returns the block
24 | func (w *BlockWrapper) Block() *cb.Block {
25 | return w.block
26 | }
27 |
28 | // Number returns the block number
29 | func (w *BlockWrapper) Number() uint64 {
30 | return w.block.Header.Number
31 | }
32 |
33 | // SetNumber sets the block number
34 | func (w *BlockWrapper) SetNumber(number uint64) {
35 | w.block.Header.Number = number
36 | }
37 |
--------------------------------------------------------------------------------
/pkg/fab/events/service/mocks/fblockwrapper.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package mocks
8 |
9 | import (
10 | pb "github.com/hyperledger/fabric-protos-go/peer"
11 | )
12 |
13 | // FilteredBlockWrapper wraps the FilteredBlock and conforms to the Block interface
14 | type FilteredBlockWrapper struct {
15 | block *pb.FilteredBlock
16 | }
17 |
18 | // NewFilteredBlockWrapper returns a new Filtered Block wrapper
19 | func NewFilteredBlockWrapper(block *pb.FilteredBlock) *FilteredBlockWrapper {
20 | return &FilteredBlockWrapper{block: block}
21 | }
22 |
23 | // Block returns the filtered block
24 | func (w *FilteredBlockWrapper) Block() *pb.FilteredBlock {
25 | return w.block
26 | }
27 |
28 | // Number returns the block number
29 | func (w *FilteredBlockWrapper) Number() uint64 {
30 | return w.block.Number
31 | }
32 |
33 | // SetNumber sets the block number
34 | func (w *FilteredBlockWrapper) SetNumber(number uint64) {
35 | w.block.Number = number
36 | }
37 |
--------------------------------------------------------------------------------
/pkg/fab/events/service/opts.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package service
8 |
9 | type params struct {
10 | eventConsumerBufferSize uint
11 | }
12 |
13 | func defaultParams() *params {
14 | return ¶ms{
15 | eventConsumerBufferSize: 100,
16 | }
17 | }
18 |
19 | func (p *params) SetEventConsumerBufferSize(value uint) {
20 | logger.Debugf("EventConsumerBufferSize: %d", value)
21 | p.eventConsumerBufferSize = value
22 | }
23 |
--------------------------------------------------------------------------------
/pkg/fab/mocks/mockcryptosuite.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package mocks
8 |
9 | import (
10 | "crypto/sha256"
11 | "hash"
12 |
13 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
14 | )
15 |
16 | // MockCryptoSuite implementation
17 | type MockCryptoSuite struct {
18 | }
19 |
20 | // KeyGen mock key gen
21 | func (m *MockCryptoSuite) KeyGen(opts core.KeyGenOpts) (k core.Key, err error) {
22 | return nil, nil
23 | }
24 |
25 | // KeyImport mock key import
26 | func (m *MockCryptoSuite) KeyImport(raw interface{},
27 | opts core.KeyImportOpts) (k core.Key, err error) {
28 | return nil, nil
29 | }
30 |
31 | // GetKey mock get key
32 | func (m *MockCryptoSuite) GetKey(ski []byte) (k core.Key, err error) {
33 | return nil, nil
34 | }
35 |
36 | // Hash mock hash
37 | func (m *MockCryptoSuite) Hash(msg []byte, opts core.HashOpts) (hash []byte, err error) {
38 | return nil, nil
39 | }
40 |
41 | // GetHash mock get hash
42 | func (m *MockCryptoSuite) GetHash(opts core.HashOpts) (hash.Hash, error) {
43 | return sha256.New(), nil
44 | }
45 |
46 | // Sign mock signing
47 | func (m *MockCryptoSuite) Sign(k core.Key, digest []byte,
48 | opts core.SignerOpts) (signature []byte, err error) {
49 | return []byte("testSignature"), nil
50 | }
51 |
52 | //Verify mock verify implementation
53 | func (m *MockCryptoSuite) Verify(k core.Key, signature, digest []byte, opts core.SignerOpts) (valid bool, err error) {
54 | return true, nil
55 | }
56 |
--------------------------------------------------------------------------------
/pkg/fab/mocks/mocklocal.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package mocks
8 |
9 | import (
10 | "fmt"
11 |
12 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
13 | )
14 |
15 | // LocalContext supplies the configuration for channel context client
16 | type LocalContext struct {
17 | *MockContext
18 | localDiscovery fab.DiscoveryService
19 | }
20 |
21 | // LocalDiscoveryService returns the local discovery service
22 | func (c *LocalContext) LocalDiscoveryService() fab.DiscoveryService {
23 | return c.localDiscovery
24 | }
25 |
26 | // NewMockLocalContext creates new mock local context
27 | func NewMockLocalContext(client *MockContext, discoveryProvider fab.LocalDiscoveryProvider) *LocalContext {
28 | var localDiscovery fab.DiscoveryService
29 | if discoveryProvider != nil {
30 | var err error
31 | localDiscovery, err = discoveryProvider.CreateLocalDiscoveryService(client.Identifier().MSPID)
32 | if err != nil {
33 | panic(fmt.Sprintf("error creating local discovery service: %s", err))
34 | }
35 |
36 | }
37 |
38 | return &LocalContext{
39 | MockContext: client,
40 | localDiscovery: localDiscovery,
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/pkg/fab/mocks/mockmembership.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package mocks
8 |
9 | // MockMembership mock member id
10 | type MockMembership struct {
11 | ValidateErr error
12 | VerifyErr error
13 | excludeMSPs []string
14 | }
15 |
16 | // NewMockMembership new mock member id
17 | func NewMockMembership() *MockMembership {
18 | return &MockMembership{}
19 | }
20 |
21 | // NewMockMembershipWithMSPFilter return new mock membership where given MSPs will be excluded for ContainsMSP test
22 | func NewMockMembershipWithMSPFilter(mspsToBeExlcluded []string) *MockMembership {
23 | return &MockMembership{excludeMSPs: mspsToBeExlcluded}
24 | }
25 |
26 | // Validate if the given ID was issued by the channel's members
27 | func (m *MockMembership) Validate(serializedID []byte) error {
28 | return m.ValidateErr
29 | }
30 |
31 | // Verify the given signature
32 | func (m *MockMembership) Verify(serializedID []byte, msg []byte, sig []byte) error {
33 | return m.VerifyErr
34 | }
35 |
36 | // ContainsMSP mocks membership.ContainsMSP
37 | func (m *MockMembership) ContainsMSP(msp string) bool {
38 | for _, v := range m.excludeMSPs {
39 | if v == msp {
40 | return false
41 | }
42 | }
43 | return true
44 | }
45 |
--------------------------------------------------------------------------------
/pkg/fab/mocks/mockselection.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package mocks
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/common/options"
11 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
12 | )
13 |
14 | // MockSelectionService implements mock selection service
15 | type MockSelectionService struct {
16 | Error error
17 | Peers []fab.Peer
18 | }
19 |
20 | // NewMockSelectionService returns mock selection service
21 | func NewMockSelectionService(err error, peers ...fab.Peer) *MockSelectionService {
22 | return &MockSelectionService{Error: err, Peers: peers}
23 | }
24 |
25 | // GetEndorsersForChaincode mockcore retrieving endorsing peers
26 | func (ds *MockSelectionService) GetEndorsersForChaincode(chaincodes []*fab.ChaincodeCall, opts ...options.Opt) ([]fab.Peer, error) {
27 |
28 | if ds.Error != nil {
29 | return nil, ds.Error
30 | }
31 |
32 | if ds.Peers == nil {
33 | mockPeer := NewMockPeer("Peer1", "http://peer1.com")
34 | peers := make([]fab.Peer, 0)
35 | peers = append(peers, mockPeer)
36 | ds.Peers = peers
37 | }
38 |
39 | return ds.Peers, nil
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/pkg/fab/orderer/testdata/ca.crt:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIICSjCCAfCgAwIBAgIRAK6U/rrDPrcAH91wP29hzmQwCgYIKoZIzj0EAwIwdjEL
3 | MAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG
4 | cmFuY2lzY28xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHzAdBgNVBAMTFnRs
5 | c2NhLm9yZzEuZXhhbXBsZS5jb20wHhcNMTgwNzIwMTg1MDI3WhcNMjgwNzE3MTg1
6 | MDI3WjB2MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UE
7 | BxMNU2FuIEZyYW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEfMB0G
8 | A1UEAxMWdGxzY2Eub3JnMS5leGFtcGxlLmNvbTBZMBMGByqGSM49AgEGCCqGSM49
9 | AwEHA0IABH59+y4yO8RntA2pGZYJC6Bwu1JNnsIkzG1tuYmgGbCAxjTI8CQ87+j6
10 | QNTQI1AGRoo8GgXNwD/KYUYLzil9AQKjXzBdMA4GA1UdDwEB/wQEAwIBpjAPBgNV
11 | HSUECDAGBgRVHSUAMA8GA1UdEwEB/wQFMAMBAf8wKQYDVR0OBCIEINukfzoSF9bs
12 | 14pllnur6eDzIE7SJ26wDodLDtX86S49MAoGCCqGSM49BAMCA0gAMEUCIQDbl/Bd
13 | 8JsQ57DUehqb7QX+soOLjobPSCdhZ+gJOcWD7AIgEKtWL5iQPnz7X32uVjgPXaoF
14 | m6e+pb1eyYGlF2KvsrY=
15 | -----END CERTIFICATE-----
16 |
--------------------------------------------------------------------------------
/pkg/fab/resource/config_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package resource
8 |
9 | import (
10 | "io/ioutil"
11 | "path/filepath"
12 | "testing"
13 |
14 | "github.com/hyperledger/fabric-sdk-go/test/metadata"
15 | )
16 |
17 | func TestExtractChannelConfig(t *testing.T) {
18 | configTx, err := ioutil.ReadFile(filepath.Join(metadata.GetProjectPath(), metadata.ChannelConfigPath, "mychannel.tx"))
19 | if err != nil {
20 | t.Fatal(err)
21 | }
22 |
23 | _, err = ExtractChannelConfig(configTx)
24 | if err != nil {
25 | t.Fatal(err)
26 | }
27 | }
28 |
29 | func TestCreateConfigSignature(t *testing.T) {
30 | ctx := setupContext()
31 |
32 | configTx, err := ioutil.ReadFile(filepath.Join(metadata.GetProjectPath(), metadata.ChannelConfigPath, "mychannel.tx"))
33 | if err != nil {
34 | t.Fatal(err)
35 | }
36 |
37 | _, err = CreateConfigSignature(ctx, configTx)
38 | if err != nil {
39 | t.Fatalf("Expected 'channel configuration required %s", err)
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/pkg/fab/resource/cscc.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package resource
8 |
9 | import (
10 | "github.com/golang/protobuf/proto"
11 | "github.com/hyperledger/fabric-protos-go/common"
12 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
13 | "github.com/pkg/errors"
14 | )
15 |
16 | const (
17 | cscc = "cscc"
18 | csccJoinChannel = "JoinChain"
19 | csccChannels = "GetChannels"
20 | )
21 |
22 | func createJoinChannelInvokeRequest(genesisBlock *common.Block) (fab.ChaincodeInvokeRequest, error) { //nolint
23 |
24 | genesisBlockBytes, err := proto.Marshal(genesisBlock)
25 | if err != nil {
26 | return fab.ChaincodeInvokeRequest{}, errors.Wrap(err, "marshal genesis block failed")
27 | }
28 |
29 | // Create join channel transaction proposal for target peers
30 | var args [][]byte
31 | args = append(args, genesisBlockBytes)
32 |
33 | cir := fab.ChaincodeInvokeRequest{
34 | ChaincodeID: cscc,
35 | Fcn: csccJoinChannel,
36 | Args: args,
37 | }
38 |
39 | return cir, nil
40 | }
41 |
42 | func createChannelsInvokeRequest() fab.ChaincodeInvokeRequest {
43 | cir := fab.ChaincodeInvokeRequest{
44 | ChaincodeID: cscc,
45 | Fcn: csccChannels,
46 | }
47 | return cir
48 | }
49 |
--------------------------------------------------------------------------------
/pkg/fab/resource/lscc_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package resource
8 |
9 | import (
10 | "testing"
11 |
12 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
13 | contextImpl "github.com/hyperledger/fabric-sdk-go/pkg/context"
14 | "github.com/hyperledger/fabric-sdk-go/pkg/fab/txn"
15 |
16 | "time"
17 |
18 | "github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks"
19 | "github.com/stretchr/testify/assert"
20 | )
21 |
22 | func TestCreateChaincodeInstallProposal(t *testing.T) {
23 | ctx := setupContext()
24 | peer := mocks.MockPeer{MockName: "Peer1", MockURL: "peer1.example.com", MockRoles: []string{}, MockCert: nil, Payload: []byte("A"), Status: 200}
25 |
26 | request := ChaincodeInstallRequest{
27 | Name: "examplecc",
28 | Path: "github.com/examplecc",
29 | Version: "1",
30 | Package: &ChaincodePackage{},
31 | }
32 |
33 | txid, err := txn.NewHeader(ctx, fab.SystemChannel)
34 | assert.Nil(t, err, "create transaction ID failed")
35 |
36 | prop, err := CreateChaincodeInstallProposal(txid, request)
37 | assert.Nil(t, err, "CreateChaincodeInstallProposal failed")
38 |
39 | reqCtx, cancel := contextImpl.NewRequest(ctx, contextImpl.WithTimeout(10*time.Second))
40 | defer cancel()
41 |
42 | _, err = txn.SendProposal(reqCtx, prop, []fab.ProposalProcessor{&peer})
43 | assert.Nil(t, err, "sending mock proposal failed")
44 | }
45 |
--------------------------------------------------------------------------------
/pkg/fab/signingmgr/signingmgr.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package signingmgr
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
11 |
12 | "github.com/hyperledger/fabric-sdk-go/pkg/core/cryptosuite"
13 | "github.com/pkg/errors"
14 | )
15 |
16 | // SigningManager is used for signing objects with private key
17 | type SigningManager struct {
18 | cryptoProvider core.CryptoSuite
19 | hashOpts core.HashOpts
20 | signerOpts core.SignerOpts
21 | }
22 |
23 | // New Constructor for a signing manager.
24 | // @param {BCCSP} cryptoProvider - crypto provider
25 | // @param {Config} config - configuration provider
26 | // @returns {SigningManager} new signing manager
27 | func New(cryptoProvider core.CryptoSuite) (*SigningManager, error) {
28 | return &SigningManager{cryptoProvider: cryptoProvider, hashOpts: cryptosuite.GetSHAOpts()}, nil
29 | }
30 |
31 | // Sign will sign the given object using provided key
32 | func (mgr *SigningManager) Sign(object []byte, key core.Key) ([]byte, error) {
33 |
34 | if len(object) == 0 {
35 | return nil, errors.New("object (to sign) required")
36 | }
37 |
38 | if key == nil {
39 | return nil, errors.New("key (for signing) required")
40 | }
41 |
42 | digest, err := mgr.cryptoProvider.Hash(object, mgr.hashOpts)
43 | if err != nil {
44 | return nil, err
45 | }
46 | signature, err := mgr.cryptoProvider.Sign(key, digest, mgr.signerOpts)
47 | if err != nil {
48 | return nil, err
49 | }
50 | return signature, nil
51 | }
52 |
--------------------------------------------------------------------------------
/pkg/fab/signingmgr/signingmgr_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package signingmgr
8 |
9 | import (
10 | "bytes"
11 | "testing"
12 |
13 | bccspwrapper "github.com/hyperledger/fabric-sdk-go/pkg/core/cryptosuite/bccsp/wrapper"
14 | fcmocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks"
15 | "github.com/hyperledger/fabric-sdk-go/pkg/msp/test/mockmsp"
16 | )
17 |
18 | func TestSigningManager(t *testing.T) {
19 |
20 | signingMgr, err := New(&fcmocks.MockCryptoSuite{})
21 | if err != nil {
22 | t.Fatalf("Failed to setup discovery provider: %s", err)
23 | }
24 |
25 | _, err = signingMgr.Sign(nil, nil)
26 | if err == nil {
27 | t.Fatal("Should have failed to sign nil object")
28 | }
29 |
30 | _, err = signingMgr.Sign([]byte(""), nil)
31 | if err == nil {
32 | t.Fatal("Should have failed to sign object empty object")
33 | }
34 |
35 | _, err = signingMgr.Sign([]byte("Hello"), nil)
36 | if err == nil {
37 | t.Fatal("Should have failed to sign object with nil key")
38 | }
39 |
40 | signedObj, err := signingMgr.Sign([]byte("Hello"), bccspwrapper.GetKey(&mockmsp.MockKey{}))
41 | if err != nil {
42 | t.Fatalf("Failed to sign object: %s", err)
43 | }
44 |
45 | expectedObj := []byte("testSignature")
46 | if !bytes.Equal(signedObj, expectedObj) {
47 | t.Fatalf("Expecting %s, got %s", expectedObj, signedObj)
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/pkg/fabsdk/defpkgsuite.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package fabsdk
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/core/logging/api"
11 | "github.com/hyperledger/fabric-sdk-go/pkg/core/logging/modlog"
12 | sdkApi "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/api"
13 | "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/factory/defcore"
14 | "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/factory/defmsp"
15 | "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/factory/defsvc"
16 | )
17 |
18 | type defPkgSuite struct{}
19 |
20 | func (ps *defPkgSuite) Core() (sdkApi.CoreProviderFactory, error) {
21 | return defcore.NewProviderFactory(), nil
22 | }
23 |
24 | func (ps *defPkgSuite) MSP() (sdkApi.MSPProviderFactory, error) {
25 | return defmsp.NewProviderFactory(), nil
26 | }
27 |
28 | func (ps *defPkgSuite) Service() (sdkApi.ServiceProviderFactory, error) {
29 | return defsvc.NewProviderFactory(), nil
30 | }
31 |
32 | func (ps *defPkgSuite) Logger() (api.LoggerProvider, error) {
33 | return modlog.LoggerProvider(), nil
34 | }
35 |
--------------------------------------------------------------------------------
/pkg/fabsdk/defpkgsuite_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package fabsdk
8 |
9 | import "testing"
10 |
11 | func TestNewPkgSuite(t *testing.T) {
12 | pkgsuite := defPkgSuite{}
13 |
14 | core, err := pkgsuite.Core()
15 | if err != nil {
16 | t.Fatal("Unexpected error getting default core factory")
17 | }
18 | if core == nil {
19 | t.Fatal("Core is nil")
20 | }
21 |
22 | msp, err := pkgsuite.MSP()
23 | if err != nil {
24 | t.Fatal("Unexpected error getting default MSP factory")
25 | }
26 | if msp == nil {
27 | t.Fatal("MSP is nil")
28 | }
29 |
30 | service, err := pkgsuite.Service()
31 | if err != nil {
32 | t.Fatal("Unexpected error getting default service factory")
33 | }
34 | if service == nil {
35 | t.Fatal("service is nil")
36 | }
37 |
38 | logger, err := pkgsuite.Logger()
39 | if err != nil {
40 | t.Fatal("Unexpected error getting default logger factory")
41 | }
42 | if logger == nil {
43 | t.Fatal("logger is nil")
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/pkg/fabsdk/fabsdk_std.go:
--------------------------------------------------------------------------------
1 | //go:build !pprof
2 | // +build !pprof
3 |
4 | /*
5 | Copyright SecureKey Technologies Inc. All Rights Reserved.
6 |
7 | SPDX-License-Identifier: Apache-2.0
8 | */
9 |
10 | // Package fabsdk enables client usage of a Hyperledger Fabric network.
11 | package fabsdk
12 |
13 | import (
14 | "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/metrics"
15 | )
16 |
17 | func (sdk *FabricSDK) initMetrics(config *configs) {
18 |
19 | sdk.clientMetrics = &metrics.ClientMetrics{} // empty channel ClientMetrics for standard build.
20 | }
21 |
--------------------------------------------------------------------------------
/pkg/fabsdk/factory.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package fabsdk
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/core/logging/api"
11 | sdkApi "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/api"
12 | )
13 |
14 | // pkgSuite provides the package factories that create clients and providers
15 | type pkgSuite interface {
16 | Core() (sdkApi.CoreProviderFactory, error)
17 | MSP() (sdkApi.MSPProviderFactory, error)
18 | Service() (sdkApi.ServiceProviderFactory, error)
19 | Logger() (api.LoggerProvider, error)
20 | }
21 |
--------------------------------------------------------------------------------
/pkg/fabsdk/factory/defsvc/svcfactory.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package defsvc
8 |
9 | import (
10 | discovery "github.com/hyperledger/fabric-sdk-go/pkg/client/common/discovery/staticdiscovery"
11 | "github.com/hyperledger/fabric-sdk-go/pkg/common/options"
12 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
13 | "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/provider/chpvdr"
14 | )
15 |
16 | // ProviderFactory represents the default SDK provider factory for services.
17 | type ProviderFactory struct{}
18 |
19 | // NewProviderFactory returns the default SDK provider factory for services.
20 | func NewProviderFactory() *ProviderFactory {
21 | f := ProviderFactory{}
22 | return &f
23 | }
24 |
25 | // CreateLocalDiscoveryProvider returns a static local discovery provider. This should be changed
26 | // to use the dynamic provider when Fabric 1.1 is no longer supported
27 | func (f *ProviderFactory) CreateLocalDiscoveryProvider(config fab.EndpointConfig) (fab.LocalDiscoveryProvider, error) {
28 | return discovery.NewLocalProvider(config)
29 | }
30 |
31 | // CreateChannelProvider returns a new default implementation of channel provider
32 | func (f *ProviderFactory) CreateChannelProvider(config fab.EndpointConfig, opts ...options.Opt) (fab.ChannelProvider, error) {
33 | return chpvdr.New(config, opts...)
34 | }
35 |
--------------------------------------------------------------------------------
/pkg/fabsdk/factory/defsvc/svcfactory_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package defsvc
8 |
9 | import (
10 | "testing"
11 |
12 | "github.com/hyperledger/fabric-sdk-go/pkg/client/common/discovery/staticdiscovery"
13 | "github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks"
14 | )
15 |
16 | func TestCreateLocalDiscoveryProvider(t *testing.T) {
17 | factory := NewProviderFactory()
18 |
19 | config := mocks.NewMockEndpointConfig()
20 |
21 | dp, err := factory.CreateLocalDiscoveryProvider(config)
22 | if err != nil {
23 | t.Fatalf("Unexpected error creating local discovery provider %s", err)
24 | }
25 |
26 | _, ok := dp.(*staticdiscovery.LocalProvider)
27 | if !ok {
28 | t.Fatal("Unexpected local discovery provider created")
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/pkg/gateway/identity.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2020 IBM All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package gateway
8 |
9 | // Identity represents a specific identity format
10 | type Identity interface {
11 | idType() string
12 | mspID() string
13 | toJSON() ([]byte, error)
14 | fromJSON(data []byte) (Identity, error)
15 | }
16 |
--------------------------------------------------------------------------------
/pkg/gateway/inmemorywallet_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2020 IBM All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package gateway
8 |
9 | import (
10 | "testing"
11 | )
12 |
13 | func createInMemoryWallet() (*Wallet, error) {
14 | return NewInMemoryWallet(), nil
15 | }
16 |
17 | func TestNewInMemoryWallet(t *testing.T) {
18 | wallet := NewInMemoryWallet()
19 | if wallet == nil {
20 | t.Fatal("Failed to create in memory wallet")
21 | }
22 | }
23 |
24 | func TestInMemoryWalletSuite(t *testing.T) {
25 | testWalletSuite(t, createInMemoryWallet)
26 | }
27 |
--------------------------------------------------------------------------------
/pkg/gateway/spi.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2020 IBM All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package gateway
8 |
9 | // This contains the service provider interface (SPI) which provides the mechanism
10 | // for implementing alternative gateway strategies, wallets, etc.
11 | // This is currently experimental and will be implemented in future user stories
12 |
13 | // WalletStore is the interface for implementations that provide backing storage for identities in a wallet.
14 | // To create create a new backing store, implement all the methods defined in this interface and provide
15 | // a factory method that wraps an instance of this in a new Wallet object. E.g:
16 | // func NewMyWallet() *Wallet {
17 | // store := &myWalletStore{ }
18 | // return &Wallet{store}
19 | // }
20 | type WalletStore interface {
21 | Put(label string, stream []byte) error
22 | Get(label string) ([]byte, error)
23 | List() ([]string, error)
24 | Exists(label string) bool
25 | Remove(label string) error
26 | }
27 |
--------------------------------------------------------------------------------
/pkg/gateway/testdata/connection-discovery.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "basic-network",
3 | "version": "1.0.0",
4 | "client": {
5 | "organization": "Org1",
6 | "connection": {
7 | "timeout": {
8 | "peer": {
9 | "endorser": "300"
10 | },
11 | "orderer": "300"
12 | }
13 | },
14 | "cryptoconfig": {
15 | "path": "${FABRIC_SDK_GO_PROJECT_PATH}/${CRYPTOCONFIG_FIXTURES_PATH}"
16 | }
17 | },
18 | "organizations": {
19 | "Org1": {
20 | "mspid": "Org1MSP",
21 | "peers": [
22 | "peer0.org1.example.com"
23 | ],
24 | "certificateAuthorities": [
25 | "ca-org1"
26 | ]
27 | }
28 | },
29 | "peers": {
30 | "peer0.org1.example.com": {
31 | "url": "grpcs://localhost:7051",
32 | "grpcOptions": {
33 | "hostnameOverride": "peer0.org1.example.com",
34 | "ssl-target-name-override": "peer0.org1.example.com",
35 | "request-timeout": 120001
36 | },
37 | "tlsCACerts": {
38 | "path": "${FABRIC_SDK_GO_PROJECT_PATH}/${CRYPTOCONFIG_FIXTURES_PATH}/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt"
39 | }
40 | }
41 | },
42 | "certificateAuthorities": {
43 | "ca-org1": {
44 | "url": "https://localhost:7054",
45 | "grpcOptions": {
46 | "verify": true
47 | },
48 | "tlsCACerts": {
49 | "path": "${FABRIC_SDK_GO_PROJECT_PATH}/${CRYPTOCONFIG_FIXTURES_PATH}/peerOrganizations/org1.example.com/ca/ca.org1.example.com-cert.pem"
50 | },
51 | "registrar": {
52 | "enrollId": "admin",
53 | "enrollSecret": "adminpw"
54 | }
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/pkg/gateway/testdata/connection.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "basic-network",
3 | "version": "1.0.0",
4 | "client": {
5 | "organization": "Org1",
6 | "connection": {
7 | "timeout": {
8 | "peer": {
9 | "endorser": "300"
10 | },
11 | "orderer": "300"
12 | }
13 | }
14 | },
15 | "channels": {
16 | "mychannel": {
17 | "orderers": [
18 | "orderer.example.com"
19 | ],
20 | "peers": {
21 | "peer0.org1.example.com": {
22 | "endorsingPeer": true,
23 | "chaincodeQuery": true,
24 | "ledgerQuery": true,
25 | "eventSource": true
26 | }
27 | }
28 | }
29 | },
30 | "organizations": {
31 | "Org1": {
32 | "mspid": "Org1MSP",
33 | "peers": [
34 | "peer0.org1.example.com"
35 | ],
36 | "certificateAuthorities": [
37 | "ca.example.com"
38 | ]
39 | }
40 | },
41 | "orderers": {
42 | "orderer.example.com": {
43 | "url": "grpc://localhost:7050"
44 | }
45 | },
46 | "peers": {
47 | "peer0.org1.example.com": {
48 | "url": "grpc://localhost:7051"
49 | }
50 | },
51 | "certificateAuthorities": {
52 | "ca.example.com": {
53 | "url": "http://localhost:7054",
54 | "caName": "ca.example.com"
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/pkg/gateway/testdata/wallet/invalid1.id:
--------------------------------------------------------------------------------
1 | Invalid format
--------------------------------------------------------------------------------
/pkg/gateway/testdata/wallet/invalid2.id:
--------------------------------------------------------------------------------
1 | ["JSON", "array", "is not valid"]
--------------------------------------------------------------------------------
/pkg/gateway/testdata/wallet/invalid3.id:
--------------------------------------------------------------------------------
1 | {"version":1,"mspId":"mspId"}
--------------------------------------------------------------------------------
/pkg/gateway/testdata/wallet/invalid4.id:
--------------------------------------------------------------------------------
1 | {"version":1,"mspId":"mspId","type":"invalid"}
--------------------------------------------------------------------------------
/pkg/gateway/testdata/wallet/x509-v1.id:
--------------------------------------------------------------------------------
1 | {"version":1,"mspId":"mspId","type":"X.509","credentials":{"certificate":"-----BEGIN CERTIFICATE-----\nMIIBWjCB3qADAgECAgYBbvXSw4QwDQYJKoZIhvcNAQELBQAwEzERMA8GA1UEAwwI\nSm9obiBEb2UwHhcNMTkxMjEwMTYzNzQwWhcNMTkxMTI2MDA1NTUxWjATMREwDwYD\nVQQDDAhKb2huIERvZTB2MBAGByqGSM49AgEGBSuBBAAiA2IABBIV2OGF/VkRcQTf\n5NjLpQMIW+kc6VmBdpd7+YJ4CrpxtCISiMcDf4LxQ2QdVhkM0FSiYCFLxnDOg8u6\nTm+uKVzlH0HEKkPycoDk784dcvyXiUuWuo6ZHXaCQJfEHNldPzANBgkqhkiG9w0B\nAQsFAANoADBlAjEAoNys0S+/R9/w3bUMwohRN7NuIh2JYmxy3oEafunF4LaNaRd8\ndG9gLBn/7LQZGUu7AjBLQQMV0GPZCNl6JN4TZyxcARxDCmpiuIAzwZuFRYpaAVTO\npJgR6ICTZ0Ko3rz4cT4=\n-----END CERTIFICATE-----\n","privateKey":"-----BEGIN PRIVATE KEY-----\nMIG/AgEAMBAGByqGSM49AgEGBSuBBAAiBIGnMIGkAgEBBDAAL3tEAlZDEPZiOxZp\njjGncTzZtLBbtO30tqT+WdTbRqwF9OpGLBAgsbzzo9nhqBagBwYFK4EEACKhZANi\nAAQSFdjhhf1ZEXEE3+TYy6UDCFvpHOlZgXaXe/mCeAq6cbQiEojHA3+C8UNkHVYZ\nDNBUomAhS8ZwzoPLuk5vrilc5R9BxCpD8nKA5O/OHXL8l4lLlrqOmR12gkCXxBzZ\nXT8=\n-----END PRIVATE KEY-----\n"}}
--------------------------------------------------------------------------------
/pkg/msp/filecertstore.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package msp
8 |
9 | import (
10 | "fmt"
11 | "path/filepath"
12 | "strings"
13 |
14 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
15 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
16 | "github.com/hyperledger/fabric-sdk-go/pkg/fab/keyvaluestore"
17 | "github.com/pkg/errors"
18 | )
19 |
20 | // NewFileCertStore ...
21 | func NewFileCertStore(cryptoConfigMSPPath string) (core.KVStore, error) {
22 | _, orgName := filepath.Split(filepath.Dir(filepath.Dir(filepath.Dir(cryptoConfigMSPPath))))
23 | opts := &keyvaluestore.FileKeyValueStoreOptions{
24 | Path: cryptoConfigMSPPath,
25 | KeySerializer: func(key interface{}) (string, error) {
26 | ck, ok := key.(*msp.IdentityIdentifier)
27 | if !ok {
28 | return "", errors.New("converting key to CertKey failed")
29 | }
30 | if ck == nil || ck.MSPID == "" || ck.ID == "" {
31 | return "", errors.New("invalid key")
32 | }
33 |
34 | // TODO: refactor to case insensitive or remove eventually.
35 | r := strings.NewReplacer("{userName}", ck.ID, "{username}", ck.ID)
36 | certDir := filepath.Join(r.Replace(cryptoConfigMSPPath), "signcerts")
37 | return filepath.Join(certDir, fmt.Sprintf("%s@%s-cert.pem", ck.ID, orgName)), nil
38 | },
39 | }
40 | return keyvaluestore.New(opts)
41 | }
42 |
--------------------------------------------------------------------------------
/pkg/msp/filekeystore_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package msp
8 |
9 | import (
10 | "path/filepath"
11 | "runtime"
12 | "testing"
13 |
14 | "github.com/stretchr/testify/assert"
15 | )
16 |
17 | func TestCryptoConfigPrivKeyPathV1(t *testing.T) {
18 | const (
19 | cryptoConfigPath = "testdata/cryptoconfig/v1/{username}"
20 | username = "user"
21 | )
22 | ski := []byte{0,1}
23 |
24 |
25 | p := cryptoConfigPrivateKeyPath(cryptoConfigPath, username, ski)
26 | assert.Contains(t, p, "0001_sk")
27 | }
28 |
29 | func TestCryptoConfigPrivKeyPathV2(t *testing.T) {
30 | const (
31 | cryptoConfigRelPath = "testdata/cryptoconfig/v2/{username}"
32 | username = "user"
33 | )
34 | ski := []byte{0,1}
35 |
36 | cryptoConfigPath := filepath.Join(testDir(), cryptoConfigRelPath)
37 | t.Log(cryptoConfigPath)
38 |
39 | p := cryptoConfigPrivateKeyPath(cryptoConfigPath, username, ski)
40 | assert.Contains(t, p, "priv_sk")
41 | }
42 |
43 | func testDir() string {
44 | _, filename, _, _ := runtime.Caller(0)
45 | return filepath.Dir(filename)
46 | }
47 |
--------------------------------------------------------------------------------
/pkg/msp/identitymgr_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package msp
8 |
9 | import (
10 | "testing"
11 |
12 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
13 | )
14 |
15 | // TODO Add tests
16 |
17 | // TestInterfaces will test if the interface instantiation happens properly, ie no nil returned
18 | func TestManagerInterfaces(t *testing.T) {
19 | var apiIM msp.IdentityManager
20 | var im IdentityManager
21 |
22 | apiIM = &im
23 | if apiIM == nil {
24 | t.Fatal("this shouldn't happen.")
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/pkg/msp/memory_key_store.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package msp
8 |
9 | import (
10 | "encoding/hex"
11 |
12 | "fmt"
13 |
14 | "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/bccsp"
15 | )
16 |
17 | // MemoryKeyStore is in-memory implementation of BCCSP key store
18 | type MemoryKeyStore struct {
19 | store map[string]bccsp.Key
20 | password []byte
21 | }
22 |
23 | // NewMemoryKeyStore creates a new MemoryKeyStore instance
24 | func NewMemoryKeyStore(password []byte) *MemoryKeyStore {
25 | store := make(map[string]bccsp.Key)
26 | return &MemoryKeyStore{store: store, password: password}
27 | }
28 |
29 | // ReadOnly returns always false
30 | func (s *MemoryKeyStore) ReadOnly() bool {
31 | return false
32 | }
33 |
34 | // GetKey returns a key for the provided SKI
35 | func (s *MemoryKeyStore) GetKey(ski []byte) (bccsp.Key, error) {
36 | key, ok := s.store[hex.EncodeToString(ski)]
37 | if !ok {
38 | return nil, fmt.Errorf("Key not found [%s]", ski)
39 | }
40 | return key, nil
41 | }
42 |
43 | // StoreKey stores a key
44 | func (s *MemoryKeyStore) StoreKey(key bccsp.Key) error {
45 | ski := hex.EncodeToString(key.SKI())
46 | s.store[ski] = key
47 | return nil
48 | }
49 |
--------------------------------------------------------------------------------
/pkg/msp/memory_user_store.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package msp
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
11 | )
12 |
13 | // MemoryUserStore is in-memory implementation of UserStore
14 | type MemoryUserStore struct {
15 | store map[string][]byte
16 | }
17 |
18 | // NewMemoryUserStore creates a new MemoryUserStore instance
19 | func NewMemoryUserStore() *MemoryUserStore {
20 | store := make(map[string][]byte)
21 | return &MemoryUserStore{store: store}
22 | }
23 |
24 | // Store stores a user into store
25 | func (s *MemoryUserStore) Store(user *msp.UserData) error {
26 | s.store[user.ID+"@"+user.MSPID] = user.EnrollmentCertificate
27 | return nil
28 | }
29 |
30 | // Load loads a user from store
31 | func (s *MemoryUserStore) Load(id msp.IdentityIdentifier) (*msp.UserData, error) {
32 | cert, ok := s.store[id.ID+"@"+id.MSPID]
33 | if !ok {
34 | return nil, msp.ErrUserNotFound
35 | }
36 | userData := msp.UserData{
37 | ID: id.ID,
38 | MSPID: id.MSPID,
39 | EnrollmentCertificate: cert,
40 | }
41 | return &userData, nil
42 | }
43 |
--------------------------------------------------------------------------------
/pkg/msp/test/mockmsp/mockkey.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package mockmsp
8 |
9 | import "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/bccsp"
10 |
11 | // MockKey mockcore BCCSP key
12 | type MockKey struct {
13 | }
14 |
15 | // Bytes ...
16 | func (m *MockKey) Bytes() ([]byte, error) {
17 | return []byte("Not implemented"), nil
18 | }
19 |
20 | // SKI ...
21 | func (m *MockKey) SKI() []byte {
22 | return []byte("Not implemented")
23 | }
24 |
25 | // Symmetric ...
26 | func (m *MockKey) Symmetric() bool {
27 | return false
28 | }
29 |
30 | // Private ...
31 | func (m *MockKey) Private() bool {
32 | return true
33 | }
34 |
35 | // PublicKey ...
36 | func (m *MockKey) PublicKey() (bccsp.Key, error) {
37 | return m, nil
38 | }
39 |
--------------------------------------------------------------------------------
/pkg/msp/test/mockmsp/mockuserstore.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package mockmsp
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
11 | )
12 |
13 | // MockUserStore ...
14 | type MockUserStore struct {
15 | }
16 |
17 | // Store ...
18 | func (m *MockUserStore) Store(*msp.UserData) error {
19 | return nil
20 | }
21 |
22 | // Load ...
23 | func (m *MockUserStore) Load(identifier msp.IdentityIdentifier) (*msp.UserData, error) {
24 | return &msp.UserData{}, nil
25 | }
26 |
--------------------------------------------------------------------------------
/pkg/msp/testdata/cryptoconfig/v1/user/keystore/0001_sk:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
--------------------------------------------------------------------------------
/pkg/msp/testdata/cryptoconfig/v2/user/keystore/priv_sk:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
--------------------------------------------------------------------------------
/pkg/msp/testdata/root.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIICYjCCAgmgAwIBAgIUB3CTDOU47sUC5K4kn/Caqnh114YwCgYIKoZIzj0EAwIw
3 | fzELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNh
4 | biBGcmFuY2lzY28xHzAdBgNVBAoTFkludGVybmV0IFdpZGdldHMsIEluYy4xDDAK
5 | BgNVBAsTA1dXVzEUMBIGA1UEAxMLZXhhbXBsZS5jb20wHhcNMTYxMDEyMTkzMTAw
6 | WhcNMjExMDExMTkzMTAwWjB/MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZv
7 | cm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEfMB0GA1UEChMWSW50ZXJuZXQg
8 | V2lkZ2V0cywgSW5jLjEMMAoGA1UECxMDV1dXMRQwEgYDVQQDEwtleGFtcGxlLmNv
9 | bTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABKIH5b2JaSmqiQXHyqC+cmknICcF
10 | i5AddVjsQizDV6uZ4v6s+PWiJyzfA/rTtMvYAPq/yeEHpBUB1j053mxnpMujYzBh
11 | MA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBQXZ0I9
12 | qp6CP8TFHZ9bw5nRtZxIEDAfBgNVHSMEGDAWgBQXZ0I9qp6CP8TFHZ9bw5nRtZxI
13 | EDAKBggqhkjOPQQDAgNHADBEAiAHp5Rbp9Em1G/UmKn8WsCbqDfWecVbZPQj3RK4
14 | oG5kQQIgQAe4OOKYhJdh3f7URaKfGTf492/nmRmtK+ySKjpHSrU=
15 | -----END CERTIFICATE-----
16 |
--------------------------------------------------------------------------------
/pkg/util/concurrent/lazycache/keys.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package lazycache
8 |
9 | // StringKey is a simple string cache key
10 | type StringKey struct {
11 | key string
12 | }
13 |
14 | // NewStringKey returns a new StringKey
15 | func NewStringKey(key string) *StringKey {
16 | return &StringKey{key: key}
17 | }
18 |
19 | // String returns the key as a string
20 | func (k *StringKey) String() string {
21 | return k.key
22 | }
23 |
--------------------------------------------------------------------------------
/pkg/util/concurrent/lazycache/refoptcheck.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package lazycache
8 |
9 | import (
10 | "time"
11 |
12 | "github.com/hyperledger/fabric-sdk-go/pkg/util/concurrent/lazyref"
13 | )
14 |
15 | // refOptCheck is used to test whether any of the lazyref options have been passed in
16 | type refOptCheck struct {
17 | useRef bool
18 | }
19 |
20 | func (p *refOptCheck) SetIdleExpiration(expiration time.Duration) {
21 | p.useRef = true
22 | }
23 |
24 | func (p *refOptCheck) SetAbsoluteExpiration(expiration time.Duration) {
25 | p.useRef = true
26 | }
27 |
28 | func (p *refOptCheck) SetExpirationProvider(expirationProvider lazyref.ExpirationProvider, expiryType lazyref.ExpirationType) {
29 | p.useRef = true
30 | }
31 |
32 | func (p *refOptCheck) SetFinalizer(value lazyref.Finalizer) {
33 | p.useRef = true
34 | }
35 |
36 | func (p *refOptCheck) SetRefreshInterval(initialInit, refreshPeriod time.Duration) {
37 | p.useRef = true
38 | }
39 |
--------------------------------------------------------------------------------
/pkg/util/concurrent/lazyref/expiration.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package lazyref
8 |
9 | import "time"
10 |
11 | // NewSimpleExpirationProvider returns an expiration provider
12 | // that sets the given expiration period
13 | func NewSimpleExpirationProvider(expiry time.Duration) ExpirationProvider {
14 | return func() time.Duration {
15 | return expiry
16 | }
17 | }
18 |
19 | // NewGraduatingExpirationProvider returns an expiration provider
20 | // that has an initial expiration and then expires in graduated increments
21 | // with a maximum expiration time.
22 | func NewGraduatingExpirationProvider(initialExpiry, increments, maxExpiry time.Duration) ExpirationProvider {
23 | var iteration uint32
24 | return func() time.Duration {
25 | expiry := initialExpiry + time.Duration(iteration)*increments
26 | if expiry > maxExpiry {
27 | return maxExpiry
28 | }
29 | iteration++
30 | return expiry
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/pkg/util/concurrent/rollingcounter/rollingcounter_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package rollingcounter
8 |
9 | import (
10 | "math/rand"
11 | "sync"
12 | "testing"
13 |
14 | "github.com/stretchr/testify/require"
15 | )
16 |
17 | func TestCounter(t *testing.T) {
18 | t.Run("Basic", func(t *testing.T) {
19 | counter := New()
20 |
21 | n := 10
22 | i := counter.Next(n)
23 | require.True(t, i < n)
24 |
25 | j := i
26 | i = counter.Next(n)
27 | require.True(t, i != j)
28 |
29 | n = 2
30 | i = counter.Next(n)
31 | require.True(t, i < n)
32 | })
33 |
34 | t.Run("Concurrent", func(t *testing.T) {
35 | counter := New()
36 |
37 | concurrency := 10
38 | iterations := 100
39 | maxN := 10
40 |
41 | var wg sync.WaitGroup
42 | wg.Add(concurrency)
43 | defer wg.Wait()
44 |
45 | for g := 0; g < concurrency; g++ {
46 | go func() {
47 | defer wg.Done()
48 | n := rand.Intn(maxN) + 1
49 | for j := 0; j < iterations; j++ {
50 | i := counter.Next(n)
51 | require.True(t, i < n, "index should be less than %d but was %d", n, i)
52 | }
53 | }()
54 | }
55 | })
56 | }
57 |
--------------------------------------------------------------------------------
/pkg/util/test/test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package test
8 |
9 | import (
10 | "bufio"
11 | "fmt"
12 | "os"
13 | "testing"
14 | )
15 |
16 | // Logf writes to stdout and flushes. Applicable for when t.Logf can't be used.
17 | func Logf(template string, args ...interface{}) {
18 | f := bufio.NewWriter(os.Stdout)
19 |
20 | _, err := f.WriteString(fmt.Sprintf(template, args...))
21 | if err != nil {
22 | panic(fmt.Sprintf("writing to output failed: %s", err))
23 | }
24 |
25 | err = f.WriteByte('\n')
26 | if err != nil {
27 | panic(fmt.Sprintf("writing to output failed: %s", err))
28 | }
29 |
30 | err = f.Flush()
31 | if err != nil {
32 | panic(fmt.Sprintf("writing to output failed: %s", err))
33 | }
34 | }
35 |
36 | // Failf - as t.Fatalf is not goroutine safe, this function behaves like t.Fatalf.
37 | func Failf(t *testing.T, template string, args ...interface{}) {
38 | f := bufio.NewWriter(os.Stdout)
39 |
40 | _, err := f.WriteString(fmt.Sprintf(template, args...))
41 | if err != nil {
42 | panic(fmt.Sprintf("writing to output failed: %s", err))
43 | }
44 |
45 | err = f.WriteByte('\n')
46 | if err != nil {
47 | panic(fmt.Sprintf("writing to output failed: %s", err))
48 | }
49 |
50 | err = f.Flush()
51 | if err != nil {
52 | panic(fmt.Sprintf("writing to output failed: %s", err))
53 | }
54 |
55 | t.Fail()
56 | }
57 |
--------------------------------------------------------------------------------
/scripts/_go/src/chaincoded/cmd/chaincoded/log.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package main
8 |
9 | import (
10 | "log"
11 | "os"
12 | )
13 |
14 | func isVerbose() bool {
15 | _, ok := os.LookupEnv("CHAINCODED_VERBOSE")
16 | return ok
17 | }
18 |
19 | func logDebugf(format string, v ...interface{}) {
20 | if isVerbose() {
21 | log.Printf(format, v...)
22 | }
23 | }
24 |
25 | func logInfof(format string, v ...interface{}) {
26 | log.Printf(format, v...)
27 | }
28 |
29 | func logWarningf(format string, v ...interface{}) {
30 | log.Printf("Warning: "+format, v...)
31 | }
32 |
33 | func logFatalf(format string, v ...interface{}) {
34 | log.Printf("Fatal: "+format, v...)
35 | }
36 |
--------------------------------------------------------------------------------
/scripts/_go/src/chaincoded/go.mod:
--------------------------------------------------------------------------------
1 | // Copyright SecureKey Technologies Inc. All Rights Reserved.
2 | //
3 | // SPDX-License-Identifier: Apache-2.0
4 |
5 | module chaincoded
6 |
7 | go 1.14
8 |
--------------------------------------------------------------------------------
/scripts/_go/src/gofilter/go.mod:
--------------------------------------------------------------------------------
1 | // Copyright SecureKey Technologies Inc. All Rights Reserved.
2 | //
3 | // SPDX-License-Identifier: Apache-2.0
4 |
5 | module gofilter
6 |
7 | go 1.14
8 |
--------------------------------------------------------------------------------
/scripts/_go/src/pkcs11helper/cmd/pkcs11helper/.gitignore:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
3 | #
4 | # SPDX-License-Identifier: Apache-2.0
5 | #
6 |
7 | /pkcs11helper
8 |
--------------------------------------------------------------------------------
/scripts/_go/src/pkcs11helper/cmd/pkcs11helper/testdata/key.ec.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN PRIVATE KEY-----
2 | MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgXa3mln4anewXtqrM
3 | hMw6mfZhslkRa/j9P790ToKjlsihRANCAARnxLhXvU4EmnIwhVl3Bh0VcByQi2um
4 | 9KsJ/QdCDjRZb1dKg447voj5SZ8SSZOUglc/v8DJFFJFTfygjwi+27gz
5 | -----END PRIVATE KEY-----
6 |
--------------------------------------------------------------------------------
/scripts/_go/src/pkcs11helper/go.mod:
--------------------------------------------------------------------------------
1 | // Copyright SecureKey Technologies Inc. All Rights Reserved.
2 | //
3 | // SPDX-License-Identifier: Apache-2.0
4 |
5 | module pkcs11helper
6 |
7 | require (
8 | github.com/miekg/pkcs11 v0.0.0-20190329070431-55f3fac3af27
9 | github.com/olekukonko/tablewriter v0.0.4 // indirect
10 | github.com/pkg/errors v0.9.1 // indirect
11 | )
12 |
13 | go 1.14
14 |
--------------------------------------------------------------------------------
/scripts/_go/src/pkcs11helper/go.sum:
--------------------------------------------------------------------------------
1 | github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
2 | github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
3 | github.com/miekg/pkcs11 v0.0.0-20190329070431-55f3fac3af27 h1:XA/VH+SzpYyukhgh7v2mTp8rZoKKITXR/x3FIizVEXs=
4 | github.com/miekg/pkcs11 v0.0.0-20190329070431-55f3fac3af27/go.mod h1:WCBAbTOdfhHhz7YXujeZMF7owC4tPb1naKFsgfUISjo=
5 | github.com/olekukonko/tablewriter v0.0.4 h1:vHD/YYe1Wolo78koG299f7V/VAS08c6IpCLn+Ejf/w8=
6 | github.com/olekukonko/tablewriter v0.0.4/go.mod h1:zq6QwlOf5SlnkVbMSr5EoBv3636FWnp+qbPhuoO21uA=
7 | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
8 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
9 |
--------------------------------------------------------------------------------
/scripts/changelog.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Copyright IBM Corp, SecureKey Technologies Inc. All Rights Reserved.
4 | #
5 | # SPDX-License-Identifier: Apache-2.0
6 | #
7 | # to update CHANGELOG.md, run this script with the latest commit of the latest release number found in CHANGELOG.md
8 | #
9 | echo "## $2\n$(date)" >> CHANGELOG.new
10 | echo "" >> CHANGELOG.new
11 | git log $1..HEAD --oneline | grep -v Merge | sed -e "s/\(FAB-[0-9]*\)/\[\1\](https:\/\/jira.hyperledger.org\/browse\/\1\)/" -e "s/\([0-9|a-z]*\)/* \[\1\](https:\/\/github.com\/hyperledger\/fabric-sdk-go\/commit\/\1)/" >> CHANGELOG.new
12 | echo "" >> CHANGELOG.new
13 | cat CHANGELOG.md >> CHANGELOG.new
14 | mv -f CHANGELOG.new CHANGELOG.md
15 |
--------------------------------------------------------------------------------
/scripts/third_party_pins/apply_thirdparty_pins.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
4 | #
5 | # SPDX-License-Identifier: Apache-2.0
6 | #
7 |
8 | # This script fetches code originating from other upstream projects
9 | # These files are checked into internal paths.
10 |
11 | set -e
12 |
13 | if output=$(git status --porcelain) && [ -z "$output" ]
14 | then
15 | echo "Working directory clean, proceeding with upstream patching"
16 | else
17 | echo "ERROR: git status must be clean before applying upstream patches"
18 | exit 1
19 | fi
20 |
21 | export UPSTREAM_COMMIT="${THIRDPARTY_FABRIC_COMMIT}"
22 | export UPSTREAM_BRANCH="${THIRDPARTY_FABRIC_BRANCH}"
23 | scripts/third_party_pins/fabric/apply_upstream.sh
24 |
25 | export UPSTREAM_COMMIT="${THIRDPARTY_FABRIC_CA_COMMIT}"
26 | export UPSTREAM_BRANCH="${THIRDPARTY_FABRIC_CA_BRANCH}"
27 | scripts/third_party_pins/fabric-ca/apply_upstream.sh
28 |
--------------------------------------------------------------------------------
/scripts/third_party_pins/common/apply_header_notice.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
4 | #
5 | # SPDX-License-Identifier: Apache-2.0
6 | #
7 |
8 | set -e
9 |
10 | FILE=$1
11 | NOTICE=$'Notice: This file has been modified for Hyperledger Fabric SDK Go usage.\nPlease review third_party pinning scripts and patches for more details.'
12 | SPDX_LICENSE_ID="SPDX-License-Identifier: Apache-2.0"
13 | OLD_APACHE_LICENSE_ID="http://www.apache.org/licenses/LICENSE-2.0"
14 | NONE_LICENSE_ID="::NONE::"
15 | ALLOW_NONE_LICENSE_ID="${ALLOW_NONE_LICENSE_ID:-false}"
16 |
17 | if [ -z $WORKING_DIR ]; then
18 | WORKING_DIR=`pwd`
19 | fi
20 |
21 | if APPLIED=`scripts/third_party_pins/common/insert_header_notice.sh ${WORKING_DIR}/${FILE} "$NOTICE" "$SPDX_LICENSE_ID"`; then
22 | echo "$APPLIED" > ${WORKING_DIR}/${FILE}
23 | elif APPLIED=`scripts/third_party_pins/common/insert_header_notice.sh ${WORKING_DIR}/${FILE} "$NOTICE" "$OLD_APACHE_LICENSE_ID"`; then
24 | echo "$APPLIED" > ${WORKING_DIR}/${FILE}
25 | elif [ "$ALLOW_NONE_LICENSE_ID" == "true" ] && APPLIED=`scripts/third_party_pins/common/insert_header_notice.sh ${WORKING_DIR}/${FILE} "$NOTICE" "$NONE_LICENSE_ID"`; then
26 | echo "$APPLIED" > ${WORKING_DIR}/${FILE}
27 | else
28 | echo "Failed to apply notice to ${WORKING_DIR}/${FILE}"
29 | exit 1
30 | fi
31 |
--------------------------------------------------------------------------------
/scripts/third_party_pins/fabric/apply_fabric_common_utils.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
4 | #
5 | # SPDX-License-Identifier: Apache-2.0
6 | #
7 |
8 | # This script pins from Hyperledger Fabric into the SDK
9 | # Note: This script must be adjusted as upstream makes adjustments
10 |
11 | set -e
12 |
13 | # Create and populate patching directory.
14 | declare TMP=`mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir'`
15 | declare PATCH_PROJECT_PATH=$TMP/src/$UPSTREAM_PROJECT
16 | cp -R ${TMP_PROJECT_PATH} ${PATCH_PROJECT_PATH}
17 | declare TMP_PROJECT_PATH=${PATCH_PROJECT_PATH}
18 |
19 | declare -a FILES=(
20 | "common/policydsl/policydsl_builder.go"
21 | "common/policydsl/policyparser.go"
22 | "core/common/ccprovider/ccprovider.go"
23 | "core/common/ccprovider/cdspackage.go"
24 | "core/ledger/kvledger/txmgmt/rwsetutil/rwset_proto_util.go"
25 | )
26 |
27 | # Copy patched project into internal paths and insert modification notice
28 | echo "Copying patched upstream project into working directory and inserting modification notice ..."
29 | for i in "${FILES[@]}"
30 | do
31 | TARGET_PATH=`dirname $INTERNAL_PATH/${i}`
32 | TARGET_BASENAME=`basename $INTERNAL_PATH/${i}`
33 | mkdir -p $TARGET_PATH && cp $TMP_PROJECT_PATH/${i} $TARGET_PATH
34 | scripts/third_party_pins/common/apply_header_notice.sh $TARGET_PATH/$TARGET_BASENAME
35 | done
36 |
37 | rm -Rf ${TMP_PROJECT_PATH}
--------------------------------------------------------------------------------
/scripts/third_party_pins/fabric/apply_fabric_external_utils.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
4 | #
5 | # SPDX-License-Identifier: Apache-2.0
6 | #
7 |
8 | # This script pins from Hyperledger Fabric into the SDK
9 | # Note: This script must be adjusted as upstream makes adjustments
10 |
11 | set -e
12 |
13 | # Create and populate patching directory.
14 | declare TMP=`mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir'`
15 | declare PATCH_PROJECT_PATH=$TMP/src/$UPSTREAM_PROJECT
16 | cp -R ${TMP_PROJECT_PATH} ${PATCH_PROJECT_PATH}
17 | declare TMP_PROJECT_PATH=${PATCH_PROJECT_PATH}
18 |
19 | declare -a FILES=(
20 | )
21 |
22 | # Copy patched project into internal paths and insert modification notice
23 | echo "Copying patched upstream project into working directory and inserting modification notice ..."
24 | for i in "${FILES[@]}"
25 | do
26 | TARGET_PATH=`dirname $INTERNAL_PATH/${i}`
27 | TARGET_BASENAME=`basename $INTERNAL_PATH/${i}`
28 | mkdir -p $TARGET_PATH && cp $TMP_PROJECT_PATH/${i} $TARGET_PATH
29 | scripts/third_party_pins/common/apply_header_notice.sh $TARGET_PATH/$TARGET_BASENAME
30 | done
31 |
32 | rm -Rf ${TMP_PROJECT_PATH}
--------------------------------------------------------------------------------
/test/fixtures/config/config_test_crypto_bccsp.yaml:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
3 | #
4 | # SPDX-License-Identifier: Apache-2.0
5 | #
6 | #
7 | # The network connection profile provides client applications the information about the target
8 | # blockchain network that are necessary for the applications to interact with it. These are all
9 | # knowledge that must be acquired from out-of-band sources. This file provides such a source.
10 | #
11 |
12 |
13 | #
14 | # Schema version of the content. Used by the SDK to apply the corresponding parsing rules.
15 | #
16 | version: 1.0.0
17 |
18 | #
19 | # The client section used by GO SDK.
20 | #
21 | client:
22 | # Some SDKs support pluggable KV stores, the properties under "credentialStore"
23 | # are implementation specific
24 | credentialStore:
25 | # [Optional]. Used by user store. Not needed if all credentials are embedded in configuration
26 | # and enrollments are performed elswhere.
27 | path: "/tmp/state-store"
28 |
29 | # [Optional]. Specific to the CryptoSuite implementation used by GO SDK. Software-based implementations
30 | # requiring a key store. PKCS#11 based implementations does not.
31 | cryptoStore:
32 | # Specific to the underlying KeyValueStore that backs the crypto key store.
33 | path: /tmp/msp
34 |
35 | # [Optional] BCCSP config for the client. Used by GO SDK.
36 | BCCSP:
37 | security:
38 | enabled: true
39 | default:
40 | provider: "SW"
41 | hashAlgorithm: "SHA2"
42 | softVerify: true
43 | level: 256
44 |
--------------------------------------------------------------------------------
/test/fixtures/dockerenv/docker-compose-negative.yaml:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
3 | #
4 | # SPDX-License-Identifier: Apache-2.0
5 | #
6 | version: '2.1'
7 |
8 | services:
9 |
10 | integration-tests:
11 | image: ${FABRIC_BASE_DOCKER_REGISTRY}${FABRIC_BASEIMAGE_FIXTURE_IMAGE}:${FABRIC_ARCH}${FABRIC_ARCH_SEP}${FABRIC_BASEIMAGE_FIXTURE_TAG}
12 | environment:
13 | - GO_TAGS
14 | - GO_TESTFLAGS
15 | - FABRIC_SDKGO_CODELEVEL_TAG
16 | - FABRIC_SDKGO_CODELEVEL_VER
17 | - FABRIC_SDKGO_TESTRUN_ID
18 | - FABRIC_FIXTURE_VERSION
19 | - FABRIC_CRYPTOCONFIG_VERSION
20 | - FABRIC_SDK_CLIENT_EVENTSERVICE_TYPE
21 | - TEST_CHANGED_ONLY
22 | - CORE_VM_ENDPOINT
23 | - CC_MODE
24 | volumes:
25 | - ${GOPATH}/pkg/mod:/opt/gopath/pkg/mod
26 | - ../../../:/opt/workspace/fabric-sdk-go
27 | command: /opt/workspace/fabric-sdk-go/test/scripts/negative.sh
28 | depends_on:
29 | - org1ca1
30 | - org2ca1
31 | - org1peer1
32 | - org2peer1
33 | - org2peer2
34 | - orderer1
35 | - builder
36 |
--------------------------------------------------------------------------------
/test/fixtures/dockerenv/docker-compose-nopkcs11-test.yaml:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
3 | #
4 | # SPDX-License-Identifier: Apache-2.0
5 | #
6 | version: '2.1'
7 |
8 | services:
9 |
10 | integration-tests:
11 | # TODO: parameterize golang version
12 | image: golang:1.14
13 | environment:
14 | - GO_TAGS
15 | - GO_TESTFLAGS
16 | - FABRIC_SDKGO_CODELEVEL_TAG
17 | - FABRIC_SDKGO_CODELEVEL_VER
18 | - FABRIC_SDKGO_TESTRUN_ID
19 | - FABRIC_FIXTURE_VERSION
20 | - FABRIC_CRYPTOCONFIG_VERSION
21 | - FABRIC_SDK_CLIENT_EVENTSERVICE_TYPE
22 | - E2E_ONLY
23 | - TEST_CHANGED_ONLY
24 | - CORE_VM_ENDPOINT
25 | - CC_MODE
26 | volumes:
27 | - ${GOPATH}/pkg/mod:/opt/gopath/pkg/mod
28 | - ../../../:/opt/workspace/fabric-sdk-go
29 | command: /opt/workspace/fabric-sdk-go/test/scripts/integration.sh
30 | depends_on:
31 | - org1ca1
32 | - org2ca1
33 | - org1peer1
34 | - org2peer1
35 | - orderer1
36 | - builder
37 |
--------------------------------------------------------------------------------
/test/fixtures/dockerenv/docker-compose-pkcs11-test.yaml:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
3 | #
4 | # SPDX-License-Identifier: Apache-2.0
5 | #
6 | version: '2.1'
7 |
8 | services:
9 |
10 | pkcs11-integration-tests:
11 | image: fabsdkgo-softhsm2
12 | environment:
13 | - FABRIC_SDK_CLIENT_BCCSP_SECURITY_DEFAULT_PROVIDER=PKCS11
14 | - GO_TAGS
15 | - GO_TESTFLAGS
16 | - FABRIC_SDKGO_CODELEVEL_TAG
17 | - FABRIC_SDKGO_CODELEVEL_VER
18 | - FABRIC_SDKGO_TESTRUN_ID
19 | - FABRIC_FIXTURE_VERSION
20 | - FABRIC_CRYPTOCONFIG_VERSION
21 | - FABRIC_SDK_CLIENT_EVENTSERVICE_TYPE
22 | - TEST_CHANGED_ONLY
23 | - CORE_VM_ENDPOINT
24 | - CC_MODE
25 | volumes:
26 | - ${GOPATH}/pkg/mod:/opt/gopath/pkg/mod
27 | - ../../../:/opt/workspace/fabric-sdk-go
28 | command: bash -c "/opt/workspace/fabric-sdk-go/test/scripts/unit-pkcs11.sh && /opt/workspace/fabric-sdk-go/test/scripts/integration-pkcs11.sh"
29 | depends_on:
30 | - org1ca1
31 | - org2ca1
32 | - org1peer1
33 | - org2peer1
34 | - orderer1
35 | - builder
36 |
--------------------------------------------------------------------------------
/test/fixtures/dockerenv/docker-compose-std.yaml:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
3 | #
4 | # SPDX-License-Identifier: Apache-2.0
5 | #
6 | version: '2.1'
7 |
8 | services:
9 |
10 | chaincoded:
11 | image: ${FABRIC_BASE_DOCKER_REGISTRY}${FABRIC_BASEIMAGE_FIXTURE_IMAGE}:${FABRIC_ARCH}${FABRIC_ARCH_SEP}${FABRIC_BASEIMAGE_FIXTURE_TAG}
12 | command: tail -F anything
13 | logging:
14 | driver: none
15 |
--------------------------------------------------------------------------------
/test/fixtures/dockerenv/latest-env.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
4 | #
5 | # SPDX-License-Identifier: Apache-2.0
6 | #
7 |
8 | export FABRIC_DOCKER_REGISTRY=""
9 | export FABRIC_CA_FIXTURE_TAG="latest"
10 | export FABRIC_ORDERER_FIXTURE_TAG="latest"
11 | export FABRIC_PEER_FIXTURE_TAG="latest"
12 | export FABRIC_COUCHDB_FIXTURE_TAG="latest"
13 | export FABRIC_BUILDER_FIXTURE_TAG="latest"
14 |
--------------------------------------------------------------------------------
/test/fixtures/dockerenv/nomutualtls-env.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
4 | #
5 | # SPDX-License-Identifier: Apache-2.0
6 | #
7 |
8 | # This file contains environment overrides to enable testing
9 | # against a fabric service that doesn't require TLS client authentication.
10 |
11 | export CORE_PEER_TLS_CLIENTAUTHREQUIRED=false
12 | export CORE_PEER_TLS_CLIENTROOTCAS_FILES=""
13 | export ORDERER_GENERAL_TLS_CLIENTAUTHENABLED=false
14 | export ORDERER_GENERAL_TLS_CLIENTROOTCAS=""
15 |
16 | export FABRIC_SDK_CLIENT_TLSCERTS_CLIENT_KEYFILE=""
17 | export FABRIC_SDK_CLIENT_TLSCERTS_CLIENT_CERTFILE=""
18 |
--------------------------------------------------------------------------------
/test/fixtures/dockerenv/prerelease-env.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
4 | #
5 | # SPDX-License-Identifier: Apache-2.0
6 | #
7 |
8 | # This file contains environment overrides to enable testing
9 | # against the latest pre-release target.
10 | export FABRIC_FIXTURE_VERSION="v1.4"
11 | export FABRIC_CRYPTOCONFIG_VERSION="v1"
12 |
13 | export FABRIC_CA_FIXTURE_TAG="1.4.0-rc2"
14 | export FABRIC_ORDERER_FIXTURE_TAG="1.4.0-rc2"
15 | export FABRIC_PEER_FIXTURE_TAG="1.4.0-rc2"
16 | export FABRIC_BUILDER_FIXTURE_TAG="1.4.0-rc2"
17 |
--------------------------------------------------------------------------------
/test/fixtures/dockerenv/prev-env.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
4 | #
5 | # SPDX-License-Identifier: Apache-2.0
6 | #
7 |
8 | # This file contains environment overrides to enable testing
9 | # against the latest pre-release target.
10 |
11 | export FABRIC_FIXTURE_VERSION="v1.4"
12 | export FABRIC_CRYPTOCONFIG_VERSION="v1"
13 |
14 | export FABRIC_CA_FIXTURE_TAG="1.4.7"
15 | export FABRIC_ORDERER_FIXTURE_TAG="1.4.7"
16 | export FABRIC_PEER_FIXTURE_TAG="1.4.7"
17 | export FABRIC_BUILDER_FIXTURE_TAG="1.4.7"
18 | export FABRIC_BASEOS_FIXTURE_TAG="0.4.20"
19 |
--------------------------------------------------------------------------------
/test/fixtures/dockerenv/stable-env.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
4 | #
5 | # SPDX-License-Identifier: Apache-2.0
6 | #
7 |
8 | # This file contains environment overrides to enable testing against
9 | # the stable target
10 |
11 |
--------------------------------------------------------------------------------
/test/fixtures/fabric/v1/config/cryptogen.yaml:
--------------------------------------------------------------------------------
1 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
2 | #
3 | # SPDX-License-Identifier: Apache-2.0
4 | #
5 |
6 | OrdererOrgs:
7 | - Name: OrdererOrg
8 | Domain: example.com
9 | Specs:
10 | - Hostname: orderer
11 |
12 | PeerOrgs:
13 | - Name: Org1
14 | Domain: org1.example.com
15 | EnableNodeOUs: false
16 | Specs:
17 | - Hostname: peer0
18 | - Hostname: peer1
19 | - Hostname: ca
20 | Users:
21 | Count: 1
22 |
23 | - Name: Org2
24 | Domain: org2.example.com
25 | EnableNodeOUs: false
26 | Specs:
27 | - Hostname: peer0
28 | - Hostname: peer1
29 | - Hostname: ca
30 | Users:
31 | Count: 1
32 |
33 | - Name: TLSOrg
34 | Domain: tls.example.com
35 | EnableNodeOUs: false
36 | Specs:
37 | - Hostname: ca
38 | Users:
39 | Count: 1
--------------------------------------------------------------------------------
/test/fixtures/softhsm2/Dockerfile:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
3 | #
4 | # SPDX-License-Identifier: Apache-2.0
5 | #
6 |
7 | ARG BASE_GO_VERSION
8 |
9 | FROM golang:${BASE_GO_VERSION}
10 |
11 | COPY test/fixtures/softhsm2/install-softhsm2.sh /tmp
12 | COPY scripts/_go/src/pkcs11helper /opt/workspace/pkcs11helper
13 | RUN bash /tmp/install-softhsm2.sh
14 | CMD ["/bin/bash"]
15 |
16 |
--------------------------------------------------------------------------------
/test/fixtures/softhsm2/install-softhsm2.sh:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright IBM Corp, SecureKey Technologies Inc. All Rights Reserved.
3 | #
4 | # SPDX-License-Identifier: Apache-2.0
5 | #
6 |
7 | set -xe
8 |
9 | apt-get update
10 |
11 | ARCH=`uname -m`
12 | if [ $ARCH = "s390x" ]; then
13 | apt-get install -y perl
14 | fi
15 |
16 | apt-get install -y --no-install-recommends softhsm2 curl git gcc g++ libtool libltdl-dev
17 | mkdir -p /var/lib/softhsm/tokens/
18 | softhsm2-util --init-token --slot 0 --label "ForFabric" --so-pin 1234 --pin 98765432
19 |
20 | cd /opt/workspace/pkcs11helper/
21 | go install pkcs11helper/cmd/pkcs11helper
22 |
--------------------------------------------------------------------------------
/test/fixtures/softhsm2/install_go.sh:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright IBM Corp, SecureKey Technologies Inc. All Rights Reserved.
3 | #
4 | # SPDX-License-Identifier: Apache-2.0
5 | #
6 |
7 | #!/bin/bash
8 |
9 | # ----------------------------------------------------------------
10 | # Install Golang
11 | # ----------------------------------------------------------------
12 |
13 | apt-get update
14 | apt-get install -y -qq wget
15 | mkdir -p $GOPATH
16 | ARCH=`uname -m | sed 's|i686|386|' | sed 's|x86_64|amd64|'`
17 |
18 | cd /tmp
19 | wget --quiet --no-check-certificate https://storage.googleapis.com/golang/go${GOVER}.linux-${ARCH}.tar.gz
20 | tar -xvf go${GOVER}.linux-${ARCH}.tar.gz
21 | mv go $GOROOT
22 | chmod 775 $GOROOT
--------------------------------------------------------------------------------
/test/fixtures/testdata/go/src/github.com/example_cc/go.mod:
--------------------------------------------------------------------------------
1 | // Copyright SecureKey Technologies Inc. All Rights Reserved.
2 | //
3 | // SPDX-License-Identifier: Apache-2.0
4 |
5 | module github.com/example_cc
6 |
7 | require (
8 | github.com/hyperledger/fabric-chaincode-go v0.0.0-20200511190512-bcfeb58dd83a
9 | github.com/hyperledger/fabric-protos-go v0.0.0-20190919234611-2a87503ac7c9
10 | )
11 |
12 | go 1.14
13 |
--------------------------------------------------------------------------------
/test/fixtures/testdata/go/src/github.com/example_pvt_cc/go.mod:
--------------------------------------------------------------------------------
1 | // Copyright SecureKey Technologies Inc. All Rights Reserved.
2 | //
3 | // SPDX-License-Identifier: Apache-2.0
4 |
5 | module github.com/example_pvt_cc
6 |
7 | require (
8 | github.com/hyperledger/fabric-chaincode-go v0.0.0-20200511190512-bcfeb58dd83a
9 | github.com/hyperledger/fabric-protos-go v0.0.0-20200506201313-25f6564b9ac4
10 | )
11 |
12 | go 1.14
13 |
--------------------------------------------------------------------------------
/test/fixtures/testdata/java/example_cc/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright IBM Corp. 2018 All Rights Reserved.
3 | *
4 | * SPDX-License-Identifier: Apache-2.0
5 | */
6 | plugins {
7 | id 'com.github.johnrengelman.shadow' version '2.0.3'
8 | id 'java'
9 | }
10 |
11 | group 'org.hyperledger.fabric-chaincode-java'
12 | version '1.0-SNAPSHOT'
13 |
14 | sourceCompatibility = 1.8
15 |
16 | repositories {
17 | mavenLocal()
18 | mavenCentral()
19 | }
20 |
21 | dependencies {
22 | compile group: 'org.hyperledger.fabric-chaincode-java', name: 'fabric-chaincode-shim', version: '1.+'
23 | testCompile group: 'junit', name: 'junit', version: '4.12'
24 | }
25 |
26 | shadowJar {
27 | baseName = 'chaincode'
28 | version = null
29 | classifier = null
30 |
31 | manifest {
32 | attributes 'Main-Class': 'org.hyperledger.fabric.example.SimpleChaincode'
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/test/fixtures/testdata/java/example_cc/settings.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright IBM Corp. 2017 All Rights Reserved.
3 | *
4 | * SPDX-License-Identifier: Apache-2.0
5 | */
6 | rootProject.name = 'fabric-chaincode-example-gradle'
7 |
8 |
--------------------------------------------------------------------------------
/test/fixtures/testdata/node/example_cc/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "chaincode_example02",
3 | "version": "1.0.0",
4 | "description": "chaincode_example02 chaincode implemented in node.js",
5 | "engines": {
6 | "node": ">=8.4.0",
7 | "npm": ">=5.3.0"
8 | },
9 | "scripts": { "start" : "node chaincode_example02.js" },
10 | "engine-strict": true,
11 | "license": "Apache-2.0",
12 | "dependencies": {
13 | "fabric-shim": "~1.4.0"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/test/integration/e2e/configless/end_to_end_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package configless
8 |
9 | import (
10 | "testing"
11 |
12 | "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
13 | "github.com/hyperledger/fabric-sdk-go/test/integration/e2e"
14 | )
15 |
16 | // this test mimics the original e2e test with the difference of injecting interface functions implementations
17 | // to programmatically supply configs instead of using a yaml file. With this change, application developers can fetch
18 | // configs from any source as long as they provide their own implementations.
19 |
20 | func TestE2E(t *testing.T) {
21 |
22 | //Using same Run call as e2e package but with programmatically overriding interfaces
23 | // since in this configless test, we are overriding all the config's interfaces, there's no need to add a configProvider
24 | //
25 | // But if someone wants to partially override the configs interfaces (by setting only some functions of either
26 | // EndpointConfig, CryptoSuiteConfig and/or IdentityConfig) then they need to provide a configProvider
27 | // with a config file that contains at least the sections that are not overridden by the provided functions
28 | e2e.RunWithoutSetup(t, nil,
29 | fabsdk.WithEndpointConfig(endpointConfigImpls...),
30 | fabsdk.WithCryptoSuiteConfig(cryptoConfigImpls...),
31 | fabsdk.WithIdentityConfig(identityConfigImpls...),
32 | fabsdk.WithMetricsConfig(operationsConfigImpls...),
33 | )
34 | }
35 |
--------------------------------------------------------------------------------
/test/integration/e2e/end_to_end_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package e2e
8 |
9 | import (
10 | "testing"
11 |
12 | "github.com/hyperledger/fabric-sdk-go/pkg/core/config"
13 | "github.com/hyperledger/fabric-sdk-go/test/integration"
14 | )
15 |
16 | func TestE2E(t *testing.T) {
17 | t.Run("Base", func(t *testing.T) {
18 | configPath := integration.GetConfigPath("config_e2e.yaml")
19 | Run(t, config.FromFile(configPath))
20 | })
21 |
22 | t.Run("NoOrderer", func(t *testing.T) {
23 | //Using setup done set above by end to end test, run below test with new config which has no orderer config inside
24 | runWithNoOrdererConfig(t, config.FromFile(integration.GetConfigPath("config_e2e_no_orderer.yaml")))
25 | })
26 | }
27 |
--------------------------------------------------------------------------------
/test/integration/e2e/orgs/multi_orgs_singleorgconfig_prev.go:
--------------------------------------------------------------------------------
1 | // +build prev
2 |
3 | /*
4 | Copyright SecureKey Technologies Inc. All Rights Reserved.
5 |
6 | SPDX-License-Identifier: Apache-2.0
7 | */
8 |
9 | package orgs
10 |
11 | import (
12 | "testing"
13 | )
14 |
15 | //TestMultiOrgWithSingleOrgConfig cannot be run in prev tests since fabric version greater than v1.1
16 | // supports dynamic discovery
17 | func TestMultiOrgWithSingleOrgConfig(t *testing.T, examplecc string) {
18 | //test nothing
19 | t.Logf("Dynamic discovery tests didn't run for '%s', since tests are running prev-release", examplecc)
20 | }
21 |
22 | // DistributedSignaturesTests is not supported in prev tests
23 | func DistributedSignaturesTests(t *testing.T, examplecc string) {
24 | t.Logf("Distributed Signatures tests require Dynamic Discovery which is not available in prev-release")
25 | }
26 |
--------------------------------------------------------------------------------
/test/integration/e2e/orgs/scripts/generate_signature.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
4 | #
5 | # SPDX-License-Identifier: Apache-2.0
6 | #
7 |
8 | set -e
9 |
10 | GO_CMD="${GO_CMD:-go}"
11 | SCRIPT_DIR="$(dirname "$0")"
12 | GOMOD_PATH=$(cd ${SCRIPT_DIR} && ${GO_CMD} env GOMOD)
13 | PROJECT_MODULE=$(awk -F' ' '$1 == "module" {print $2}' ${GOMOD_PATH})
14 | PROJECT_DIR=$(dirname ${GOMOD_PATH})
15 |
16 | PWD_ORIG=$(pwd)
17 | # need org in lowercase
18 | ORG_N=$1
19 | ORG=$(echo $ORG_N | tr '[:upper:]' '[:lower:]')
20 | USER=$2
21 | CH_CFG=$3
22 | echo "CH_CFG is $CH_CFG, ORG is $ORG, USER is $USER"
23 | KEY_PATH_DIR=${PROJECT_DIR}/../fixtures/fabric/v1/crypto-config/peerOrganizations/${ORG}.example.com/users/${USER}\@${ORG}.example.com/msp/keystore
24 | SIGNATURE_PATH=$4
25 | cd $KEY_PATH_DIR
26 | KEY_NAME=$(ls)
27 | echo "KEY_NAME is $KEY_NAME"
28 | cd ${PWD_ORIG}
29 | SIGNATURE_FILE=${SIGNATURE_PATH}/${CH_CFG}_${ORG_N}_${USER}_sbytes.txt.sha256
30 | openssl dgst -sha256 -sign ${KEY_PATH_DIR}/${KEY_NAME} -out ${SIGNATURE_FILE} ${SIGNATURE_PATH}/${CH_CFG}_${ORG_N}_${USER}_sbytes.txt
31 |
32 | echo "signature file generated name:[${CH_CFG}_${ORG_N}_${USER}_sbytes.txt.sha256] - content:[$(<${SIGNATURE_FILE})]"
--------------------------------------------------------------------------------
/test/integration/e2e/pkcs11/e2e_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package pkcs11
8 |
9 | import (
10 | "testing"
11 |
12 | "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
13 | "github.com/hyperledger/fabric-sdk-go/test/integration"
14 |
15 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
16 | "github.com/hyperledger/fabric-sdk-go/pkg/core/config"
17 | cryptosuite "github.com/hyperledger/fabric-sdk-go/pkg/core/cryptosuite/bccsp/pkcs11"
18 | "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/factory/defcore"
19 | "github.com/hyperledger/fabric-sdk-go/test/integration/e2e"
20 | )
21 |
22 | const (
23 | // ConfigTestFile contains the path and filename of the config for integration tests
24 | ConfigTestFilename = "config_e2e_pkcs11.yaml"
25 | )
26 |
27 | func TestE2E(t *testing.T) {
28 | // Create SDK setup for the integration tests
29 | e2e.Run(t,
30 | config.FromFile(integration.GetConfigPath(ConfigTestFilename)),
31 | fabsdk.WithCorePkg(&CustomCryptoSuiteProviderFactory{}))
32 | }
33 |
34 | // CustomCryptoSuiteProviderFactory is will provide custom cryptosuite (bccsp.BCCSP)
35 | type CustomCryptoSuiteProviderFactory struct {
36 | defcore.ProviderFactory
37 | }
38 |
39 | // CreateCryptoSuiteProvider returns a new default implementation of BCCSP
40 | func (f *CustomCryptoSuiteProviderFactory) CreateCryptoSuiteProvider(config core.CryptoSuiteConfig) (core.CryptoSuite, error) {
41 | return cryptosuite.GetSuiteByConfig(config)
42 | }
43 |
--------------------------------------------------------------------------------
/test/integration/go.mod:
--------------------------------------------------------------------------------
1 | // Copyright SecureKey Technologies Inc. All Rights Reserved.
2 | //
3 | // SPDX-License-Identifier: Apache-2.0
4 |
5 | module github.com/hyperledger/fabric-sdk-go/test/integration
6 |
7 | replace github.com/hyperledger/fabric-sdk-go => ../../
8 |
9 | require (
10 | github.com/golang/protobuf v1.3.3
11 | github.com/hyperledger/fabric-config v0.0.5
12 | github.com/hyperledger/fabric-protos-go v0.0.0-20200707132912-fee30f3ccd23
13 | github.com/hyperledger/fabric-sdk-go v0.0.0-00010101000000-000000000000
14 | github.com/pkg/errors v0.8.1
15 | github.com/stretchr/testify v1.5.1
16 | google.golang.org/grpc v1.29.1
17 | )
18 |
19 | go 1.14
20 |
--------------------------------------------------------------------------------
/test/integration/negative/testdata/ordererOrganizations/example.com/expiredtlsca/expired.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIByDCCAW4CCQDduc2dMnKaijAKBggqhkjOPQQDAjBsMQswCQYDVQQGEwJVUzET
3 | MBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEUMBIG
4 | A1UEChMLZXhhbXBsZS5jb20xGjAYBgNVBAMTEXRsc2NhLmV4YW1wbGUuY29tMB4X
5 | DTE4MDQwMjE3MTYyNVoXDTE4MDQwMzE3MTYyNVowbDELMAkGA1UEBhMCVVMxEzAR
6 | BgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBGcmFuY2lzY28xFDASBgNV
7 | BAoTC2V4YW1wbGUuY29tMRowGAYDVQQDExF0bHNjYS5leGFtcGxlLmNvbTBZMBMG
8 | ByqGSM49AgEGCCqGSM49AwEHA0IABB+Apvh1vneh03N0xec/kVlNlMXO047XIu8I
9 | cOh9I19M+r+C7D5hiTtk2aGWGPwkcUbp1PJtz1Bv8c6H2GGBilcwCgYIKoZIzj0E
10 | AwIDSAAwRQIhAPXQkC+p+32R58IFuR/mzNFIxJxYMBEs7c64H7W8nvFgAiBqvFz3
11 | 38RhOBOx5ZU5S8MMTB+rqyQ/B1dwxqU+HIPvUw==
12 | -----END CERTIFICATE-----
--------------------------------------------------------------------------------
/test/integration/negative/testdata/peerOrganizations/org1.example.com/expiredtlsca/expired.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIB3DCCAYICCQCJFxiDfROTkTAKBggqhkjOPQQDAjB2MQswCQYDVQQGEwJVUzET
3 | MBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEZMBcG
4 | A1UEChMQb3JnMS5leGFtcGxlLmNvbTEfMB0GA1UEAxMWdGxzY2Eub3JnMS5leGFt
5 | cGxlLmNvbTAeFw0xODA0MDUxOTM1MTZaFw0xODA0MDQxOTM1MTZaMHYxCzAJBgNV
6 | BAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1TYW4gRnJhbmNp
7 | c2NvMRkwFwYDVQQKExBvcmcxLmV4YW1wbGUuY29tMR8wHQYDVQQDExZ0bHNjYS5v
8 | cmcxLmV4YW1wbGUuY29tMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEw6IbxSmV
9 | ZOzz3zNn334+EMc9sqNkgMdUb7NBeinDxKo11fc0CZlQpRSwnwlnczj0mrgyzwQd
10 | ITBB/Qh/HcgIezAKBggqhkjOPQQDAgNIADBFAiEA3XpCm7q8McNJHCjbQeN8KnN6
11 | 5IVbo/7iiUrDRjhOQ9sCIB016KigprCaJZN+ENzKa+n0pNoLEL5hDufhf0kCxSjb
12 | -----END CERTIFICATE-----
--------------------------------------------------------------------------------
/test/integration/pkg/client/channel/main_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | package channel
7 |
8 | import (
9 | "testing"
10 |
11 | "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
12 | "github.com/hyperledger/fabric-sdk-go/test/integration"
13 | "github.com/hyperledger/fabric-sdk-go/test/integration/util/runner"
14 | "github.com/stretchr/testify/require"
15 | )
16 |
17 | const (
18 | org1Name = "Org1"
19 | org2Name = "Org2"
20 | org1AdminUser = "Admin"
21 | org2AdminUser = "Admin"
22 | org1User = "User1"
23 | orgChannelID = "orgchannel"
24 | )
25 |
26 | var mainSDK *fabsdk.FabricSDK
27 | var mainTestSetup *integration.BaseSetupImpl
28 | var mainChaincodeID string
29 |
30 | func TestMain(m *testing.M) {
31 | r := runner.NewWithExampleCC()
32 | r.Initialize()
33 | mainSDK = r.SDK()
34 | mainTestSetup = r.TestSetup()
35 | mainChaincodeID = r.ExampleChaincodeID()
36 |
37 | r.Run(m)
38 | }
39 |
40 | func setupMultiOrgContext(t *testing.T, sdk *fabsdk.FabricSDK) []*integration.OrgContext {
41 | orgContext, err := integration.SetupMultiOrgContext(sdk, org1Name, org2Name, org1AdminUser, org2AdminUser)
42 | require.NoError(t, err)
43 |
44 | return orgContext
45 | }
46 |
--------------------------------------------------------------------------------
/test/integration/pkg/client/common/discovery/main_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | package discovery
7 |
8 | import (
9 | "testing"
10 |
11 | "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
12 | "github.com/hyperledger/fabric-sdk-go/test/integration"
13 | "github.com/hyperledger/fabric-sdk-go/test/integration/util/runner"
14 | )
15 |
16 | const (
17 | org1Name = "Org1"
18 | org2Name = "Org2"
19 | adminUser = "Admin"
20 | org1User = "User1"
21 | orgChannelID = "orgchannel"
22 | )
23 |
24 | var mainSDK *fabsdk.FabricSDK
25 | var mainTestSetup *integration.BaseSetupImpl
26 |
27 | func TestMain(m *testing.M) {
28 | r := runner.New()
29 | r.Initialize()
30 | mainSDK = r.SDK()
31 | mainTestSetup = r.TestSetup()
32 |
33 | r.Run(m)
34 | }
35 |
--------------------------------------------------------------------------------
/test/integration/pkg/client/common/selection/main_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | package selection
7 |
8 | import (
9 | "testing"
10 |
11 | "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
12 | "github.com/hyperledger/fabric-sdk-go/test/integration"
13 | "github.com/hyperledger/fabric-sdk-go/test/integration/util/runner"
14 | "github.com/stretchr/testify/require"
15 | )
16 |
17 | const (
18 | org1Name = "Org1"
19 | org2Name = "Org2"
20 | adminUser = "Admin"
21 | org1User = "User1"
22 | orgChannelID = "orgchannel"
23 | )
24 |
25 | var mainSDK *fabsdk.FabricSDK
26 | var mainTestSetup *integration.BaseSetupImpl
27 |
28 | func TestMain(m *testing.M) {
29 | r := runner.New()
30 | r.Initialize()
31 | mainSDK = r.SDK()
32 | mainTestSetup = r.TestSetup()
33 |
34 | r.Run(m)
35 | }
36 |
37 | func setupMultiOrgContext(t *testing.T, sdk *fabsdk.FabricSDK) []*integration.OrgContext {
38 | orgContext, err := integration.SetupMultiOrgContext(sdk, org1Name, org2Name, adminUser, adminUser)
39 | require.NoError(t, err)
40 |
41 | return orgContext
42 | }
43 |
--------------------------------------------------------------------------------
/test/integration/pkg/client/event/main_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | package event
7 |
8 | import (
9 | "testing"
10 |
11 | "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
12 | "github.com/hyperledger/fabric-sdk-go/test/integration"
13 | "github.com/hyperledger/fabric-sdk-go/test/integration/util/runner"
14 | )
15 |
16 | const (
17 | org1Name = "Org1"
18 | org1User = "User1"
19 | )
20 |
21 | var mainSDK *fabsdk.FabricSDK
22 | var mainTestSetup *integration.BaseSetupImpl
23 | var mainChaincodeID string
24 |
25 | func TestMain(m *testing.M) {
26 | r := runner.NewWithExampleCC()
27 | r.Initialize()
28 | mainSDK = r.SDK()
29 | mainTestSetup = r.TestSetup()
30 | mainChaincodeID = r.ExampleChaincodeID()
31 |
32 | r.Run(m)
33 | }
34 |
--------------------------------------------------------------------------------
/test/integration/pkg/client/ledger/main_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | package ledger
7 |
8 | import (
9 | "testing"
10 |
11 | "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
12 | "github.com/hyperledger/fabric-sdk-go/test/integration"
13 | "github.com/hyperledger/fabric-sdk-go/test/integration/util/runner"
14 | )
15 |
16 | const (
17 | org1Name = "Org1"
18 | org1AdminUser = "Admin"
19 | )
20 |
21 | var mainSDK *fabsdk.FabricSDK
22 | var mainTestSetup *integration.BaseSetupImpl
23 | var mainChaincodeID string
24 |
25 | func TestMain(m *testing.M) {
26 | r := runner.NewWithExampleCC()
27 | r.Initialize()
28 | mainSDK = r.SDK()
29 | mainTestSetup = r.TestSetup()
30 | mainChaincodeID = r.ExampleChaincodeID()
31 |
32 | r.Run(m)
33 | }
34 |
--------------------------------------------------------------------------------
/test/integration/pkg/client/msp/cainfo_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package msp
8 |
9 | import (
10 | "testing"
11 |
12 | "github.com/hyperledger/fabric-sdk-go/test/integration"
13 | )
14 |
15 | func TestGetCAInfo(t *testing.T) {
16 | mspClient, sdk := setupClient(t)
17 | defer integration.CleanupUserData(t, sdk)
18 |
19 | resp, err := mspClient.GetCAInfo()
20 | if err != nil {
21 | t.Fatalf("Get CAInfo failed: %s", err)
22 | }
23 | if resp.CAName != "ca.org1.example.com" {
24 | t.Fatalf("Name should be 'ca.org1.example.com'")
25 | }
26 |
27 | if resp.CAChain == nil {
28 | t.Fatalf("CAChain shouldn't be nil")
29 | }
30 | t.Logf("CAChain: %+v", resp.CAChain)
31 |
32 | if resp.IssuerPublicKey == nil {
33 | t.Fatalf("IssuerPublicKey shouldn't be nil")
34 | }
35 | t.Logf("IssuerPublicKey: %+v", resp.IssuerPublicKey)
36 |
37 | if resp.Version == "" {
38 | t.Fatalf("Version shouldn't be empty")
39 | }
40 | t.Logf("Version: %+v", resp.Version)
41 | }
42 |
--------------------------------------------------------------------------------
/test/integration/pkg/client/msp/custom_msp_factory.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package msp
8 |
9 | import (
10 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
11 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
12 | "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
13 | "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/factory/defmsp"
14 | )
15 |
16 | // ========== MSP Provider Factory with custom user store ============= //
17 |
18 | // CustomMSPFactory is a custom factory for tests.
19 | type CustomMSPFactory struct {
20 | defaultFactory *defmsp.ProviderFactory
21 | customUserStore msp.UserStore
22 | }
23 |
24 | // NewCustomMSPFactory creates a custom MSPFactory
25 | func NewCustomMSPFactory(customUserStore msp.UserStore) *CustomMSPFactory {
26 | return &CustomMSPFactory{defaultFactory: defmsp.NewProviderFactory(), customUserStore: customUserStore}
27 | }
28 |
29 | // CreateUserStore creates UserStore
30 | func (f *CustomMSPFactory) CreateUserStore(config msp.IdentityConfig) (msp.UserStore, error) {
31 | return f.customUserStore, nil
32 | }
33 |
34 | // CreateIdentityManagerProvider creates an IdentityManager provider
35 | func (f *CustomMSPFactory) CreateIdentityManagerProvider(endpointConfig fab.EndpointConfig, cryptoProvider core.CryptoSuite, userStore msp.UserStore) (msp.IdentityManagerProvider, error) {
36 | return f.defaultFactory.CreateIdentityManagerProvider(endpointConfig, cryptoProvider, f.customUserStore)
37 | }
38 |
--------------------------------------------------------------------------------
/test/integration/pkg/client/resmgmt/main_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | package resmgmt
7 |
8 | import (
9 | "testing"
10 |
11 | "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
12 | "github.com/hyperledger/fabric-sdk-go/test/integration"
13 | "github.com/hyperledger/fabric-sdk-go/test/integration/util/runner"
14 | "github.com/stretchr/testify/require"
15 | )
16 |
17 | const (
18 | org1Name = "Org1"
19 | org2Name = "Org2"
20 | org1AdminUser = "Admin"
21 | org2AdminUser = "Admin"
22 | orgChannelID = "orgchannel"
23 | )
24 |
25 | var mainSDK *fabsdk.FabricSDK
26 | var mainTestSetup *integration.BaseSetupImpl
27 | var mainChaincodeID string
28 |
29 | func TestMain(m *testing.M) {
30 | r := runner.NewWithExampleCC()
31 | r.Initialize()
32 | mainSDK = r.SDK()
33 | mainTestSetup = r.TestSetup()
34 | mainChaincodeID = r.ExampleChaincodeID()
35 |
36 | r.Run(m)
37 | }
38 |
39 | func setupMultiOrgContext(t *testing.T, sdk *fabsdk.FabricSDK) []*integration.OrgContext {
40 | orgContext, err := integration.SetupMultiOrgContext(sdk, org1Name, org2Name, org1AdminUser, org2AdminUser)
41 | require.NoError(t, err)
42 | return orgContext
43 | }
44 |
--------------------------------------------------------------------------------
/test/integration/pkg/context/main_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | package context
7 |
8 | import (
9 | "testing"
10 |
11 | "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
12 | "github.com/hyperledger/fabric-sdk-go/test/integration"
13 | "github.com/hyperledger/fabric-sdk-go/test/integration/util/runner"
14 | )
15 |
16 | const (
17 | org1Name = "Org1"
18 | org1AdminUser = "Admin"
19 | )
20 |
21 | var mainSDK *fabsdk.FabricSDK
22 | var mainTestSetup *integration.BaseSetupImpl
23 | var mainChaincodeID string
24 |
25 | func TestMain(m *testing.M) {
26 | r := runner.NewWithExampleCC()
27 | r.Initialize()
28 | mainSDK = r.SDK()
29 | mainTestSetup = r.TestSetup()
30 | mainChaincodeID = r.ExampleChaincodeID()
31 |
32 | r.Run(m)
33 | }
34 |
--------------------------------------------------------------------------------
/test/integration/pkg/fab/main_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | package fab
7 |
8 | import (
9 | "testing"
10 |
11 | "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
12 | "github.com/hyperledger/fabric-sdk-go/test/integration"
13 | "github.com/hyperledger/fabric-sdk-go/test/integration/util/runner"
14 | )
15 |
16 | var mainSDK *fabsdk.FabricSDK
17 | var mainTestSetup *integration.BaseSetupImpl
18 | var mainChaincodeID string
19 |
20 | const (
21 | org1Name = "Org1"
22 | org1User = "User1"
23 | )
24 |
25 | func TestMain(m *testing.M) {
26 | r := runner.NewWithExampleCC()
27 | r.Initialize()
28 | mainSDK = r.SDK()
29 | mainTestSetup = r.TestSetup()
30 | mainChaincodeID = r.ExampleChaincodeID()
31 |
32 | r.Run(m)
33 | }
34 |
--------------------------------------------------------------------------------
/test/integration/pkg/fabsdk/provider/main_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | package provider
7 |
8 | import (
9 | "testing"
10 |
11 | "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
12 | "github.com/hyperledger/fabric-sdk-go/test/integration"
13 | "github.com/hyperledger/fabric-sdk-go/test/integration/util/runner"
14 | )
15 |
16 | const (
17 | org1Name = "Org1"
18 | org1User = "User1"
19 | org1AdminUser = "Admin"
20 | )
21 |
22 | var mainSDK *fabsdk.FabricSDK
23 | var mainTestSetup *integration.BaseSetupImpl
24 |
25 | func TestMain(m *testing.M) {
26 | r := runner.New()
27 | r.Initialize()
28 | mainSDK = r.SDK()
29 | mainTestSetup = r.TestSetup()
30 |
31 | r.Run(m)
32 | }
33 |
--------------------------------------------------------------------------------
/test/integration/pkg/gateway/gateway_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2020 IBM All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package gateway
8 |
9 | import (
10 | "testing"
11 | )
12 |
13 | func TestGatewayFromConfig(t *testing.T) {
14 | t.Run("Base", func(t *testing.T) {
15 | RunWithConfig(t)
16 | })
17 | }
18 |
19 | func TestGatewayFromSDK(t *testing.T) {
20 | t.Run("Base", func(t *testing.T) {
21 | RunWithSDK(t)
22 | })
23 | }
24 |
25 | func TestGatewayWithSubmit(t *testing.T) {
26 | t.Run("Base", func(t *testing.T) {
27 | RunWithSubmit(t)
28 | })
29 | }
30 |
31 | func TestGatewayWithWallet(t *testing.T) {
32 | t.Run("Base", func(t *testing.T) {
33 | RunWithWallet(t)
34 | })
35 | }
36 |
37 | func TestTransientData(t *testing.T) {
38 | t.Run("Base", func(t *testing.T) {
39 | RunWithTransient(t)
40 | })
41 | }
42 |
43 | func TestContractEvent(t *testing.T) {
44 | t.Run("Base", func(t *testing.T) {
45 | RunWithContractEvent(t)
46 | })
47 | }
48 |
49 | func TestBlockEvent(t *testing.T) {
50 | t.Run("Base", func(t *testing.T) {
51 | RunWithBlockEvent(t)
52 | })
53 | }
54 |
--------------------------------------------------------------------------------
/test/metadata/metadata.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright SecureKey Technologies Inc. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | // Package metadata contains variables used by tests
8 | package metadata
9 |
10 | // ChannelConfigPath is the relative path to the generated channel artifacts directory
11 | var ChannelConfigPath = "test/fixtures/fabric/v2.2/channel"
12 |
13 | // CryptoConfigPath is the relative path to the generated crypto config directory
14 | var CryptoConfigPath = "test/fixtures/fabric/v1/crypto-config"
15 |
16 | // SDKConfigPath is the relative path to the SDK configuration test fixtures directory
17 | var SDKConfigPath = "test/fixtures/config"
18 |
19 | // Project is the Go project name relative to the Go Path
20 | var Project = "github.com/hyperledger/fabric-sdk-go"
21 |
22 | // ProjectPath is the path to the source of fabric-sdk-go
23 | var ProjectPath = ""
24 |
25 | // TestRunID is an identifier for the current run of tests
26 | var TestRunID = ""
27 |
28 | // CCMode is an identifier for the cc mode: lifecycle or lscc
29 | var CCMode = "lifecycle"
30 |
--------------------------------------------------------------------------------
/test/performance/go.mod:
--------------------------------------------------------------------------------
1 | // Copyright SecureKey Technologies Inc. All Rights Reserved.
2 | //
3 | // SPDX-License-Identifier: Apache-2.0
4 |
5 | module github.com/hyperledger/fabric-sdk-go/test/performance
6 |
7 | replace github.com/hyperledger/fabric-sdk-go => ../../
8 |
9 | require (
10 | github.com/golang/protobuf v1.3.3
11 | github.com/hyperledger/fabric-protos-go v0.0.0-20200707132912-fee30f3ccd23
12 | github.com/hyperledger/fabric-sdk-go v0.0.0-00010101000000-000000000000
13 | github.com/hyperledger/fabric-sdk-go/test/integration v0.0.0-20200909154308-842c4b3ea51e // indirect
14 | github.com/pkg/errors v0.8.1
15 | github.com/stretchr/testify v1.5.1
16 | golang.org/x/net v0.0.0-20190613194153-d28f0bde5980
17 | google.golang.org/grpc v1.29.1
18 | )
19 |
20 | go 1.14
21 |
--------------------------------------------------------------------------------
/test/performance/prometheus/docker-compose.yaml:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
3 | #
4 | # SPDX-License-Identifier: Apache-2.0
5 | #
6 | #
7 |
8 | version: '2'
9 |
10 | services:
11 | metrics.example.com:
12 | container_name: metrics.example.com
13 | image: prom/prometheus
14 | ports:
15 | - 9095:9090
16 | volumes:
17 | - ./prometheus.yml:/etc/prometheus/prometheus.yml
--------------------------------------------------------------------------------
/test/performance/prometheus/prometheus.yml:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
3 | #
4 | # SPDX-License-Identifier: Apache-2.0
5 | #
6 | #
7 |
8 | # my global config
9 | global:
10 | scrape_interval: 2s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
11 | evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
12 | # scrape_timeout is set to the global default (10s).
13 |
14 | # Alertmanager configuration
15 | alerting:
16 | alertmanagers:
17 | - static_configs:
18 | - targets:
19 | # - alertmanager:9093
20 |
21 | # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
22 | rule_files:
23 | # - "first_rules.yml"
24 | # - "second_rules.yml"
25 |
26 | # A scrape configuration containing exactly one endpoint to scrape:
27 | # Here it's Prometheus itself.
28 | scrape_configs:
29 | # The job name is added as a label `job=` to any timeseries scraped from this config.
30 | - job_name: 'prometheus'
31 |
32 | # metrics_path defaults to '/metrics'
33 | # scheme defaults to 'http'.
34 |
35 | static_configs:
36 | - targets: ['peer0.org1.example.com:8080', 'docker.for.mac.localhost:8080', 'docker.for.win.localhost:8080']
37 |
--------------------------------------------------------------------------------
/test/scripts/chaincoded.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
4 | #
5 | # SPDX-License-Identifier: Apache-2.0
6 | #
7 |
8 | set -e
9 |
10 | GO_CMD="${GO_CMD:-go}"
11 | GOPATH="${GOPATH:-$HOME/go}"
12 | CHAINCODE_PATH="${CHAINCODE_PATH:-${GOPATH}/src}"
13 | CHAINCODED_PATH="${CHAINCODED_PATH:-${GOPATH}/src}"
14 |
15 | # Temporary fix for Fabric base image
16 | unset GOCACHE
17 |
18 | echo "Installing chaincodes ..."
19 | cd ${CHAINCODE_PATH}/github.com/example_cc
20 | ${GO_CMD} install github.com/example_cc
21 | cd ${CHAINCODE_PATH}/github.com/example_pvt_cc
22 | ${GO_CMD} install github.com/example_pvt_cc
23 | cd ${CHAINCODED_PATH}
24 | ${GO_CMD} install chaincoded/cmd/chaincoded
25 |
26 | PEERS=(
27 | peer0.org1.example.com:7052
28 | peer1.org1.example.com:7152
29 | peer0.org2.example.com:8052
30 | peer1.org2.example.com:9052
31 | )
32 |
33 | # You can set CHAINCODED_VERBOSE environment variable to see additional chaincoded logs.
34 | #export CHAINCODED_VERBOSE=true
35 |
36 | echo "Running chaincoded ..."
37 | chaincoded ":9375" ${PEERS[@]}
--------------------------------------------------------------------------------
/test/scripts/check_lint.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
4 | #
5 | # SPDX-License-Identifier: Apache-2.0
6 | #
7 | # This script runs Go linting and vetting tools
8 |
9 | set -e
10 | LINT_CHANGED_ONLY="${LINT_CHANGED_ONLY:-false}"
11 | GO_CMD="${GO_CMD:-go}"
12 | SCRIPT_DIR="$(dirname "$0")"
13 | PKG_ROOT="${PKG_ROOT:-./}"
14 |
15 | PROJECT_MODULE=$(awk -F' ' '$1 == "module" {print $2}' < $(${GO_CMD} env GOMOD))
16 | PROJECT_DIR=$(dirname $(${GO_CMD} env GOMOD))
17 |
18 | CONFIG_DIR=${PROJECT_DIR}
19 |
20 | echo "Running" $(basename "$0") "(${MODULE} ${PKG_ROOT})"
21 |
22 | source ${SCRIPT_DIR}/lib/find_packages.sh
23 | source ${SCRIPT_DIR}/lib/linter.sh
24 |
25 | # Find all packages that should be linted.
26 | PWD_ORIG=$(pwd)
27 | cd "${PROJECT_DIR}/${MODULE#${PROJECT_MODULE}}"
28 | declare -a PKG_SRC=(
29 | "${PKG_ROOT}"
30 | )
31 | declare PKG_EXCLUDE=""
32 | findPackages
33 |
34 | # Reduce Linter checks to changed packages.
35 | if [ "$LINT_CHANGED_ONLY" = true ]; then
36 | findChangedLinterPkgs
37 | fi
38 |
39 | if [ ${#PKGS[@]} -eq 0 ]; then
40 | echo "Skipping tests since no packages were changed"
41 | exit 0
42 | fi
43 |
44 | runLinter
45 | cd ${PWD_ORIG}
46 |
--------------------------------------------------------------------------------
/test/scripts/check_status.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
4 | #
5 | # SPDX-License-Identifier: Apache-2.0
6 | #
7 | set -e
8 | file_path=$1
9 |
10 | DOCKER_CMD="${DOCKER_CMD:-docker}"
11 | DOCKER_COMPOSE_CMD="${DOCKER_COMPOSE_CMD:-docker-compose}"
12 |
13 | $DOCKER_COMPOSE_CMD $file_path ps -q | xargs $DOCKER_CMD inspect -f '{{ .Name }},{{ .State.ExitCode }}' | \
14 |
15 | while read name ; do
16 | if echo "$name" | grep -q "softhsm2"
17 | then
18 | statusCode="${name: -1}"
19 | echo $statusCode
20 | if [ "$statusCode" != "0" ]
21 | then
22 | exit $statusCode
23 | else
24 | exit 0
25 | fi
26 | fi
27 | done
28 |
29 |
--------------------------------------------------------------------------------
/test/scripts/fabric_test_commitlevel.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | #
3 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
4 | #
5 | # SPDX-License-Identifier: Apache-2.0
6 | #
7 |
8 | # This variable can be altered to test against prebuilt fabric and fabric-ca images
9 | # If set to false, CI will build images from scratch for the commit levels specified below
10 | export USE_PREBUILT_IMAGES=true
11 |
12 | # versions of fabric to build (if USE_PREBUILT_IMAGES=false)
13 | export FABRIC_COMMIT=
14 | export FABRIC_CA_COMMIT=
15 |
--------------------------------------------------------------------------------
/test/scripts/lib/docker.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
4 | #
5 | # SPDX-License-Identifier: Apache-2.0
6 | #
7 |
8 | function waitForCoreVMUp {
9 | # When dockerd handles chaincode operation, we need to wait for it to be ready
10 | # (it takes time to start due to chaincode compilation).
11 | if [[ "${CORE_VM_ENDPOINT}" =~ http://(.*):(.*) ]]; then
12 | declare attempt=1
13 | declare host=${BASH_REMATCH[1]}
14 | declare port=${BASH_REMATCH[2]}
15 |
16 | if [[ "${TEST_LOCAL}" = true ]]; then
17 | host="localhost"
18 | fi
19 |
20 | echo "Waiting for VM endpoint to listen [${host}:${port}]..."
21 | while true; do
22 | if [[ ${attempt} -gt 300 ]]; then
23 | echo "VM endpoint is not listening after ${attempt} attempt(s)"
24 | exit 1
25 | fi
26 |
27 | alive=$(curl -s --head --request GET ${host}:${port}/info || true)
28 | if [[ "${alive}" =~ ^HTTP/(.*)200 ]]; then
29 | break
30 | fi
31 |
32 | sleep 1
33 | attempt=$((attempt + 1))
34 | done
35 | echo "VM endpoint is listening after ${attempt} attempt(s)"
36 | fi
37 | }
--------------------------------------------------------------------------------
/test/scripts/lib/linter.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright SecureKey Technologies Inc. All Rights Reserved.
4 | #
5 | # SPDX-License-Identifier: Apache-2.0
6 | #
7 |
8 | GOLANGCI_LINT_PKG="github.com/golangci/golangci-lint/cmd/golangci-lint"
9 | GOLANGCI_LINT_VER="${GOLANGCI_LINT_VER:-}"
10 |
11 | if [ "${GOLANGCI_LINT_VER}" != "" ]; then
12 | GOLANGCI_LINT_AT_VER="@${GOLANGCI_LINT_VER}"
13 | fi
14 |
15 | GOLANGCI_LINT_CMD="${GOLANGCI_LINT_CMD:-gobin -run ${GOLANGCI_LINT_PKG}${GOLANGCI_LINT_AT_VER}}"
16 |
17 | function runLinter {
18 | packagesToDirs
19 |
20 | echo "Directories to lint: ${DIRS[@]}"
21 |
22 | echo "Running golangci-lint${GOLANGCI_LINT_AT_VER} ..."
23 | ${GOLANGCI_LINT_CMD} run -c "${CONFIG_DIR}/golangci.yml" "${DIRS[@]}"
24 | echo "golangci-lint finished successfully"
25 | }
26 |
27 | function findChangedLinterPkgs {
28 | findChangedFiles
29 | declare matcher='( |^)(test/fixtures/|test/metadata/|test/scripts/|Makefile( |$)|go.mod( |$))'
30 | if [[ "${CHANGED_FILES[@]}" =~ ${matcher} ]]; then
31 | echo "Test scripts, fixtures or metadata changed - running all tests"
32 | else
33 | findChangedPackages
34 | filterExcludedPackages
35 | appendDepPackages
36 | PKGS=(${DEP_PKGS[@]})
37 | fi
38 | }
--------------------------------------------------------------------------------