Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GetTransactions method with workchain, shard and seqno parameters #131

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions TonSdk.Client/src/Client/ITonClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,26 @@ public interface ITonClient
/// <summary>
/// Retrieves transaction information for the specified address.
/// </summary>
/// <param name="address">The address object to retrieve transaction information for.</param>
/// <param name="address">The address object to retrieve transaction information for (optional for <c>HTTP_TONCENTERAPIV3</c>).</param>
/// <param name="workchain">Block workchain (optional).</param>
/// <param name="shard">Block shard id. Must be sent with workchain (optional).</param>
/// <param name="seqno">Block block seqno. Must be sent with workchain and shard (optional).</param>
/// <param name="limit">The maximum number of transactions to retrieve (default: 10).</param>
/// <param name="lt">The logical time of the transaction to start retrieving from (optional).</param>
/// <param name="hash">The hash of the transaction to start retrieving from (optional).</param>
/// <param name="to_lt">The logical time of the transaction to retrieve up to (optional).</param>
/// <param name="archival">Specifies whether to retrieve transactions from archival nodes (optional).</param>
/// <returns>An array of transaction information results.</returns>
Task<TransactionsInformationResult[]> GetTransactions(Address address, uint limit = 10,
ulong? lt = null, string hash = null, ulong? to_lt = null, bool? archival = null);
Task<TransactionsInformationResult[]> GetTransactions(
Address address = null,
int? workchain = null,
long? shard = null,
long? seqno = null,
uint limit = 10,
ulong? lt = null,
string hash = null,
ulong? to_lt = null,
bool? archival = null);

