Skip to content

Commit 2881e70

Browse files
committed
Added TransactionHistory and OutputDetails routes
1 parent 1434ab2 commit 2881e70

File tree

6 files changed

+146
-17
lines changed

6 files changed

+146
-17
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace IotaExplorerNet.Domain.Common.Interfaces
77
[Headers("Content-Type: application/json")]
88
public interface ITestnetExplorerApi
99
{
10-
[Get("/stardust/balance/testnet/{address}")]
10+
[Get(TestnetRoutesResolver.AddressBalanceRoute)]
1111
Task<AddressBalanceResponse> GetAddressBalanceAsync(string address);
1212

1313
[Get("/stardust/transaction/testnet/{transactionId}")]
@@ -16,6 +16,14 @@ public interface ITestnetExplorerApi
1616
[Get("/stardust/address/outputs/nft/testnet/{address}")]
1717
//Task<ApiResponse<string>> GetNftBalanceAsync(string address);
1818
Task<ApiResponse<NftBalancesResponse>> GetNftBalanceAsync(string address);
19+
20+
[Get(TestnetRoutesResolver.TransactionHistoryRoute)]
21+
Task<ApiResponse<TransactionHistoryResponse>> GetTransactionHistoryAsync(string address);
22+
23+
[Get(TestnetRoutesResolver.OutputDetailsRoute)]
24+
//Task<ApiResponse<string>> GetOutputDetailsAsync(string outputId);
25+
Task<ApiResponse<OutputDetailsResponse>> GetOutputDetailsAsync(string outputId);
26+
1927
}
2028

