laconicd/utils/types.go
Bipul Prasad 505ad2ab70
[vulcanize/dxns#8] Migrating auctions module from DXNS (#3)
* Migrating auctions module from DXNS

* Adding appropriate comments on proto definitions

* Addressing review comments and fixing build issues

* Addressing review comments

* Adding README for auction module and fixing build/run issues

* Removing DXNS references and migrating DXNS utils to Ethermint

* Setting default genesis param values

* Defining constants in params and assigning ParamSetPairs

* Fixing issues with auction bid reveals

Co-authored-by: bipulprasad <Bipul@qubecinema.com>
2021-10-01 15:19:01 +05:30

53 lines
844 B
Go

//
// Copyright 2020 Wireline, Inc.
//
package utils
import (
"bytes"
"encoding/binary"
"sort"
set "github.com/deckarep/golang-set"
)
func Int64ToBytes(num int64) []byte {
buf := new(bytes.Buffer)
binary.Write(buf, binary.BigEndian, num)
return buf.Bytes()
}
func SetToSlice(set set.Set) []string {
names := []string{}
for name := range set.Iter() {
if name, ok := name.(string); ok && name != "" {
names = append(names, name)
}
}
sort.SliceStable(names, func(i, j int) bool { return names[i] < names[j] })
return names
}
func SliceToSet(names []string) set.Set {
set := set.NewThreadUnsafeSet()
for _, name := range names {
if name != "" {
set.Add(name)
}
}
return set
}
func AppendUnique(list []string, element string) []string {
set := SliceToSet(list)
set.Add(element)
return SetToSlice(set)
}