Fix issue when node creates tx with different hash but with the same content (because of slightly diffeent timestamp)
This commit is contained in:
parent
bb3bf032d5
commit
f59aaa6cf2
@ -21,7 +21,7 @@ type Transaction struct {
|
|||||||
func CreateTransaction(data []byte) *Transaction {
|
func CreateTransaction(data []byte) *Transaction {
|
||||||
timestamp := time.Now()
|
timestamp := time.Now()
|
||||||
encodedData := hex.EncodeToString(data)
|
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{
|
return &Transaction{
|
||||||
Hash: hash,
|
Hash: hash,
|
||||||
Timestamp: timestamp,
|
Timestamp: timestamp,
|
||||||
@ -31,6 +31,6 @@ func CreateTransaction(data []byte) *Transaction {
|
|||||||
|
|
||||||
func (tx *Transaction) ValidateHash() bool {
|
func (tx *Transaction) ValidateHash() bool {
|
||||||
encodedData := hex.EncodeToString(tx.Data)
|
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)
|
return bytes.Equal(h, tx.Hash)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user