WeCross部署方案 - EN

WeCross deployment plan

Environmental requirements

Hardware

WeCross is responsible for managing multiple stubs and communicating with multiple chains. At the same time, it provides RPC call service as a Web Server. In order to ensure the stability of the service, use the recommended configuration as much as possible.

Configuration Minimum configuration Recommended configuration
CPU 1.5GHz 2.4GHz
RAM 4GB 8GB
core 4-core 8-core
bandwidth 2Mb 10Mb

Supported platforms

  • Ubuntu 16.04 and above
  • CentOS 7.2 and above
  • macOS 10.14 and above

Software dependency

As a Java project, WeCross needs to install the Java environment including:

  • JDK1.8.0_251 and above

Currently the JDK versions that have been tested are: OracleJDK 1.8.0_251, OracleJDK 1.8.0_271, OracleJDK 14, OracleJDK 15, OpenJDK 1.8.0_282, OpenJDK 14, OpenJDK 15.

  • Gradle 5.0 and above
  • MySQL 5.6 and above

WeCross provides a variety of scripts to help users experience them quickly. These scripts rely on openssl, curl, expect,. Use the following instructions to install.

# Ubuntu
sudo apt-get install -y openssl curl expect tree fontconfig

# CentOS
sudo yum install -y openssl curl expect tree

# macOS
brew install openssl curl expect tree md5sha1sum

Deployment process

The manual networking tutorial takes the ~/wecross-networks/directory as an example :

# Create a directory operation manual networking
mkdir -p ~/wecross-networks && cd ~/wecross-networks

Basic component deployment

—Deploy WeCross basic components, including cross-chains route, account service, console, web management console

Enter the operation directory:

cd ~/wecross-networks

Download WeCross

–Download WeCross, use the tools in WeCross to generate cross-chains route, and start it.

WeCross contains tools for generating cross-chains route, to execute the following commands to download , and download the program to~/wecross-networks/WeCross/

