1. 程式人生 > >EOS學習筆記(三)- 智慧合約

EOS學習筆記(三)- 智慧合約

環境:自己啟動的單測試節點

注意:

1.一個賬號只能釋出一個合約,釋出多個會導致呼叫合約的時候出錯,具體原因需要檢視原始碼,或者是我的使用方法不正確

2.一個key可以繫結多個錢包和賬戶

3.同一個賬號同一個合約可以更新

*4.合約中的資料庫儲存結構在第一次的時候要設計好,否則以後如果對儲存結構擴充套件會報資料越界的錯誤:(Failed with error: Out of Range (8)),可以減少,不能增加,如果要擴充套件,參考下面的方法:https://eosio.stackexchange.com/questions/481/best-practice-to-handle-table-migrations#

[When making structural changes to tables there are 2 basic approaches:
1add versioning in the data from day 1 and then support old versions of the data well enough to do "just in time" upgrades.
2deploy a migration contract in-between version N and N+1 which can read the data and convert it, OR ingests transactions with data converted in an out-of-chain process; then issue the setcode with the N+1 code.

Both of these require some pre-planning (like the ability to put your contract into a maintenance mode for user feedback)]

大概就是說加版本控制,對舊資料結構不修改,新增新的一個數據結構,處理的時候自己把舊資料同步到新結構裡。

但是這個可以:uint32_t value; => uint16_t value1; uint16_t value2;

這樣在get table的時候就不會出現上面的錯誤。


官方參考文件:https://github.com/EOSIO/eos/wiki/Programs-&-Tools#eosiocpp

參考文件2:https://eosfans.io/wiki/smart-contracts


補充:

1.除錯可以使用eosio::print列印除錯資訊,前提是得在config.ini(預設路徑:~/.local/share/eosio/nodeos/config)裡修改contracts-console的值為true

2.可下斷點除錯合約,我沒試過

https://github.com/learnforpractice/pyeos

3.Action是合約和賬戶之間進行通訊的方式。
Action名字約束:Action的型別是 base32被編碼為64-bit整數. 這意味著它的字符集長度是12,並且只能包含a-z,1-5,和'.'。 如果長度超過12個,他會自動擷取前12個符合規則的字元作為action的名字(原文是:If there is a 13th character then it is restricted to the first 16 characters ('.' and a-p).,應該是寫錯了)