Skip to content

Commit 298168b

Browse files
committed
TelemintRecipes added, base Tep81Recipes added, RootDnsRecipes updated
1 parent c0ef97f commit 298168b

15 files changed

+899
-193
lines changed

TonLibDotNet.Demo/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.Extensions.DependencyInjection;
22
using Microsoft.Extensions.Hosting;
33
using TonLibDotNet.Samples;
4+
using TonLibDotNet.Samples.Recipes;
45
using TonLibDotNet.Types;
56

67
namespace TonLibDotNet
@@ -46,6 +47,8 @@ public static async Task Main(string[] args)
4647
services.AddTransient<ISample, ReadInfoFromSmartContracts>();
4748
services.AddTransient<ISample, BocAndCells>();
4849
services.AddTransient<ISample, DomainAuctionInfo>();
50+
services.AddTransient<ISample, RootDnsGetAllInfo>();
51+
services.AddTransient<ISample, TelemintGetAllInfo>();
4952
});
5053

5154
/// Add types from current assembly (see <see cref="LibraryExtensibility"/> class for more info).

TonLibDotNet.Demo/Samples/DomainAuctionInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public async Task Run(bool inMainnet)
4949
logger.LogInformation("Auction info (method 1-bis): last bid = {Value} TON, bidder is {Address}, auction ends at {Time}", ai!.MaxBidAmount, ai.MaxBidAddress, ai.AuctionEndTime);
5050

