美文网首页Hyperledger Fabric 文档
5.2.1 Hyperledger Fabric - 教程 -

5.2.1 Hyperledger Fabric - 教程 -

作者: furnace | 来源:发表于2019-12-05 19:55 被阅读0次

    教程 - Commercial Paper

    0. 清除历史

    $ sudo docker rm -f $(sudo docker ps -aq)
    $ sudo docker rmi -f $(sudo docker images | grep papercontract | awk '{print $3}')
    

    1. 创建网络

    $ cd fabric-samples/basic-network
    $ sudo ./start.sh
    
    $ sudo docker ps
    CONTAINER ID        IMAGE                        COMMAND                  CREATED              STATUS              PORTS                                            NAMES
    ada3d078989b        hyperledger/fabric-peer      "peer node start"        About a minute ago   Up About a minute   0.0.0.0:7051->7051/tcp, 0.0.0.0:7053->7053/tcp   peer0.org1.example.com
    1fa1fd107bfb        hyperledger/fabric-orderer   "orderer"                About a minute ago   Up About a minute   0.0.0.0:7050->7050/tcp                           orderer.example.com
    53fe614274f7        hyperledger/fabric-couchdb   "tini -- /docker-ent…"   About a minute ago   Up About a minute   4369/tcp, 9100/tcp, 0.0.0.0:5984->5984/tcp       couchdb
    469201085a20        hyperledger/fabric-ca        "sh -c 'fabric-ca-se…"   About a minute ago   Up About a minute   0.0.0.0:7054->7054/tcp                           ca.example.com
    
    $ sudo docker network inspect net_basic
    
        {
            "Name": "net_basic",
            "Id": "62e9d37d00a0eda6c6301a76022c695f8e01258edaba6f65e876166164466ee5",
            "Created": "2018-11-07T13:46:30.4992927Z",
            "Containers": {
                "1fa1fd107bfbe61522e4a26a57c2178d82b2918d5d423e7ee626c79b8a233624": {
                    "Name": "orderer.example.com",
                    "IPv4Address": "172.20.0.4/16",
                },
                "469201085a20b6a8f476d1ac993abce3103e59e3a23b9125032b77b02b715f2c": {
                    "Name": "ca.example.com",
                    "IPv4Address": "172.20.0.2/16",
                },
                "53fe614274f7a40392210f980b53b421e242484dd3deac52bbfe49cb636ce720": {
                    "Name": "couchdb",
                    "IPv4Address": "172.20.0.3/16",
                },
                "ada3d078989b568c6e060fa7bf62301b4bf55bed8ac1c938d514c81c42d8727a": {
                    "Name": "peer0.org1.example.com",
                    "IPv4Address": "172.20.0.5/16",
                }
            },
            "Labels": {}
        }
    

    2. Working as MagnetoCorp

    打开新窗口。

    (magnetocorp admin)$ cd commercial-paper/organization/magnetocorp/configuration/cli/
    (magnetocorp admin)$ sudo ./monitordocker.sh net_basic
    
    (magnetocorp admin)$ sudo ./monitordocker.sh net_basic <port_number>
    

    打开新窗口。

    (magnetocorp admin)$ cd commercial-paper/organization/magnetocorp/configuration/cli/
    (magnetocorp admin)$ sudo docker-compose -f docker-compose.yml up -d cliMagnetoCorp
    
    (magnetocorp admin)$ sudo docker ps
    
    CONTAINER ID        IMAGE                        COMMAND                  CREATED              STATUS              PORTS                                            NAMES
    562a88b25149        hyperledger/fabric-tools     "/bin/bash"              About a minute ago   Up About a minute                                                    cliMagnetoCorp
    b7f3586e5d02        gliderlabs/logspout          "/bin/logspout"          7 minutes ago        Up 7 minutes        127.0.0.1:8000->80/tcp                           logspout
    ada3d078989b        hyperledger/fabric-peer      "peer node start"        29 minutes ago       Up 29 minutes       0.0.0.0:7051->7051/tcp, 0.0.0.0:7053->7053/tcp   peer0.org1.example.com
    1fa1fd107bfb        hyperledger/fabric-orderer   "orderer"                29 minutes ago       Up 29 minutes       0.0.0.0:7050->7050/tcp                           orderer.example.com
    53fe614274f7        hyperledger/fabric-couchdb   "tini -- /docker-ent…"   29 minutes ago       Up 29 minutes       4369/tcp, 9100/tcp, 0.0.0.0:5984->5984/tcp       couchdb
    469201085a20        hyperledger/fabric-ca        "sh -c 'fabric-ca-se…"   29 minutes ago       Up 29 minutes       0.0.0.0:7054->7054/tcp                           ca.example.com
    

    3. Smart contract

    打开新窗口。

    (magnetocorp developer)$ cd commercial-paper/organization/magnetocorp/contract
    (magnetocorp developer)$ ls
    index.js  ledger-api  lib  package.json  package-lock.json  test
    

    4. Install contract

    (magnetocorp admin)$ sudo docker exec cliMagnetoCorp peer chaincode install -n papercontract -v 0 -p /opt/gopath/src/github.com/contract -l node
    

    5. Instantiate contract

    (magnetocorp admin)$ sudo docker exec cliMagnetoCorp peer chaincode instantiate -n papercontract -v 0 -l node -c '{"Args":["org.papernet.commercialpaper:instantiate"]}' -C mychannel -P "AND ('Org1MSP.member')"
    
    (magnetocorp admin)$ sudo docker ps
    
    CONTAINER ID        IMAGE                                              COMMAND                  CREATED             STATUS              PORTS          NAMES
    4fac1b91bfda        dev-peer0.org1.example.com-papercontract-0-d96...  "/bin/sh -c 'cd /usr…"   2 minutes ago       Up 2 minutes                       dev-peer0.org1.example.com-papercontract-0
    

    6. Application structure

    打开一个新窗口。

    (magnetocorp user)$ cd commercial-paper/organization/magnetocorp/application/
    (magnetocorp user)$ ls
    addToWallet.js      issue.js        package.json
    

    7. Application dependencies

    (magnetocorp user)$ npm install
    

    8. Wallet

    (isabella)$ node addToWallet.js
    
    done
    
    (isabella)$ ls ../identity/user/isabella/wallet/
    
    User1@org1.example.com
    
    (isabella)$ ls ../identity/user/isabella/wallet/User1@org1.example.com
    
    User1@org1.example.com      c75bd6911a...-priv      c75bd6911a...-pub
    

    9. Issue application

    (isabella)$ node issue.js
    
    Connect to Fabric gateway.
    Use network channel: mychannel.
    Use org.papernet.commercialpaper smart contract.
    Submit commercial paper issue transaction.
    Process issue transaction response.
    MagnetoCorp commercial paper : 00001 successfully issued for value 5000000
    Transaction complete.
    Disconnect from Fabric gateway.
    Issue program complete.
    

    10. Working as DigiBank

    打开新窗口。

    (digibank admin)$ cd commercial-paper/organization/digibank/configuration/cli/
    (digibank admin)$ sudo docker-compose -f docker-compose.yml up -d cliDigiBank
    
    (...)
    Creating cliDigiBank ... done
    
    CONTAINER ID        IMAGE                            COMMAND                  CREATED             STATUS              PORT         NAMES
    858c2d2961d4        hyperledger/fabric-tools         "/bin/bash"              18 seconds ago      Up 18 seconds                    cliDigiBank
    

    11. Digibank applications

    打开新窗口。

    (balaji)$ cd commercial-paper/organization/digibank/application/
    (balaji)$ ls
    
    addToWallet.js  buy.js  package.json  package-lock.json  redeem.js
    

    12. Run as DigiBank

    打开新窗口。

    (digibank admin)$ cd commercial-paper/organization/digibank/application/
    (digibank admin)$ npm install
    
    (            ) extract:lodash: sill extract ansi-styles@3.2.1
    (...)
    added 738 packages in 46.701s
    

    打开新窗口。

    (balaji)$ node addToWallet.js
    
    done
    

    13. Buy application

    (balaji)$ node buy.js
    
    Connect to Fabric gateway.
    Use network channel: mychannel.
    Use org.papernet.commercialpaper smart contract.
    Submit commercial paper buy transaction.
    Process buy transaction response.
    MagnetoCorp commercial paper : 00001 successfully purchased by DigiBank
    Transaction complete.
    Disconnect from Fabric gateway.
    Buy program complete.
    

    14. Redeem application

    (balaji)$ node redeem.js
    
    Connect to Fabric gateway.
    Use network channel: mychannel.
    Use org.papernet.commercialpaper smart contract.
    Submit commercial paper redeem transaction.
    Process redeem transaction response.
    MagnetoCorp commercial paper : 00001 successfully redeemed with MagnetoCorp
    Transaction complete.
    Disconnect from Fabric gateway.
    Redeem program complete.
    

    Reference

    项目源代码

    项目源代码会逐步上传到 Github,地址为 https://github.com/windstamp

    Contributor

    1. Windstamp, https://github.com/windstamp

    相关文章

      网友评论

        本文标题:5.2.1 Hyperledger Fabric - 教程 -

        本文链接:https://www.haomeiwen.com/subject/uhejgctx.html