主頁 > 區塊鏈 > 超級賬本 fabric2.0 集群多機部署--docker swarm集群(4個組織8個peer)

超級賬本 fabric2.0 集群多機部署--docker swarm集群(4個組織8個peer)

2020-12-17 11:56:35 區塊鏈

超級賬本 fabric2.0 集群多機部署

首先按照確保已經安裝好fabric2.0相關環境,且保證docker環境一致(先跑通first-network!!!)

搭建fabric2.0環境請參考
fabric2.0開發 基本環境安裝配置
fabric2.0開發 部署fabric環境和fabric-samples的啟動

我們使用 docker swarm 進行集群管理

組織架構

在這里插入圖片描述

4臺服務器 4個組織 8個peer

服務器分別為

192.168.1.188   (host1)

192.168.1.201   (host2)

192.168.1.202   (host3)

192.168.1.206   (host4)

其中每臺服務器一個組織兩個peer

部署程序

1.拉取docker swarm 鏡像(分別在host1,host2,host3,host4拉取鏡像)

docker pull swarm

2.host1執行命令(終端192.168.1.188)

docker swarm init --advertise-addr 192.168.1.188

執行截圖

在這里插入圖片描述

3.執行獲取其他機器連接的manager命令(終端192.168.1.188)

docker swarm join-token manager

在這里插入圖片描述

  • 執行此命令我們可以看到回傳了一個加入集群的命令
  • 命令 docker swarm join --token SWMTKN-1-4jpo4z6xnd9jz2ne2blzoe8erzo28vbqja83m5qd01pqfd88p1-9ir3qsc5ctdqnlnlkizwqi6yy 192.168.1.188:2377

4.使用最后的輸出,將其他節點以管理者身份加入swarm

  • 在host2,host3,host4分別執行剛付訓傳的命令
  • host2執行:docker swarm join --token SWMTKN-1-4jpo4z6xnd9jz2ne2blzoe8erzo28vbqja83m5qd01pqfd88p1-9ir3qsc5ctdqnlnlkizwqi6yy 192.168.1.188:2377(終端192.168.1.201)
  • host3執行:docker swarm join --token SWMTKN-1-4jpo4z6xnd9jz2ne2blzoe8erzo28vbqja83m5qd01pqfd88p1-9ir3qsc5ctdqnlnlkizwqi6yy 192.168.1.188:2377(終端192.168.1.202)
  • host4執行:docker swarm join --token SWMTKN-1-4jpo4z6xnd9jz2ne2blzoe8erzo28vbqja83m5qd01pqfd88p1-9ir3qsc5ctdqnlnlkizwqi6yy 192.168.1.188:2377(終端192.168.1.206)

5.從host 1創建疊加網路first-network(終端192.168.1.188)

  • 執行命令如下

  • docker network create --attachable --driver overlay first-network

  • 使用docker network ls 查看我們創建的疊加網路
    在這里插入圖片描述

  • 我們去查看其他其他三臺主機

  • 主機192.168.1.201
    在這里插入圖片描述

  • 主機192.168.1.202
    在這里插入圖片描述

  • 主機192.168.1.206

在這里插入圖片描述

