Skip to content

Commit 29979e7

Browse files
Added XrplPaymentFlags to XrplPaymentTransaction. (#20)
- Added `XrplPaymentFlags` to `XrplPaymentTransaction`. - Created an extension method to create a `XummPostJsonPayload` based on an object. - Ability to set `DeliverMin` and `SendMax` as XRP or `XrplTransactionCurrencyAmount`.
1 parent 1542e63 commit 29979e7

File tree

7 files changed

+118
-33
lines changed

7 files changed

+118
-33
lines changed

src/XUMM.NET.SDK/Clients/XummHttpClient.cs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
using System.Net.Http.Headers;
44
using System.Text;
55
using System.Text.Json;
6-
using System.Text.Json.Serialization;
76
using System.Threading.Tasks;
87
using Microsoft.Extensions.Logging;
98
using Microsoft.Extensions.Options;
109
using XUMM.NET.SDK.Clients.Interfaces;
1110
using XUMM.NET.SDK.Configs;
11+
using XUMM.NET.SDK.Helpers;
1212
using XUMM.NET.SDK.Models;
1313

1414
namespace XUMM.NET.SDK.Clients;
@@ -18,7 +18,6 @@ public class XummHttpClient : IXummHttpClient
1818
private readonly ApiConfig _config;
1919
private readonly IHttpClientFactory _httpClientFactory;
2020
private readonly ILogger<XummHttpClient> _logger;
21-
private readonly JsonSerializerOptions _serializerOptions;
2221

2322
public XummHttpClient(
2423
IHttpClientFactory httpClientFactory,
@@ -28,19 +27,6 @@ public XummHttpClient(
2827
_config = options.Value;
2928
_httpClientFactory = httpClientFactory;
3029
_logger = logger;
31-
32-
_serializerOptions = new JsonSerializerOptions
33-
{
34-
#if NET5_0_OR_GREATER
35-
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
36-
#else
37-
IgnoreNullValues = true,
38-
#endif
39-
Converters =
40-
{
41-
new JsonStringEnumConverter()
42-
}
43-
};
4430
}
4531

4632
public async Task<T> GetAsync<T>(string endpoint)
@@ -55,7 +41,7 @@ public async Task<T> GetPublicAsync<T>(string endpoint)
5541

5642
public async Task<T> PostAsync<T>(string endpoint, object content)
5743
{
58-
return await PostAsync<T>(endpoint, JsonSerializer.Serialize(content, _serializerOptions));
44+
return await PostAsync<T>(endpoint, JsonSerializer.Serialize(content, JsonHelper.SerializerOptions));
5945
}
6046

6147
public async Task<T> PostAsync<T>(string endpoint, string json)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
3+
namespace XUMM.NET.SDK.Enums;
4+
5+
[Flags]
6+
public enum XrplPaymentFlags
7+
{
8+
/// <summary>
9+
/// Do not use the default path; only use paths included in the Paths field. This is intended to force the transaction to take arbitrage opportunities. Most clients do not need this.
10+
/// </summary>
11+
tfNoDirectRipple = 65536,
12+
13+
/// <summary>
14+
/// If the specified Amount cannot be sent without spending more than SendMax, reduce the received amount instead of failing outright.
15+
/// </summary>
16+
tfPartialPayment = 131072,
17+
18+
/// <summary>
19+
/// Only take paths where all the conversions have an input:output ratio that is equal or better than the ratio of Amount:SendMax.
20+
/// </summary>
21+
tfLimitQuality = 262144
22+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Text.Json;
2+
using XUMM.NET.SDK.Helpers;
3+
using XUMM.NET.SDK.Models.Payload;
4+
5+
namespace XUMM.NET.SDK.Extensions
6+
{
7+
public static class XummPayloadExtensions
8+
{
9+
/// <summary>
10+
/// Serialize the <paramref name="payloadObject"/> as the <see cref="XummPostJsonPayload.TxJson"/> of <see cref="XummPostJsonPayload"/>.
11+
/// </summary>
12+
public static XummPostJsonPayload ToXummPostJsonPayload(this object payloadObject)
13+
{
14+
var json = JsonSerializer.Serialize(payloadObject, JsonHelper.SerializerOptions);
15+
return new XummPostJsonPayload(json);
16+
}
17+
}
18+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Text.Json;
2+
using System.Text.Json.Serialization;
3+
4+
namespace XUMM.NET.SDK.Helpers
5+
{
6+
internal class JsonHelper
7+
{
8+
internal static JsonSerializerOptions SerializerOptions => new JsonSerializerOptions
9+
{
10+
#if NET5_0_OR_GREATER
11+
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
12+
#else
13+
IgnoreNullValues = true,
14+
#endif
15+
Converters =
16+
{
17+
new JsonStringEnumConverter()
18+
}
19+
};
20+
}
21+
}

src/XUMM.NET.SDK/Models/Payload/XRPL/XrplPaymentTransaction.cs

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ public XrplPaymentTransaction()
2525
TransactionType = XrplTransactionType.Payment.ToString();
2626
}
2727

28+
/// <summary>
29+
/// Transactions of the Payment type support additional values in the Flags field.
30+
/// </summary>
31+
[JsonPropertyName("Flags")]
32+
public new XrplPaymentFlags? Flags { get; set; }
33+
2834
/// <summary>
2935
/// The unique address of the account receiving the payment.
3036
/// </summary>
@@ -53,14 +59,14 @@ public XrplPaymentTransaction()
5359
/// rates, and slippage.
5460
/// </summary>
5561
[JsonPropertyName("SendMax")]
56-
public XrplTransactionCurrencyAmount? SendMax { get; set; }
62+
public object? SendMax { get; private set; }
5763

5864
/// <summary>
5965
/// (Optional) Minimum amount of destination currency this transaction should deliver. Only valid if this is a partial
6066
/// payment.
6167
/// </summary>
6268
[JsonPropertyName("DeliverMin")]
63-
public XrplTransactionCurrencyAmount? DeliverMin { get; set; }
69+
public object? DeliverMin { get; private set; }
6470

6571
/// <summary>
6672
/// XRP Amount
@@ -70,6 +76,22 @@ public void SetAmount(decimal amount)
7076
Amount = amount.XrpToDropsString();
7177
}
7278

79+
/// <summary>
80+
/// XRP Amount
81+
/// </summary>
82+
public void SetSendMaxAmount(decimal amount)
83+
{
84+
SendMax = amount.XrpToDropsString();
85+
}
86+
87+
/// <summary>
88+
/// XRP Amount
89+
/// </summary>
90+
public void SetDeliverMinAmount(decimal amount)
91+
{
92+
DeliverMin = amount.XrpToDropsString();
93+
}
94+
7395
/// <summary>
7496
/// Non-XRP Amounts
7597
/// </summary>
@@ -82,4 +104,30 @@ public void SetAmount(string currency, decimal amount, string issuer)
82104
Issuer = issuer
83105
};
84106
}
107+
108+
/// <summary>
109+
/// Non-XRP Amounts
110+
/// </summary>
111+
public void SetSendMaxAmount(string currency, decimal amount, string issuer)
112+
{
113+
SendMax = new XrplTransactionCurrencyAmount
114+
{
115+
Currency = currency,
116+
Value = amount.ToString(CultureInfo.InvariantCulture),
117+
Issuer = issuer
118+
};
119+
}
120+
121+
/// <summary>
122+
/// Non-XRP Amounts
123+
/// </summary>
124+
public void SetDeliverMinAmount(string currency, decimal amount, string issuer)
125+
{
126+
DeliverMin = new XrplTransactionCurrencyAmount
127+
{
128+
Currency = currency,
129+
Value = amount.ToString(CultureInfo.InvariantCulture),
130+
Issuer = issuer
131+
};
132+
}
85133
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
using XUMM.NET.SDK.Enums;
1+
using System.Collections.Generic;
2+
using XUMM.NET.SDK.Enums;
23

34
namespace XUMM.NET.SDK.Models.Payload.Xumm
45
{
5-
public class XummPayloadTransaction : XummPayloadTransactionBase
6+
public class XummPayloadTransaction : Dictionary<string, object>
67
{
7-
public XummPayloadTransaction(XummTransactionType transactionType) : base(transactionType.ToString())
8+
public XummPayloadTransaction(XummTransactionType transactionType)
89
{
10+
Add("TransactionType", transactionType.ToString());
911
}
1012
}
1113
}

src/XUMM.NET.SDK/Models/Payload/Xumm/XummPayloadTransactionBase.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)