5151
// Method 2: Use TonRecipes to parse all DNS Item data.
52-
var di = await TonRecipes.RootDns.GetAllInfo(tonClient, domainName);
52+
var di = await TonRecipes.RootDns.GetAllInfo(tonClient, domainAddress);
5353
logger.LogInformation("Auction info (method 2): last bid = {Value} TON, bidder is {Address}, auction ends at {Time}", di.AuctionInfo!.MaxBidAmount, di.AuctionInfo.MaxBidAddress, di.AuctionInfo.AuctionEndTime);
5454
}
5555

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System.Text.Json;
2+
using Microsoft.Extensions.Logging;
3+
4+
namespace TonLibDotNet.Samples.Recipes
5+
{
6+
public class RootDnsGetAllInfo : ISample
7+
{
8+
private readonly ITonClient tonClient;
9+
private readonly ILogger logger;
10+
11+
public RootDnsGetAllInfo(ITonClient tonClient, ILogger<RootDnsGetAllInfo> logger)
12+
{
13+
this.tonClient = tonClient ?? throw new ArgumentNullException(nameof(tonClient));
14+
this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
15+
}
16+
17+
public async Task Run(bool inMainnet)
18+
{
19+
if (!inMainnet)
20+
{
21+
logger.LogWarning("Recipes_GetDomainInfo() sample in Testnet is disabled, because I don't know valid DNS Contract addresses. Switch to mainnet in Program.cs and try again.");
22+
return;
23+
}
24+
25+
await tonClient.InitIfNeeded();
26+
27+
var domain = "foundation.ton";
28+
29+
var di = await TonRecipes.RootDns.GetAllInfoByName(tonClient, domain);
30+
31+
logger.LogInformation(
32+
"TonRecipes info for '{Domain}':\r\n{Info}",
33+
domain,
34+
JsonSerializer.Serialize(di, new JsonSerializerOptions() { WriteIndented = true }));
35+
}
36+
}
37+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Text.Json;
2+
using Microsoft.Extensions.Logging;
3+
4+
namespace TonLibDotNet.Samples.Recipes
5+
{
6+
public class TelemintGetAllInfo : ISample
7+
{
8+
private readonly ITonClient tonClient;
9+
private readonly ILogger logger;
10+
11+
public TelemintGetAllInfo(ITonClient tonClient, ILogger<TelemintGetAllInfo> logger)
12+
{
13+
this.tonClient = tonClient ?? throw new ArgumentNullException(nameof(tonClient));
14+
this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
15+
}
16+
17+
public async Task Run(bool inMainnet)
18+
{
19+
if (!inMainnet)
20+
{
21+
logger.LogWarning("Recipes_GetTelemintInfo() sample in Testnet is disabled, because I don't know valid DNS Contract addresses. Switch to mainnet in Program.cs and try again.");
22+
return;
23+
}
24+
25+
await tonClient.InitIfNeeded();
26+
27+
var domain = "dolboeb.t.me";
28+
29+
var ti = await TonRecipes.Telemint.GetAllInfoByName(tonClient, domain);
30+
31+
// Output as JSON because I'm too lazy to write separate lines for each field.
32+
logger.LogInformation(
33+
"Info about '{Domain}':\r\n{Json}",
34+
domain,
35+
JsonSerializer.Serialize(ti, new JsonSerializerOptions() { WriteIndented = true }));
36+
}
37+
}
38+
}

TonLibDotNet.Demo/Samples/ResolveDomains.cs

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using System.Text;
2-
using Microsoft.Extensions.Logging;
1+
using Microsoft.Extensions.Logging;
2+
using TonLibDotNet.Samples.Recipes;
33
using TonLibDotNet.Types.Dns;
44

55
namespace TonLibDotNet.Samples
@@ -12,9 +12,6 @@ public class ResolveDomains : ISample
1212
// Values below may change over time. Verify them using explorers as first troubleshooting step.
1313
private const string DomainName = "toncenter";
1414
private const string DomainNameFull = "toncenter.ton";
15-
private const string CollectionAddress = "EQC3dNlesgVD8YbAazcauIrXBPfiVhMMr5YYk2in0Mtsz0Bz";
16-
private const string DomainNftAddress = "EQAiIsvar4OYBn8BGBf9flfin6tl5poBx4MgJe4CQJYasy51";
17-
private const string OwnerAddress = "EQCh-GaMveITkw41cHEvi13ZzAXNVtRksHq_PvGuMFENnhrT";
1815

1916
public ResolveDomains(ITonClient tonClient, ILogger<ResolveDomains> logger)
2017
{
@@ -66,36 +63,8 @@ public async Task Run(bool inMainnet)
6663
logger.LogInformation("Site (Storage):{Value}", entries.SiteToStorage);
6764
logger.LogInformation("Next Resolver: {Value}", entries.DnsNextResolver);
6865

69-
7066
// Method 3: Use TonRecipes and recieve all info with one call
71-
var di = await TonRecipes.RootDns.GetAllInfo(tonClient, DomainNameFull);
72-
73-
logger.LogInformation("TonRecipes info for '{Domain}':", di.Name);
74-
logger.LogInformation(" Collection is: {Value}", di.CollectionAddress);
75-
logger.LogInformation(" Index is: {Value}", Convert.ToBase64String(di.Index));
76-
logger.LogInformation(" NFT address: {Value}", di.Address);
77-
logger.LogInformation(" Deployed?: {Value}", di.IsDeployed);
78-
79-
if (di.IsDeployed)
80-
{
81-
logger.LogInformation(" Owner: {Value}", di.EditorAddress);
82-
logger.LogInformation(" In auction: {Value}", di.AuctionInfo != null);
83-
if (di.AuctionInfo != null)
84-
{
85-
logger.LogInformation(" Max Bid: {Value}", di.AuctionInfo.MaxBidAmount);
86-
logger.LogInformation(" Max Bidder: {Value}", di.AuctionInfo.MaxBidAddress);
87-
logger.LogInformation(" End time: {Value}", di.AuctionInfo.AuctionEndTime);
88-
}
89-
90-
logger.LogInformation(" Last fill-up: {Value}", di.LastFillUpTime);
91-
92-
logger.LogInformation(" DNS Entries:");
93-
logger.LogInformation(" Wallet: {Value}", di.Entries.Wallet);
94-
logger.LogInformation(" Site (ADNL):{Value}", di.Entries.SiteToAdnl);
95-
logger.LogInformation(" Site (Stor):{Value}", di.Entries.SiteToStorage);
96-
logger.LogInformation(" Storage: {Value}", di.Entries.Storage);
97-
logger.LogInformation(" Next resolv:{Value}", di.Entries.DnsNextResolver);
98-
}
67+
logger.LogWarning("Also, check {Name}!", nameof(RootDnsGetAllInfo));
9968
}
10069
}
10170
}

TonLibDotNet.Demo/SamplesRunner.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@ public async Task StartAsync(CancellationToken cancellationToken)
1919
await tonClient.InitIfNeeded();
2020
await tonClient.Sync();
2121

22-
var samples = services.GetServices(typeof(ISample)).Cast<ISample>().OrderBy(x => x.GetType().Name).ToList();
22+
var samples = services.GetServices(typeof(ISample)).Cast<ISample>().OrderBy(x => x.GetType().FullName).ToList();
2323

2424
var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
2525

