zoukankan      html  css  js  c++  java
  • smart contract 知识点

    知识点

    memory vs storage vs stack

    • storage , where all the contract state variables reside. Every contract has its own storage and it is persistent between function calls and quite expensive to use.

    • memory , this is used to hold temporary values. It is erased between (external) function calls and is cheaper to use.

    • stack , which is used to hold small local variables. It is almost free to use, but can only hold a limited amount of values.

    There are defaults for the storage location depending on which type of variable it concerns:

    state variables are always in storage
    function arguments are in memory by default
    local variables of struct, array or mapping type reference storage by default
    local variables of value type (i.e. neither array, nor struct nor mapping) are stored in the stack

    constanst vs view vs pure

    • constant: Starting with solc 0.4.17, constant is deprecated in favor of two new and more specific modifiers.
    • View: This is generally the replacement for constant. It indicates that the function will not alter the storage state in any way.
    • Pure: This is even more restrictive, indicating that it won't even read the storage state.
      function returnTrue() public pure returns(bool response) {
        return true;
      }
    

    ref

    require vs assert vs revert vs throw(if)

    简化:
    require() and revert() will cause refund the remaining gas
    assert() will used up all the remaining gas

    Use require() to:

    • generally it will be used at the begining of a function, validate user inputs : such as invalid input
    • should be used more often

    use assert() to :

    • prevent condition that should never, ever be possible : such as fatal error
    • generally it will be used at the end of a function
    • should be used less often

    revert() it was said that revert can handle more complex logic.(emit that, I think we should use require() instead)
    throw : deprecated

    ref

    ref

    todo:

    lib
    use external source(local sol or git)
    call from another contract
    msg.sender what's in msg

    ide 调试

    string compare
    return struct
    testing

    more useful ref:
    best practise

    FAQ about Error

    Error: VM Exception while processing transaction: invalid opcode
    -- out of index

    Error: Invalid number of arguments to Solidity function
    -- 参数不对

    good REF

  • 相关阅读:
    TensorFlow进阶(六)---模型保存与恢复、自定义命令行参数
    TensorFlow进阶(五)---图与会话
    TensorFlow进阶(四)---名称域和共享变量
    spark中数据倾斜解决方案
    Hive窗口函数之LAG、LEAD、FIRST_VALUE、LAST_VALUE的用法
    java.lang.RuntimeException: HRegionServer Aborted
    hive中的优化问题
    读取hbase数据到mysql
    用mapreduce读取hdfs数据到hbase上
    centos7下安装elasticSearch错误总结(单节点模式)
  • 原文地址:https://www.cnblogs.com/no7dw/p/9529776.html
Copyright © 2011-2022 走看看