// System using System; using System.Reflection; // Unity using UnityEngine; namespace GUPS.AntiCheat.Protected.Collection.Chain { /// /// Represents a transaction inside a block from a blockchain. A transaction contains a timestamp (the time it was added to the blockchain) /// and a content of type T. /// /// The type of the content of the transaction. [Serializable] [Obfuscation(Exclude = true)] public class Transaction : ITransaction where T : struct { /// /// The timestamp of the transaction, when it was added to the blockchain. Recommended to use at least milliseconds. /// [SerializeField] public Int64 timestamp; /// /// The timestamp of the transaction, when it was added to the blockchain. Recommended to use at least milliseconds. /// public Int64 Timestamp { get => timestamp; private set => timestamp = value; } /// /// The serializeable content of the transaction. /// [SerializeField] public T content; /// /// The serializeable content of the transaction. /// public T Content { get => content; private set => content = value; } /// /// Create a new transaction with the current timestamp and content. /// /// The content of the transaction. public Transaction(T _Content) :this(DateTimeOffset.UtcNow.Ticks, _Content) { } /// /// Create a new transaction with the passed index, timestamp and content. /// /// The imestamp of the transaction. /// The content of the transaction. public Transaction(Int64 _Timestamp, T _Content) { this.timestamp = _Timestamp; this.content = _Content; } /// /// Calculate the hash code of the transaction based on its timestamp and content. /// /// The hash code of the transaction. public override int GetHashCode() { return (Int32)this.timestamp ^ this.Content.GetHashCode(); } } }