-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTxIn.cs
More file actions
69 lines (58 loc) · 1.79 KB
/
TxIn.cs
File metadata and controls
69 lines (58 loc) · 1.79 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
using System;
using BitcoinKernel.Exceptions;
using BitcoinKernel.Interop;
namespace BitcoinKernel.Primitives;
/// <summary>
/// Managed wrapper for a Bitcoin transaction input.
/// </summary>
public sealed class TxIn : IDisposable
{
private IntPtr _handle;
private bool _disposed;
private readonly bool _ownsHandle;
internal TxIn(IntPtr handle, bool ownsHandle = true)
{
_handle = handle;
_ownsHandle = ownsHandle;
}
/// <summary>
/// Gets the nSequence value of this input.
/// </summary>
public uint Sequence => NativeMethods.TransactionInputGetSequence(_handle);
/// <summary>
/// Gets the out point of this input. The returned out point is not owned and
/// depends on the lifetime of the transaction.
/// </summary>
public IntPtr GetOutPoint()
{
IntPtr outPointPtr = NativeMethods.TransactionInputGetOutPoint(_handle);
if (outPointPtr == IntPtr.Zero)
throw new TransactionException("Failed to get out point from transaction input");
return outPointPtr;
}
/// <summary>
/// Creates a copy of this transaction input.
/// </summary>
public TxIn Copy()
{
IntPtr copyHandle = NativeMethods.TransactionInputCopy(_handle);
if (copyHandle == IntPtr.Zero)
throw new TransactionException("Failed to copy transaction input");
return new TxIn(copyHandle, ownsHandle: true);
}
internal IntPtr Handle => _handle;
public void Dispose()
{
if (!_disposed && _handle != IntPtr.Zero && _ownsHandle)
{
NativeMethods.TransactionInputDestroy(_handle);
_handle = IntPtr.Zero;
_disposed = true;
}
GC.SuppressFinalize(this);
}
~TxIn()
{
Dispose();
}
}