Fix issue when node creates tx with different hash but with the same content (because of slightly diffeent timestamp)

This commit is contained in:
ChronosX88 2021-07-19 21:41:42 +03:00
parent bb3bf032d5
commit f59aaa6cf2
Signed by: ChronosXYZ
GPG Key ID: 085A69A82C8C511A

View File

@ -21,7 +21,7 @@ type Transaction struct {
func CreateTransaction(data []byte) *Transaction {
timestamp := time.Now()
encodedData := hex.EncodeToString(data)
hash := crypto.Keccak256([]byte(fmt.Sprintf("%d_%s", timestamp.Unix(), encodedData)))
hash := crypto.Keccak256([]byte(fmt.Sprintf("%s", encodedData)))
return &Transaction{
Hash: hash,
Timestamp: timestamp,
@ -31,6 +31,6 @@ func CreateTransaction(data []byte) *Transaction {
func (tx *Transaction) ValidateHash() bool {
encodedData := hex.EncodeToString(tx.Data)
h := crypto.Keccak256([]byte(fmt.Sprintf("%d_%s", tx.Timestamp.Unix(), encodedData)))
h := crypto.Keccak256([]byte(fmt.Sprintf("%s", encodedData)))
return bytes.Equal(h, tx.Hash)
}