EOS開發教程(3.1):啟動序列(2)

in #eoslast month
  1. “perhaps we need to replay”:當妳重啟nodeos時缺少 — hard-replay參數,就會報這個錯誤, — hard-replay參數會重放所有從創世節點發出的轉賬。要修復這個錯誤,需要在hard_replay.sh shell腳本中加入 — hard-replay參數。
    可以用來重啟nodeos的其他參數為:
    · — truncate-at-block
    · — delete-all-blocks
    · — replay-blockchain
    · — hard-replay-blockchain
    下面是使用了 — hard-replay-blockchain參數的hard_replay.sh shell腳本:
    #!/bin/bashDATADIR=”./blockchain”
    if [ ! -d $DATADIR ]; then
    mkdir -p $DATADIR;fi
    nodeos
    — signature-provider EOS_PUB_DEV_KEY=KEY:EOS_PRIV_DEV_KEY
    — plugin eosio::producer_plugin
    — plugin eosio::producer_api_plugin
    — plugin eosio::chain_plugin
    — plugin eosio::chain_api_plugin
    — plugin eosio::http_plugin
    — plugin eosio::history_api_plugin
    — plugin eosio::history_plugin
    — data-dir $DATADIR”/data”
    — blocks-dir $DATADIR”/blocks”
    — config-dir $DATADIR”/config”
    — producer-name eosio
    — http-server-address 127.0.0.1:8888
    — p2p-listen-endpoint 127.0.0.1:9010
    — access-control-allow-origin=*
    — contracts-console
    — http-validate-host=false
    — verbose-http-errors
    — enable-stale-production
    — p2p-peer-address localhost:9011
    — p2p-peer-address localhost:9012
    — p2p-peer-address localhost:9013
    — hard-replay-blockchain >> $DATADIR”/nodeos.log” 2>&1 & \echo $! > $DATADIR”/eosd.pid”
    從零開始重啟nodeos
    復制下面的內容,創建壹個shell腳本clean.sh 然後賦予它執行權限:
    #!/bin/bash
    rm -fr blockchain
    ls -al
    如果妳想刪除當前的配置,區塊鏈數據,以及日誌,首先運行stop.sh腳本,然後運行clean.sh腳本,clean.sh腳本通過使用下面的內容創建:
    cd ~/biosboot/genesis/
    ./stop.sh
    ./clean.sh
    ./genesis_start.sh
    1.6. 查看 nodeos.log 文件
    使用下面的命令查看nodeos.log文件,使用CTRL+C退出.
    cd ~/biosboot/genesis/
    tail -f ./blockchain/nodeos.log
    1.7. 創建重要的系統賬號
    有些系統賬號是必需的,名字如下:
    eosio.bpay
    eosio.msig
    eosio.names
    eosio.ram
    eosio.ramfee
    eosio.saving
    eosio.stake
    eosio.token
    eosio.vpay
    eosio.rex
    重復以下步驟,創建每壹個系統賬號。在本例中,對於賬號的owner和active密鑰我們將使用相同的密鑰對,所以我們只需要在命令行中提供壹次密鑰值。對於多數普通賬號的owner和active密鑰,最好使用不同的密鑰對。腳本對所有的eosio*賬號都使用相同的密鑰。妳可以對不同的賬號使用不同的密鑰。
    cleos create key — to-console
    Private key: 5KAVVPzPZnbAx8dHz6UWVPFDVFtU1P5ncUzwHGQFuTxnEbdHJL4
    Public key: EOS84BLRbGbFahNJEpnnJHYCoW9QPbQEk2iHsHGGS6qcVUq9HhutG
    cleos wallet import — private-key
    5KAVVPzPZnbAx8dHz6UWVPFDVFtU1P5ncUzwHGQFuTxnEbdHJL4
    imported private key for: EOS84BLRbGbFahNJEpnnJHYCoW9QPbQEk2iHsHGGS6qcVUq9HhutG
    cleos create account eosio eosio.bpay EOS84BLRbGbFahNJEpnnJHYCoW9QPbQEk2iHsHGGS6qcVUq9HhutG
    executed transaction: ca68bb3e931898cdd3c72d6efe373ce26e6845fc486b42bc5d185643ea7a90b1 200 bytes 280 us

