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).,应该是写错了)

猜你喜欢

转载自blog.csdn.net/GrimRaider/article/details/80743290
今日推荐