Skip to content

Commit

Permalink
Fix equatability
Browse files Browse the repository at this point in the history
  • Loading branch information
flcl42 committed Oct 25, 2024
1 parent 3a751ff commit efca776
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ protected virtual long Refund(Transaction tx, BlockHeader header, IReleaseSpec s
private static void ThrowInvalidDataException(string message) => throw new InvalidDataException(message);
}

public readonly struct TransactionResult(string? error)
public readonly struct TransactionResult(string? error) : IEquatable<TransactionResult>
{
[MemberNotNullWhen(true, nameof(Fail))]
[MemberNotNullWhen(false, nameof(Success))]
Expand All @@ -792,6 +792,12 @@ public readonly struct TransactionResult(string? error)

public static implicit operator TransactionResult(string? error) => new(error);
public static implicit operator bool(TransactionResult result) => result.Success;
public bool Equals(TransactionResult other) => (Success && other.Success) || (Error == other.Error);
public static bool operator ==(TransactionResult obj1, TransactionResult obj2) => obj1.Equals(obj2);
public static bool operator !=(TransactionResult obj1, TransactionResult obj2) => !obj1.Equals(obj2);
public override bool Equals(object? obj) => obj is TransactionResult result && Equals(result);
public override int GetHashCode() => Success ? 1 : Error.GetHashCode();

public override string ToString() => Error is not null ? $"Fail : {Error}" : "Success";

public static readonly TransactionResult Ok = new();
Expand Down

0 comments on commit efca776

Please sign in to comment.