6.在host1上準備材料(終端192.168.1.188)

  • 執行命令
    cd fabric-samples
    mkdir asset_network
    cd asset_network
  • 直接從first-network拷貝crypto-config.yaml和configtx.yaml檔案
    cp …/first-network/crypto-config.yaml .
    cp …/first-network/configtx.yaml .
    mkdir scripts
    cp …/first-network/scripts/* ./scripts
  • 接下來我們開始修改用于生成MSP相關證書組織架構和節點數的crypto-config.yaml檔案(修改如下)
  # Copyright IBM Corp. All Rights Reserved.
  #
  # SPDX-License-Identifier: Apache-2.0
  #
  
  # ---------------------------------------------------------------------------
  # "OrdererOrgs" - Definition of organizations managing orderer nodes
  # ---------------------------------------------------------------------------
  OrdererOrgs:
    # ---------------------------------------------------------------------------
    # Orderer
    # ---------------------------------------------------------------------------
    - Name: Orderer
      Domain: example.com
      # ---------------------------------------------------------------------------
      # "Specs" - See PeerOrgs below for complete description
      # ---------------------------------------------------------------------------
      Specs:
        - Hostname: orderer
        - Hostname: orderer2
        - Hostname: orderer3
        - Hostname: orderer4
        - Hostname: orderer5
  
  # ---------------------------------------------------------------------------
  # "PeerOrgs" - Definition of organizations managing peer nodes
  # ---------------------------------------------------------------------------
  PeerOrgs:
    # ---------------------------------------------------------------------------
    # Org1
    # ---------------------------------------------------------------------------
    - Name: Org1
      Domain: org1.example.com
      EnableNodeOUs: true
      # ---------------------------------------------------------------------------
      # "Specs"
      # ---------------------------------------------------------------------------
      # Uncomment this section to enable the explicit definition of hosts in your
      # configuration.  Most users will want to use Template, below
      #
      # Specs is an array of Spec entries.  Each Spec entry consists of two fields:
      #   - Hostname:   (Required) The desired hostname, sans the domain.
      #   - CommonName: (Optional) Specifies the template or explicit override for
      #                 the CN.  By default, this is the template:
      #
      #                              "{{.Hostname}}.{{.Domain}}"
      #
      #                 which obtains its values from the Spec.Hostname and
      #                 Org.Domain, respectively.
      # ---------------------------------------------------------------------------
      # Specs:
      #   - Hostname: foo # implicitly "foo.org1.example.com"
      #     CommonName: foo27.org5.example.com # overrides Hostname-based FQDN set above
      #   - Hostname: bar
      #   - Hostname: baz
      # ---------------------------------------------------------------------------
      # "Template"
      # ---------------------------------------------------------------------------
      # Allows for the definition of 1 or more hosts that are created sequentially
      # from a template. By default, this looks like "peer%d" from 0 to Count-1.
      # You may override the number of nodes (Count), the starting index (Start)
      # or the template used to construct the name (Hostname).
      #
      # Note: Template and Specs are not mutually exclusive.  You may define both
      # sections and the aggregate nodes will be created for you.  Take care with
      # name collisions
      # ---------------------------------------------------------------------------
      Template:
        Count: 2
        # Start: 5
        # Hostname: {{.Prefix}}{{.Index}} # default
      # ---------------------------------------------------------------------------
      # "Users"
      # ---------------------------------------------------------------------------
      # Count: The number of user accounts _in addition_ to Admin
      # ---------------------------------------------------------------------------
      Users:
        Count: 1
    # ---------------------------------------------------------------------------
    # Org2: See "Org1" for full specification
    # ---------------------------------------------------------------------------
    - Name: Org2
      Domain: org2.example.com
      EnableNodeOUs: true
      Template:
        Count: 2
      Users:
        Count: 1
  
    # ---------------------------------------------------------------------------
    # add org3
    # ---------------------------------------------------------------------------
    - Name: Org3
      Domain: org3.example.com
      EnableNodeOUs: true
      Template:
        Count: 2
      Users:
        Count: 1
  
    - Name: Org4
      Domain: org4.example.com
      EnableNodeOUs: true
      Template:
        Count: 2
      Users:
        Count: 1
  • 接下來我們開始修改用于生成創世區塊,交易通道configtx.yaml組態檔(修改如下)

  • # Copyright IBM Corp. All Rights Reserved.
    #
    # SPDX-License-Identifier: Apache-2.0
    #
    
    ---
    ################################################################################
    #
    #   Section: Organizations
    #
    #   - This section defines the different organizational identities which will
    #   be referenced later in the configuration.
    #
    ################################################################################
    Organizations:
    
        # SampleOrg defines an MSP using the sampleconfig.  It should never be used
        # in production but may be used as a template for other definitions
        - &OrdererOrg
            # DefaultOrg defines the organization which is used in the sampleconfig
            # of the fabric.git development environment
            Name: OrdererOrg
    
            # ID to load the MSP definition as
            ID: OrdererMSP
    
            # MSPDir is the filesystem path which contains the MSP configuration
            MSPDir: crypto-config/ordererOrganizations/example.com/msp
    
            # Policies defines the set of policies at this level of the config tree
            # For organization policies, their canonical path is usually
            #   /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
            Policies:
                Readers:
                    Type: Signature
                    Rule: "OR('OrdererMSP.member')"
                Writers:
                    Type: Signature
                    Rule: "OR('OrdererMSP.member')"
                Admins:
                    Type: Signature
                    Rule: "OR('OrdererMSP.admin')"
    
            OrdererEndpoints:
                - orderer.example.com:7050
    
        - &Org1
            # DefaultOrg defines the organization which is used in the sampleconfig
            # of the fabric.git development environment
            Name: Org1MSP
    
            # ID to load the MSP definition as
            ID: Org1MSP
    
            MSPDir: crypto-config/peerOrganizations/org1.example.com/msp
    
            # Policies defines the set of policies at this level of the config tree
            # For organization policies, their canonical path is usually
            #   /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
            Policies:
                Readers:
                    Type: Signature
                    Rule: "OR('Org1MSP.admin', 'Org1MSP.peer', 'Org1MSP.client')"
                Writers:
                    Type: Signature
                    Rule: "OR('Org1MSP.admin', 'Org1MSP.client')"
                Admins:
                    Type: Signature
                    Rule: "OR('Org1MSP.admin')"
                Endorsement:
                    Type: Signature
                    Rule: "OR('Org1MSP.peer')"
    
            # leave this flag set to true.
            AnchorPeers:
                # AnchorPeers defines the location of peers which can be used
                # for cross org gossip communication.  Note, this value is only
                # encoded in the genesis block in the Application section context
                - Host: peer0.org1.example.com
                  Port: 7051
    
        - &Org2
            # DefaultOrg defines the organization which is used in the sampleconfig
            # of the fabric.git development environment
            Name: Org2MSP
    
            # ID to load the MSP definition as
            ID: Org2MSP
    
            MSPDir: crypto-config/peerOrganizations/org2.example.com/msp
    
            # Policies defines the set of policies at this level of the config tree
            # For organization policies, their canonical path is usually
            #   /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
            Policies:
                Readers:
                    Type: Signature
                    Rule: "OR('Org2MSP.admin', 'Org2MSP.peer', 'Org2MSP.client')"
                Writers:
                    Type: Signature
                    Rule: "OR('Org2MSP.admin', 'Org2MSP.client')"
                Admins:
                    Type: Signature
                    Rule: "OR('Org2MSP.admin')"
                Endorsement:
                    Type: Signature
                    Rule: "OR('Org2MSP.peer')"
    
            AnchorPeers:
                # AnchorPeers defines the location of peers which can be used
                # for cross org gossip communication.  Note, this value is only
                # encoded in the genesis block in the Application section context
                - Host: peer0.org2.example.com
                  Port: 7050
    
        - &Org3
            # DefaultOrg defines the organization which is used in the sampleconfig
            # of the fabric.git development environment
            Name: Org3MSP
    
            # ID to load the MSP definition as
            ID: Org3MSP
    
            MSPDir: crypto-config/peerOrganizations/org3.example.com/msp
    
            # Policies defines the set of policies at this level of the config tree
            # For organization policies, their canonical path is usually
            #   /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
            Policies:
                Readers:
                    Type: Signature
                    Rule: "OR('Org3MSP.admin', 'Org3MSP.peer', 'Org3MSP.client')"
                Writers:
                    Type: Signature
                    Rule: "OR('Org3MSP.admin', 'Org3MSP.client')"
                Admins:
                    Type: Signature
                    Rule: "OR('Org3MSP.admin')"
                Endorsement:
                    Type: Signature
                    Rule: "OR('Org3MSP.peer')"
    
            AnchorPeers:
                # AnchorPeers defines the location of peers which can be used
                # for cross org gossip communication.  Note, this value is only
                # encoded in the genesis block in the Application section context
                - Host: peer0.org3.example.com
                  Port: 7050
    
        - &Org4
            # DefaultOrg defines the organization which is used in the sampleconfig
            # of the fabric.git development environment
            Name: Org4MSP
    
            # ID to load the MSP definition as
            ID: Org4MSP
    
            MSPDir: crypto-config/peerOrganizations/org4.example.com/msp
    
            # Policies defines the set of policies at this level of the config tree
            # For organization policies, their canonical path is usually
            #   /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
            Policies:
                Readers:
                    Type: Signature
                    Rule: "OR('Org4MSP.admin', 'Org4MSP.peer', 'Org4MSP.client')"
                Writers:
                    Type: Signature
                    Rule: "OR('Org4MSP.admin', 'Org4MSP.client')"
                Admins:
                    Type: Signature
                    Rule: "OR('Org4MSP.admin')"
                Endorsement:
                    Type: Signature
                    Rule: "OR('Org4MSP.peer')"
    
            AnchorPeers:
                # AnchorPeers defines the location of peers which can be used
                # for cross org gossip communication.  Note, this value is only
                # encoded in the genesis block in the Application section context
                - Host: peer0.org4.example.com
                  Port: 7050
            
    
    ################################################################################
    #
    #   SECTION: Capabilities
    #
    #   - This section defines the capabilities of fabric network. This is a new
    #   concept as of v1.1.0 and should not be utilized in mixed networks with
    #   v1.0.x peers and orderers.  Capabilities define features which must be
    #   present in a fabric binary for that binary to safely participate in the
    #   fabric network.  For instance, if a new MSP type is added, newer binaries
    #   might recognize and validate the signatures from this type, while older
    #   binaries without this support would be unable to validate those
    #   transactions.  This could lead to different versions of the fabric binaries
    #   having different world states.  Instead, defining a capability for a channel
    #   informs those binaries without this capability that they must cease
    #   processing transactions until they have been upgraded.  For v1.0.x if any
    #   capabilities are defined (including a map with all capabilities turned off)
    #   then the v1.0.x peer will deliberately crash.
    #
    ################################################################################
    Capabilities:
        # Channel capabilities apply to both the orderers and the peers and must be
        # supported by both.
        # Set the value of the capability to true to require it.
        Channel: &ChannelCapabilities
            # V2_0 capability ensures that orderers and peers behave according
            # to v2.0 channel capabilities. Orderers and peers from
            # prior releases would behave in an incompatible way, and are therefore
            # not able to participate in channels at v2.0 capability.
            # Prior to enabling V2.0 channel capabilities, ensure that all
            # orderers and peers on a channel are at v2.0.0 or later.
            V2_0: true
    
        # Orderer capabilities apply only to the orderers, and may be safely
        # used with prior release peers.
        # Set the value of the capability to true to require it.
        Orderer: &OrdererCapabilities
            # V2_0 orderer capability ensures that orderers behave according
            # to v2.0 orderer capabilities. Orderers from
            # prior releases would behave in an incompatible way, and are therefore
            # not able to participate in channels at v2.0 orderer capability.
            # Prior to enabling V2.0 orderer capabilities, ensure that all
            # orderers on channel are at v2.0.0 or later.
            V2_0: true
    
        # Application capabilities apply only to the peer network, and may be safely
        # used with prior release orderers.
        # Set the value of the capability to true to require it.
        Application: &ApplicationCapabilities
            # V2_0 application capability ensures that peers behave according
            # to v2.0 application capabilities. Peers from
            # prior releases would behave in an incompatible way, and are therefore
            # not able to participate in channels at v2.0 application capability.
            # Prior to enabling V2.0 application capabilities, ensure that all
            # peers on channel are at v2.0.0 or later.
            V2_0: true
    
    ################################################################################
    #
    #   SECTION: Application
    #
    #   - This section defines the values to encode into a config transaction or
    #   genesis block for application related parameters
    #
    ################################################################################
    Application: &ApplicationDefaults
    
        # Organizations is the list of orgs which are defined as participants on
        # the application side of the network
        Organizations:
    
        # Policies defines the set of policies at this level of the config tree
        # For Application policies, their canonical path is
        #   /Channel/Application/<PolicyName>
        Policies:
            Readers:
                Type: ImplicitMeta
                Rule: "ANY Readers"
            Writers:
                Type: ImplicitMeta
                Rule: "ANY Writers"
            Admins:
                Type: ImplicitMeta
                Rule: "MAJORITY Admins"
            LifecycleEndorsement:
                Type: ImplicitMeta
                Rule: "MAJORITY Endorsement"
            Endorsement:
                Type: ImplicitMeta
                Rule: "MAJORITY Endorsement"
    
        Capabilities:
            <<: *ApplicationCapabilities
    ################################################################################
    #
    #   SECTION: Orderer
    #
    #   - This section defines the values to encode into a config transaction or
    #   genesis block for orderer related parameters
    #
    ################################################################################
    Orderer: &OrdererDefaults
    
        # Orderer Type: The orderer implementation to start
        OrdererType: etcdraft
    
        # Batch Timeout: The amount of time to wait before creating a batch
        BatchTimeout: 2s
    
        # Batch Size: Controls the number of messages batched into a block
        BatchSize:
    
            # Max Message Count: The maximum number of messages to permit in a batch
            MaxMessageCount: 10
    
            # Absolute Max Bytes: The absolute maximum number of bytes allowed for
            # the serialized messages in a batch.
            AbsoluteMaxBytes: 99 MB
    
            # Preferred Max Bytes: The preferred maximum number of bytes allowed for
            # the serialized messages in a batch. A message larger than the preferred
            # max bytes will result in a batch larger than preferred max bytes.
            PreferredMaxBytes: 512 KB
    
        # Organizations is the list of orgs which are defined as participants on
        # the orderer side of the network
        Organizations:
    
        # Policies defines the set of policies at this level of the config tree
        # For Orderer policies, their canonical path is
        #   /Channel/Orderer/<PolicyName>
        Policies:
            Readers:
                Type: ImplicitMeta
                Rule: "ANY Readers"
            Writers:
                Type: ImplicitMeta
                Rule: "ANY Writers"
            Admins:
                Type: ImplicitMeta
                Rule: "MAJORITY Admins"
            # BlockValidation specifies what signatures must be included in the block
            # from the orderer for the peer to validate it.
            BlockValidation:
                Type: ImplicitMeta
                Rule: "ANY Writers"
    
    ################################################################################
    #
    #   CHANNEL
    #
    #   This section defines the values to encode into a config transaction or
    #   genesis block for channel related parameters.
    #
    ################################################################################
    Channel: &ChannelDefaults
        # Policies defines the set of policies at this level of the config tree
        # For Channel policies, their canonical path is
        #   /Channel/<PolicyName>
        Policies:
            # Who may invoke the 'Deliver' API
            Readers:
                Type: ImplicitMeta
                Rule: "ANY Readers"
            # Who may invoke the 'Broadcast' API
            Writers:
                Type: ImplicitMeta
                Rule: "ANY Writers"
            # By default, who may modify elements at this config level
            Admins:
                Type: ImplicitMeta
                Rule: "MAJORITY Admins"
    
        # Capabilities describes the channel level capabilities, see the
        # dedicated Capabilities section elsewhere in this file for a full
        # description
        Capabilities:
            <<: *ChannelCapabilities
    
    ################################################################################
    #
    #   Profile
    #
    #   - Different configuration profiles may be encoded here to be specified
    #   as parameters to the configtxgen tool
    #
    ################################################################################
    Profiles:
    
        FourOrgsChannel:
            Consortium: SampleConsortium
            <<: *ChannelDefaults
            Application:
                <<: *ApplicationDefaults
                Organizations:
                    - *Org1
                    - *Org2
                    - *Org3
                    - *Org4
                Capabilities:
                    <<: *ApplicationCapabilities
    
        SampleMultiNodeEtcdRaft:
            <<: *ChannelDefaults
            Capabilities:
                <<: *ChannelCapabilities
            Orderer:
                <<: *OrdererDefaults
                OrdererType: etcdraft
                EtcdRaft:
                    Consenters:
                    - Host: orderer.example.com
                      Port: 7050
                      ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
                      ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
                    - Host: orderer2.example.com
                      Port: 7050
                      ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/server.crt
                      ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/server.crt
                    - Host: orderer3.example.com
                      Port: 7050
                      ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer3.example.com/tls/server.crt
                      ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer3.example.com/tls/server.crt
                    - Host: orderer4.example.com
                      Port: 7050
                      ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer4.example.com/tls/server.crt
                      ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer4.example.com/tls/server.crt
                    - Host: orderer5.example.com
                      Port: 8050
                      ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer5.example.com/tls/server.crt
                      ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer5.example.com/tls/server.crt
                Addresses:
                    - orderer.example.com:7050
                    - orderer2.example.com:7050
                    - orderer3.example.com:7050
                    - orderer4.example.com:7050
                    - orderer5.example.com:8050
    
                Organizations:
                - *OrdererOrg
                Capabilities:
                    <<: *OrdererCapabilities
            Application:
                <<: *ApplicationDefaults
                Organizations:
                - <<: *OrdererOrg
            Consortiums:
                SampleConsortium:
                    Organizations:
                    - *Org1
                    - *Org2
                    - *Org3
                    - *Org4
    
  • 然后根據組態檔生成必要的密碼學資料

  • ../bin/cryptogen generate --config=./crypto-config.yaml
    
    export FABRIC_CFG_PATH=$PWD
    
    mkdir channel-artifacts
    
    ../bin/configtxgen -profile SampleMultiNodeEtcdRaft -outputBlock ./channel-artifacts/genesis.block -channelID byfn-sys-channel
    
    ../bin/configtxgen -profile FourOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
    
    ../bin/configtxgen -profile FourOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
    
    ../bin/configtxgen -profile FourOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
    
    ../bin/configtxgen -profile FourOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org3MSPanchors.tx -channelID mychannel -asOrg Org3MSP
    
    ../bin/configtxgen -profile FourOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org4MSPanchors.tx -channelID mychannel -asOrg Org4MSP
    

7.為所有主機準備docker-compose檔案,需要創建6個docker-compose檔案以及一個env檔案(終端192.168.1.188)

檔案名解釋
base/peer-base.yaml生成peer節點的基礎組態檔
base/docker-compose-peer.yaml各org,peer,order的docker部署組態檔
host1.yaml主機192.168.1.188啟動服務的組態檔
host2.yaml主機192.168.1.201啟動服務的組態檔
host3.yaml主機192.168.1.202啟動服務的組態檔
host4.yaml主機192.168.1.206啟動服務的組態檔
.env組態檔
  • 針對相關檔案的修改
    • base/peer-base.yaml中,CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE修改為
      我們之前創建的疊加網路first-network
    • base/docker-compose-base.yaml中,由于我們添加了兩個組織,且每個組織都在不同的機器上,一方面修改了映射的埠,一方面添加了對應的兩個組織和組織對應的peer,
    • 在所有的hostn.yaml檔案中,我們添加疊加網路first-network
      現在我們在host 1上準備好了所有資料,將該目錄拷貝到其他主機,由于不能跨EC2實體拷貝檔案,我們使用本地機器進行橋接操作,將準備好的檔案分別發送到其他3臺主機上去:

8.將我們創建及生成的檔案打包(終端192.168.1.188)

cd ..
tar cf asset_network.tar asset_network
scp asset_network.tar root@192.168.1.201:/root/go/src/github.com/hyperledger/fabric-samples
scp asset_network.tar root@192.168.1.202:/root/go/src/github.com/hyperledger/fabric-samples
scp asset_network.tar root@192.168.1.206:/root/go/src/github.com/hyperledger/fabric-samples

9.分別登陸剛剛遠程復制的機器進行解壓包

#在host2、host3、host4上分別執行
cd /root/go/src/github.com/hyperledger/fabric-samples
rm -rf asset_network
tar xf asset_network.tar
cd asset_network

現在所有的節點都有了同樣的密碼學資料和docker-compose檔案,我們可以啟動容器了,

10.分別在各個主機上使用docker-composer啟動應用程式

  • host2 (終端192.168.1.188)
    docker-compose -f host1.yaml up -d
    使用docker ps查看服務
    在這里插入圖片描述

  • host2 (終端192.168.1.201)
    docker-compose -f host2.yaml up -d
    使用docker ps查看服務
    在這里插入圖片描述

  • host3 (終端192.168.1.202)
    docker-compose -f host3.yaml up -d
    使用docker ps查看服務
    在這里插入圖片描述

  • host4 (終端192.168.1.206)
    docker-compose -f host4.yaml up -d
    使用docker ps查看服務

在這里插入圖片描述

如下為 docker-compose -f host1.yaml up -d 命令回傳截圖

在這里插入圖片描述

11.為mychannel通道創建創世區塊(終端192.168.1.188)

docker exec cli peer channel create -o orderer.example.com:7050 -c mychannel \
       -f ./channel-artifacts/channel.tx --tls true \
       --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

結果如下圖

在這里插入圖片描述

12.將peer0.org1加入mychannel(終端192.168.1.188)

docker exec cli peer channel join -b mychannel.block

在這里插入圖片描述

13.將peer1.org1加入mychannel(終端192.168.1.188)

docker exec -e CORE_PEER_ADDRESS=peer1.org1.example.com:8051 -e CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/ca.crt cli peer channel join -b mychannel.block

在這里插入圖片描述

14.將peer0.org2加入mychannel(終端192.168.1.188)

docker exec -e CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp \
       -e CORE_PEER_ADDRESS=peer0.org2.example.com:7051 -e CORE_PEER_LOCALMSPID="Org2MSP" \
       -e CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt \
       cli peer channel join -b mychannel.block

15.將peer1.org2加入mychannel(終端192.168.1.188)

docker exec -e CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp \
       -e CORE_PEER_ADDRESS=peer1.org2.example.com:8051 -e CORE_PEER_LOCALMSPID="Org2MSP" \
       -e CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls/ca.crt \
       cli peer channel join -b mychannel.block

在這里插入圖片描述
16.將peer0.org3加入mychannel(終端192.168.1.188)

docker exec -e CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp \
       -e CORE_PEER_ADDRESS=peer0.org3.example.com:7051 -e CORE_PEER_LOCALMSPID="Org3MSP" \
       -e CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt \
       cli peer channel join -b mychannel.block

在這里插入圖片描述

17.將peer1.org3加入mychannel(終端192.168.1.188)

docker exec -e CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp \
       -e CORE_PEER_ADDRESS=peer1.org3.example.com:8051 -e CORE_PEER_LOCALMSPID="Org3MSP" \
       -e CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer1.org3.example.com/tls/ca.crt \
       cli peer channel join -b mychannel.block

在這里插入圖片描述
18.將peer0.org4加入mychannel(終端192.168.1.188)

docker exec -e CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org4.example.com/users/Admin@org4.example.com/msp \
       -e CORE_PEER_ADDRESS=peer0.org4.example.com:7051 -e CORE_PEER_LOCALMSPID="Org4MSP" \
       -e CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org4.example.com/peers/peer0.org4.example.com/tls/ca.crt \
       cli peer channel join -b mychannel.block

在這里插入圖片描述

19.將peer1.org4加入mychannel(終端192.168.1.188)

docker exec -e CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org4.example.com/users/Admin@org4.example.com/msp \
       -e CORE_PEER_ADDRESS=peer1.org4.example.com:8051 -e CORE_PEER_LOCALMSPID="Org4MSP" \
       -e CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org4.example.com/peers/peer1.org4.example.com/tls/ca.crt \
       cli peer channel join -b mychannel.block

在這里插入圖片描述

到此我們已經啊將所有組織和peer加入到了我們的channel通道中

20.安裝并實體化Fabcar鏈碼(終端192.168.1.188)

  • 進入到docker的cli終端
    docker exec -it cli bash

  • 查看環境變數
    env
    在這里插入圖片描述

  • 設定go 的訪問源
    go env -w GOPROXY=https://goproxy.io,direct

  • 開始打包chaincode

  • peer lifecycle chaincode package mycc1.tar.gz --path /opt/gopath/src/github.com/chaincode/abstore/go/ --lang golang --label mycc_1
    

    命令解釋:
    mycc2.tar.gz :打包合約包檔案名
    –path 智能合約路徑,可以在host1.yaml中查看cli容器的資料卷配置查詢
    –lang 智能合約語言 支持golang、node、java
    –label 智能合約標簽,描述作用

  • 開始安裝chaincode
    peer lifecycle chaincode install mycc1.tar.gz

  • 驗證合約安裝是否安裝到節點
    peer lifecycle chaincode queryinstalled
    出現如下結果表示安裝成功

在這里插入圖片描述

  • 當前組織同意合約定義(注意下面命令使用的mycc_1對應的包id應該是使用剛剛驗證時回傳的包id!!!)

  • peer lifecycle chaincode approveformyorg --tls true \
     --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem \
     --channelID mychannel --name mycc1 --version 1 --init-required --package-id mycc_1:9098a2442d1c40119cb0a085a206d89e61859649ebcca587357e2b56a3b3fe73 --sequence 1 --waitForEvent
    

    在這里插入圖片描述

    • 命令解釋:
      –tls 是否啟動tls
      –ca ca證書路徑
      –channelID 智能合約安裝通道
      –name 合約名
      –version 合約版本
      –package-id queryinstalled查詢的合約ID
      –sequence 序列號
      –waitForEvent 等待peer提交交易回傳
      –init-required 合約是否必須執行init
  • 檢查合約是否滿足策略

  • peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name mycc1  --version 1 --sequence 1 --output json --init-required
    

    在這里插入圖片描述

    • 通過檢查合約策略如上圖,我們可知Org1MSP 已經通過策略,但由于我們的策略定義是滿足過半數
      在這里插入圖片描述

    • 現在明顯不滿足,我們還是執行commit合約看一下會怎么樣

    • peer lifecycle chaincode commit -o orderer.example.com:7050 \
       --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem \
       --channelID mychannel --name mycc1 --peerAddresses peer0.org1.example.com:7051 \
       --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt \
       --peerAddresses peer0.org2.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt \
      --peerAddresses peer0.org3.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt \
      --peerAddresses peer0.org4.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org4.example.com/peers/peer0.org4.example.com/tls/ca.crt \
       --version 1 --sequence 1 --init-required
      

      在這里插入圖片描述

    • chaincode definition not agreed to by this org (Org2MSP) 鏈碼合約定義還沒取得Org2MSP的同意,這時候我們需要把Org2MSP,Org3MSP,Org4MSP也同意這個合約定義

  • Org2MSP 同意合約

    • 從新定義環境變數

    • export CORE_PEER_LOCALMSPID=Org2MSP
      export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
      export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
      export CORE_PEER_ADDRESS=peer0.org2.example.com:7051
      
    • 從新安裝合約到節點
      peer lifecycle chaincode install mycc1.tar.gz
      在這里插入圖片描述

    • 驗證合約安裝是否安裝到節點
      peer lifecycle chaincode queryinstalled

    • 當前組織同意合約定義(注意下面命令使用的mycc_1對應的包id應該是使用剛剛驗證時回傳的包id!!!)

    • peer lifecycle chaincode approveformyorg --tls true \
       --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem \
       --channelID mychannel --name mycc1 --version 1 --init-required --package-id mycc_1:9098a2442d1c40119cb0a085a206d89e61859649ebcca587357e2b56a3b3fe73 --sequence 1 --waitForEvent
      
    • 檢查合約是否滿足策略

    • peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name mycc1  --version 1 --sequence 1 --output json --init-required
      

      在這里插入圖片描述

      此時我們可以看到,現在Org2MSP也已經顯示為true,組織二也滿足了策略
      后面請按照<Org2MSP 同意合約>走的程式,在將Org3MSP,Org4MSP再走一遍上述流程,使Org3MSP,Org4MSP也同意策略

      最終所有組織都同意合約回傳入下圖所以

  • 在滿足合約定義的策略后,提交合約

  • peer lifecycle chaincode commit -o orderer.example.com:7050 \
     --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem \
     --channelID mychannel --name mycc1 --peerAddresses peer0.org1.example.com:7051 \
     --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt \
     --peerAddresses peer0.org2.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt \
    --peerAddresses peer0.org3.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt \
    --peerAddresses peer0.org4.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org4.example.com/peers/peer0.org4.example.com/tls/ca.crt \
     --version 1 --sequence 1 --init-required
    

    回傳如下圖
    在這里插入圖片描述

    引數解釋
    –tls 是否啟動tls
    –ca ca證書路徑
    –channelID 智能合約安裝通道
    –name 合約名
    –version 合約版本
    –package-id queryinstalled查詢的合約ID
    –sequence 序列號
    –waitForEvent 等待peer提交交易回傳
    –init-required 合約是否必須執行init
    –peerAddresses 節點路徑
    –tlsRootCertFiles 節點ca根證書路徑(–peerAddresses --tlsRootCertFiles 連用,可多個節點,多個節點即將合約部署到對應節點集合上)
    在宿主機(192.168.1.201)中查看智能合約容器,此時合約容器已經啟動,其他主機請自行查看
    在這里插入圖片描述

  • 查看節點已提交合約

  • peer lifecycle chaincode querycommitted --channelID mychannel --name mycc1
    

    在這里插入圖片描述

  • 操作合約

  • peer chaincode invoke -o orderer.example.com:7050 --tls true \
    --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem \
    -C mychannel -n mycc1 --peerAddresses peer0.org1.example.com:7051 \
    --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt \
    --peerAddresses peer0.org2.example.com:7051 \
    --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt \
    --peerAddresses peer0.org3.example.com:7051 \
    --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt \
    --peerAddresses peer0.org4.example.com:7051 \
    --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org4.example.com/peers/peer0.org4.example.com/tls/ca.crt \
    --isInit -c '{"Args":["Init","a","100","b","100"]}'
    

    如下圖我們可以看到我們成功初始化合約
    在這里插入圖片描述

  • 查詢
    peer chaincode query -C mychannel -n mycc1 -c ‘{“Args”:[“query”,“a”]}’
    如下圖我們可以看到查詢到我們需要的資料,a賬戶余額為100
    在這里插入圖片描述

  • 呼叫 invoke方法, a ->b 轉賬20

  • peer chaincode invoke -o orderer.example.com:7050 --tls true \
    --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem \
    -C mychannel -n mycc1 --peerAddresses peer0.org1.example.com:7051 \
    --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt \
    --peerAddresses peer0.org2.example.com:7051 \
    --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt  \
    --peerAddresses peer0.org3.example.com:7051 \
    --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt  \
    --peerAddresses peer0.org4.example.com:7051 \
    --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org4.example.com/peers/peer0.org4.example.com/tls/ca.crt  \
    -c  '{"Args":["invoke","a","b","20"]}'
    

    如下圖我們可以看到已經成功給b轉賬20
    在這里插入圖片描述

  • 我們再次查詢a的余額

  • peer chaincode query -C mychannel -n mycc1 -c '{"Args":["query","a"]}'
    

    在這里插入圖片描述

    我們可以看到a的余額已經減少20為80,到此我們成功多機部署了fabric環境,

轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/236097.html

標籤:區塊鏈

上一篇:新手玩合約最怕什么?

下一篇:Go資料型別、關鍵字、識別符號- DateWhale開源學習

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • JAVA使用 web3j 進行token轉賬

    最近新學習了下區塊鏈這方面的知識,所學不多,給大家分享下。 # 1. 關于web3j web3j是一個高度模塊化,反應性,型別安全的Java和Android庫,用于與智能合約配合并與以太坊網路上的客戶端(節點)集成。 # 2. 準備作業 jdk版本1.8 引入maven <dependency> < ......

    uj5u.com 2020-09-10 03:03:06 more
  • 以太坊智能合約開發框架Truffle

    前言 部署智能合約有多種方式,命令列的瀏覽器的渠道都有,但往往跟我們程式員的風格不太相符,因為我們習慣了在IDE里寫了代碼然后打包運行看效果。 雖然現在IDE中已經存在了Solidity插件,可以撰寫智能合約,但是部署智能合約卻要另走他路,沒辦法進行一個快捷的部署與測驗。 如果團隊管理的區塊節點多、 ......

    uj5u.com 2020-09-10 03:03:12 more
  • 谷歌二次驗證碼成為區塊鏈專用安全碼,你怎么看?

    前言 谷歌身份驗證器,前些年大家都比較陌生,但隨著國內互聯網安全的加強,它越來越多地出現在大家的視野中。 比較廣泛接觸的人群是國際3A游戲愛好者,游戲盜號現象嚴重+國外賬號安全應用廣泛,這類游戲一般都會要求用戶系結名為“兩步驗證”、“雙重驗證”等,平臺一般都推薦用谷歌身份驗證器。 后來區塊鏈業務風靡 ......

    uj5u.com 2020-09-10 03:03:17 more
  • 密碼學DAY1

    目錄 ##1.1 密碼學基本概念 密碼在我們的生活中有著重要的作用,那么密碼究竟來自何方,為何會產生呢? 密碼學是網路安全、資訊安全、區塊鏈等產品的基礎,常見的非對稱加密、對稱加密、散列函式等,都屬于密碼學范疇。 密碼學有數千年的歷史,從最開始的替換法到如今的非對稱加密演算法,經歷了古典密碼學,近代密 ......

    uj5u.com 2020-09-10 03:03:50 more
  • 密碼學DAY1_02

    目錄 ##1.1 ASCII編碼 ASCII(American Standard Code for Information Interchange,美國資訊交換標準代碼)是基于拉丁字母的一套電腦編碼系統,主要用于顯示現代英語和其他西歐語言。它是現今最通用的單位元組編碼系統,并等同于國際標準ISO/IE ......

    uj5u.com 2020-09-10 03:04:50 more
  • 密碼學DAY2

    ##1.1 加密模式 加密模式:https://docs.oracle.com/javase/8/docs/api/javax/crypto/Cipher.html ECB ECB : Electronic codebook, 電子密碼本. 需要加密的訊息按照塊密碼的塊大小被分為數個塊,并對每個塊進 ......

    uj5u.com 2020-09-10 03:05:42 more
  • NTP時鐘服務器的特點(京準電子)

    NTP時鐘服務器的特點(京準電子) NTP時鐘服務器的特點(京準電子) 京準電子官V——ahjzsz 首先對時間同步進行了背景介紹,然后討論了不同的時間同步網路技術,最后指出了建立全球或區域時間同步網存在的問題。 一、概 述 在通信領域,“同步”概念是指頻率的同步,即網路各個節點的時鐘頻率和相位同步 ......

    uj5u.com 2020-09-10 03:05:47 more
  • 標準化考場時鐘同步系統推進智能化校園建設

    標準化考場時鐘同步系統推進智能化校園建設 標準化考場時鐘同步系統推進智能化校園建設 安徽京準電子科技官微——ahjzsz 一、背景概述隨著教育事業的快速發展,學校建設如雨后春筍,隨之而來的學校教育、管理、安全方面的問題成了學校管理人員面臨的最大的挑戰,這些問題同時也是學生家長所擔心的。為了讓學生有更 ......

    uj5u.com 2020-09-10 03:05:51 more
  • 位元幣入門

    引言 位元幣基本結構 位元幣基礎知識 1)哈希演算法 2)非對稱加密技術 3)數字簽名 4)MerkleTree 5)哪有位元幣,有的是UTXO 6)位元幣挖礦與共識 7)區塊驗證(共識) 總結 引言 上一篇我們已經知道了什么是區塊鏈,此篇說一下區塊鏈的第一個應用——位元幣。其實先有位元幣,后有的區塊 ......

    uj5u.com 2020-09-10 03:06:15 more
  • 北斗對時服務器(北斗對時設備)電力系統應用

    北斗對時服務器(北斗對時設備)電力系統應用 北斗對時服務器(北斗對時設備)電力系統應用 京準電子科技官微(ahjzsz) 中國北斗衛星導航系統(英文名稱:BeiDou Navigation Satellite System,簡稱BDS),因為是目前世界范圍內唯一可以大面積提供免費定位服務的系統,所以 ......

    uj5u.com 2020-09-10 03:06:20 more
最新发布
  • web3 產品介紹:metamask 錢包 使用最多的瀏覽器插件錢包

    Metamask錢包是一種基于區塊鏈技術的數字貨幣錢包,它允許用戶在安全、便捷的環境下管理自己的加密資產。Metamask錢包是以太坊生態系統中最流行的錢包之一,它具有易于使用、安全性高和功能強大等優點。 本文將詳細介紹Metamask錢包的功能和使用方法。 一、 Metamask錢包的功能 數字資 ......

    uj5u.com 2023-04-20 08:46:47 more
  • Hyperledger Fabric 使用 CouchDB 和復雜智能合約開發

    在上個實驗中,我們已經實作了簡單智能合約實作及客戶端開發,但該實驗中智能合約只有基礎的增刪改查功能,且其中的資料管理功能與傳統 MySQL 比相差甚遠。本文將在前面實驗的基礎上,將 Hyperledger Fabric 的默認資料庫支持 LevelDB 改為 CouchDB 模式,以實作更復雜的資料... ......

    uj5u.com 2023-04-16 07:28:31 more
  • .NET Core 波場鏈離線簽名、廣播交易(發送 TRX和USDT)筆記

    Get Started NuGet You can run the following command to install the Tron.Wallet.Net in your project. PM> Install-Package Tron.Wallet.Net 配置 public reco ......

    uj5u.com 2023-04-14 08:08:00 more
  • DKP 黑客分析——不正確的代幣對比率計算

    概述: 2023 年 2 月 8 日,針對 DKP 協議的閃電貸攻擊導致該協議的用戶損失了 8 萬美元,因為 execute() 函式取決于 USDT-DKP 對中兩種代幣的余額比率。 智能合約黑客概述: 攻擊者的交易:0x0c850f,0x2d31 攻擊者地址:0xF38 利用合同:0xf34ad ......

    uj5u.com 2023-04-07 07:46:09 more
  • Defi開發簡介

    Defi開發簡介 介紹 Defi是去中心化金融的縮寫, 是一項旨在利用區塊鏈技術和智能合約創建更加開放,可訪問和透明的金融體系的運動. 這與傳統金融形成鮮明對比,傳統金融通常由少數大型銀行和金融機構控制 在Defi的世界里,用戶可以直接從他們的電腦或移動設備上訪問廣泛的金融服務,而不需要像銀行或者信 ......

    uj5u.com 2023-04-05 08:01:34 more
  • solidity簡單的ERC20代幣實作

    // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.9.0; import "hardhat/console.sol"; //ERC20 同質化代幣,每個代幣的本質或性質都是相同 //ETH 是原生代幣,它不是ERC20代幣, ......

    uj5u.com 2023-03-21 07:56:29 more
  • solidity 參考型別修飾符memory、calldata與storage 常量修飾符C

    在solidity語言中 參考型別修飾符(參考型別為存盤空間不固定的數值型別) memory、calldata與storage,它們只能修飾參考型別變數,比如字串、陣列、位元組等... memory 適用于方法傳參、返參或在方法體內使用,使用完就會清除掉,釋放記憶體 calldata 僅適用于方法傳參 ......

    uj5u.com 2023-03-08 07:57:54 more
  • solidity注解標簽

    在solidity語言中 注釋符為// 注解符為/* 內容*/ 或者 是 ///內容 注解中含有這幾個標簽給予我們使用 @title 一個應該描述合約/介面的標題 contract, library, interface @author 作者的名字 contract, library, interf ......

    uj5u.com 2023-03-08 07:57:49 more
  • 評價指標:相似度、GAS消耗

    【代碼注釋自動生成方法綜述】 這些評測指標主要來自機器翻譯和文本總結等研究領域,可以評估候選文本(即基于代碼注釋自動方法而生成)和參考文本(即基于手工方式而生成)的相似度. BLEU指標^[^?88^^?^]^:其全稱是bilingual evaluation understudy.該指標是最早用于 ......

    uj5u.com 2023-02-23 07:27:39 more
  • 基于NOSTR協議的“公有制”版本的Twitter,去中心化社交軟體Damus

    最近,一個幽靈,Web3的幽靈,在網路游蕩,它叫Damus,這玩意詮釋了什么叫做病毒式營銷,滑稽的是,一個Web3產品卻在Web2的產品鏈上瘋狂傳銷,各方大佬紛紛為其背書,到底發生了什么?Damus的葫蘆里,賣的是什么藥? 注冊和簡單實用 很少有什么產品在用戶注冊環節會有什么噱頭,但Damus確實出 ......

    uj5u.com 2023-02-05 06:48:39 more