Skip to content

Commit 1434ab2

Browse files
committed
Added getnftbalance
1 parent 4f48aa8 commit 1434ab2

File tree

6 files changed

+107
-18
lines changed

6 files changed

+107
-18
lines changed

IotaExplorerNet/IotaExplorerNet.Domain/Common/Extensions/DependencyInjectionExtensions.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
using IotaExplorerNet.Domain.Common.Interfaces;
22
using Microsoft.Extensions.DependencyInjection;
33
using Refit;
4-
using System;
5-
using System.Collections.Generic;
6-
using System.Linq;
7-
using System.Reflection;
8-
using System.Text;
9-
using System.Threading.Tasks;
104

115
namespace IotaExplorerNet.Domain.Common.Extensions
126
{
@@ -16,7 +10,13 @@ public static IServiceCollection AddIotaExplorerServices(this IServiceCollection
1610
{
1711

1812
serviceDescriptors
19-
.AddSingleton(testnetApiProvider => new Func<string, ITestnetExplorerApi>((url) => RestService.For<ITestnetExplorerApi>(url)));
13+
.AddSingleton(testnetApiProvider => new Func<string, ITestnetExplorerApi>((url) =>
14+
{
15+
NewtonsoftJsonContentSerializer newtonsoftJsonContentSerializer = new NewtonsoftJsonContentSerializer();
16+
RefitSettings refitSettings = new RefitSettings(contentSerializer: newtonsoftJsonContentSerializer);
17+
18+
return RestService.For<ITestnetExplorerApi>(url, refitSettings);
19+
}));
2020

2121
return serviceDescriptors;
2222
}

IotaExplorerNet/IotaExplorerNet.Domain/Common/Interfaces/ITestnetExplorerApi.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ namespace IotaExplorerNet.Domain.Common.Interfaces
88
public interface ITestnetExplorerApi
99
{
1010
[Get("/stardust/balance/testnet/{address}")]
11-
Task<AddressBalanceResponse> GetAddressBalance(string address);
11+
Task<AddressBalanceResponse> GetAddressBalanceAsync(string address);
1212

13-
[Get("/stardust/transaction/testnet/:transactionId")]
13+
[Get("/stardust/transaction/testnet/{transactionId}")]
1414
Task<string> GetTransactionAsync(string transactionId);
15+
16+
[Get("/stardust/address/outputs/nft/testnet/{address}")]
17+
//Task<ApiResponse<string>> GetNftBalanceAsync(string address);
18+
Task<ApiResponse<NftBalancesResponse>> GetNftBalanceAsync(string address);
1519
}
1620

1721
}

IotaExplorerNet/IotaExplorerNet.Domain/Common/Responses/AddressBalanceResponse.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
namespace IotaExplorerNet.Domain.Common.Responses
1+

2+
namespace IotaExplorerNet.Domain.Common.Responses
23
{
34
public class AddressBalanceResponse
45
{
@@ -23,5 +24,11 @@ public AddressBalanceResponse(string balance, IReadOnlyDictionary<string, string
2324
public string Bech32 { get; set; }
2425

2526
public int Type { get; set; }
27+
28+
29+
//public override string ToString()
30+
//{
31+
// return JsonConvert.SerializeObject(this, Formatting.Indented);
32+
//}
2633
}
2734
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
namespace IotaExplorerNet.Domain.Common.Responses
2+
{
3+
public class Address
4+
{
5+
public int Type { get; set; }
6+
public string PubKeyHash { get; set; } = string.Empty;
7+
public string NftId { get; set; } = string.Empty;
8+
}
9+
10+
public class ImmutableFeature
11+
{
12+
public int Type { get; set; }
13+
public Address Address { get; set; } = new Address();
14+
public string Data { get; set; }
15+
}
16+
17+
public class NftBalanceOutputMetadata
18+
{
19+
public string BlockId { get; set; } = string.Empty;
20+
public string TransactionId { get; set; } = string.Empty;
21+
public int OutputIndex { get; set; }
22+
public bool IsSpent { get; set; }
23+
public int MilestoneIndexBooked { get; set; }
24+
public int MilestoneTimestampBooked { get; set; }
25+
public int LedgerIndex { get; set; }
26+
}
27+
28+
public class NftBalanceOutputDetails
29+
{
30+
public NftBalanceOutputMetadata Metadata { get; set; } = new NftBalanceOutputMetadata();
31+
public NftBalanceOutput Output { get; set; } = new NftBalanceOutput();
32+
}
33+
34+
public class NftBalanceOutput
35+
{
36+
public int Type { get; set; }
37+
public string Amount { get; set; } = string.Empty;
38+
public string NftId { get; set; } = string.Empty;
39+
public List<UnlockCondition> UnlockConditions { get; } = new List<UnlockCondition>();
40+
public List<ImmutableFeature> ImmutableFeatures { get; } = new List<ImmutableFeature>();
41+
}
42+
43+
public class NftBalancesResponse
44+
{
45+
public List<NftBalanceOutputDetails> Outputs { get; } = new List<NftBalanceOutputDetails>();
46+
}
47+
48+
public class UnlockCondition
49+
{
50+
public int Type { get; set; }
51+
public Address Address { get; set; } = new Address();
52+
}
53+
54+
55+
56+
57+
}

IotaExplorerNet/IotaExplorerNet.Domain/IotaExplorerNet.Domain.csproj

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,29 @@
44
<TargetFramework>net6.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7+
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
8+
<PackageId>IotaExplorerNet</PackageId>
9+
<Title>IotaExplorerNet</Title>
10+
<Authors>Razali</Authors>
11+
<Company>Razali</Company>
12+
<Product>IotaExplorerNet</Product>
13+
<Description>Library for interacting with the IOTA's official explorer</Description>
14+
<PackageProjectUrl>https://github.com/IOTA-NET/IotaExplorer.NET</PackageProjectUrl>
15+
<PackageReadmeFile>README.md</PackageReadmeFile>
16+
<RepositoryUrl>https://github.com/IOTA-NET/IotaExplorer.NET</RepositoryUrl>
17+
<PackageTags>iota;shimmer;smr;explorer;.net</PackageTags>
718
</PropertyGroup>
819

920
<ItemGroup>
10-
<PackageReference Include="Refit" Version="6.3.2" />
11-
<PackageReference Include="Refit.HttpClientFactory" Version="6.3.2" />
12-
<PackageReference Include="Refit.Newtonsoft.Json" Version="6.3.2" />
21+
<None Include="..\..\README.md">
22+
<Pack>True</Pack>
23+
<PackagePath>\</PackagePath>
24+
</None>
25+
</ItemGroup>
26+
27+
<ItemGroup>
28+
<PackageReference Include="Refit.HttpClientFactory" Version="7.0.0" />
29+
<PackageReference Include="Refit.Newtonsoft.Json" Version="7.0.0" />
1330
</ItemGroup>
1431

1532
</Project>

IotaExplorerNet/IotaExplorerNet.Main/Program.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using IotaExplorerNet.Domain.Common.Extensions;
22
using IotaExplorerNet.Domain.Common.Interfaces;
3-
using IotaExplorerNet.Domain.Common.Responses;
43
using Microsoft.Extensions.DependencyInjection;
5-
using System;
64

75
namespace IotaExplorerNet.Main
86
{
@@ -21,11 +19,17 @@ static async Task Main(string[] args)
2119

2220
ITestnetExplorerApi testnetExplorerApi = testnetExplorerProvider(BASE_URL);
2321

24-
//AddressBalanceResponse addressBalanceResponse = await testnetExplorerApi.GetAddressBalance("rms1qp8rknypruss89dkqnnuedm87y7xmnmdj2tk3rrpcy3sw3ev52q0vzl42tr");
22+
var x = await testnetExplorerApi.GetNftBalanceAsync("rms1qptynkddm3gjgmuwtstfzy529j4r55z9r5qeszedxncy3p5uurerwm85n0r");
23+
Console.WriteLine(x);
24+
string s = @"{""outputs"":[{""metadata"":{""blockId"":""0x022000902b1a41014c66343e8106e0373d1ebef0c46c02322ef2f0d193b64b9b"",""transactionId"":""0x3ad68d91450e60e613d4d350ef4c7a47724c3bcab3466ef5811c4f668349371f"",""outputIndex"":0,""isSpent"":false,""milestoneIndexBooked"":7456755,""milestoneTimestampBooked"":1695952313,""ledgerIndex"":7693149},""output"":{""type"":6,""amount"":""92000"",""nftId"":""0x48179e2655a99ce58b24cacb10e1d8f466af302cc8e1b5fb08bd7d6c00d5aa57"",""unlockConditions"":[{""type"":0,""address"":{""type"":0,""pubKeyHash"":""0x5649d9addc51246f8e5c1691128a2caa3a50451d01980b2d34f048869ce0f237""}}],""immutableFeatures"":[{""type"":1,""address"":{""type"":16,""nftId"":""0xc9210f64c3455f6ffbcb7bb7af587dafea79a9f1158db5512068d2fae293ce7f""}},{""type"":2,""data"":""0x7b227374616e64617264223a224952433237222c2276657273696f6e223a2276312e30222c2274797065223a226170706c69636174696f6e2f6a736f6e222c22757269223a2268747470733a2f2f6769746875622e636f6d2f546f6b656e4761746557656233222c226e616d65223a224964656e74697479546f6b656e222c22636f6c6c656374696f6e4e616d65223a6e756c6c2c226973737565724e616d65223a6e756c6c2c226465736372697074696f6e223a6e756c6c2c22726f79616c74696573223a7b7d2c2261747472696275746573223a5b7b22747261697454797065223a2276657273696f6e222c2276616c7565223a22312e30227d2c7b22747261697454797065223a22757365726e616d65222c2276616c7565223a224461736861204e616e676c65227d2c7b22747261697454797065223a2261646472657373222c2276616c7565223a22726d7331717074796e6b64646d33676a676d7577747374667a793532396a347235357a3972357165737a6564786e63793370357575726572776d38356e3072227d5d2c22696e7465726e616c41747472696275746573223a5b5d7d""}]}}]}
25+
";
26+
//var xx= JsonConvert.DeserializeObject<NftBalancesResponse>(x.Content!);
27+
28+
//AddressBalanceResponse addressBalanceResponse = await testnetExplorerApi.GetAddressBalance("rms1qptynkddm3gjgmuwtstfzy529j4r55z9r5qeszedxncy3p5uurerwm85n0r");
2529
//Console.WriteLine(addressBalanceResponse);
2630

27-
var r = await testnetExplorerApi.GetTransactionAsync("0xc7246c93cf58541d040d791104be7fee3c7a5e7d73fae3a09dadd47f6c56ee4c");
28-
Console.WriteLine(r);
31+
//var r = await testnetExplorerApi.GetTransactionAsync("0xc7246c93cf58541d040d791104be7fee3c7a5e7d73fae3a09dadd47f6c56ee4c");
32+
//Console.WriteLine(r);
2933
//0x8137f2fc2f2874ffa036e38450b8922d552d4d77880e8ce52a0100bbdd9546dd block
3034
}
3135
}

0 commit comments

Comments
 (0)