HashTxn generates a SHA-256 hash of a transaction's relevant fields. This ensures the integrity of the transaction by creating a unique hash from its details.
()
| 41 | // HashTxn generates a SHA-256 hash of a transaction's relevant fields. |
| 42 | // This ensures the integrity of the transaction by creating a unique hash from its details. |
| 43 | func (transaction *Transaction) HashTxn() string { |
| 44 | // Concatenate the transaction's fields into a single string. |
| 45 | data := fmt.Sprintf("%f%s%s%s%s", transaction.Amount, transaction.Reference, transaction.Currency, transaction.Source, transaction.Destination) |
| 46 | hash := sha256.Sum256([]byte(data)) // Hash the concatenated data. |
| 47 | return hex.EncodeToString(hash[:]) // Return the hex-encoded hash. |
| 48 | } |
| 49 | |
| 50 | // compare compares two *big.Int values based on the provided condition (e.g., >, <, ==). |
| 51 | // Returns true if the condition holds, otherwise false. |
no outgoing calls