最近在写合约时遇到一些坑,作一下总结;java
介绍主要分一下三个方面:git
进入正题以前,我稍微简单介绍一下什么是区块链,区块链干吗用的(特色),智能合约是作什么的,为何要写只能合约(一下是我的理解仅供参考)github
A blockchain is a globally shared, transactional database.算法
译文:区块链是一个全局共享的事物数据库;(就是个数据库)数据库
既然当前区块链这么火,那么总要有火的理由吧,它到底用来干什么的呢?而体现区块链自己的商业价值,说白了就是能靠它的独有的特色赚钱;数组
A contract in the sense of Solidity is a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereum blockchain.网络
译文:Solidity意义上的合约是代码(其功能)和数据(其状态)的集合,它位于以太坊区块链的特定地址。分布式
关键字:code (its functions) 、 data (its state)、addresside
在写合约时遇到一下几个问题; 其实这些问题google上都能查到,但也是须要大量时间,有些还不必定对,小编对下述问题作一个总结与概括;之后也给本身方便;函数
答:Yes, but only in internal function calls.
使用 internal 时,与平时的 function 写法同样便可
答:You have to do it manually for now.
说白了就是没有,要本身实现; 方案1:https://github.com/Arachnid/solidity-stringutils/blob/master/src/strings.sol
方案2:这是小编根据google查得作了一些小改的,仅供参考
/// 内部访问函数,internal /// 实现将string _a, _b1,_b2,_c拼接成一个string function strConcat(string _a, bytes1 _b1,bytes1 _b2, string _c) internal pure returns (string){ bytes memory _ba = bytes(_a); bytes memory _bc = bytes(_c); string memory abcde = new string(_ba.length + _b1.length + _b2.length + _bc.length); bytes memory babcde = bytes(abcde); uint k = 0; for (uint i = 0; i < _ba.length; i++) babcde[k++] = _ba[i]; for (i = 0; i < _b1.length; i++) babcde[k++] = _b1[i]; for (i = 0; i < _b2.length; i++) babcde[k++] = _b2[i]; for (i = 0; i < _bc.length; i++) babcde[k++] = _bc[i]; return string(babcde); }
答:能够,但不能返回动态数组; 什么意思呢,就是说能够 int[] uint[] 等等,若是是string[] 则须要给string []定length长度,不然编译失败; 那么业务上就须要 returns(string[])怎么办? 小编的解决方案是return string来代替,将每个string拼接起来,拼接符能够用ASCII码中不可见字符如:0x01,0x02等等,千万别用常见字符;(以前作hyperledger fabric的java sdk解析时发现也用到了)
说明编码这里顺带说一句,
All identifiers(contract names,function names and variable names) are restricted to the ASCII character set. It is possible to store UTF-8 encoded data in string variables.
答:The address type is a 160-bit value that does not allow any arithmetic operations.
答:据我所知,没有影响,由于对evm来讲它只是执行了,solidity经过solc编译以后产生的bin、abi文件,进行编译;
solidity的版本若高于solc编译环境的版本则会没法编译
本文篇幅没啥干货,就随意聊聊浅谈一下;