mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-05-24 15:56:42 +00:00

* [NOD-1567] Add clone methods to data stores types * [NOD-1567] Fix comments * [NOD-1567] Fix test
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package externalapi
|
|
|
|
import "encoding/hex"
|
|
|
|
// DomainHashSize of array used to store hashes.
|
|
const DomainHashSize = 32
|
|
|
|
// DomainHash is the domain representation of a Hash
|
|
type DomainHash [DomainHashSize]byte
|
|
|
|
// String returns the Hash as the hexadecimal string of the byte-reversed
|
|
// hash.
|
|
func (hash DomainHash) String() string {
|
|
for i := 0; i < DomainHashSize/2; i++ {
|
|
hash[i], hash[DomainHashSize-1-i] = hash[DomainHashSize-1-i], hash[i]
|
|
}
|
|
return hex.EncodeToString(hash[:])
|
|
}
|
|
|
|
// Clone clones the hash
|
|
func (hash *DomainHash) Clone() *DomainHash {
|
|
if hash == nil {
|
|
return nil
|
|
}
|
|
|
|
hashClone := *hash
|
|
return &hashClone
|
|
}
|
|
|
|
// CloneHashes returns a clone of the given hashes slice
|
|
func CloneHashes(hashes []*DomainHash) []*DomainHash {
|
|
clone := make([]*DomainHash, len(hashes))
|
|
for i, hash := range hashes {
|
|
clone[i] = hash.Clone()
|
|
}
|
|
return clone
|
|
}
|
|
|
|
// DomainHashesToStrings returns a slice of strings representing the hashes in the given slice of hashes
|
|
func DomainHashesToStrings(hashes []*DomainHash) []string {
|
|
strings := make([]string, len(hashes))
|
|
for i, hash := range hashes {
|
|
strings[i] = hash.String()
|
|
}
|
|
|
|
return strings
|
|
}
|