Skip to content

Commit c274a01

Browse files
committed
move to correct location, remove optional parameters from constructor, add missed extensions, update demo for test
1 parent 9fa6713 commit c274a01

File tree

3 files changed

+76
-5
lines changed

3 files changed

+76
-5
lines changed

TonLibDotNet.Demo/Samples/AccountBalanceAndTransactions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class AccountBalanceAndTransactions : ISample
88
private readonly ITonClient tonClient;
99
private readonly ILogger logger;
1010

11-
private const string account = "EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N"; // TON Foundation wallet
11+
private const string account = "Ef8zMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzM0vF"; // Elector wallet
1212

1313
public AccountBalanceAndTransactions(ITonClient tonClient, ILogger<AccountBalanceAndTransactions> logger)
1414
{
@@ -34,7 +34,7 @@ public async Task Run(bool inMainnet)
3434
var rast = await tonClient.RawGetAccountState(account);
3535
logger.LogInformation("Acc info via RawGetAccountState(): balance = {Value} nanoton or {Value} TON", rast.Balance, TonUtils.Coins.FromNano(rast.Balance));
3636

37-
var txs = await tonClient.RawGetTransactions(account, rast.LastTransactionId);
37+
var txs = await tonClient.RawGetTransactionsV2(account, rast.LastTransactionId, 5);
3838
foreach (var item in txs.TransactionsList)
3939
{
4040
if (item.InMsg?.Value > 0)

TonLibDotNet/Extensions/TonClientRawExtensions.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,77 @@ public static Task<Transactions> RawGetTransactions(this ITonClient client, stri
5757
{
5858
return RawGetTransactions(client, new Types.AccountAddress(accountAddress), fromTransactionId);
5959
}
60+
61+
/// <summary>
62+
/// Get specified number of transactions for specified account, starting from specified one.
63+
/// </summary>
64+
/// <param name="client">ITonClient instance.</param>
65+
/// <param name="accountAddress">Address to get transactions for.</param>
66+
/// <param name="fromTransactionId">Transaction to start from (this and previous will be returned).</param>
67+
/// <param name="count">Number of transactions to return.</param>
68+
/// <remarks>To get recent/last transactions - use LastTransactionId value from <see cref="RawGetAccountState(ITonClient, Types.AccountAddress)"/> or <see cref="TonClientExtensions.GetAccountState(ITonClient, Types.AccountAddress)"/> responses.</remarks>
69+
/// <seealso href="https://github.com/ton-blockchain/ton/blob/v2023.01/tonlib/tonlib/TonlibClient.cpp#L2826"/>
70+
public static Task<Transactions> RawGetTransactionsV2(this ITonClient client, Types.AccountAddress accountAddress, Types.Internal.TransactionId fromTransactionId, int count)
71+
{
72+
ArgumentNullException.ThrowIfNull(accountAddress);
73+
ArgumentNullException.ThrowIfNull(fromTransactionId);
74+
if (string.IsNullOrEmpty(accountAddress.Value))
75+
{
76+
throw new ArgumentNullException(nameof(accountAddress));
77+
}
78+
if (string.IsNullOrEmpty(fromTransactionId.Hash))
79+
{
80+
throw new ArgumentNullException(nameof(fromTransactionId));
81+
}
82+
if (count <= 0)
83+
{
84+
throw new ArgumentOutOfRangeException(nameof(count), "Must be positive");
85+
}
86+
87+
return client.Execute(new GetTransactionsV2(accountAddress, fromTransactionId, count));
88+
}
89+
90+
/// <inheritdoc cref="RawGetTransactionsV2(ITonClient, Types.AccountAddress, Types.Internal.TransactionId, int)"/>
91+
public static Task<Transactions> RawGetTransactionsV2(this ITonClient client, string accountAddress, Types.Internal.TransactionId fromTransactionId, int count)
92+
{
93+
return RawGetTransactionsV2(client, new Types.AccountAddress(accountAddress), fromTransactionId, count);
94+
}
95+
96+
/// <summary>
97+
/// Get specified number of transactions for specified account, starting from specified one, and try to decrypt messages with specified private key.
98+
/// </summary>
99+
/// <param name="client">ITonClient instance.</param>
100+
/// <param name="privateKey">Private key to decode messages.</param>
101+
/// <param name="accountAddress">Address to get transactions for.</param>
102+
/// <param name="fromTransactionId">Transaction to start from (this and previous will be returned).</param>
103+
/// <param name="count">Number of transactions to return.</param>
104+
/// <remarks>To get recent/last transactions - use LastTransactionId value from <see cref="RawGetAccountState(ITonClient, Types.AccountAddress)"/> or <see cref="TonClientExtensions.GetAccountState(ITonClient, Types.AccountAddress)"/> responses.</remarks>
105+
/// <seealso href="https://github.com/ton-blockchain/ton/blob/v2023.01/tonlib/tonlib/TonlibClient.cpp#L2826"/>
106+
public static Task<Transactions> RawGetTransactionsV2(this ITonClient client, Types.InputKey privateKey, Types.AccountAddress accountAddress, Types.Internal.TransactionId fromTransactionId, int count)
107+
{
108+
ArgumentNullException.ThrowIfNull(privateKey);
109+
ArgumentNullException.ThrowIfNull(accountAddress);
110+
ArgumentNullException.ThrowIfNull(fromTransactionId);
111+
if (string.IsNullOrEmpty(accountAddress.Value))
112+
{
113+
throw new ArgumentNullException(nameof(accountAddress));
114+
}
115+
if (string.IsNullOrEmpty(fromTransactionId.Hash))
116+
{
117+
throw new ArgumentNullException(nameof(fromTransactionId));
118+
}
119+
if (count <= 0)
120+
{
121+
throw new ArgumentOutOfRangeException(nameof(count), "Must be positive");
122+
}
123+
124+
return client.Execute(new GetTransactionsV2(accountAddress, fromTransactionId, count) { PrivateKey = privateKey, TryDecodeMessages = true });
125+
}
126+
127+
/// <inheritdoc cref="RawGetTransactionsV2(ITonClient, Types.InputKey, Types.AccountAddress, Types.Internal.TransactionId, int)"/>
128+
public static Task<Transactions> RawGetTransactionsV2(this ITonClient client, Types.InputKey privateKey, string accountAddress, Types.Internal.TransactionId fromTransactionId, int count)
129+
{
130+
return RawGetTransactionsV2(client, privateKey, new Types.AccountAddress(accountAddress), fromTransactionId, count);
131+
}
60132
}
61133
}

TonLibDotNet/Requests/GetTransactionsV2.cs renamed to TonLibDotNet/Requests/Raw/GetTransactionsV2.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
namespace TonLibDotNet.Requests.Raw
44
{
5-
[TLSchema("raw.getTransactionsV2 private_key:InputKey account_address:accountAddress from_transaction_id:internal.transactionId count:# try_decode_messages:Bool = raw.Transactions;")]
5+
[TLSchema("raw.getTransactionsV2 private_key:InputKey account_address:accountAddress from_transaction_id:internal.transactionId count:# try_decode_messages:Bool = raw.Transactions")]
66
public class GetTransactionsV2 : RequestBase<Types.Raw.Transactions>
77
{
8-
public GetTransactions(AccountAddress accountAddress, Types.Internal.TransactionId fromTransactionId, int count = 3, bool tryDecodeMessages = false)
8+
public GetTransactionsV2(AccountAddress accountAddress, Types.Internal.TransactionId fromTransactionId, int count)
99
{
1010
AccountAddress = accountAddress ?? throw new ArgumentNullException(nameof(accountAddress));
1111
FromTransactionId = fromTransactionId ?? throw new ArgumentNullException(nameof(fromTransactionId));
1212
Count = count;
13-
TryDecodeMessages = tryDecodeMessages;
1413
}
1514

1615
public InputKey? PrivateKey { get; set; }

0 commit comments

Comments
 (0)