From f59aaa6cf2bf6eefca7a1db857de1141a1656dbf Mon Sep 17 00:00:00 2001 From: ChronosX88 Date: Mon, 19 Jul 2021 21:41:42 +0300 Subject: [PATCH] Fix issue when node creates tx with different hash but with the same content (because of slightly diffeent timestamp) --- blockchain/types/transaction.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blockchain/types/transaction.go b/blockchain/types/transaction.go index a3b8ebb..96481bf 100644 --- a/blockchain/types/transaction.go +++ b/blockchain/types/transaction.go @@ -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) }