/// <summary>
/// Executes a specific method on the specified address.
Expand Down
2 changes: 1 addition & 1 deletion TonSdk.Client/src/Client/Jetton/Jetton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ await JettonUtils.ParseMetadata(((VmStackCell)result.Value.StackItems[3]).Value)
/// <returns>An array of parsed jetton transactions.</returns>
public async Task<IJettonTransaction[]> GetTransactions(Address jettonWallet, int limit = 5, uint? decimals = null, BlockIdExtended? block = null)
{
TransactionsInformationResult[] transactionsInformationResults = await client.GetTransactions(jettonWallet, (uint)limit);
TransactionsInformationResult[] transactionsInformationResults = await client.GetTransactions(address: jettonWallet, limit: (uint)limit);
uint jettonDecimals = decimals ?? await GetDecimalsByWallet(jettonWallet, block);

IJettonTransaction[] parsedTransactions = new IJettonTransaction[transactionsInformationResults.Length];
Expand Down
15 changes: 11 additions & 4 deletions TonSdk.Client/src/Client/TonClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,24 +249,31 @@ public async Task<bool> IsContractDeployed(Address address, BlockIdExtended? blo
/// <summary>
/// Retrieves transaction information for the specified address.
/// </summary>
/// <param name="address">The address object to retrieve transaction information for.</param>
/// <param name="address">The address object to retrieve transaction information for (optional for <c>HTTP_TONCENTERAPIV3</c>).</param>
/// <param name="workchain">Block workchain (optional).</param>
/// <param name="shard">Block shard id. Must be sent with workchain (optional).</param>
/// <param name="seqno">Block block seqno. Must be sent with workchain and shard (optional).</param>
/// <param name="limit">The maximum number of transactions to retrieve (default: 10).</param>
/// <param name="lt">The logical time of the transaction to start retrieving from (optional).</param>
/// <param name="hash">The hash of the transaction to start retrieving from (optional).</param>
/// <param name="to_lt">The logical time of the transaction to retrieve up to (optional).</param>
/// <param name="archival">Specifies whether to retrieve transactions from archival nodes (optional).</param>
/// <returns>An array of transaction information results.</returns>
public async Task<TransactionsInformationResult[]?> GetTransactions(Address address, uint limit = 10,
ulong? lt = null, string hash = null, ulong? to_lt = null, bool? archival = null)
public async Task<TransactionsInformationResult[]> GetTransactions(Address address = null,
int? workchain = null, long? shard = null, long? seqno = null,
uint limit = 10, ulong? lt = null, string hash = null, ulong? to_lt = null, bool? archival = null)
{
if(_type == TonClientType.LITECLIENT && (lt == null || hash == null))
throw new ArgumentException("From lt and hash, must be defined for LiteClient type.");

if (_type != TonClientType.HTTP_TONCENTERAPIV3 && (workchain != null || shard != null || seqno != null))
throw new ArgumentException($"Workchain, shard and seqno parameters are not supported for {_type} client type.");

return _type switch
{
TonClientType.HTTP_TONCENTERAPIV2 => await _httpApi.GetTransactions(address, limit, lt, hash, to_lt, archival),
TonClientType.HTTP_TONWHALESAPI => await _httpWhales.GetTransactions(address, limit, lt, hash, to_lt, archival),
TonClientType.HTTP_TONCENTERAPIV3 => await _httpApiV3.GetTransactions(address, limit, lt, hash, to_lt, archival),
TonClientType.HTTP_TONCENTERAPIV3 => await _httpApiV3.GetTransactions(address, workchain, shard, seqno, limit, lt, hash, to_lt, archival),
TonClientType.LITECLIENT => await _liteClientApi.GetTransactions(address, limit, (long)lt, hash),
_ => null
};
Expand Down
3 changes: 3 additions & 0 deletions TonSdk.Client/src/HttpApi/HttpsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ internal async Task<BlockTransactionsResult> GetBlockTransactions(
internal async Task<TransactionsInformationResult[]> GetTransactions(Address address, uint limit = 10,
ulong? lt = null, string hash = null, ulong? to_lt = null, bool? archival = null)
{
if (address is null)
throw new ArgumentException($"Address must be defined for {nameof(TonClientType.HTTP_TONCENTERAPIV2)} client type.");

InTransactionsBody requestBody = new InTransactionsBody()
{
address = address.ToString(AddressType.Base64, new AddressStringifyOptions(true, false, false)),
Expand Down
87 changes: 39 additions & 48 deletions TonSdk.Client/src/HttpApi/HttpsApiV3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,30 +112,11 @@ internal async Task<ShardsInformationResult> Shards(long seqno)
return new ShardsInformationResult(JsonConvert.DeserializeObject<OutV3ShardsInformationResult>(result));
}

internal async Task<TransactionsInformationResult[]> GetTransactions(Address address, uint limit = 10,
ulong? lt = null, string hash = null, ulong? to_lt = null, bool? archival = null)
internal async Task<TransactionsInformationResult[]> GetTransactions(Address address = null,
int? workchain = null, long? shard = null, long? seqno = null,
uint limit = 10, ulong? lt = null, string hash = null, ulong? to_lt = null, bool? archival = null)
{
var dict = new Dictionary<string, object>()
{
{
"account", address.ToString()
},
{
"offset", "0"
},
{
"limit", limit.ToString()
},
{
"sort", "desc"
}
};

if (lt != null)
dict.Add("start_lt", lt.ToString());
if (to_lt != null)
dict.Add("end_lt", to_lt.ToString());

var dict = BuildGetTransactionsRequestParameters(workchain, shard, seqno, address, hash, lt, to_lt, limit);
string result = await new TonRequestV3(new RequestParametersV3("transactions", dict), _httpClient).CallGet();

var data = JsonConvert.DeserializeObject<RootTransactions>(result).Transactions;
Expand All @@ -154,31 +135,7 @@ internal async Task<BlockTransactionsResult> GetBlockTransactions(
{
try
{
var dict = new Dictionary<string, object>()
{
{
"workchain", workchain.ToString()
},
{
"shard", shard.ToString("X")
},
{
"seqno", seqno.ToString()
},
{
"offset", "0"
},
{
"limit", count != null ? count.ToString() : "10"
},
{
"sort", "desc"
}
};

if (afterLt != null)
dict.Add("start_lt", afterLt.ToString());

var dict = BuildGetTransactionsRequestParameters(workchain: workchain, shard: shard, seqno: seqno, startLt: afterLt, limit: count ?? 10);
string result = await new TonRequestV3(new RequestParametersV3("transactions", dict), _httpClient).CallGet();

var data = JsonConvert.DeserializeObject<RootBlockTransactions>(result).Transactions;
Expand Down Expand Up @@ -269,6 +226,40 @@ internal async Task<EstimateFeeResultExtended> EstimateFee(MessageX message, boo

return JsonConvert.DeserializeObject<EstimateFeeResultExtended>(result);
}

private Dictionary<string, object> BuildGetTransactionsRequestParameters(
int? workchain = null,
long? shard = null,
long? seqno = null,
Address address = null,
string hash = null,
ulong? startLt = null,
ulong? endLt = null,
uint limit = 10,
int offset = 0,
SortDirection sort = SortDirection.DESC)
{
var queryParameters = new Dictionary<string, object>
{
{ "offset", offset.ToString() },
{ "limit", limit.ToString() },
{ "sort", sort.ToString().ToLower() }
};

if (workchain.HasValue) queryParameters.Add("workchain", workchain.ToString());
if (shard.HasValue) queryParameters.Add("shard", shard.Value.ToString("X"));
if (seqno.HasValue) queryParameters.Add("seqno", seqno.ToString());

if (address != null)
queryParameters.Add("account", address.ToString(AddressType.Raw));

if (!string.IsNullOrEmpty(hash)) queryParameters.Add("hash", hash);

if (startLt != null) queryParameters.Add("start_lt", startLt.ToString());
if (endLt != null) queryParameters.Add("end_lt", endLt.ToString());

return queryParameters;
}

public async Task<string> CustomGetMethodCall(string request, List<string[]> body)
{
Expand Down
3 changes: 3 additions & 0 deletions TonSdk.Client/src/HttpApi/HttpsWhales.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ internal async Task<BlockTransactionsResult> GetBlockTransactions(
internal async Task<TransactionsInformationResult[]> GetTransactions(Address address, uint limit = 10,
ulong? lt = null, string hash = null, ulong? to_lt = null, bool? archival = null)
{
if (address is null)
throw new ArgumentException($"Address must be defined for {nameof(TonClientType.HTTP_TONWHALESAPI)} client type.");

InTransactionsBody requestBody = new InTransactionsBody()
{
address = address.ToString(AddressType.Base64, new AddressStringifyOptions(true, false, false)),
Expand Down
3 changes: 3 additions & 0 deletions TonSdk.Client/src/LiteClientApi/LiteClientApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ internal async Task<TransactionsInformationResult[]> GetTransactions(Address add
{
try
{
if (address is null)
throw new ArgumentException($"Address must be defined for {nameof(TonClientType.LITECLIENT)} client type.");

var result = new List<TransactionsInformationResult>();
await Init();

Expand Down
6 changes: 6 additions & 0 deletions TonSdk.Client/src/Models/Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ public enum TonClientType
LITECLIENT,

}

public enum SortDirection
{
ASC,
DESC
}

public interface ITonClientOptions {}

Expand Down
6 changes: 3 additions & 3 deletions TonSdk.Client/src/Models/Transformers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ internal struct OutRawMessage
[JsonProperty("value")] public string Value;
[JsonProperty("fwd_fee")] public string FwdFee;
[JsonProperty("ihr_fee")] public string IhrFee;
[JsonProperty("created_lt")] public ulong CreaterLt;
[JsonProperty("created_lt")] public ulong? CreaterLt;
[JsonProperty("body_hash")] public string BodyHash;
[JsonProperty("msg_data")] public OutRawMessageData MsgData;
[JsonProperty("message")] public string Message;
Expand All @@ -471,7 +471,7 @@ internal struct OutV3RawMessage
[JsonProperty("opcode")] public string OpCode;
[JsonProperty("fwd_fee")] public string FwdFee;
[JsonProperty("ihr_fee")] public string IhrFee;
[JsonProperty("created_lt")] public ulong CreatedLt;
[JsonProperty("created_lt")] public ulong? CreatedLt;
[JsonProperty("message_content")] public OutV3RawMessageData MsgData;
}

Expand Down Expand Up @@ -852,7 +852,7 @@ public struct RawMessage
public Coins Value;
public Coins FwdFee;
public Coins IhrFee;
public ulong CreatedLt;
public ulong? CreatedLt;
public string OpCode;
public string BodyHash;
public RawMessageData MsgData;
Expand Down
2 changes: 1 addition & 1 deletion TonSdk.Client/test/LiteClientApi.test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async Task Test_GetBlockTransactions()
[Test]
public async Task Test_GetTransactions()
{
var result = await _client.GetTransactions(new Address("EQCwHyzOrKP1lBHbvMrFHChifc1TLgeJVpKgHpL9sluHU-gV"), 10, 20075201000003, "KC2THpE1CsLKCUJQj/CVtzZ1gTPt/Ho36h8bwIlcyII=");
var result = await _client.GetTransactions(address: new Address("EQCwHyzOrKP1lBHbvMrFHChifc1TLgeJVpKgHpL9sluHU-gV"), limit: 10, lt: 20075201000003, hash: "KC2THpE1CsLKCUJQj/CVtzZ1gTPt/Ho36h8bwIlcyII=");
Console.WriteLine(JsonConvert.SerializeObject(result));
}

Expand Down