-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathClaimPredicateBeforeAbsoluteTime.cs
More file actions
61 lines (54 loc) · 2.38 KB
/
ClaimPredicateBeforeAbsoluteTime.cs
File metadata and controls
61 lines (54 loc) · 2.38 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
using System;
using StellarDotnetSdk.Xdr;
using xdr_Int64 = StellarDotnetSdk.Xdr.Int64;
namespace StellarDotnetSdk.Claimants;
/// <summary>
/// Represents a claim predicate that is valid only before a specified absolute point in time.
/// The claimable balance can be claimed only before the given Unix timestamp.
/// </summary>
public class ClaimPredicateBeforeAbsoluteTime : ClaimPredicate
{
/// <summary>
/// Initializes a new instance of the <see cref="ClaimPredicateBeforeAbsoluteTime" /> class
/// with a <see cref="DateTimeOffset" /> representing the deadline.
/// </summary>
/// <param name="dateTime">The absolute point in time before which the balance can be claimed.</param>
public ClaimPredicateBeforeAbsoluteTime(DateTimeOffset dateTime)
{
TimePoint.InnerValue = new Uint64((ulong)dateTime.ToUnixTimeSeconds());
}
/// <summary>
/// Initializes a new instance of the <see cref="ClaimPredicateBeforeAbsoluteTime" /> class
/// with an XDR <see cref="Xdr.TimePoint" /> value.
/// </summary>
/// <param name="timePoint">The XDR time point representing the deadline as a Unix timestamp.</param>
public ClaimPredicateBeforeAbsoluteTime(TimePoint timePoint)
{
TimePoint = timePoint;
}
/// <summary>
/// Initializes a new instance of the <see cref="ClaimPredicateBeforeAbsoluteTime" /> class
/// with a Unix timestamp in seconds.
/// </summary>
/// <param name="timePoint">The Unix timestamp (in seconds) before which the balance can be claimed.</param>
public ClaimPredicateBeforeAbsoluteTime(ulong timePoint)
{
TimePoint = new TimePoint(new Uint64(timePoint));
}
/// <summary>
/// Gets the absolute deadline as a <see cref="DateTimeOffset" />, converted from the underlying Unix timestamp.
/// </summary>
public DateTimeOffset DateTime => DateTimeOffset.FromUnixTimeSeconds((long)TimePoint.InnerValue.InnerValue);
public TimePoint TimePoint { get; } = new();
public override Xdr.ClaimPredicate ToXdr()
{
return new Xdr.ClaimPredicate
{
Discriminant = new ClaimPredicateType
{
InnerValue = ClaimPredicateType.ClaimPredicateTypeEnum.CLAIM_PREDICATE_BEFORE_ABSOLUTE_TIME,
},
AbsBefore = new xdr_Int64((long)TimePoint.InnerValue.InnerValue),
};
}
}