Skip to content

Commit d097a15

Browse files
AccountHistory endpoint update
1 parent 3c4b26d commit d097a15

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

src/Mx.NET.SDK/Domain/Data/Accounts/AccountHistory.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Mx.NET.SDK.Core.Domain.Values;
44
using Mx.NET.SDK.Provider.Dtos.API.Accounts;
55
using Mx.NET.SDK.Domain.Helper;
6+
using System.Linq;
67

78
namespace Mx.NET.SDK.Domain.Data.Accounts
89
{
@@ -40,5 +41,15 @@ public static AccountHistory From(AccountHistoryDto accountHistory)
4041
IsSender = accountHistory.IsSender,
4142
};
4243
}
44+
public static AccountHistory[] From(AccountHistoryDto[] accountHistories)
45+
{
46+
return accountHistories.Select(accountHistory => new AccountHistory()
47+
{
48+
Address = Address.FromBech32(accountHistory.Address),
49+
Balance = ESDTAmount.From(accountHistory.Balance),
50+
HistoryTime = accountHistory.Timestamp.ToDateTime(),
51+
IsSender = accountHistory.IsSender,
52+
}).ToArray();
53+
}
4354
}
4455
}

src/Mx.NET.SDK/Domain/Data/Accounts/AccountHistoryToken.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Mx.NET.SDK.Core.Domain.Values;
44
using Mx.NET.SDK.Provider.Dtos.API.Accounts;
55
using Mx.NET.SDK.Domain.Helper;
6+
using System.Linq;
67

78
namespace Mx.NET.SDK.Domain.Data.Accounts
89
{
@@ -16,7 +17,7 @@ public class AccountHistoryToken
1617
/// <summary>
1718
/// Account EGLD Balance
1819
/// </summary>
19-
public ESDTAmount Balance { get; set; }
20+
public string Balance { get; set; }
2021

2122
/// <summary>
2223
/// History moment
@@ -40,11 +41,23 @@ public static AccountHistoryToken From(AccountHistoryTokenDto accountHistoryToke
4041
return new AccountHistoryToken()
4142
{
4243
Address = Address.FromBech32(accountHistoryToken.Address),
43-
Balance = ESDTAmount.From(accountHistoryToken.Balance),
44+
Balance = accountHistoryToken.Balance,
4445
HistoryTime = accountHistoryToken.Timestamp.ToDateTime(),
4546
IsSender = accountHistoryToken.IsSender,
4647
Token = accountHistoryToken.Token
4748
};
4849
}
50+
51+
public static AccountHistoryToken[] From(AccountHistoryTokenDto[] accountHistoriesToken)
52+
{
53+
return accountHistoriesToken.Select(accountHistoryToken => new AccountHistoryToken()
54+
{
55+
Address = Address.FromBech32(accountHistoryToken.Address),
56+
Balance = accountHistoryToken.Balance,
57+
HistoryTime = accountHistoryToken.Timestamp.ToDateTime(),
58+
IsSender = accountHistoryToken.IsSender,
59+
Token = accountHistoryToken.Token
60+
}).ToArray();
61+
}
4962
}
5063
}

src/Mx.NET.SDK/Provider/API/IAccountsProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public interface IAccountsProvider
229229
/// <param name="size">Number of items to retrieve (max 10000)</param>
230230
/// <param name="from">Number of items to skip for the result set</param>
231231
/// <returns><see cref="AccountHistoryDto"/></returns>
232-
Task<AccountHistoryDto[]> GetAccountHistory(string address, int size = 100, int from = 0);
232+
Task<AccountHistoryDto[]> GetAccountHistory(string address, int size = 100, int from = 0, Dictionary<string, string> parameters = null);
233233

234234
/// <summary>
235235
/// Returns account Token balance history
@@ -239,6 +239,6 @@ public interface IAccountsProvider
239239
/// <param name="size">Number of items to retrieve (max 10000)</param>
240240
/// <param name="from">Number of items to skip for the result set</param>
241241
/// <returns><see cref="AccountHistoryTokenDto"/></returns>
242-
Task<AccountHistoryTokenDto[]> GetAccountHistoryToken(string address, string tokenIdentifier, int size = 100, int from = 0);
242+
Task<AccountHistoryTokenDto[]> GetAccountHistoryToken(string address, string tokenIdentifier, int size = 100, int from = 0, Dictionary<string, string> parameters = null);
243243
}
244244
}

src/Mx.NET.SDK/Provider/ApiProvider.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,22 @@ public async Task<string> GetAccountContractsCount(string address)
240240
return await Get<string>($"accounts/{address}/contracts/count");
241241
}
242242

243-
public async Task<AccountHistoryDto[]> GetAccountHistory(string address, int size = 100, int from = 0)
243+
public async Task<AccountHistoryDto[]> GetAccountHistory(string address, int size = 100, int from = 0, Dictionary<string, string> parameters = null)
244244
{
245245
size = size > 10000 ? 10000 : size;
246-
return await Get<AccountHistoryDto[]>($"accounts/{address}/history?from={from}&size={size}");
246+
string args = "";
247+
if (parameters != null)
248+
args = $"&{string.Join("&", parameters.Select(e => $"{e.Key}={e.Value}"))}";
249+
return await Get<AccountHistoryDto[]>($"accounts/{address}/history?from={from}&size={size}{args}");
247250
}
248251

249-
public async Task<AccountHistoryTokenDto[]> GetAccountHistoryToken(string address, string tokenIdentifier, int size = 100, int from = 0)
252+
public async Task<AccountHistoryTokenDto[]> GetAccountHistoryToken(string address, string tokenIdentifier, int size = 100, int from = 0, Dictionary<string, string> parameters = null)
250253
{
251254
size = size > 10000 ? 10000 : size;
252-
return await Get<AccountHistoryTokenDto[]>($"accounts/{address}/history/{tokenIdentifier}?from={from}&size={size}");
255+
string args = "";
256+
if (parameters != null)
257+
args = $"&{string.Join("&", parameters.Select(e => $"{e.Key}={e.Value}"))}";
258+
return await Get<AccountHistoryTokenDto[]>($"accounts/{address}/history/{tokenIdentifier}?from={from}&size={size}{args}");
253259
}
254260

255261
#endregion

0 commit comments

Comments
 (0)