gosdk

command
v0.0.0-...-f7d5a40 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

README

Test Modules - gosdk(Work In Progress)

Quick start test modules development

Prerequisites
  • docker
  • docker-compose
  • golang
  • dep
Quick start
Provisioning a fabric network for testing
cd fixtures
./network_setup.sh up
Start with the sample code

This part is only to demo how to use fabric-sdk-go

dep ensure -vendor-only
cd sample
go build
./sample
Build gosdk test modules

From modules/gosdk directory

dep ensure -vendor-only
go build

This will generate an executable binary file named as gosdk in modules/gosdk directory

Example

After you have build the gosdk ,you may run the gosdk_example.sh. This script will help you create/join/update/query channels and install/instantiate/invoke chaincode Just run :

    ./gosdk_example.sh

Notes: 1. If you are running hfrd test modules in sample network,you must set host env TEST_TYPE to local.

     export TESTR_TYPE=local
  1. You can set CRYPTO_ROOT_PATH to your certs root directory.Default setting is /fabric/keyfiles
    export CRYPTO_ROOT_PATH=/fabric/keyfiles
  1. Certs directory structure must be exactly the same as official requirements.
                $CRYPTO_ROOT_PATH/orgname/users/{username}@orgname/msp
                $CRYPTO_ROOT_PATH/orgname/tlsca/tlsca.orgname-cert.pem
Channel
Create

With the fabric network created in Privisioning a fabric network for testing, we can create channels with yaml configuration file From modules/gosdk directory

./gosdk channel create -c ./fixtures/ConnectionProfile_org1.yaml --channelNamePrefix mychannel --channelConsortium SampleConsortium \
--channelOrgs org1,org2 --ordererName orderer.example.com --iterationCount 10 --iterationInterval 1s
Join

With the channel created above,we can specify which member to join which channel From modules/gosdk directory

./gosdk channel join -c ./fixtures/ConnectionProfile_org1.yaml --channelNamePrefix mychannel \
--peers peer0.org1.example.com,peer1.org1.example.com --ordererName orderer.example.com --iterationCount 10 --iterationInterval 1s

./gosdk channel join -c ./fixtures/ConnectionProfile_org2.yaml --channelNamePrefix mychannel \
--peers peer0.org2.example.com,peer1.org2.example.com --ordererName orderer.example.com --iterationCount 10 --iterationInterval 1s

Update

With the channel created above,we can update the channel configurations member like batchTimeout/maxMessageCount/absoluteMaxBytes/anchorPeers From modules/gosdk directory

./gosdk channel update -c ./fixtures/ConnectionProfile_org1.yaml --channelNamePrefix mychannel \
        --ordererOrgName ordererorg --ordererName orderer.example.com --peers peer0.org1.example.com\
        --batchTimeout 20s --maxMessageCount 200 --absoluteMaxBytes 103802353 --anchorPeers peer0.org1.example.com:7051 \
        --iterationCount 2 --iterationInterval 2s

./gosdk channel update -c ./fixtures/ConnectionProfile_org2.yaml --channelNamePrefix mychannel \
        --ordererOrgName ordererorg --ordererName orderer.example.com --peers peer0.org2.example.com\
        --anchorPeers peer0.org2.example.com:7051 \
        --iterationCount 2 --iterationInterval 2s

Query

With the channel created/joined/updated above,we can query the channel configurations member like batchTimeout/maxMessageCount/absoluteMaxBytes/anchorPeers From modules/gosdk directory

./gosdk channel query -c ./fixtures/ConnectionProfile_org2.yaml --channelNamePrefix mychannel --peers peer0.org2.example.com --iterationCount 2 --iterationInterval 2s

./gosdk channel query -c ./fixtures/ConnectionProfile_org1.yaml --channelNamePrefix mychannel --peers peer0.org1.example.com --iterationCount 2 --iterationInterval 2s

Chaincode
Install

With the fabric network created in Privisioning a fabric network for testing. From modules/gosdk directory

./gosdk chaincode install -c ./fixtures/ConnectionProfile_org1.yaml --chaincodeNamePrefix samplecc- --chaincodeVersion v1 \
--path hfrd/chaincode/samplecc --peers peer0.org1.example.com,peer1.org1.example.com \
--iterationCount 2 --iterationInterval 1s

Use ./gosdk chaincode install -h for help

Instantiate

After 1) creating channels 2). peers joining channels 3). installing chaincodes on peers, we can instantiate chaincode on a specified channel

./gosdk chaincode instantiate -c ./fixtures/ConnectionProfile_org1.yaml --chaincodeNamePrefix samplecc- --chaincodeVersion v1 \
--channelName mychannel0 --path hfrd/chaincode/samplecc \
--peers peer0.org1.example.com --iterationCount 1

Use ./gosdk chaincode instantiate -h for help

Invoke
./gosdk chaincode invoke  -c ./fixtures/ConnectionProfile_org1.yaml --chaincodeName samplecc-0 --channelName mychannel0 \
--chaincodeParams invoke,put,a,b --peers peer0.org1.example.com \
--iterationCount 100

Use ./gosdk chaincode invoke -h for help. If --peers parameter is not specified, then gosdk will randomly(round robin) pick a peer of the org specified in connection profile to send proposal to.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package reggen generates text based on regex definitions This lib is from https://github.com/lucasjones/reggen/blob/master/reggen.go
Package reggen generates text based on regex definitions This lib is from https://github.com/lucasjones/reggen/blob/master/reggen.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL