MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / HashTxn

Method HashTxn

model/model.go:43–48  ·  view source on GitHub ↗

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.

()

Source from the content-addressed store, hash-verified

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.
43func (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.

Callers 6

TestTransaction_HashTxnFunction · 0.95
finalizeCommitmentMethod · 0.80
setTransactionMetadataFunction · 0.80

Calls

no outgoing calls

Tested by 2

TestTransaction_HashTxnFunction · 0.76