2129
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using IotaWalletNet.Domain.Common.Interfaces;
2+
using IotaWalletNet.Domain.Common.Models.Explorer;
3+
4+
namespace IotaExplorerNet.Domain.Common.Responses
5+
{
6+
public class OutputDetailsResponse
7+
{
8+
//public OutputDetailsResponse(IOutputType output, OutputMetadataResponse metadata)
9+
//{
10+
// this.output = output;
11+
// this.metadata = metadata;
12+
//}
13+
14+
//public IOutputType? output { get; set; }
15+
public OutputResponse Output { get; set; }
16+
17+
}
18+
19+
public class OutputResponse
20+
{
21+
//public OutputDetailsResponse(IOutputType output, OutputMetadataResponse metadata)
22+
//{
23+
// this.output = output;
24+
// this.metadata = metadata;
25+
//}
26+
27+
public IOutputType? Output { get; set; }
28+
29+
public OutputMetadataResponse Metadata { get; set; } = new OutputMetadataResponse();
30+
}
31+
32+
public class OutputMetadataResponse
33+
{
34+
35+
/**
36+
* The block id the output was contained in.
37+
*/
38+
public string? BlockId { get; set; }
39+
40+
/**
41+
* The transaction id for the output.
42+
*/
43+
public string? TransactionId { get; set; }
44+
45+
/**
46+
* The index for the output.
47+
*/
48+
public uint OutputIndex { get; set; }
49+
/**
50+
* Is the output spent.
51+
*/
52+
public bool IsSpent { get; set; }
53+
54+
/**
55+
* The milestone index at which this output was booked into the ledger.
56+
*/
57+
public uint MilestoneIndexBooked { get; set; }
58+
59+
/**
60+
* The milestone timestamp this output was booked in the ledger.
61+
*/
62+
public uint MilestoneTimestampBooked { get; set; }
63+
64+
/**
65+
* The ledger index at which these output was available at.
66+
*/
67+
public uint LedgerIndex { get; set; }
68+
}
69+
70+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace IotaExplorerNet.Domain.Common.Responses
2+
{
3+
public class TransactionHistoryResponse
4+
{
5+
public string Address { get; set; } = "";
6+
7+
public List<OutputTransactionHistory> Items { get; set; } = new();
8+
}
9+
10+
public class OutputTransactionHistory
11+
{
12+
public string OutputId { get; set; } = "";
13+
14+
public bool IsSpent { get; set; } = false;
15+
16+
public int MilestoneIndex { get; set; }
17+
18+
public int MilestoneTimestamp { get; set; }
19+
}
20+
}
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
namespace IotaExplorerNet.Domain.Common
22
{
3-
public static class RoutesResolver
3+
public static class TestnetRoutesResolver
44
{
5-
public static bool IsTestnet { get; set; } = false;
6-
7-
public static string GetAddressBalanceRoute()
8-
=> IsTestnet
9-
? "/stardust/balance/testnet/{address}"
10-
: "/stardust/balance/shimmer/{address}";
11-
5+
public const string AddressBalanceRoute = "/stardust/balance/testnet/{address}";
6+
public const string TransactionHistoryRoute = "/stardust/transactionhistory/testnet/{address}?pageSize=10&sort=newest";
7+
public const string OutputDetailsRoute = "/stardust/output/testnet/{outputId}";
8+
}
129

10+
public static class ShimmerRoutesResolver
11+
{
12+
public const string AddressBalanceRoute = "/stardust/balance/shimmer/{address}";
13+
public const string TransactionHistoryRoute = "/stardust/transactionhistory/shimmer/{address}?pageSize=10&sort=newest";
14+
public const string OutputDetailsRoute = "/stardust/output/shimmer/{outputId}";
1315

1416
}
1517
}

IotaExplorerNet/IotaExplorerNet.Domain/IotaExplorerNet.Domain.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
</ItemGroup>
2626

2727
<ItemGroup>
28+
<PackageReference Include="IotaWallet.Net" Version="0.3.6.1-alpha" />
29+
<PackageReference Include="JsonSubTypes" Version="2.0.1" />
2830
<PackageReference Include="Refit.HttpClientFactory" Version="7.0.0" />
2931
<PackageReference Include="Refit.Newtonsoft.Json" Version="7.0.0" />
3032
</ItemGroup>

IotaExplorerNet/IotaExplorerNet.Main/Program.cs

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
using IotaExplorerNet.Domain.Common.Extensions;
22
using IotaExplorerNet.Domain.Common.Interfaces;
3+
using IotaExplorerNet.Domain.Common.Responses;
4+
using IotaWalletNet.Domain.Common.Extensions;
5+
using IotaWalletNet.Domain.Common.Interfaces;
6+
using IotaWalletNet.Domain.Common.Models.Output.FeatureTypes;
7+
using IotaWalletNet.Domain.Common.Models.Output.OutputTypes;
38
using Microsoft.Extensions.DependencyInjection;
9+
using Newtonsoft.Json;
410

511
namespace IotaExplorerNet.Main
612
{
@@ -19,18 +25,39 @@ static async Task Main(string[] args)
1925

2026
ITestnetExplorerApi testnetExplorerApi = testnetExplorerProvider(BASE_URL);
2127

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!);
28+
//var x = await testnetExplorerApi.GetNftBalanceAsync("rms1qptynkddm3gjgmuwtstfzy529j4r55z9r5qeszedxncy3p5uurerwm85n0r");
29+
//Console.WriteLine(x);
2730

2831
//AddressBalanceResponse addressBalanceResponse = await testnetExplorerApi.GetAddressBalance("rms1qptynkddm3gjgmuwtstfzy529j4r55z9r5qeszedxncy3p5uurerwm85n0r");
2932
//Console.WriteLine(addressBalanceResponse);
3033

31-
//var r = await testnetExplorerApi.GetTransactionAsync("0xc7246c93cf58541d040d791104be7fee3c7a5e7d73fae3a09dadd47f6c56ee4c");
32-
//Console.WriteLine(r);
33-
//0x8137f2fc2f2874ffa036e38450b8922d552d4d77880e8ce52a0100bbdd9546dd block
34+
var x = await testnetExplorerApi.GetTransactionHistoryAsync("rms1qp2qnal79rglwe2mc60ee8crhk2pnk4yt0v4jt6kuwz8sactau6yyevsatr");
35+
Console.WriteLine(JsonConvert.SerializeObject(x.Content, Formatting.Indented));
36+
TransactionHistoryResponse transactionHistoryResponse = x.Content!;
37+
38+
var outputIdsList = transactionHistoryResponse.Items.Select(x => x.OutputId).ToList();
39+
40+
foreach (var outputId in outputIdsList)
41+
{
42+
var r = await testnetExplorerApi.GetOutputDetailsAsync(outputId);
43+
var outputDetails = r.Content!;
44+
if (outputDetails.Output!.Output!.Type != 3)
45+
continue;
46+
47+
var basicOutput = (BasicOutput)outputDetails.Output.Output;
48+
if (basicOutput.Features?.Any(x => x.Type == 2) == true)
49+
{
50+
// The collection is not null and contains an element with Type == 2
51+
var metadata = (MetadataFeature)basicOutput.Features.First(x => x.Type == 2);
52+
string data = metadata.Data.FromHexString();
53+
54+
Console.WriteLine(data);
55+
}
56+
57+
58+
}
59+
60+
3461
}
3562
}
3663
}

0 commit comments

Comments
 (0)