| | 1 | | namespace NLightning.Domain.Bitcoin.Transactions.Models; |
| | 2 | |
|
| | 3 | | using NLightning.Domain.Bitcoin.ValueObjects; |
| | 4 | | using NLightning.Domain.Channels.ValueObjects; |
| | 5 | |
|
| | 6 | | public class WatchedTransactionModel |
| | 7 | | { |
| 12 | 8 | | public ChannelId ChannelId { get; } |
| 16 | 9 | | public TxId TransactionId { get; } |
| 60 | 10 | | public uint RequiredDepth { get; } |
| 64 | 11 | | public uint? FirstSeenAtHeight { get; private set; } |
| 16 | 12 | | public ushort? TransactionIndex { get; private set; } |
| 12 | 13 | | public bool IsCompleted { get; private set; } |
| | 14 | |
|
| 16 | 15 | | public WatchedTransactionModel(ChannelId channelId, TxId transactionId, uint requiredDepth) |
| | 16 | | { |
| 16 | 17 | | ChannelId = channelId; |
| 16 | 18 | | TransactionId = transactionId; |
| 16 | 19 | | RequiredDepth = requiredDepth; |
| 16 | 20 | | } |
| | 21 | |
|
| | 22 | | public void SetHeightAndIndex(uint height, ushort txIndex) |
| | 23 | | { |
| 8 | 24 | | if (FirstSeenAtHeight.HasValue) |
| 0 | 25 | | throw new InvalidOperationException($"{nameof(FirstSeenAtHeight)} is already set."); |
| | 26 | |
|
| 8 | 27 | | if (TransactionIndex.HasValue) |
| 0 | 28 | | throw new InvalidOperationException($"{nameof(TransactionIndex)} is already set."); |
| | 29 | |
|
| 8 | 30 | | FirstSeenAtHeight = height; |
| 8 | 31 | | TransactionIndex = txIndex; |
| 8 | 32 | | } |
| | 33 | |
|
| | 34 | | public void MarkAsCompleted() |
| | 35 | | { |
| 4 | 36 | | if (IsCompleted) |
| 0 | 37 | | throw new InvalidOperationException("Transaction is already marked as completed."); |
| | 38 | |
|
| 4 | 39 | | IsCompleted = true; |
| 4 | 40 | | } |
| | 41 | | } |