-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTxValidationState.cs
More file actions
75 lines (65 loc) · 1.96 KB
/
TxValidationState.cs
File metadata and controls
75 lines (65 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using BitcoinKernel.Interop;
using BitcoinKernel.Interop.Enums;
namespace BitcoinKernel.Core.TransactionValidation;
/// <summary>
/// Represents the validation state of a transaction after consensus checks.
/// </summary>
public sealed class TxValidationState : IDisposable
{
private IntPtr _handle;
private bool _disposed;
internal TxValidationState(IntPtr handle)
{
_handle = handle != IntPtr.Zero
? handle
: throw new ArgumentException("Invalid validation state handle", nameof(handle));
}
/// <summary>
/// Gets the validation mode (VALID, INVALID, or INTERNAL_ERROR).
/// </summary>
public ValidationMode Mode
{
get
{
ThrowIfDisposed();
return NativeMethods.TxValidationStateGetValidationMode(_handle);
}
}
/// <summary>
/// Gets the detailed validation result indicating why the transaction was invalid.
/// </summary>
public TxValidationResult Result
{
get
{
ThrowIfDisposed();
return NativeMethods.TxValidationStateGetTxValidationResult(_handle);
}
}
/// <summary>
/// Returns true if the transaction is valid.
/// </summary>
public bool IsValid => Mode == ValidationMode.VALID;
/// <summary>
/// Returns true if the transaction is invalid.
/// </summary>
public bool IsInvalid => Mode == ValidationMode.INVALID;
/// <summary>
/// Returns true if an internal error occurred during validation.
/// </summary>
public bool IsError => Mode == ValidationMode.INTERNAL_ERROR;
private void ThrowIfDisposed()
{
if (_disposed)
throw new ObjectDisposedException(nameof(TxValidationState));
}
public void Dispose()
{
if (!_disposed && _handle != IntPtr.Zero)
{
NativeMethods.TxValidationStateDestroy(_handle);
_handle = IntPtr.Zero;
_disposed = true;
}
}
}