GitHub download method:
bash <(curl -sL https://github.com/WeBankBlockchain/WeCross/releases/download/resources/download_wecross.sh)

Gitee download method:
bash <(curl -sL https://gitee.com/WeBank/WeCross/raw/master/scripts/download_wecross.sh)

Deploy cross-chains route

In this example, two cross-chains routes will be constructed. First, create an ipfileconfiguration file,and save the two cross-chains routes information(ip:rpc_port:p2p_port)that needs to be constructed into a file separated by lines.

Note : Please make sure that the 825025500ports of the machine are not occupied.

cd ~/wecross-networks
vim ipfile

# type the following in the file
127.0.0.1:8250:25500

After generating the ipfile file, use the script build_wecross.sh to generate two cross-chains routes.

bash ./WeCross/build_wecross.sh -n payment -o routers-payment -f ipfile

 #.. note::
    - -n specifies the cross-chain zone identifier (zone id) , cross-chain zone is distinguished by the zone id and can be understood as the business name. ( Needed when calling the chain code, it is recommended that both parties communicate in advance ) 
    - -o Specify the output directory, and generate a cross-chains route under the directory. 
    - -f specifies the need to generate WeCross cross-chains routes from the list, including the ip address, rpc ports, P2P ports, the generated router has completed the interconnection configuration. 
    
# Output successfully following information
[INFO] Create routers-payment/127.0.0.1-8250-25500 successfully
[INFO] All completed. WeCross routers are generated in: routers-payment/

Two cross-chains routes are generated in the routers-payment directory.

tree routers-payment/ -L 1
routers-payment/
├── 127.0.0.1-8250-25500
└── cert

The content of the generated cross-chains routes directory is as follows, taking the 127.0.0.1-8250-25500 as an example.

# Blocked lib and pages directory, the directory stores all the dependent jar packages
tree routers-payment/127.0.0.1-8250-25500/
routers-payment/127.0.0.1-8250-25500/
├── add_chain.sh      # block chain configuration file creates a script
├── apps
│   └── WeCross.jar   # WeCross route jar package
├── build_wecross.sh
├── conf              # profile directory 
│   ├── accounts      # account configuration directory
│   ├── application.properties 
│   ├── chains        # block chain configuration directory accesses different chain, in this configuration directory
│   ├── log4j2.xml    
│   ├── ca.crt        # root certificate 
│   ├── ssl.crt       # cross-chains route certificate
│   ├── ssl.key       # cross-chains route private
│   ├── node.nodeid   # cross-chains route nodeid
│   └── wecross.toml  # WeCross Router main configuration file
├── create_cert.sh    # certificate generation script 
├── download_wecross.sh
├── pages             # web-based management platform page file
├── plugin            # plugin directory, and plug in for accessing the corresponding type of chain
│   ├── bcos-stub-gm.jar
│   ├── bcos-stub.jar
│   └── fabric-stub.jar
├── start.sh          # startup script
└── stop.sh           # stop script

Deploy account service

  • download

~~The configuration of the corresponding database needs to be entered during the execution

The database configuration filled in this step needs to communicate with the existing account_ Manager !!!!!!!!

cd ~/wecross-networks
bash <(curl -sL https://github.com/WeBankBlockchain/WeCross/releases/download/resources/download_account_manager.sh)

# If there is a long time to download WeCross-Account-Manager package fails, try Re-download with the following command:
bash <(curl -sL https://gitee.com/WeBank/WeCross/raw/master/scripts/download_account_manager.sh)
  • Copy certificate
cd ~/wecross-networks/WeCross-Account-Manager/
cp ~/wecross-networks/routers-payment/cert/sdk/* conf/
  • Generate private key
bash create_rsa_keypair.sh -d conf/
  • Configuration
cp conf/application-sample.toml conf/application.toml
vim conf/application.toml

The content to be configured includes:

admin: configure the admin account, default here, the admin account in the router needs to correspond to this, used to log in to the account service

db:Configure your own database account password

[service]
    address = '0.0.0.0'
    port = 8340
    sslKey = 'classpath:ssl.key'
    sslCert = 'classpath:ssl.crt'
    caCert = 'classpath:ca.crt'
    sslOn = true

[admin] 
    # admin account configuration, write into DB on first startup, starts after a check field name 
    name = 'org1-admin' # admin account name 
    password = '123456' # password

[auth]
    # for issuring token
    name = 'org1'
    expires = 18000 # 5 h
    noActiveExpires = 600 # 10 min

[db]
    # for connect database
    url = 'jdbc:mysql://localhost:3306/wecross_account_manager'
    username = 'root'     # Configuration database account 
    password = '123456'   # Configuration database password, not support an empty password 
[ext]
    # for image auth code, allow image auth token empty
    allowImageAuthCodeEmpty = true
  • start up
bash start.sh

Start cross-chains route

Modify cross-chain configuration wecross.toml

# Modify cross-chain configuration
vi  /root/wecross-networks/routers-payment/127.0.0.1-8250-25500/conf/wecross.toml

The following items need to be configured

peers:IP address of the WeCross Router list to be connected :Port

[common]
    zone = 'payment'   # string; Cross-chain partition identifier; Typically a cross-chain business/application is a cross-chain partition
    visible = true
    enableAccessControl = false

[chains]
    path = 'classpath:chains'

[rpc] # rpc ip & port
    address = '127.0.0.1'
    port = 8250
    caCert = 'classpath:ca.crt'
    sslCert = 'classpath:ssl.crt'
    sslKey = 'classpath:ssl.key'
    sslSwitch = 2  # disable ssl:2, SSL without client auth:1 , SSL with client and server auth: 0
    webRoot = 'classpath:pages'
    mimeTypesFile = 'classpath:conf/mime.types' # set the content-types of a file

[p2p]
    listenIP = '0.0.0.0'
    listenPort = 25500 
    caCert = 'classpath:ca.crt'
    sslCert = 'classpath:ssl.crt'
    sslKey = 'classpath:ssl.key'
    peers = ['127.0.0.1:25500']   #  IP address of the WeCross Router list to be connected :Port

[account-manager]
    server =  '127.0.0.1:8340'      
    admin = 'org1-admin'
    password = '123456'
    sslKey = 'classpath:ssl.key'
    sslCert = 'classpath:ssl.crt'
    caCert = 'classpath:ca.crt'

#[[htlc]]
#    selfPath = 'payment.bcos.htlc'
#    account1 = 'bcos_default_account'
#    counterpartyPath = 'payment.fabric.htlc'
#    account2 = 'fabric_default_account'

Start router-8250

# Start router-8250
cd ~/wecross-networks/routers-payment/127.0.0.1-8250-25500/
bash start.sh

The startup is successful, and the output is as follows:

WeCross booting up .........
WeCross start successfully

If the startup fails, check whether ports 8250, 25500 are occupied.

netstat -napl | grep 8250
netstat -napl | grep 25500

Deployment console

WeCross provides a console to facilitate cross-chain development and debugging. The console can be built through the script build_console.sh.

  • download

Execute the following command to download (three download methods are provided, and you can choose the appropriate method to download according to the network environment). After downloaded, the WeCross-Console directory will be generated in the current directory.

# Download WeCross console
# Command download

GitHub download method:
bash <(curl -sL https://github.com/WeBankBlockchain/WeCross/releases/download/resources/download_console.sh)

Gitee download method:
bash <(curl -sL https://gitee.com/WeBank/WeCross/raw/master/scripts/download_console.sh)
  • Configuration
cd ~/wecross-networks/WeCross-Console

# copy connected router desired TLS certificate from the generated routers-payment / cert / sdk directory
cp ~/wecross-networks/routers-payment/cert/sdk/* conf/ 

# Copy the configuration file, and configure the crosee-chains route RPC service address and port. The default configuration is used and connected to the local port 8250 by default .

cp conf/application-sample.toml conf/application.toml
.. important::
    - - If the IP and port for building WeCross are not using the default configuration, you need to change
WeCross-Console/conf/application.toml by yourself
  • start up
bash start.sh

If the startup is successful, the following information will be output, and the console help can be viewed through help .

=================================================================================
Welcome to WeCross console(v1.1.0)!
Type 'help' or 'h' for help. Type 'quit' or 'q' to quit console.
=================================================================================
  • Test function
# If entered normally, you can be exit the console at first and wait for subsequent configuration

[WeCross]> quit

Blockchain entry and account configuration

----After completing the deployment of WeCross basic components, the next step is to access the blockchain, configure cross-chain accounts, and build a real cross-chain network!

Connect to the blockchain

Access to Hyperledger Fabric:access to cross-chains router-8250

Configure built-in account

In the cross-chains route, a built-in account for interacting with the Fabric chain needs to be configured. Multiple built-in accounts need to be configured:

  • admin account: required, an admin account is used to access this Fabric chain
  • Institutional admin account: optional, each Org of Fabric configures an admin account, which is used to deploy system contracts on each Org .

Generate account configuration framework

# Handover to a corresponding cross-chains route from the home directory
cd ~/wecross-networks/routers-payment/127.0.0.1-8250-25500/

# script generating Fabric account configuration: Account Type ( Fabric1.4 ), account name ( fabric_admin )
# access to Fabric chain need to configure an admin account
bash add_account.sh -t Fabric1.4 -n fabric_admin 

# each Org of Fabric chain has a configuration admin account, and there are two ORG ( Org1 and Org2 ), each has two accounts

# the admin with Org1
bash add_account.sh -t Fabric1.4 -n fabric_admin_org1

# the admin with Org2
bash add_account.sh -t Fabric1.4 -n fabric_admin_org2

Complete the configuration

Modify account configuration

The generated account configuration with the default mspid is Org1MSP, and the mspid of the Org2 account needs to be configured as Org2MSP. You only need to modify the configuration of the fabric_admin_org2 account.

vim conf/accounts/fabric_admin_org2/account.toml

# modify mspid, change 'Org1MSP' to 'Org2MSP'
Copy the certificate file

The certificate of the fabric chain is located in the crypto-config directory. Please refer to the following command and complete the copy of the relevant certificate according to the actual situation .

cd ~/wecross-networks/routers-payment/127.0.0.1-8250-25500

# Configure fabric_admin 
# copy private     
cp xxxxxx/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore/*_sk   conf/accounts/fabric_admin/account.key
# copy certificate
cp xxxxxx/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/signcerts/[email protected]   conf/accounts/fabric_admin/account.crt

# Configure fabric_admin_org1 
# copy private
cp xxxxxx/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore/*_sk   conf/accounts/fabric_admin_org1/account.key
# copy certificate
cp xxxxxx/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/signcerts/[email protected]   conf/accounts/fabric_admin_org1/account.crt

# Configure fabric_admin_org2 
# copy private
cp xxxxxx/crypto-config/peerOrganizations/org2.example.com/users/[email protected]/msp/keystore/*_sk   conf/accounts/fabric_admin_org2/account.key
# copy certificate
cp xxxxxx/crypto-config/peerOrganizations/org2.example.com/users/[email protected]/msp/signcerts/[email protected]   conf/accounts/fabric_admin_org2/account.crt

After completing the certificate copy, the account directory structure is as follows:

tree conf/accounts/
conf/accounts/
├── fabric_admin
│   ├── account.crt
│   ├── account.key
│   └── account.toml
├── fabric_admin_org1
│   ├── account.crt
│   ├── account.key
│   └── account.toml
└── fabric_admin_org2
    ├── account.crt
    ├── account.key
    └── account.toml

Configure plugin

Generate plugin configuration framework

Enter the main directory of the cross-chain router , and use the add_chain.sh script to generate the configuration framework of the Fabric chain in the conf directory.

cd ~/wecross-networks/routers-payment/127.0.0.1-8250-25500

 # -t chain type, -n specifies the chain name, you can view the instructions according to -h
bash add_chain.sh -t Fabric1.4 -n fabric

The execution is successful, and the output is as follows. If you make an error, please check the screen and print the prompt.

SUCCESS: Chain "fabric" config framework has been generated to "conf/chains/fabric"

The generated directory structure is as follows:

tree conf/chains/fabric/
conf/chains/fabric/
├── chaincode
│   ├── WeCrossHub
│   │   └── hub.go    # bridge contract
│   └── WeCrossProxy
│       └── proxy.go  # proxy contract
└── stub.toml         # plug-in configuration file

Complete the configuration

Copy certificate

The relevant certificates are also located in the crypto-config directory. Please refer to the following commands and complete the copy of the relevant certificates according to the actual situation.

# Assumed that the current cross-chain route located at a home directory
# copy orderer certificate
cp xxxxxx/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem   conf/chains/fabric/orderer-tlsca.crt

# copy org1 certificate 
cp xxxxxx/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt   conf/chains/fabric/org1-tlsca.crt

# copy org2 certificate 
cp xxxxxx/crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt   conf/chains/fabric/org2-tlsca.crt

Edit configuration file

The configuration items of the plugin configuration file conf/chains/fabric/stub.tomlinclude:

  • Configure resource information
  • Configure SDK connection information and interact with the chain

Edit each configuration item of [fabricServices][orgs] according to the actual situation

[common]
    name = 'fabric'				# Name of the specified connection chain is consistent with the directory name where the configuration file is corresponding to the path of {zone}/{chain}/{resource} of catena alberghiera 
    type = 'Fabric1.4'			# Type of plugin

[fabricServices]
    channelName = 'mychannel'
    orgUserName = 'fabric_admin' # specifies a mechanism admin account for the orderer communication
    ordererTlsCaFile = 'orderer-tlsca.crt' # orderer certificate name is pointing to the certificate in the same configuration file directory
    ordererAddress = 'grpcs://localhost:7050' # orderer's URL

[orgs] # mechanism node list 
    [orgs.Org1] # mechanism1:Org1
         tlsCaFile = 'org1-tlsca.crt' # Org1's certificate 
         adminName = 'fabric_admin_org1' # The admin account of Org1 is configured in the next step
         endorsers = ['grpcs://localhost:7051'] # Endorser IP address: Port list. Multiple endorser IP addresses can be configured

    [orgs.Org2] # mechanism2:Org2
         tlsCaFile = 'org2-tlsca.crt' # Org2's certificate 
         adminName = 'fabric_admin_org2' # The admin account of Org2 is configured in the next step
         endorsers = ['grpcs://localhost:9051'] # Endorser IP address: Port list. Multiple endorser IP addresses can be configured

Deploy system contract

Each stub needs to deploy two system contracts, which are proxy contract and bridge contract. The proxy contract is responsible for managing affairs and the invocation of business contracts. The bridge contract is used to record contract cross-chain requests. Execute the following commands from the cross-chain route home directory:

# Deployment agent contract
bash deploy_system_contract.sh -t Fabric1.4 -c chains/fabric -P

# Deploying the bridge contract
bash deploy_system_contract.sh -t Fabric1.4 -c chains/fabric -H

#  If there is a subsequent need to update the system contract, update the system contract code under conf/chains/fabric at first, add the -u parameter to the above command, execute and restart the cross-chains route

If the deployment is successful, the following content will be output. If it fails, you can view the prompt information and error log.

SUCCESS: WeCrossProxy has been deployed to chains/fabric
SUCCESS: WeCrossHub has been deployed to chains/fabric

After completing the blockchain, restart the cross-chains router to load the configured cross-chain resources.

# Restart router-8250
cd ~/wecross-networks/routers-payment/127.0.0.1-8250-25500/
bash stop.sh && bash start.sh 

Check the log, you can see the loaded cross-chain resources are flushed out , and ctrl + c exits.

tail -f logs/info.log |grep "active resources"

2020-12-05 21:07:30.925 [Thread-3] INFO  WeCrossHost() - Current active resources: payment.bcos.WeCrossProxy(local), payment.bcos.WeCrossHub(local)
2020-12-05 21:07:40.940 [Thread-3] INFO  WeCrossHost() - Current active resources: payment.bcos.WeCrossProxy(local), payment.bcos.WeCrossHub(local)
2020-12-05 21:07:50.956 [Thread-3] INFO  WeCrossHost() - Current active resources: payment.bcos.WeCrossProxy(local), payment.bcos.WeCrossHub(local)

Configure cross-chain accounts

After the blockchain is linked in, the corresponding account must be configured to complete the resource call.

WeCross aggregates various types of chain accounts and manages them uniformly with cross-chain accounts. In WeCross, users log in with cross-chain accounts and then operate various resources. To send transactions to the specific type of chain, you only need to add the corresponding type of chain account to the cross-chain account.

Add Fabric Chain account

Note: Before adding a Fabric chain account, please make sure that the Fabric chain has been set up.

  • Copy public and private keys

Copy the public and private keys of the fabric chain to the console directory to prepare for adding chain accounts.

cp -r ~/wecross-networks/routers-payment/127.0.0.1-8250-25500/conf/accounts/* ~/wecross-networks/WeCross-Console/conf/accounts/
  • Start the console
cd ~/wecross-networks/WeCross-Console/
bash start.sh
  • Log in

Log in with the default cross-chain account: org1-admin, password: 123456 (the default account is configured in WeCross-Account-Manager/conf/application.toml).

[WeCross]> login org1-admin 123456
Result: success
=============================================================================================
Universal Account:
username: org1-admin
pubKey  : 3059301306...
uaID    : 3059301306...
  • Add chain account

Add a chain account for sending transactions to the currently logged-in cross-chain account.

# Parameters:addChainAccount Fabric1.4 private location public position MSPID is set to send the default transaction chain account

# Add fabric_admin_org1
[WeCross.org1-admin]> addChainAccount Fabric1.4 conf/accounts/fabric_admin_org1/account.crt conf/accounts/fabric_admin_org1/account.key Org1MSP true 

# Add fabric_admin_org2
[WeCross.org1-admin]> addChainAccount Fabric1.4 conf/accounts/fabric_admin_org2/account.crt conf/accounts/fabric_admin_org2/account.key Org2MSP true

View chain account

View all chain accounts under the currently logged-in cross-chain account. If isDefault is true, it means the default account for sending transactions.

[WeCross.org1-admin]> listAccount
Universal Account:
username: org1-admin
pubKey  : 3059301306...
uaID    : 3059301306...
chainAccounts: [
        BCOS2.0 Account:
        keyID    : 0
        type     : BCOS2.0
        address  : 0x4e89af80184147fcddc391c64ad673512236af67
        isDefault: true
        ----------
        Fabric1.4 Account:
        keyID    : 2
        type     : Fabric1.4
        MembershipID : Org2MSP
        isDefault: true
        ----------
        Fabric1.4 Account:
        keyID    : 1
        type     : Fabric1.4
        MembershipID : Org1MSP
        isDefault: false
        ----------
]

The operation is successful. Exit the console.

[WeCross.org1-admin]> quit

Resource deployment and initialization operations

Deploy Hyperledger Fabric cross-chain resources

WeCross supports deploying chaincode to the Fabric chain through the console. The deployment steps are as follows:

  • Prepare chaincode code (take sacc as an example)

The chaincode of the console is stored in the directory:conf/contracts/chaincode/, where the sacc code is placed in the directory:conf/contracts/chaincode/sacc(the directory name sacc is the name of the chaincode), and the chaincode code is placed in the sacc directory: sacc.go (Arbitrary code name).

tree conf/contracts/chaincode/sacc
conf/contracts/chaincode/sacc
├── policy.yaml
└── sacc.go
  • Deploy chaincode

Install the same chaincode for different Orgs.

# Login
[WeCross]> login org1-admin 123456
# In the login state, view the default chain account and see that the Fabric1.4 default account is Org2MSP
[WeCross.org1-admin]> listAccount
Universal Account:
username: org1-admin
pubKey  : 3059301306...
uaID    : 3059301306...
chainAccounts: [
        BCOS2.0 Account:
        keyID    : 0
        type     : BCOS2.0
        address  : 0x4e89af80184147fcddc391c64ad673512236af67
        isDefault: true
        ----------
        Fabric1.4 Account:
        keyID    : 2
        type     : Fabric1.4
        MembershipID : Org2MSP
        isDefault: true
        ----------
        Fabric1.4 Account:
        keyID    : 1
        type     : Fabric1.4
        MembershipID : Org1MSP
        isDefault: false
        ----------
]

# Before install to the Org1, set default account of Fabric1.4 to Org1MSP, parameters: setDefaultAccount Fabric1.4 keyID
[WeCross.org1-admin]> setDefaultAccount Fabric1.4 1

# Install the SACC for Org1 with the following parameters: path、 Org、 chaincode location、 version、 chaincode language
[WeCross.org1-admin]> fabricInstall payment.fabric.sacc Org1 contracts/chaincode/sacc 1.0 GO_LANG
path: classpath:contracts/chaincode/sacc
Result: Success

# Before installing to Org2, set default account of Fabric1.4 to Org2MSP, parameters: setDefaultAccount Fabric1.4 keyID
[WeCross.org1-admin]> setDefaultAccount Fabric1.4 2

# Install the SACC for Org2 with the following parameter: path、 Org、 chaincode location、 version、 chaincode language
[WeCross.org1-admin]> fabricInstall payment.fabric.sacc Org2 contracts/chaincode/sacc 1.0 GO_LANG
path: classpath:contracts/chaincode/sacc
Result: Success

Instantiate the specified chaincode.

Parameters: ipath, corresponding Orgs, chaincode code project directory, specified version, chaincode language, endorsement strategy (default here), initialization parameters

# fabricInstantiate default Org1MSP or Org2MSP chain account can be used here, Org2MSP
[WeCross.org1-admin]> fabricInstantiate payment.fabric.sacc ["Org1","Org2"] contracts/chaincode/sacc 1.0 GO_LANG default ["a","10"]

Result: Instantiating... Please wait and use 'listResources' to check. See router's log for more information.

After instantiate request, you need to wait about 1 minute. Use listResources to check if it is successful. If instantiate is successful, the resource payment.fabric.sacccan be queried .

[WeCross.org1-admin]> listResources
path: payment.bcos.HelloWorld, type: BCOS2.0, distance: 0
path: payment.fabric.WeCrossHub, type: Fabric1.4, distance: 1
path: payment.bcos.WeCrossHub, type: BCOS2.0, distance: 0
path: payment.fabric.sacc, type: Fabric1.4, distance: 1
total: 4

[WeCross.org1-admin]> quit # Quit the console

Operating cross-chain resources

View cross-chain resources

  • Log in

Log in with the default cross-chain account: org1-admin, password: 123456. (The default account is configured in WeCross-Account-Manager/conf/application.toml)

[WeCross]> login org1-admin 123456
Result: success
=============================================================================================
Universal Account:
username: org1-admin
pubKey  : 3059301306...
uaID    : 3059301306...
  • Get resources lis

Use the listResources command to view all resources in the WeCross cross-chain network. You can see that there are many resources:

payment.bcos.HelloWorld:Corresponds to the HelloWorld.sol contract on the FISCO BCOS chain.

payment.fabric.sacc:corresponds to the sacc.go contract on the Fabric chain.

payment.xxxx.WeCrossHub: The Hub contract installed by default on each chain is used to receive cross-chain calls initiated by the contract on the chain.

[WeCross.org1-admin]> listResources
path: payment.bcos.HelloWorld, type: BCOS2.0, distance: 0
path: payment.fabric.WeCrossHub, type: Fabric1.4, distance: 1
path: payment.bcos.WeCrossHub, type: BCOS2.0, distance: 0
path: payment.fabric.sacc, type: Fabric1.4, distance: 1
total: 4

Operation payment.fabric.sacc

Cross-chain resources are the unification and abstraction of resources on different chains, so the operating commands are consistent.

  • Read resources
# Call the query interfaces of mycc contract
[WeCross.org1-admin]> call payment.fabric.sacc get a
Result: [10] // The first get, a is 10
  • Write resources
#  Call the set Interface of sacc contract
[WeCross.org1-admin]> sendTransaction payment.fabric.sacc set a 666
Txhash  : aa3a7cd62d4b4c56b486f11fae2d903b7f07c2a3fa315ee2b44d5f5c43f5a8dc
BlockNum: 8
Result  : [666]

[WeCross.org1-admin]> call payment.fabric.sacc get a
Result: [666] // Get again, a becomes 666

#  quit WeCross console
[WeCross.org1-admin]> quit # To start the Console again, go to wecros-console and run start.sh

Cross-chain call test — Contract cross-chain call (Interchain)

Operation example

The WeCross console provides two language versions of cross-chain calling sample contracts. The interface of the sample contract includes:

init(): Pass in the bridge contract address of this chain to initialize

interchain(): the initiation interface of the cross-chain call, which internally calls the interchainInvoke interface of the bridge contract

get(): get data

set(): update data

callback(): Update the data with the result of the cross-chain call

**Two example contracts linkage processes **:the example contract of the A chain initiates a cross-chain call, and calls the set interface of the example contract of the B chain, to updates the data of the B chain, and then triggers a callback, calls the callback interface of the A chain and updates the data of the A chain .

Through the above method, console call can complete the update of the two chains’ data per time.

Preliminary preparation

The following operation example involves two chains, FISCO BCOS and Hyperledger Fabric.

Deploy a sample contract for cross-chain calls

After completing the environment setup, execute the following commands in the WeCross console:

# Login in
[WeCross]> login org1-admin 123456

# Switch the default Fabric account
[WeCross.org1-admin]> setDefaultAccount Fabric1.4 2

# Install the chaincode
[WeCross.org1-admin]> fabricInstall payment.fabric.interchain Org2 contracts/chaincode/interchain 1.0 GO_LANG

path: classpath:contracts/chaincode/interchain
Result: Success

# switching the default Fabric account
[WeCross.org1-admin]> setDefaultAccount Fabric1.4 1

# Install the chaincode
[WeCross.org1-admin]> fabricInstall payment.fabric.interchain Org1 contracts/chaincode/interchain 1.0 GO_LANG

path: classpath:contracts/chaincode/interchain
Result: Success

# instantiated chaincode
[WeCross.org1-admin]> fabricInstantiate payment.fabric.interchain ["Org1","Org2"] contracts/chaincode/interchain 1.0 GO_LANG default []

# wait for completing instantiation

Initialize the sample contract

Execute the following commands in the WeCross console:

#  Login
[WeCross]> login org1-admin 123456

# initialize Fabric example contract, which the channel name is mychannel
[WeCross.org1-admin]> sendTransaction payment.fabric.interchain init mychannel WeCrossHub

Initiate cross-chain call

Execute the following commands in the WeCross console:

# Login
[WeCross]> login org1-admin 123456

# view the original status of sample contract
[WeCross.org1-admin]> call payment.fabric.interchain get

Result: [["Talk is cheap, show me the code."]]

[WeCross.org1-admin]> call payment.bcos.interchain get

Result: [["Talk is cheap, show me the code."]]

# # Fabric initiates a cross-chain call ( communicate in advance the resource name of the bcos chain to be called and parameter )
[WeCross.org1-admin]> sendTransaction payment.fabric.interchain interchain payment.bcos.interchain set "Hello WeCross" payment.fabric.interchain callback

Txhash  : cf7eda25f1c0515b68d702ed495fdbbefed6bdcfd4a3bc68aaab315631d3d102
BlockNum: 2386
Result  : [1]

# Querying Example Contracts
[WeCross.org1-admin]> call payment.bcos.interchain get

Result: [[ "Hello WeCross" ]]

[WeCross.org1-admin]> call payment.fabric.interchain get

Result: [[ "Hello WeCross" ]]

# Query the result of invoking the callback
[WeCross.org1-admin]> call payment.fabric.WeCrossHub selectCallbackResult 1

Result: [["0","0","0","Success","[ \"Hello WeCross\" ]"]]

how me the code."]]

[WeCross.org1-admin]> call payment.bcos.interchain get

Result: [[“Talk is cheap, show me the code.”]]

# Fabric initiates a cross-chain call ( communicate in advance the resource name of the bcos chain to be called and parameter )

[WeCross.org1-admin]> sendTransaction payment.fabric.interchain interchain payment.bcos.interchain set “Hello WeCross” payment.fabric.interchain callback

Txhash : cf7eda25f1c0515b68d702ed495fdbbefed6bdcfd4a3bc68aaab315631d3d102
BlockNum: 2386
Result : [1]

Querying Example Contracts

[WeCross.org1-admin]> call payment.bcos.interchain get

Result: [[ “Hello WeCross” ]]

[WeCross.org1-admin]> call payment.fabric.interchain get

Result: [[ “Hello WeCross” ]]

Query the result of invoking the callback

[WeCross.org1-admin]> call payment.fabric.WeCrossHub selectCallbackResult 1

Result: [[“0”,“0”,“0”,“Success”,"[ “Hello WeCross” ]"]]


猜你喜欢

转载自blog.csdn.net/qq_42750537/article/details/120747491
en