Skip to content
Snippets Groups Projects

[V124-specific] semi random asgard vault selection based on tx inhash and block height

Merged dixitaniket requested to merge ani/1718 into develop
2 files
+ 13
1
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 12
0
@@ -2,6 +2,7 @@ package common
import (
"crypto/sha256"
"encoding/binary"
"errors"
"fmt"
"strings"
@@ -44,6 +45,17 @@ func (tx TxID) Equals(tx2 TxID) bool {
return strings.EqualFold(tx.String(), tx2.String())
}
func (tx TxID) HashWithAttrs(attrs ...interface{}) int64 {
toHash := tx.String()
for _, attr := range attrs {
toHash = fmt.Sprintf("%s|%s", toHash, attr)
}
checksum := sha256.Sum256([]byte(toHash))
// using uint32 to avoid overflows
return int64(binary.BigEndian.Uint32(checksum[:4]))
}
// IsEmpty return true when the tx represent empty string
func (tx TxID) IsEmpty() bool {
return strings.TrimSpace(tx.String()) == ""
Loading