certichain

Blockchain built from scratch for verifying document's legitimacy.
Log | Files | Refs | README | LICENSE

commit c7208d9d468281f1958cef174d7549af03da6b3d
parent cce403c4cb34816a6ba5c70d5344df0f0f0b9522
Author: Shivakumar <[email protected]>
Date:   Thu, 30 Jul 2026 00:19:24 +0530

feat(transaction): add Compare and Equal

Signed-off-by: Shivakumar <[email protected]>

Diffstat:
Minternal/transaction/transaction.go | 22++++++++++++++++++++++
1 file changed, 22 insertions(+), 0 deletions(-)

diff --git a/internal/transaction/transaction.go b/internal/transaction/transaction.go @@ -16,6 +16,7 @@ package transaction import ( "bytes" + "cmp" "crypto/ed25519" "crypto/rand" "encoding/binary" @@ -161,6 +162,27 @@ func (tx *Transaction) Clone() *Transaction { } } +// Equal compares two Transactions and returns a bool. +func (tx *Transaction) Equal(other *Transaction) bool { + if tx == nil || other == nil { + return tx == other + } + return tx.IssuerDID == other.IssuerDID && + tx.Timestamp == other.Timestamp && + bytes.Equal(tx.TxID, other.TxID) && + bytes.Equal(tx.Nonce, other.Nonce) && + bytes.Equal(tx.MerkleRoot, other.MerkleRoot) && + bytes.Equal(tx.Signature, other.Signature) +} + +// Comapre compares two Transactions for ordering. +func Compare(a, b *Transaction) int { + if c := cmp.Compare(a.Timestamp, b.Timestamp); c != 0 { + return c + } + return bytes.Compare(a.TxID, b.TxID) +} + // calculateTxID computes the SHA-256 hash of the transaction's canonical fields. func (tx *Transaction) calculateTxID() ([]byte, error) { sb, err := tx.signingBytes()