The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
woop/utils/utils.go

34 lines
603 B

package utils
7 years ago
import (
7 years ago
"bytes"
"encoding/binary"
"log"
"strconv"
"strings"
7 years ago
)
// IntToHex converts an int64 to a byte array
func IntToHex(num int64) []byte {
7 years ago
buff := new(bytes.Buffer)
err := binary.Write(buff, binary.BigEndian, num)
if err != nil {
log.Panic(err)
}
7 years ago
7 years ago
return buff.Bytes()
7 years ago
}
7 years ago
// ConvertIntoInts is to convert '1,2,3,4' into []int{1,2,3,4}.
7 years ago
func ConvertIntoInts(data string) []int {
7 years ago
var res = []int{}
items := strings.Split(data, ",")
7 years ago
for _, value := range items {
intValue, err := strconv.Atoi(value)
if err == nil {
res = append(res, intValue)
}
7 years ago
}
return res
7 years ago
}