36 lines
		
	
	
		
			751 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
		
			751 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package biginthelper
 | 
						|
 | 
						|
import (
 | 
						|
	"math/big"
 | 
						|
	"regexp"
 | 
						|
	"strconv"
 | 
						|
)
 | 
						|
 | 
						|
// ParseBigInt 将字符串转换为 big.Int
 | 
						|
func ParseBigInt(value string) *big.Int {
 | 
						|
	bi := new(big.Int)
 | 
						|
	i, ok := bi.SetString(value, 10)
 | 
						|
	if !ok {
 | 
						|
		return bi
 | 
						|
	}
 | 
						|
	return i
 | 
						|
}
 | 
						|
 | 
						|
// IntToHex convert int to hexadecimal representation
 | 
						|
// int64转换为16进制字符串
 | 
						|
func IntToHex(i int64) string {
 | 
						|
	return strconv.FormatInt(i, 16)
 | 
						|
}
 | 
						|
 | 
						|
// BigToHex 将bigint转化为16进制带 0x 的字符串
 | 
						|
func BigToHex(bigInt big.Int) string {
 | 
						|
	return "0x" + IntToHex(bigInt.Int64())
 | 
						|
}
 | 
						|
 | 
						|
// CheckIsAddress Check is a eth Address
 | 
						|
// 检查是否是以太坊地址 正则匹配
 | 
						|
func CheckIsAddress(addr string) bool {
 | 
						|
	re := regexp.MustCompile("^0x[0-9a-fA-F]{40}$")
 | 
						|
	return re.MatchString(addr)
 | 
						|
}
 |