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
1 unresolved thread
2 files
+ 13
1
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 12
0
@@ -2,6 +2,7 @@ package common
@@ -2,6 +2,7 @@ package common
import (
import (
"crypto/sha256"
"crypto/sha256"
 
"encoding/binary"
"errors"
"errors"
"fmt"
"fmt"
"strings"
"strings"
@@ -44,6 +45,17 @@ func (tx TxID) Equals(tx2 TxID) bool {
@@ -44,6 +45,17 @@ func (tx TxID) Equals(tx2 TxID) bool {
return strings.EqualFold(tx.String(), tx2.String())
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
// IsEmpty return true when the tx represent empty string
func (tx TxID) IsEmpty() bool {
func (tx TxID) IsEmpty() bool {
return strings.TrimSpace(tx.String()) == ""
return strings.TrimSpace(tx.String()) == ""
Loading