For example,the data collection of the Internet of Things,5G transmission,big data processing,the use of artificial intelligence and the guarantee of blockchain,each technology only completes a part of the life cycle of data elements,and needs larger and more focused concepts,scenarios and business models to drive the further integration of the new generation of information technology,so as to build an infrastructure oriented to the digital ecosystem to support the complex application logic of the metauniverse Business innovation and business model.Therefore,from a technical point of view,Metauniverse is a trusted digital value interaction network based on the support of Web3.0 technology system and operation mechanism,a new Web3.0 digital ecosystem with blockchain as the core,and an important means to promote digital industrialization and industrial digitalization.
地址工具
用于检测某个地址是否为合约的工具
pragma solidity^0.4.24library AddressUtils{function isContract(address addr)internal view returns(bool){uint256 size;assembly{size:=extcodesize(addr)}//assembly指明后面程序为内联汇编。extcodesizs取得参数addr对应账户关联地址的EVM字节码长度。return size>0;//}}
这个合约是一个librray,只有一个函数isContract,且被声明为internal view.internal限制这个函数只能由import这个合约内部使用;view声明这个函数不会改变状态
限制子合约的余额
限制子合约以太币余额的基础合约
pragam solidity^0.4.24;contract LimitBlance{uint256 public limit;constructor(uint256 _limit)public{limit=_limit;}modifier limitedPayable{require(address(this).blance<=limit);_;}}
安全算术(SafeMath.sol)
对uint256类型进行算术四则运算的库,也是最常用库,防止溢出。
pragma solidity^0.4.24;library SafeMath{function mul(uint256 _a,uint256 _b)internal pure returns(uint256 c){if(_a==0){//a==0比a!=0便宜。原因:=只执行了一个EVM判断return 0;}c=_a_b;assert(c/_a==_b);//_a_b结果可能超过最大值,判断有没有溢出。return c;}function div(uint256 _a,uint256 _b)internal pure returns(uint256){return _a/_b;//结果不为整,小数会被舍弃。}function sub(uint256 _a,uint256 _b)internal pure returns(uint256 c){assert(_a>=_b);//防止下溢(2^256+_a-_b)return _a-_b;}function add(uint256 _a,uint256 _b)internal pure returns(uint256 c){c=_a+_b;assert(c>=_b);//防止上溢((a+b)mod 2^256)return c;}}
自省(ERC165)
这是一个向外界提供一个特定函数的基础合约,这个函数可以用来查询合约支持的接口(函数)。
pragma solidity^0.4.24;interface ERC165{function supportsInterface(bytes64 _interfaceId)external//外部函数view//不会修改状态returns(bool);}//gas消耗控制在30000以内
_interfaceId函数选择器,是合约某个函数的标识(合约函数调用数据的前4个字节)
接口查找基础合约
pragma solidity^0.4.24;contract SupportsInterfaceWithLiikUp is ERC165{bytes4 public constant InterfaceId_ERC165=0x01ffc9a7;//0x01ffc9a7===bytes4(keccak256('SupportsInterface(bytes4)'))mapping(bytes4=>bool)internal supportsInterfaces;constructor()public{_registerInterface(InterfaceId_ERC165);}function _registerInterface(bytes4 _interfaceId)internal{require(interfaceId!=0xffffffff);supportsInterface[_interfaceId]=true;}}