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

feat: make onchain metadata type configurable for /assets/<id> endpoint #57

Closed
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
4 changes: 2 additions & 2 deletions src/Blockfrost.Api/Models/Cardano/Assets/AssetResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//namespace Blockfrost.Api.Models.Cardano.Assets
namespace Blockfrost.Api
{
public partial class AssetResponse
public partial class AssetResponse<TMetadata>
{
/// <summary>Hex-encoded asset name of the asset</summary>
[JsonPropertyName("asset_name")]
Expand Down Expand Up @@ -36,7 +36,7 @@ public partial class AssetResponse
/// <br/>community discussion around the standard ongoing at https://github.com/cardano-foundation/CIPs/pull/85
/// <br/></summary>
[JsonPropertyName("onchain_metadata")]
public Onchain_metadata Onchain_metadata { get; set; }
public TMetadata Onchain_metadata { get; set; }

/// <summary>Policy ID of the asset</summary>
[JsonPropertyName("policy_id")]
Expand Down
27 changes: 23 additions & 4 deletions src/Blockfrost.Api/Services/Cardano/AssetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,36 @@ public async Task<ICollection<AssetsResponse>> AssetsAll2Async(int? count, int?
/// <param name="asset">Concatenation of the policy_id and hex-encoded asset_name</param>
/// <returns>Return the information about a specific asset</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
public Task<AssetResponse> AssetsAsync(string asset)
public Task<AssetResponse<Onchain_metadata>> AssetsAsync(string asset)
{
return AssetsAsync(asset, CancellationToken.None);
return AssetsAsync<Onchain_metadata>(asset, CancellationToken.None);
}

/// <summary>Specific asset</summary>
/// <param name="asset">Concatenation of the policy_id and hex-encoded asset_name</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>Return the information about a specific asset</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
public Task<AssetResponse<Onchain_metadata>> AssetsAsync(string asset, CancellationToken cancellationToken)
{
return AssetsAsync<Onchain_metadata>(asset, cancellationToken);
}

/// <summary>Specific asset</summary>
/// <param name="asset">Concatenation of the policy_id and hex-encoded asset_name</param>
/// <returns>Return the information about a specific asset</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
public async Task<AssetResponse> AssetsAsync(string asset, CancellationToken cancellationToken)
public Task<AssetResponse<TMetadata>> AssetsAsync<TMetadata>(string asset)
{
return AssetsAsync<TMetadata>(asset, CancellationToken.None);
}

/// <summary>Specific asset</summary>
/// <param name="asset">Concatenation of the policy_id and hex-encoded asset_name</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>Return the information about a specific asset</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
public async Task<AssetResponse<TMetadata>> AssetsAsync<TMetadata>(string asset, CancellationToken cancellationToken)
{
if (asset == null)
{
Expand All @@ -87,7 +106,7 @@ public async Task<AssetResponse> AssetsAsync(string asset, CancellationToken can
_ = urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/assets/{asset}");
_ = urlBuilder_.Replace("{asset}", System.Uri.EscapeDataString(ConvertToString(asset, System.Globalization.CultureInfo.InvariantCulture)));

return await SendGetRequestAsync<AssetResponse>(urlBuilder_, cancellationToken);
return await SendGetRequestAsync<AssetResponse<TMetadata>>(urlBuilder_, cancellationToken);
}

/// <summary>Asset addresses</summary>
Expand Down
16 changes: 14 additions & 2 deletions src/Blockfrost.Api/Services/IAssetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,25 @@ Task<ICollection<AssetsResponse>> AssetsAll2Async(int? count, int? page, ESortOr
/// Use <see cref="IBlockfrostService.InserMethodName"/> instead
/// </summary>
//[System.Obsolete("Service methods without 'Get' prefix will be no longer supported. See comments for details.")]
Task<AssetResponse> AssetsAsync(string asset);
Task<AssetResponse<Onchain_metadata>> AssetsAsync(string asset);

/// <summary>
/// Use <see cref="IBlockfrostService.InserMethodName"/> instead
/// </summary>
//[System.Obsolete("Service methods without 'Get' prefix will be no longer supported. See comments for details.")]
Task<AssetResponse> AssetsAsync(string asset, CancellationToken cancellationToken);
Task<AssetResponse<Onchain_metadata>> AssetsAsync(string asset, CancellationToken cancellationToken);

/// <summary>
/// Use <see cref="IBlockfrostService.InserMethodName"/> instead
/// </summary>
//[System.Obsolete("Service methods without 'Get' prefix will be no longer supported. See comments for details.")]
Task<AssetResponse<TMetadata>> AssetsAsync<TMetadata>(string asset);

/// <summary>
/// Use <see cref="IBlockfrostService.InserMethodName"/> instead
/// </summary>
//[System.Obsolete("Service methods without 'Get' prefix will be no longer supported. See comments for details.")]
Task<AssetResponse<TMetadata>> AssetsAsync<TMetadata>(string asset, CancellationToken cancellationToken);

/// <summary>
/// Use <see cref="IBlockfrostService.InserMethodName"/> instead
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ public Task<ICollection<StakeAddressAddressesAssetsResponse>> AssetsAllAsync(str
return Accounts.AssetsAllAsync(stake_address, count, page, order, cancellationToken);
}

public Task<AssetResponse> AssetsAsync(string asset)
public Task<AssetResponse<Onchain_metadata>> AssetsAsync(string asset)
{
return Assets.AssetsAsync(asset);
}

public Task<AssetResponse> AssetsAsync(string asset, CancellationToken cancellationToken)
public Task<AssetResponse<Onchain_metadata>> AssetsAsync(string asset, CancellationToken cancellationToken)
{
return Assets.AssetsAsync(asset, cancellationToken);
}
Expand Down