github.com/turingchain2020/turingchain@v1.1.21/types/const.go (about)

     1  // Copyright Turing Corp. 2018 All Rights Reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package types
     6  
     7  import (
     8  	"reflect"
     9  
    10  	"github.com/turingchain2020/turingchain/system/crypto/ed25519"
    11  	"github.com/turingchain2020/turingchain/system/crypto/secp256k1"
    12  	"github.com/turingchain2020/turingchain/system/crypto/sm2"
    13  )
    14  
    15  var slash = []byte("-")
    16  var sharp = []byte("#")
    17  
    18  //Debug 调试开关
    19  var Debug = false
    20  
    21  //LogErr log错误信息
    22  type LogErr []byte
    23  
    24  //LogReserved LogReserved信息
    25  type LogReserved []byte
    26  
    27  //LogInfo loginfo信息
    28  type LogInfo struct {
    29  	Ty   reflect.Type
    30  	Name string
    31  }
    32  
    33  //UserKeyX 用户自定义执行器前缀字符串
    34  const (
    35  	UserKeyX = "user."
    36  	ParaKeyX = "user.p."
    37  	NoneX    = "none"
    38  )
    39  
    40  //DefaultCoinsSymbol 默认的主币名称
    41  const (
    42  	DefaultCoinsSymbol = "trc"
    43  )
    44  
    45  //UserKeyX 用户自定义执行器前缀byte类型
    46  var (
    47  	UserKey    = []byte(UserKeyX)
    48  	ParaKey    = []byte(ParaKeyX)
    49  	ExecerNone = []byte(NoneX)
    50  )
    51  
    52  //基本全局常量定义
    53  const (
    54  	InputPrecision        float64 = 1e4
    55  	Multiple1E4           int64   = 1e4
    56  	TRC                           = "TRC"
    57  	TxGroupMaxCount               = 20
    58  	MinerAction                   = "miner"
    59  	Int1E4                int64   = 10000
    60  	Float1E4              float64 = 10000.0
    61  	AirDropMinIndex       uint32  = 100000000         //通过钱包的seed生成一个空投地址,最小index索引
    62  	AirDropMaxIndex       uint32  = 101000000         //通过钱包的seed生成一个空投地址,最大index索引
    63  	MaxBlockCountPerTime  int64   = 1000              //从数据库中一次性获取block的最大数 1000个
    64  	MaxBlockSizePerTime           = 100 * 1024 * 1024 //从数据库中一次性获取block的最大size100M
    65  	AddBlock              int64   = 1
    66  	DelBlock              int64   = 2
    67  	MainChainName                 = "main"
    68  	MaxHeaderCountPerTime int64   = 10000 //从数据库中一次性获取header的最大数 10000个
    69  
    70  )
    71  
    72  //ty = 1 -> secp256k1
    73  //ty = 2 -> ed25519
    74  //ty = 3 -> sm2
    75  //ty = 4 -> onetimeed25519
    76  //ty = 5 -> RingBaseonED25519
    77  //ty = 1+offset(1<<8) ->auth_ecdsa
    78  //ty = 2+offset(1<<8) -> auth_sm2
    79  const (
    80  	Invalid   = 0
    81  	SECP256K1 = secp256k1.ID
    82  	ED25519   = ed25519.ID
    83  	AuthSM2   = sm2.ID
    84  )
    85  
    86  //log type
    87  const (
    88  	TyLogReserved = 0
    89  	TyLogErr      = 1
    90  	TyLogFee      = 2
    91  	//TyLogTransfer coins
    92  	TyLogTransfer        = 3
    93  	TyLogGenesis         = 4
    94  	TyLogDeposit         = 5
    95  	TyLogExecTransfer    = 6
    96  	TyLogExecWithdraw    = 7
    97  	TyLogExecDeposit     = 8
    98  	TyLogExecFrozen      = 9
    99  	TyLogExecActive      = 10
   100  	TyLogGenesisTransfer = 11
   101  	TyLogGenesisDeposit  = 12
   102  	TyLogRollback        = 13
   103  	TyLogMint            = 14
   104  	TyLogBurn            = 15
   105  )
   106  
   107  //SystemLog 系统log日志
   108  var SystemLog = map[int64]*LogInfo{
   109  	TyLogReserved:        {reflect.TypeOf(LogReserved{}), "LogReserved"},
   110  	TyLogErr:             {reflect.TypeOf(LogErr{}), "LogErr"},
   111  	TyLogFee:             {reflect.TypeOf(ReceiptAccountTransfer{}), "LogFee"},
   112  	TyLogTransfer:        {reflect.TypeOf(ReceiptAccountTransfer{}), "LogTransfer"},
   113  	TyLogDeposit:         {reflect.TypeOf(ReceiptAccountTransfer{}), "LogDeposit"},
   114  	TyLogExecTransfer:    {reflect.TypeOf(ReceiptExecAccountTransfer{}), "LogExecTransfer"},
   115  	TyLogExecWithdraw:    {reflect.TypeOf(ReceiptExecAccountTransfer{}), "LogExecWithdraw"},
   116  	TyLogExecDeposit:     {reflect.TypeOf(ReceiptExecAccountTransfer{}), "LogExecDeposit"},
   117  	TyLogExecFrozen:      {reflect.TypeOf(ReceiptExecAccountTransfer{}), "LogExecFrozen"},
   118  	TyLogExecActive:      {reflect.TypeOf(ReceiptExecAccountTransfer{}), "LogExecActive"},
   119  	TyLogGenesisTransfer: {reflect.TypeOf(ReceiptAccountTransfer{}), "LogGenesisTransfer"},
   120  	TyLogGenesisDeposit:  {reflect.TypeOf(ReceiptAccountTransfer{}), "LogGenesisDeposit"},
   121  	TyLogRollback:        {reflect.TypeOf(LocalDBSet{}), "LogRollback"},
   122  	TyLogMint:            {reflect.TypeOf(ReceiptAccountMint{}), "LogMint"},
   123  	TyLogBurn:            {reflect.TypeOf(ReceiptAccountBurn{}), "LogBurn"},
   124  }
   125  
   126  //exec type
   127  const (
   128  	ExecErr  = 0
   129  	ExecPack = 1
   130  	ExecOk   = 2
   131  )
   132  
   133  // TODO 后续调试确认放的位置
   134  //func init() {
   135  //	S("TxHeight", false)
   136  //}
   137  
   138  //flag:
   139  
   140  //TxHeight 选项
   141  //设计思路:
   142  //提供一种可以快速查重的交易类型,和原来的交易完全兼容
   143  //并且可以通过开关控制是否开启这样的交易
   144  
   145  //TxHeightFlag 标记是一个时间还是一个 TxHeight
   146  var TxHeightFlag int64 = 1 << 62
   147  
   148  //HighAllowPackHeight txHeight打包上限高度
   149  //eg: currentHeight = 10000
   150  //某交易的expire=TxHeightFlag+ currentHeight + 10, 则TxHeight=10010
   151  //打包的区块高度必须满足, Height >= TxHeight - LowAllowPackHeight && Height <= TxHeight + HighAllowPackHeight
   152  //那么交易可以打包的范围是: 10010 - 100 = 9910 , 10010 + 200 =  10210 (9910,10210)
   153  //注意,这两个条件必须同时满足.
   154  //关于交易查重:
   155  //也就是说,两笔相同的交易必然有相同的expire,即TxHeight相同,以及对应的打包区间一致,只能被打包在这个区间(9910,10210)。
   156  //那么检查交易重复的时候,我只要检查 9910 - currentHeight 这个区间的交易是否有重复
   157  var HighAllowPackHeight int64 = 600
   158  
   159  //LowAllowPackHeight 允许打包的low区块高度
   160  var LowAllowPackHeight int64 = 200
   161  
   162  //MaxAllowPackInterval 允许打包的最大区间值
   163  var MaxAllowPackInterval int64 = 5000