1、谈谈区块链(36)-深入理解以太坊智能合约作者简介:谈国鹏,比特宝()创始人,最早比特币支付的探索者。一直从事比特币、以太坊、hyperledger等区块链研究探索工作,现任*集团区块链研发负责人。微信公众号 微信公众号:ttblockchain加入小密圈 小密圈:谈谈区块链课程大纲 Internal function call vs message call .call Exceptions Contract Constant keyword & web3.js Fallback函数 Msg.sender vs tx.originInternal function call vs messa
2、ge call stack based EVM This 关键字 不能用于构造函数中 Public/private External/internal Message call 1024 restriction Internal function has no restriction Can have infinite loops (restricted by gas limit).call .value() .gas() Payable 能知道ABI的情况下用类似于: feed.info.value(10).gas(800)() 不要用call 尽量使用send()而不是call()来发送e
3、ther 安全问题 http:/solidity.readthedocs.io/en/develop/types.html发送ether问题 通过transaction发送ether 普通帐户,收气21000 合约账户,收气21000 + fallback函数花费(一般小于2300) 通过message call发送ether 直接发送 .send() .call.value()() 间接发送 相应函数必须是payable someContract.sendPayableMethod.value()()exceptions Exception effect: The current messa
4、ge call is stopped and reverted The gas transferred to this call is ALL consumed Manual throw: Examples in http:/solidity.readthedocs.io/en/develop/control-structures.html Exception is not yet accessiblecontract Inhert from address Create contract Form web3.js (by sending a transaction to 0 address)
5、 From new keyword inside smart contract return new OwnedToken(name); 支持继承 contract named is owned, mortal 继承是代码拷贝 支持abstruct contract(和interface) https:/ keyword & web3.js Constant keyword used to determine: myContractInstance.myMethod myContractInstance.myMethod.call myContractInstance.myMethod.sen
6、dTransaction https:/ethereum.gitbooks.io/frontier-guide/content/web3.html#web3ethsendtransaction Call vs sendTransaction consensus rule Compare with fabric 1.0 endorsement policy Fallback函数 当交易payload中指定的函数找不到,或没有指定时,执行fallback函数 E.g. send ether 默认情况不能超过2300气,否则exception .call()则传递所有气(可以超过2300) Fallback不是必须的 当需要接收ether则必须有fallback(不考虑通过其它payable函数接收ether)Msg.sender vs tx.origin http:/solidity.readthedocs.io/en/develop/security-considerations.html 总是使用msg.sender,不使用tx.origin完整视频 微信公众号:ttblockchain 微博: 巴比特专栏:http:/ 优酷视频:搜索“谈谈区块链”