EOS 智能合约源代码解读 symbol.hpp

Posted thefist11

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了EOS 智能合约源代码解读 symbol.hpp相关的知识,希望对你有一定的参考价值。

token的名称和数字精度

  • 名称大写
 /**
class symbol represents a token and contains precision and name.
When encoded as a uint64_t, first byte represents the number of decimals, remaining bytes
represent token name.
Name must only include upper case alphabets.
from_string constructs a symbol from an input a string of the form "4,TTT"
where the integer represents number of decimals. Number of decimals must be larger than zero.
*/

 class symbol : fc::reflect_init {
    public:
        static constexpr uint8_t max_precision = 18;

       explicit symbol(uint8_t p, const char* s): m_value(string_to_symbol(p, s)) {
          xxx_ASSERT(valid(), symbol_type_exception, "invalid symbol: ${s}", ("s",s));
       }

uint64_t value() const { return m_value; }

          string name() const
            {
               uint64_t v = m_value;
               v >>= 8;
               string result;
               while (v > 0) {
                  char c = v & 0xFF;
                  result += c;
                  v >>= 8;
               }
               return result;
            }

      private:
            uint64_t m_value;
            friend struct fc::reflector<symbol>;
      }; // class symbol

      struct extended_symbol {
         symbol       sym;
         text_name    contract;
      };

以上是关于EOS 智能合约源代码解读 symbol.hpp的主要内容,如果未能解决你的问题,请参考以下文章

EOS 智能合约源代码解读 总体说明

EOS 智能合约源代码解读 合约开发示例

EOS 智能合约源代码解读 bios合约

EOS 智能合约源代码解读 合约之action

EOS 智能合约源代码解读 class contract

EOS 智能合约源代码解读 (10)token合约“简介”