EOS 學習階段性總結
來自專欄 EOS中文
dawn3.0編譯過程參考https://github.com/eosio/eos Paywall
```shell
# 創建默認錢包
./cleos wallet create
# 設置基礎配置智能合約:eosio.bios
./cleos set contract eosio ../../contracts/eosio.bios -p eosio -j
# 設置系統智能合約:eosio.system 部署了該智能合約,eosio賬戶才可以改包括自己在內的所有賬戶發行EOS token,才可以執行,註冊producer,投票者下注,投票等操作
./cleos set contract eosio ../../contracts/eosio.system -j
# 給eosio賬戶發行EOS token 10個億
./cleos push action eosio issue {"to":"eosio","quantity":"1000000000.0000 EOS"} --permission eosio@active -j
# 創建兩組密鑰對
./cleos create key
#keypair1
#Private key: 5JZ5Wwb8uQbi3A7DmMsD2zevcKCYw1pxmitij1x4xCjU8gv7ucj
#Public key: EOS6a5pr4DS4CksCQSHqTdKMPbAdCyrE4b7QExDwTuCxH1vbkYMqG
#keypair2
#Private key: 5JKkei9CFtawsvnHt728DUQaahcjHm5nqJsNgZzna9XZKq8eA5c
#Public key: EOS5NiFNF4bG7T49S6f7qVXMAt4RN2WM211s77UZrwD4cz2Xu6gw9
# 導入密鑰到默認錢包
./cleos wallet import 5JZ5Wwb8uQbi3A7DmMsD2zevcKCYw1pxmitij1x4xCjU8gv7ucj
./cleos wallet import 5JKkei9CFtawsvnHt728DUQaahcjHm5nqJsNgZzna9XZKq8eA5c
# 查看錢包中的密鑰對
./cleos wallet keys
# 創建賬戶 currency
./cleos create account eosio currency EOS6a5pr4DS4CksCQSHqTdKMPbAdCyrE4b7QExDwTuCxH1vbkYMqG EOS5NiFNF4bG7T49S6f7qVXMAt4RN2WM211s77UZrwD4cz2Xu6gw9 -j
# 設置currency的智能合約
./cleos set contract currency ../../contracts/currency -j
# currency 創建合約token CUR 最大發行量10個億
./cleos push action currency create {"issuer":"currency","maximum_supply":"1000000000.0000 CUR","can_freeze":0,"can_recall":0,"can_whitelist":0} --permission currency@active -j
# 給currency賬戶發行 10萬 CUR
./cleos push action currency issue {"to":"currency","quantity":"100000.0000 CUR","memo":""} --permission currency@active -j
```
```shell
# 查詢 currency 賬戶中CUR tokenr的總量
./cleos get currency balance currency currency
# currency token 轉賬
./cleos push action currency transfer {"from":"currency","to":"eosio","quantity":"200.0000 CUR","memo":"my first transfer"} --permission currency@active -j
# 查詢餘額 CUR
./cleos get currency balance currency eosio
./cleos get currency balance currency currency
# EOS token 轉賬有問題,轉賬可以成功,餘額查詢為空,原來這是EOS的一個BUG,
#eosio 給currency 轉賬 EOS幣後,currency餘額查不到,eosio有兩個餘額
#然後currency 再給eosio轉帳0個EOS,再查餘額,一切正常。
./cleos transfer eosio currency 100000000 -j
# 查詢餘額 EOS,eosio賬戶會有兩個餘額,currency賬戶是空的
./cleos get currency balance eos eosio
./cleos get currency balance eos currency
# 執行這個迴轉0,後面查詢就正確了
./cleos transfer currency eosio 0 -j
# 查詢餘額 EOS 一切正常
./cleos get currency balance eos eosio
./cleos get currency balance eos currency
```
如果還是不正常,可能需要修改chain_plugin.cpp文件 321行開始,get_currency_balance修改成下面這樣
```java
vector<asset> read_only::get_currency_balance( const read_only::get_currency_balance_params& p )const {
vector<asset> results;
if (p.code.to_string() == "eos") {
const auto& d = db.get_database();
auto &kvi = d.get_index<contracts::key_value_index>().indices();
for (auto ite = kvi.begin(); ite != kvi.end(); ++ite) {
if (ite->id._id > 1){
if (p.account == ite->payer){
share_type balance;
fc::datastream<const char *> ds(ite->value.data(), ite->value.size());
fc::raw::unpack(ds, balance);
auto cursor = asset(balance, symbol(ite->primary_key));
if (cursor.symbol_name() == "EOS"){
results.emplace_back(balance, symbol(ite->primary_key));
}
//ilog("account:${payer}",("payer",p.account));
//ilog("${payer}:${cursor};id:${id};t_id:${t_id}",
// ("payer",ite->payer)("cursor",cursor)("id",ite->id._id)("t_id",ite->t_id._id));
}
}
}
} else {
walk_table<contracts::key_value_index, contracts::by_scope_primary>(p.code, p.account, N(accounts), [&](const contracts::key_value_object& obj){
share_type balance;
fc::datastream<const char *> ds(obj.value.data(), obj.value.size());
fc::raw::unpack(ds, balance);
auto cursor = asset(balance, symbol(obj.primary_key));
if( !p.symbol || cursor.symbol_name().compare(*p.symbol) == 0 ) {
results.emplace_back(balance, symbol(obj.primary_key));
}
// return false if we are looking for one and found it, true otherwise
return !p.symbol || cursor.symbol_name().compare(*p.symbol) != 0;
});
}
return results;
}
```
```shell
# 下面的命令的註冊礦工、押注、投票、使礦工開始工作,並撤銷押注,礦工停止工作的命令,只是命令實例
# 可以寫腳本生成52個賬戶,26個投票,另外26個註冊成producer
# 然後 投票賬戶押注
# 最後一對一投票,可實現21個礦工輪流出塊。
# 如需筆者提供腳本,可以@我 caokun_8341@sina.com
# 創建三個賬戶,一個用來投票vo.a,另外兩個是礦工 bp.a,bp.b
# 先導入三對私鑰,用來創建三個賬戶,使用默認錢包
# 導入bp.a的私鑰
./cleos wallet import 5KXWvLDQnqyDkGwSNhpJc9rWdYdxGHMXSCfyRsaezfWhNxGT8ag
./cleos wallet import 5JaWKNP1uyfxNey6U2T1rJ1GuqakNQCeJ7pmsomL2vf67HQS9nE
# 導入bp.b的私鑰
./cleos wallet import 5J8YadJ1Y2HhSRamPMDUNQnSM95BfDiCBiEf1NrAooi9LQAsDUC
./cleos wallet import 5JXUfyVAmMh6sSxNXAdLzk3rDwjyMh8cspWcpD7rPSvHy4c3QFV
# 導入vo.a的私鑰
./cleos wallet import 5JPkqi92pc7B6CH2Hftn27BvA6cu1vswUKANLWJ2Fobjg9X3CCq
./cleos wallet import 5JbioArDrpG6EnUp6qtgxHUFTTjBNYiLsr3wzPuCxBzDy7U3B3y
# 創建三個賬戶 bp.a bp.b vo.a
./cleos create account eosio bp.a EOS8dtXWZQWqSv4mk3WPrpMKGywA5pBY1MWxbpSGSLVvV4k98kvxs EOS7fhfs1j5BBQC9bsM5c8c2WZy6NPG6mbAGMuuYJCnKNHfb3vrND
./cleos create account eosio bp.b EOS7PcVKaTP9sLPv8Hff55y3qiLyNtz1vtDtrSdF2DGigmwiMgqCp EOS5nqrTB9Tj4B41AUrHPUf7sfnN1r25b6v6qtYM57n74bpqwXd3e
./cleos create account eosio vo.a EOS6aGsSSs36TytGdwaSb6WN6Jayr5uL5FqqJi97oDSSz7puqNtCu EOS7zKxE4HNRboD2SeZHUcKGbinquBim4FtAqoWJtcQFPQjiZ83bh
# 給三個賬戶發放EOS token
./cleos push action eosio issue {"to":"bp.a","quantity":"10000.0000 EOS"} --permission eosio@active
./cleos push action eosio issue {"to":"bp.b","quantity":"10000.0000 EOS"} --permission eosio@active
./cleos push action eosio issue {"to":"vo.a","quantity":"10000.0000 EOS"} --permission eosio@active
# bp.a bp.b 註冊礦工 producer_key 需要把對應賬戶的producer_key active 公鑰轉換成16進位編碼
./cleos push action eosio regproducer {"producer":"bp.a","producer_key":"00036e0d69f6d267173ff478815c077bc8f34b24bc687e81f4dec22c4dd6e2fb37b3","prefs":{"base_per_transaction_net_usage":102,"base_per_transaction_cpu_usage":102,"base_per_action_cpu_usage":102,"base_setcode_cpu_usage":102,"per_signature_cpu_usage":102,"per_lock_net_usage":102,"context_free_discount_cpu_usage_num":3,"context_free_discount_cpu_usage_den":102,"max_transaction_cpu_usage":1000002,"max_transaction_net_usage":1000002,"max_block_cpu_usage":10000002,"target_block_cpu_usage_pct":12,"max_block_net_usage":10000002,"target_block_net_usage_pct":12,"max_transaction_lifetime":3602,"max_transaction_exec_time":9902,"max_authority_depth":8,"max_inline_depth":6,"max_inline_action_size":4098,"max_generated_transaction_count":12,"percent_of_max_inflation_rate":52,"storage_reserve_ratio":102}} --permission {eosio@active,bp.a@active}
./cleos push action eosio regproducer {"producer":"bp.b","producer_key":"000276dff979ee0ab622c57577e5ce70041eeae33cdf1d4a00803bebc6dbeaaa5a13","prefs":{"base_per_transaction_net_usage":102,"base_per_transaction_cpu_usage":102,"base_per_action_cpu_usage":102,"base_setcode_cpu_usage":102,"per_signature_cpu_usage":102,"per_lock_net_usage":102,"context_free_discount_cpu_usage_num":3,"context_free_discount_cpu_usage_den":102,"max_transaction_cpu_usage":1000002,"max_transaction_net_usage":1000002,"max_block_cpu_usage":10000002,"target_block_cpu_usage_pct":12,"max_block_net_usage":10000002,"target_block_net_usage_pct":12,"max_transaction_lifetime":3602,"max_transaction_exec_time":9902,"max_authority_depth":8,"max_inline_depth":6,"max_inline_action_size":4098,"max_generated_transaction_count":12,"percent_of_max_inflation_rate":52,"storage_reserve_ratio":102}} --permission {eosio@active,bp.b@active}
# vo.a 押注
./cleos push action eosio delegatebw {"from":"vo.a","receiver":"vo.a","stake_net":"100.0000 EOS","stake_cpu":"100.0000 EOS","stake_storage":"0.0000 EOS"} --permission vo.a@active
# vo.a給 bp.a 投票
./cleos push action eosio voteproducer {"voter":"vo.a","proxy":"","producers":["bp.a"]} --permission vo.a@active
# vo.a給 bp.b 投票
./cleos push action eosio voteproducer {"voter":"vo.a","proxy":"","producers":["bp.b"]} --permission vo.a@active
# 查vo.a的餘額
./cleos get currency balance eos vo.a
#減少押注
./cleos push action eosio undelegatebw {"from": "vo.a","receiver": "vo.a","unstake_net": "299.0000 EOS","unstake_cpu": "299.0000 EOS","unstake_bytes": 0} --permission vo.a@active
# 查vo.a的餘額
./cleos get currency balance eos vo.a
#減少押注
./cleos push action eosio undelegatebw {"from": "vo.z","receiver": "vo.z","unstake_net": "1.0000 EOS","unstake_cpu": "1.0000 EOS","unstake_bytes": 0} --permission vo.z@active
# 取消礦工註冊
./cleos push action eosio unregprod {"producer":"bp.a"} --permission {eosio@active,bp.a@active}
./cleos push action eosio unregprod {"producer":"bp.b"} --permission {eosio@active,bp.b@active}
```
結論性總結:
1. 首先需要創建個錢包,才可以做其它操作
2. 如果要進行EOS token 發行,轉賬,超級節點註冊,投票人押注,投票等操作,部署eosio.bios和eosio.system這兩個系統合約是必要前提
3. 需要生成密鑰,並導入到錢包,才可創建賬戶
4. procucer 工作前要現創建賬戶,再註冊成為producer,可以腳本實現批量生成密鑰和創建賬戶
5.投票人投票前需要先押注
6. 使用相關命令使21個producer正常工作
7. 在prodcuer滿21個工作的時候,投票人撤銷下注,對應的producer停止工作;在只有一個producer工作的情況下,投票人撤銷下注,prodcuer的工作不會停止
8. 21個producer 工作過程中,按照對應投票人押注的多少,確定打塊順序,一人12打個塊,打完就走,等待下輪
9. 投票人可以隨時增加押注,也可以減少押注,減少的部分代幣不會立即回到賬戶
10. 隨著投票人押注多少的變化打塊順序會有相應調整
11. 如果備選的producers中有某一個支持者(投票人)的押注數量超過目前當選的21個producer中的至少一個prodcuer,被超過的那個當前producer會被超過他的備選producer替換
12. 總之投票可以是一直在進行的,當前21個producer,隨時有可能被替換
13. 有人說EOS 只有21個超級節點產生區塊數據,並非真正的去中心化,其實我覺得:投票不止,替換不息。
文章地址:
EOS 學習階段性總結 · eosfans-EOS中文社區推薦閱讀:
※空投糖果騙局大剖析,都在這裡
※HelloEOS梓岑專訪:分紅是最懶惰的處理節點收益的方式
※EOS是BTC的 側鏈?
※中文版|EOS.IO技術白皮書第二版
※EOS大跌早在意料之中,不聽老狼言,吃虧在眼前!5月1日行情分析