2626
while (!cts.IsCancellationRequested)
2727
{
28+
var trimLength = "TonLibDotNet.Samples.".Length;
2829
Console.WriteLine();
2930
Console.WriteLine("Available samples:");
3031
for (var i = 0; i < samples.Count; i++)
3132
{
32-
Console.WriteLine(" {0}: {1}", i, samples[i].GetType().Name);
33+
Console.WriteLine(" {0}: {1}", i, samples[i].GetType().FullName![trimLength..]);
3334
}
3435

3536
while (!cts.IsCancellationRequested)
@@ -69,7 +70,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
6970
var sample = samples[index];
7071

7172
Console.WriteLine();
72-
Console.WriteLine("Running {0} sample...", sample.GetType().Name);
73+
Console.WriteLine("Running {0} sample...", sample.GetType().FullName);
7374
Console.WriteLine();
7475

7576
await sample.Run(Program.UseMainnet).ConfigureAwait(false);

TonLibDotNet.Tests/Recipes/RootDnsRecipes_GetNftAddress_Tests.cs

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
namespace TonLibDotNet.Recipes
2+
{
3+
[Collection(TonClientMainnetCollection.Definition)]
4+
public class RootDnsRecipes_Tests
5+
{
6+
private readonly Func<Task<ITonClient>> getTonClient;
7+
8+
private const string FoundationTonAddress = "EQB43-VCmf17O7YMd51fAvOjcMkCw46N_3JMCoegH_ZDo40e";
9+
10+
public RootDnsRecipes_Tests(TonClientMainnetFixture fixture)
11+
{
12+
getTonClient = fixture.GetTonClient;
13+
}
14+
15+
[Fact]
16+
public void GetNftIndexWorks()
17+
{
18+
var index = TonRecipes.RootDns.GetNftIndex("toncenter.ton");
19+
var valid = Convert.FromHexString("AFBE954CF1C028D02B3CEDF915D55249F2FCAD54808DB4FB91C7509677373CCF");
20+
Assert.Equal(valid, index);
21+
}
22+
23+
[Fact]
24+
public async Task ResolveWithSuffix()
25+
{
26+
var tonClient = await getTonClient();
27+
28+
var adr = await TonRecipes.RootDns.GetNftAddress(tonClient, "foundation.ton");
29+
Assert.Equal(FoundationTonAddress, adr);
30+
}
31+
32+
[Fact]
33+
public async Task ResolveWithoutSuffix()
34+
{
35+
var tonClient = await getTonClient();
36+
37+
var adr = await TonRecipes.RootDns.GetNftAddress(tonClient, "foundation");
38+
Assert.Equal(FoundationTonAddress, adr);
39+
}
40+
41+
[Fact]
42+
public async Task ResolveNotMinted()
43+
{
44+
var tonClient = await getTonClient();
45+
46+
// Does not exist as NFT at time of writing this test
47+
var adr = await TonRecipes.RootDns.GetNftAddress(tonClient, "not-yet-minted-domain.ton");
48+
49+
// How to get expected value?
50+
// go to https://dns.ton.org/#not-yet-minted-domain and sniff toncenter requests in Developer Console
51+
Assert.Equal("EQBZoyjQa3ywgrlG_A4lYrhtKxity6BCfMsMEjLNFYSckQGX", adr);
52+
}
53+
54+
[Fact]
55+
public async Task FailsForNonTonDomains()
56+
{
57+
var tonClient = await getTonClient();
58+
await Assert.ThrowsAsync<ArgumentOutOfRangeException>(() => TonRecipes.RootDns.GetNftAddress(tonClient, "alice.t.me"));
59+
}
60+
61+
[Theory]
62+
[InlineData("subdomain.domain.ton")]
63+
[InlineData("subdomain.domain")]
64+
public async Task FailsForThirdlevelDomains(string domain)
65+
{
66+
var tonClient = await getTonClient();
67+
await Assert.ThrowsAsync<ArgumentOutOfRangeException>(() => TonRecipes.RootDns.GetNftAddress(tonClient, domain));
68+
}
69+
70+
[Fact]
71+
public async Task GetEditorWorks()
72+
{
73+
var tonClient = await getTonClient();
74+
var ed = await TonRecipes.RootDns.GetEditor(tonClient, FoundationTonAddress);
75+
Assert.Equal("EQCdqXGvONLwOr3zCNX5FjapflorB6ZsOdcdfLrjsDLt3Fy9", ed);
76+
}
77+
78+
[Fact]
79+
public async Task GetDomainNameWorks()
80+
{
81+
var tonClient = await getTonClient();
82+
var dn = await TonRecipes.RootDns.GetDomainName(tonClient, FoundationTonAddress);
83+
Assert.Equal("foundation", dn);
84+
}
85+
86+
[Fact]
87+
public async Task GetAllInfoWorks()
88+
{
89+
var tonClient = await getTonClient();
90+
var ti = await TonRecipes.RootDns.GetAllInfo(tonClient, FoundationTonAddress);
91+
Assert.NotNull(ti);
92+
}
93+
94+
[Fact]
95+
public async Task GetAllInfoByNameWorks()
96+
{
97+
var tonClient = await getTonClient();
98+
var ti = await TonRecipes.RootDns.GetAllInfoByName(tonClient, "foundation.ton");
99+
Assert.NotNull(ti);
100+
}
101+
}
102+
}

0 commit comments

Comments
 (0)