-
Notifications
You must be signed in to change notification settings - Fork 147
/
matrix.go
92 lines (79 loc) · 1.79 KB
/
matrix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright (c) 2018 The MATRIX Authors
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php
package common
import (
"math/big"
"reflect"
)
type ElectRoleType uint8
const (
ElectRoleMiner ElectRoleType = 0x00
ElectRoleMinerBackUp ElectRoleType = 0x01
ElectRoleValidator ElectRoleType = 0x02
ElectRoleValidatorBackUp ElectRoleType = 0x03
ElectRoleCandidateValidator ElectRoleType = 0x04
ElectRoleNil ElectRoleType = 0xff
)
var (
SignLog = "SignLog"
)
func (ert ElectRoleType) Transfer2CommonRole() RoleType {
switch ert {
case ElectRoleMiner:
return RoleMiner
case ElectRoleMinerBackUp:
return RoleBackupMiner
case ElectRoleValidator:
return RoleValidator
case ElectRoleValidatorBackUp:
return RoleBackupValidator
case ElectRoleCandidateValidator:
return RoleCandidateValidator
}
return RoleNil
}
func GetRoleTypeFromPosition(position uint16) RoleType {
return ElectRoleType(position >> 12).Transfer2CommonRole()
}
func GeneratePosition(index uint16, electRole ElectRoleType) uint16 {
if electRole >= ElectRoleNil {
return 0xffff
}
return uint16(electRole)<<12 + index
}
type Echelon struct {
MinMoney *big.Int
MaxNum int
Ratio uint16
}
var (
ManValue = new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil)
)
func IsNil(i interface{}) bool {
vi := reflect.ValueOf(i)
if vi.Kind() == reflect.Ptr {
flag := vi.IsNil()
return flag
}
return false
}
type VIPRoleType uint16
const (
VIP_Nil VIPRoleType = 0
VIP_1 VIPRoleType = 1
VIP_2 VIPRoleType = 2
VIP_3 VIPRoleType = 3
)
func GetVIPLevel(index int) VIPRoleType {
switch index {
case 1:
return VIP_1
case 2:
return VIP_2
case 3:
return VIP_3
default:
return VIP_Nil
}
}