Esta página ainda não está disponível no idioma selecionado. Estamos trabalhando para adicionar mais opções de idiomas. Agradecemos sua compreensão.
- What's New
- Function Overview
- Service Overview
- Billing
- Getting Started
-
User Guide
- Enhanced Hyperledger Fabric BCS Management
- Best Practices
-
Developer Guide
- Overview
- Chaincode Development
- Application Development
- Demos
-
Blockchain Middleware APIs
- Overview
- Chaincode Invoking (OBT)
-
Chaincode Management
- Obtaining a Token
- Installing a Chaincode
- Instantiating a Chaincode
- Listing Installed Chaincodes
- Querying Version of a Specified Chaincode
- Querying Chaincode Installation Information
- Querying Chaincode Instantiation Information
- Querying an Appchain
- Listing Blocks
- Listing Transactions
- Querying Transaction Quantity
- Listing Block Transactions
- Querying Transaction Details
- Querying Peers
- Querying diskUsage of a Node
- Querying the System-Hosted Certificate Status
- Deleting a Chaincode
- Downloading a Report
- Distributed Identity (OBT)
- Trusted Data Exchange (OBT)
- Appendix
-
API Reference
- Before You Start
- API Overview
- Examples
- Calling APIs
-
APIs (Enhanced Hyperledger Fabric)
-
BCS Management
- Creating a BCS Service
- Querying Creation Status of a BCS Service
- Querying a BCS Service
- Modifying a BCS Service
- Creating Channels
- Querying Channel Information
- Adding Peers to a Channel
- Removing Organizations from a Channel
- Downloading Certificates
- Downloading the SDK Configuration
- Generating a User Certificate
- Unfreezing a User Certificate
- Freezing a User Certificate
- Querying Quotas
- Querying Flavors
- Querying Peer Information
- Querying Asynchronous Operation Results
- Querying the BCS Service List
- Deleting a BCS Service
- Removing a Peer from a Channel
- Deleting a Channel
- BCS Consortium
- BCS Monitoring
-
BCS Management
- Permissions Policies and Supported Actions
- Appendix
- Change History
- SDK Reference
-
FAQs
-
Enhanced Hyperledger Fabric
- Billing
-
Instance Management
-
Consultation
- How Do I Determine Whether a Blockchain Is Necessary?
- What Underlying Framework Is Used for Huawei Cloud BCS?
- Can BCS Instances Deployed on the Public Cloud Access Blockchain Nodes on Other Clouds?
- What Competitive Advantages Does Huawei Cloud BCS Have?
- In Which Direction and What Capabilities Will Huawei Cloud BCS Develop?
- What Are the Specifications of VMs to Be Purchased for BCS?
- How Do I Get Access to the Partners of Huawei Cloud BCS for More Services?
- What Are the Differences Between Channel Isolation and Privacy Protection?
- How Well Does BCS Perform?
- Does BCS Support Customized Development?
- When Do I Need to Hibernate or Wake an Instance?
-
Service Usage
- Which Ports of a Security Group Are Opened When I Create a BCS Instance?
- How Do I Check Whether the ICAgent Is Installed for the Cluster?
- What Can I Do If I Can't Open the Blockchain Management Console?
- What Should I Do If My BCS Instance Remains in the Creating State?
- What Should I Do If a Peer Restarts Frequently with the Error Message "PanicDB not exist"?
- What Can I Do If the CPU Usage of a Blockchain Node Reaches 100%?
- Why Can't I Log In to the Blockchain Management Console?
- BCS.4009100: System Error
- How Can I Obtain Private Keys and Certificates for Enhanced Hyperledger Fabric Blockchains?
- Why Does Chaincode Instantiation Fail When I Deploy a Fabric v1.4 Instance Using a v1.19 CCE Cluster?
- Can All Blocks Be Saved As More and More Blocks Are Created?
-
What Can I Do If I Fail to Purchase a BCS Instance?
- General Checks
-
Detailed Checks
- CCE Cluster Quota Used Up
- Failed to Create a Cluster
- Failed to Create a PVC
- Cluster Already In Use
- SFS Turbo File System Quota Exceeded
- No EIP Bound
- CCE Is Abnormal
- Cluster Status Is Abnormal
- Subnet Unavailable
- Quick Deployment in Progress
- CCE Status Check Times Out
- Insufficient Master Nodes in the AZ of the CCE Cluster
-
Abnormal Instance Statuses
- What Can I Do If a BCS Instance Is in the Abnormal State?
- What Can I Do If a BCS Instance Is in the Unknown State?
- What Can I Do If a BCS Instance Is in the EIP abnormal State?
- What Can I Do If a BCS Instance Is in the Frozen or Cluster frozen State?
- What Can I Do If the BCS Instance and the peer-xxx StatefulSet Are Abnormal After an Organization or a Peer Is Added?
- Other Issues
-
Consultation
- Chaincode Management
- Data Storage to the Blockchain
- Demos and APIs
- O&M and Monitoring
- Consortium Management
-
Enhanced Hyperledger Fabric
- Videos
-
More Documents
-
User Guide (ME-Abu Dhabi Region)
- Service Overview
- Managing Enhanced Hyperledger Fabric Instances
-
FAQs
-
BCS FAQs
-
Instance Management
-
Consultation
- How Do I Determine Whether a Blockchain Is Necessary?
- What Underlying Framework Is Used for BCS?
- What Competitive Advantages Does BCS Have?
- What Are the Specifications of VMs to Be Created for BCS?
- What Are the Differences Between Channel Isolation and Privacy Protection?
- How Well Does BCS Perform?
- When Do I Need to Hibernate or Wake an Instance?
-
Service Usage
- How Do I Check Whether the ICAgent Is Installed for the Cluster?
- What Can I Do If I Can't Open the Blockchain Management Console?
- What Should I Do If My BCS Instance Remains in the Creating State?
- What Should I Do If a Peer Restarts Frequently with the Error Message "PanicDB not exist"?
- What Can I Do If the CPU Usage of a Blockchain Node Reaches 100%?
- Why Can't I Log In to the Blockchain Management Console?
- BCS.4009100: System Error
- How Can I Obtain Private Keys and Certificates for Enhanced Hyperledger Fabric Blockchains?
- Can All Blocks Be Saved As More and More Blocks Are Created?
- Abnormal Instance Statuses
- Other Issues
-
Consultation
- Chaincode Management
- Data Storage to the Blockchain
- Demos and APIs
- O&M and Monitoring
- Consortium Management
-
Instance Management
-
BCS FAQs
- Change History
- Developer Guide (ME-Abu Dhabi Region)
-
User Guide (ME-Abu Dhabi Region)
- General Reference
Show all
Copied.
Sample Application
This section provides an example application code and the corresponding chaincode to describe the use of the homomorphic encryption library. The main function of this application is money transfer between users, and the homomorphic encryption library is used to protect the transfer transaction information of the users.
The application involves three steps: user registration (including initializing the users' balances), money transfer, and balance query.
The application uses the command line interface (CLI) to perform service operations. The procedure is as follows.
Note
Query the domain names of orderers and peers in the downloaded sdk.yaml file, and add "EIP + Domain name of each orderer" and "EIP + Domain name of each peer" to the /etc/hosts file. When Fabric v1.1 is used, set public network IP addresses as the EIPs of peers. When Fabric1.4 is used, set private network IP addresses for the peers. Otherwise, the network cannot be connected, causing transaction verification failures.
Perform the following steps to add the domain name mapping of the orderers and peers to the /etc/hosts file:
X.X.X.X orderer-e5ad7831affbe8e6e2e7984b098f92406930a688-0.orderer-e5ad7831affbe8e6e2e7984b098f92406930a688.default.svc.cluster.local X.X.X.X peer-d524b0817aaed85490368776cb88042a149a56b5-0.peer-d524b0817aaed85490368776cb88042a149a56b5.default.svc.cluster.local X.X.X.X peer-d524b0817aaed85490368776cb88042a149a56b5-1.peer-d524b0817aaed85490368776cb88042a149a56b5.default.svc.cluster.local
Use real EIPs to replace X.X.X.X.
Registration
Usage: appdemo register [flags] Flags: -C, --channel string channel id (default "mychannel") -c, --config string configuration file path (default "./config_test.yaml") -I, --idcc string idendity chaincode name (default "IDChaincode") -i, --initbalance string init initbalance -o, --orgid string organization id (default "org1") -p, --protectpwd string protect pwd -T, --txcc string transaction chaincode name (default "TxChaincode") -u, --userid string user id ./appdemo register -u A -p test -i 100
If you do not set certain parameters, the default values are used. For the default values, see the Flags part. If a configured value is different from the default value, specify it for the parameter.
- Generating a pair of public and private keys for homogenous encryption
When a new user registers, a pair of public and private keys are generated for the user (identified by the user ID). This demo writes the key pair to the local ${userid} .data file for each user.
privKeyStr, pubKeyStr, err := pswapi_sdk.GenerateKey(propwd) check(err) fmt.Println("key is nil") userdata.PubKey = pubKeyStr userdata.PriKey = privKeyStr
- Registering the public key
The Fabric SDK API is invoked to initiate registration with the IDChaincode, carrying the generated public key.
The registration is implemented using the chaincode function of blockchains. Public keys are registered for sharing. During the money transfer transaction, the public key of the payer is used to encrypt the transaction data to protect privacy. Only the private key holder can decrypt the transaction data.
res, err := sdk_client.Invoke(setup, "Register", [][]byte{[]byte(userdata.PubKey), []byte(senderAddr)}) if err != nil { fmt.Println("Fail to register user pk ", err.Error()) } else { addrByte := res[0].ProposalResponse.GetResponse().Payload fmt.Println("Register addr: ", string(addrByte)) }
- Registering the initial balance
- The sdk.InitBalance API is used to initialize and encrypt the balance, generating the initial balanceinfo.
- The balanceinfo is sent to the transaction chaincode.
balanceInfo, err := pswapi_sdk.InitBalance(initbalance, userdata.PubKey) check(err) setup.ChainCodeID = txchaincode _, err = sdk_client.Invoke(setup, "init", [][]byte{[]byte(userdata.PubKey), []byte(balanceInfo)}) if err != nil { fmt.Println("Initbalance error for user: ", senderAddr, err.Error()) } else { fmt.Println("init balance successfully: ", senderAddr) } check(err)
Transaction
Usage: appdemo transaction [flags] Flags: -b, --AddrB string B' addr -t, --Tx string Transaction Num -C, --channel string channel id (default "mychannel") -c, --config string configuration file path (default "./config_test.yaml") -I, --idcc string idendity chaincode name (default "IDChaincode") -o, --orgid string organization id (default "org1") -p, --protectpwd string protect pwd -T, --txcc string transaction chaincode name (default "TxChaincode") -u, --userid string user id ./appdemo transaction -u A -p test -b a0760184f7ed24e0d86f5b2df40a973a9e1b5da9a1ae886532ac9cd634b59d59 -t 10 // Note: The character string following -b is the account address of user B (displayed upon successful registration of user B).
Query
Usage: appdemo querybalance [flags] Flags: -C, --channel string channel id (default "mychannel") -c, --config string configuration file path (default "./config_test.yaml") -I, --idcc string idendity chaincode name (default "IDChaincode") -o, --orgid string organization id (default "org1") -p, --protectpwd string protect pwd -T, --txcc string transaction chaincode name (default "TxChaincode") -u, --userid string user id ./appdemo querybalance -p test -u A
Query code:
- The InitBalance API provided by the SDK is invoked to initialize the balance.
- The Fabirc SDK is invoked to send the transaction information.
get balance setup.ChainCodeID = txchaincode transRec := sdk_client.TransRecord{} fmt.Println("query balance") resps, err := sdk_client.Query(setup, "QueryBalance", [][]byte{[]byte(addrA)}) if err != nil { fmt.Println("Fail to query balance :", err.Error()) return err } err = json.Unmarshal(resps[0].ProposalResponse.GetResponse().Payload, &transRec) if err != nil { fmt.Println("unmarshal query result error: ", err.Error()) return err }
decrypt balance curbalance, err := pswapi_sdk.Decrypt(transRec.Balance, userdata.PriKey, propwd) if err != nil { fmt.Println("sdk Decrypt error: ", err.Error()) return err } fmt.Println("current balance:" + curbalance.String())
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot