Skip to content
Snippets Groups Projects
Commit 0b213c6b authored by dixitaniket's avatar dixitaniket Committed by dixitaniket
Browse files

removing sha

parent 69d66b96
No related branches found
No related tags found
Loading
Pipeline #1059451545 passed
This commit is part of merge request !3210. Comments created here will be created in the context of that merge request.
......@@ -2,7 +2,7 @@ package common
import "math/rand"
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
const letterBytes = "abcdefABCDEF0123456789"
const (
letterIdxBits = 6 // 6 bits to represent a letter index
letterIdxMask = 1<<letterIdxBits - 1 // All 1-bits, as many as letterIdxBits
......
......@@ -2,9 +2,9 @@ package common
import (
"crypto/sha256"
"encoding/binary"
"errors"
"fmt"
"math/big"
"strings"
"gitlab.com/thorchain/thornode/common/cosmos"
......@@ -45,11 +45,14 @@ func (tx TxID) Equals(tx2 TxID) bool {
return strings.EqualFold(tx.String(), tx2.String())
}
func (tx TxID) HashWithBlockHeight(blockHeight int64) int64 {
toHash := fmt.Sprintf("%s|%v", tx.String(), blockHeight)
checksum := sha256.Sum256([]byte(toHash))
// using uint32 to avoid overflows
return int64(binary.BigEndian.Uint32(checksum[:4]))
func (tx TxID) Int64() int64 {
last8Chars := tx.String()[len(tx.String())-8:]
// using last8 chars to prevent negative int64
val, success := new(big.Int).SetString(last8Chars, 16)
if !success {
panic("Failed to convert")
}
return val.Int64()
}
// IsEmpty return true when the tx represent empty string
......
......@@ -413,7 +413,7 @@ func (s *SlasherVCUR) LackSigning(ctx cosmos.Context, mgr Manager) error {
vault = active[0]
}
} else {
rep := int(tx.InHash.HashWithBlockHeight(ctx.BlockHeight()))
rep := int(tx.InHash.Int64() + ctx.BlockHeight())
if vault.PubKey.Equals(available[rep%len(available)].PubKey) {
// looks like the new vault is going to be the same as the
// old vault, increment rep to ensure a differ asgard is
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment