Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UtxoReferee Refactoring
- Loading branch information
Showing
5 changed files
with
106 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using NBitcoin; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using WalletWasabi.Helpers; | ||
|
||
namespace WalletWasabi.Models | ||
{ | ||
public class BannedUtxoRecord | ||
{ | ||
public OutPoint Utxo { get; } | ||
public int Severity { get; } | ||
public DateTimeOffset TimeOfBan { get; } | ||
public bool IsNoted { get; } | ||
public long BannedForRound { get; } | ||
public TimeSpan BannedRemaining => DateTimeOffset.UtcNow - TimeOfBan; | ||
|
||
public BannedUtxoRecord(OutPoint utxo, int severity, DateTimeOffset timeOfBan, bool isNoted, long bannedForRound) | ||
{ | ||
Utxo = Guard.NotNull(nameof(utxo), utxo); | ||
Severity = severity; | ||
TimeOfBan = timeOfBan; | ||
IsNoted = isNoted; | ||
BannedForRound = bannedForRound; | ||
} | ||
|
||
/// <summary> | ||
/// Deserializes an instance from its text representation. | ||
/// </summary> | ||
public static BannedUtxoRecord FromString(string str) | ||
{ | ||
var parts = str.Split(':'); | ||
var isNoted = bool.Parse(parts[4]); | ||
var bannedForRound = long.Parse(parts[5]); | ||
var utxo = new OutPoint(new uint256(parts[3]), int.Parse(parts[2])); | ||
var severity = int.Parse(parts[1]); | ||
var timeParts = parts[0].Split('-', ' ').Select(x => int.Parse(x)).ToArray(); | ||
var timeOfBan = new DateTimeOffset(timeParts[0], timeParts[1], timeParts[2], timeParts[3], timeParts[4], timeParts[5], TimeSpan.Zero); | ||
|
||
return new BannedUtxoRecord(utxo, severity, timeOfBan, isNoted, bannedForRound); | ||
} | ||
|
||
/// <summary> | ||
/// Serializes the instance to its text representation. | ||
/// </summary> | ||
public override string ToString() | ||
{ | ||
return $"{TimeOfBan.ToString("yyyy-MM-dd HH-mm-ss")}:{Severity}:{Utxo.N}:{Utxo.Hash}:{IsNoted}:{BannedForRound}"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters