github.com/nnlgsakib/mind-dpos@v0.0.0-20230606105614-f3c8ca06f808/common/hexutil/custom_hex_prefix.go (about) 1 // Copyright 2018 The gttc Authors 2 // This file is part of the gttc library. 3 // 4 // The gttc library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The gttc library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the gttc library. If not, see <http://www.gnu.org/licenses/>. 16 17 // PM want to change the prefix of hex from 0x to anything they want, @#$%@#$%@#%^ ;-) 18 // Just set the CustomHashPrefix to "0x" , everything will back to normal. 19 20 package hexutil 21 22 const CustomHexPrefix = "0x" 23 24 var PossibleCustomHexPrefixMap = map[string]bool{ 25 "0x": true, 26 "0X": true, 27 "t0": true, 28 "t1": true, 29 "t2": true, 30 "t3": true, 31 "t4": true, 32 "t5": true, 33 "t6": true, 34 "t7": true, 35 "t8": true, 36 "t9": true, 37 "T0": true, 38 "T1": true, 39 "T2": true, 40 "T3": true, 41 "T4": true, 42 "T5": true, 43 "T6": true, 44 "T7": true, 45 "T8": true, 46 "T9": true, 47 } 48 49 func CPToHex(s string) string { 50 if len(s) > len(CustomHexPrefix) { 51 if _, ok := PossibleCustomHexPrefixMap[s[:2]]; ok { 52 return "0x" + s[2:] 53 } 54 } 55 return s 56 } 57 58 func HexToCP(s string) string { 59 if len(s) > 2 { 60 if s[:2] == "0x" || s[:2] == "0X" { 61 return CustomHexPrefix + s[2:] 62 } 63 } 64 return s 65 }