eosio <= eosio::newaccount {“creator”:”eosio”,”name”:”eosio.bpay”,”owner”:{“threshold”:1,”keys”:[{“key”:”EOS84BLRbGbFahNJEpnnJH…

1.8. 創建eosio合約
要創建eosio.contracts合約,先為這個合約創建壹個文件夾,克隆eosio.contracts源並創建它們。在終端打印當前的文件夾,並做個標記。當前的文件夾將被稱作EOSIO_CONTRACTS_DIRECTORY。
cd ~
git clone https://github.com/EOSIO/eosio.contracts.git
cd ./eosio.contracts/
./build.sh
cd ./build/contracts/
pwd
妳還需要壹個舊版的eosio.contracts合約,尤其是v1.8.0.使用下面的指令來創建它,並記下它的路徑:

  1. 要安裝1.6.3版的eosio.cdt,請參看安裝eosio.cdt二進制文件教程。
  2. 1.6.3版eosio.cdt安裝完成之後,妳就可以編譯舊版的eosio.contracts了:
    cd ~
    git clone https://github.com/EOSIO/eosio.contracts.git eosio.contracts-1.8.x
    cd ./eosio.contracts-1.8.x/
    git checkout release/1.8.x
    ./build.sh
    cd ./build/contracts/
    pwd
    記下打印出來的本地路徑,我們把這個文件夾稱為EOSIO_OLD_CONTRACTS_DIRECTORY.
  3. 把eosio.cdt版本恢復到本教程開始時安裝的版本.
    1.9. 安裝 eosio.token 合約
    現在我們開始設置eosio.token合約。這個合約能讓妳創建,發行,傳送,以及獲取token的相關信息。要設置eosio.toekn合約,需要執行下面的命令:
    cleos set contract eosio.token EOSIO_CONTRACTS_DIRECTORY/eosio.token/
    它會輸出:
    Reading WAST/WASM from /users/documents/eos/contracts/eosio.token/eosio.token.wasm…
    Using already assembled WASM…
    Publishing contract…
    executed transaction: 17fa4e06ed0b2f52cadae2cd61dee8fb3d89d3e46d5b133333816a04d23ba991 8024 bytes 974 us

eosio <= eosio::setcode {“account”:”eosio.token”,”vmtype”:0,”vmversion”:0,”code”:”0061736d01000000017f1560037f7e7f0060057f7e…

eosio <= eosio::setabi {“account”:”eosio.token”,”abi”:{“types”:[],”structs”:[{“name”:”transfer”,”base”:””,”fields”:[{“name”…

1.10. 設置 eosio.msig 合約
eosio.msig合約能並簡化定義和管理許可層級,以及執行多簽名action。要設置eosio.msig合約,需要執行下面的命令:
cleos set contract eosio.msig EOSIO_CONTRACTS_DIRECTORY/eosio.msig/
它會輸出:
Reading WAST/WASM from /users/documents/eos/build/contracts/eosio.msig/eosio.msig.wasm…
Using already assembled WASM…
Publishing contract…
executed transaction: 007507ad01de884377009d7dcf409bc41634e38da2feb6a117ceced8554a75bc 8840 bytes 925 us

eosio <= eosio::setcode {“account”:”eosio.msig”,”vmtype”:0,”vmversion”:0,”code”:”0061736d010000000198011760017f0060047f7e7e7…

eosio <= eosio::setabi {“account”:”eosio.msig”,”abi”:{“types”:[{“new_type_name”:”account_name”,”type”:”name”}],”structs”:[{…

1.11. 創建並分配SYS 代幣
創建SYS代幣,它的最大數量為100億。然後,發行10億代幣。可以把SYS替換為妳指定的代幣.

  1. 第壹步,eosio.token合約的create action,由eosio.token賬號授權,使用eosio賬號創建10億代幣。這樣就創建了代幣,但沒有把代幣投入市場進行流通。沒有流通的代幣可以當作儲備。
    cleos push action eosio.token create ‘[ “eosio”, “10000000000.0000 SYS” ]’ -p [email protected]
    它的輸出:
    executed transaction: 0440461e0d8816b4a8fd9d47c1a6a53536d3c7af54abf53eace884f008429697 120 bytes 326 us

eosio.token <= eosio.token::create {“issuer”:”eosio”,”maximum_supply”:”10000000000.0000 SYS”}

  1. 第二步中,eosio.token合約的issue action從儲備中拿出1億SYS代幣,把它們投入流通。在發行的時候,這些代幣由eosio賬號持有。由於eosio賬號持有未流通代幣,要執行這個action就需要取得它的授權.
    cleos push action eosio.token issue ‘[ “eosio”, “1000000000.0000 SYS”, “memo” ]’ -p [email protected]
    輸出:
    executed transaction: a53961a566c1faa95531efb422cd952611b17d728edac833c9a55582425f98ed 128 bytes 432 us

eosio.token <= eosio.token::issue {“to”:”eosio”,”quantity”:”1000000000.0000 SYS”,”memo”:”memo”}

註意
從經濟的角度來看,從利益的角度來看,通過發行代幣等方式將代幣從儲備轉為流通是壹種通脹行為。發行代幣只是通脹發生的壹種方式。
1.12. 設置eosio.system 合約
激活 PREACTIVATE_FEATURE 協議
v1.8和v2.0中引入的所有協議升級功能首先需要激活壹個特殊的協議功能(代號為PREACTIVATE_FEATURE),並且需要使用該功能引入的功能進行部署的系統合約的更新版本。.
要激活 PREACTIVATE_FEATURE協議,妳需要:
curl — request POST
— url http://127.0.0.1:8888/v1/producer/schedule_protocol_feature_activations
-d ‘{“protocol_features_to_activate”: [“0ec7e080177b2c02b278d5088611686b49d739925a92d9bfcacd7fc6b74053bd”]}’
設置 eosio.system 合約
系統合約為所有基於代幣的操作行為提供action。在安裝系統合約之前,action就會獨立地完成計數。壹旦系統合約可以使用,對於它們來說action就有了經濟元素。需要支付系統資源(CPU,網絡,內存)以及新賬號。系統合約允許抵押代幣以及解除抵押,允許購買資源,允許註冊潛在的生產者,允許投票,認領生產回報,設置優先權以及限制等等功能.
在第壹階段,我們將安裝舊版本的eosio.system合約.
cleos set contract eosio EOSIO_OLD_CONTRACTS_DIRECTORY/eosio.system/
Reading WAST/WASM from /users/documents/eos/build/contracts/eosio.system/eosio.system.wasm…
Using already assembled WASM…
Publishing contract…
executed transaction: 2150ed87e4564cd3fe98ccdea841dc9ff67351f9315b6384084e8572a35887cc 39968 bytes 4395 us

eosio <= eosio::setcode {“account”:”eosio”,”vmtype”:0,”vmversion”:0,”code”:”0061736d0100000001be023060027f7e0060067f7e7e7f7f…

eosio <= eosio::setabi {“account”:”eosio”,”abi”:{“types”:[],”structs”:[{“name”:”buyrambytes”,”base”:””,”fields”:[{“name”:”p…

開啟功能
在妳設置了eosio.system合約之後,運行下面的命令,開啟剩下的功能,我們強烈建議妳開啟這些功能,如果妳要使用EOSIO區塊鏈的話。.
註意:開啟這些功能是可選的。妳可以開啟或者不開啟這些功能。.

GET_SENDER

cleos push action eosio activate ‘[“f0af56d2c5a48d60a4a5b5c903edfb7db3a736a94ed589d0b797df33ff9d3e1d”]’ -p eosio

FORWARD_SETCODE

cleos push action eosio activate ‘[“2652f5f96006294109b3dd0bbde63693f55324af452b799ee137a81a905eed25”]’ -p eosio

ONLY_BILL_FIRST_AUTHORIZER

cleos push action eosio activate ‘[“8ba52fe7a3956c5cd3a656a3174b931d3bb2abb45578befc59f283ecd816a405”]’ -p eosio

RESTRICT_ACTION_TO_SELF

cleos push action eosio activate ‘[“ad9e3d8f650687709fd68f4b90b41f7d825a365b02c23a636cef88ac2ac00c43”]’ -p eosio

DISALLOW_EMPTY_PRODUCER_SCHEDULE

cleos push action eosio activate ‘[“68dcaa34c0517d19666e6b33add67351d8c5f69e999ca1e37931bc410a297428”]’ -p eosio

FIX_LINKAUTH_RESTRICTION

cleos push action eosio activate ‘[“e0fb64b1085cc5538970158d05a009c24e276fb94e1a0bf6a528b48fbc4ff526”]’ -p eosio

REPLACE_DEFERRED

cleos push action eosio activate ‘[“ef43112c6543b88db2283a2e077278c315ae2c84719a8b25f25cc88565fbea99”]’ -p eosio

NO_DUPLICATE_DEFERRED_ID

cleos push action eosio activate ‘[“4a90c00d55454dc5b059055ca213579c6ea856967712a56017487886a4d4cc0f”]’ -p eosio

ONLY_LINK_TO_EXISTING_PERMISSION

cleos push action eosio activate ‘[“1a99a59d87e06e09ec5b028a9cbb7749b4a5ad8819004365d02dc4379a8b7241”]’ -p eosio

RAM_RESTRICTIONS

cleos push action eosio activate ‘[“4e7bf348da00a945489b2a681749eb56f5de00b900014e137ddae39f48f69d67”]’ -p eosio

WEBAUTHN_KEY

cleos push action eosio activate ‘[“4fca8bd82bbd181e714e283f83e1b45d95ca5af40fb89ad3977b653c448f78c2”]’ -p eosio

WTMSIG_BLOCK_SIGNATURES

cleos push action eosio activate ‘[“299dcb6af692324b899b39f16d5a530a33062804e41f09dc97e9f156b4476707”]’ -p eosio
部署
現在部署最新版的eosio.system合約:
cleos set contract eosio EOSIO_CONTRACTS_DIRECTORY/eosio.system/