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

Resource holders endpoint. #755

Merged
merged 18 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 16 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: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ Release built: _not released yet_
- Added support for the Native Resource Details in the `/state/entity/details` endpoint, returned when the `native_resource_details` opt-in is enabled.
- Brand-new `native_resource_details` property on the `details` property.
- Includes **unit** redemption value for the Validator LSU token and the unit tokens of various Pools.
- Added new endpoint `/extensions/resource-holders/page` which returns information about all holders of the queried resource.

### Database changes
- Replaced relationship-related columns (`*_entity_id`) in the `entities` table with more generic collection implementation using `correlated_entity_*` columns.
- Replaced per-epoch validator emissions (`validator_emission_statistics` table) with their cumulative statistics (`validator_cumulative_emission_history` table).
- Added `non_fungible_data_mutable_fields` to `entities` table. Which contains list of all mutable non fungible data fields for non fungible resource entities.
- New `ledger_transaction_markers` type with the `event_global_emitter` discriminator. It represents the global emitter for each event.
- Added new `unverified_standard_metadata_*` tables. They hold **some** of the metadata entries using db-friendly (normalized) model. See https://docs.radixdlt.com/docs/metadata-standards
- Added new `unverified_standard_metadata_*` tables. They hold **some** of the metadata entries using db-friendly (normalized) model. See https://docs.radixdlt.com/docs/metadata-standards
- Extended list of supported entity correlations in the `entities` table.
- Renamed values of the `entity_relationship` enum type.
- Added new `resource_holders` table. It keeps information about all holders of each fungible and non fungible resource.

## 1.6.3
Release built: 06.08.2024
Expand Down
3 changes: 2 additions & 1 deletion apps/DataAggregator/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,8 @@
"dependencies": {
"JsonSubTypes": "[2.0.1, )",
"Newtonsoft.Json": "[13.0.3, )",
"Polly": "[8.3.0, )"
"Polly": "[8.3.0, )",
"RadixDlt.NetworkGateway.Abstractions": "[1.7.0-develop, )"
}
},
"radixdlt.networkgateway.postgresintegration": {
Expand Down
3 changes: 2 additions & 1 deletion apps/DatabaseMigrations/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,8 @@
"dependencies": {
"JsonSubTypes": "[2.0.1, )",
"Newtonsoft.Json": "[13.0.3, )",
"Polly": "[8.3.0, )"
"Polly": "[8.3.0, )",
"RadixDlt.NetworkGateway.Abstractions": "[1.7.0-develop, )"
}
},
"radixdlt.networkgateway.postgresintegration": {
Expand Down
82 changes: 82 additions & 0 deletions apps/GatewayApi/Controllers/ExtensionsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* Copyright 2021 Radix Publishing Ltd incorporated in Jersey (Channel Islands).
*
* Licensed under the Radix License, Version 1.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
*
* radixfoundation.org/licenses/LICENSE-v1
*
* The Licensor hereby grants permission for the Canonical version of the Work to be
* published, distributed and used under or by reference to the Licensor’s trademark
* Radix ® and use of any unregistered trade names, logos or get-up.
*
* The Licensor provides the Work (and each Contributor provides its Contributions) on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
* including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT,
* MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.
*
* Whilst the Work is capable of being deployed, used and adopted (instantiated) to create
* a distributed ledger it is your responsibility to test and validate the code, together
* with all logic and performance of that code under all foreseeable scenarios.
*
* The Licensor does not make or purport to make and hereby excludes liability for all
* and any representation, warranty or undertaking in any form whatsoever, whether express
* or implied, to any entity or person, including any representation, warranty or
* undertaking, as to the functionality security use, value or other characteristics of
* any distributed ledger nor in respect the functioning or value of any tokens which may
* be created stored or transferred using the Work. The Licensor does not warrant that the
* Work or any use of the Work complies with any law or regulation in any territory where
* it may be implemented or used or that it will be appropriate for any specific purpose.
*
* Neither the licensor nor any current or former employees, officers, directors, partners,
* trustees, representatives, agents, advisors, contractors, or volunteers of the Licensor
* shall be liable for any direct or indirect, special, incidental, consequential or other
* losses of any kind, in tort, contract or otherwise (including but not limited to loss
* of revenue, income or profits, or loss of use or data, or loss of reputation, or loss
* of any economic or other opportunity of whatsoever nature or howsoever arising), arising
* out of or in connection with (without limitation of any use, misuse, of any ledger system
* or use made or its functionality or any performance or operation of any code or protocol
* caused by bugs or programming or logic errors or otherwise);
*
* A. any offer, purchase, holding, use, sale, exchange or transmission of any
* cryptographic keys, tokens or assets created, exchanged, stored or arising from any
* interaction with the Work;
*
* B. any failure in a transmission or loss of any token or assets keys or other digital
* artefacts due to errors in transmission;
*
* C. bugs, hacks, logic errors or faults in the Work or any communication;
*
* D. system software or apparatus including but not limited to losses caused by errors
* in holding or transmitting tokens by any third-party;
*
* E. breaches or failure of security including hacker attacks, loss or disclosure of
* password, loss of private key, unauthorised use or misuse of such passwords or keys;
*
* F. any losses including loss of anticipated savings or other benefits resulting from
* use of the Work or any changes to the Work (however implemented).
*
* You are solely responsible for; testing, validating and evaluation of all operation
* logic, functionality, security and appropriateness of using the Work for any commercial
* or non-commercial purpose and for any reproduction or redistribution by You of the
* Work. You assume all risks associated with Your use of the Work and the exercise of
* permissions under this License.
*/

using Microsoft.AspNetCore.Mvc;
using RadixDlt.NetworkGateway.GatewayApi.Handlers;
using System.Threading;
using System.Threading.Tasks;
using GatewayModel = RadixDlt.NetworkGateway.GatewayApiSdk.Model;

namespace GatewayApi.Controllers;

[ApiController]
[Route("extensions")]
public class ExtensionsController(IExtensionsHandler extensionsHandler) : ControllerBase
{
[HttpPost("resource-holders/page")]
public async Task<GatewayModel.ResourceHoldersResponse> ResourceHoldersPage(GatewayModel.ResourceHoldersRequest request, CancellationToken token)
{
return await extensionsHandler.ResourceHolders(request, token);
}
}
11 changes: 2 additions & 9 deletions apps/GatewayApi/Controllers/StatisticsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,11 @@ namespace GatewayApi.Controllers;

[ApiController]
[Route("statistics")]
public class StatisticsController : ControllerBase
public class StatisticsController(IValidatorHandler validatorHandler) : ControllerBase
{
private readonly IValidatorHandler _validatorHandler;

public StatisticsController(IValidatorHandler validatorHandler)
{
_validatorHandler = validatorHandler;
}

[HttpPost("validators/uptime")]
public async Task<GatewayModel.ValidatorsUptimeResponse> ValidatorsUptime(GatewayModel.ValidatorsUptimeRequest request, CancellationToken token)
{
return await _validatorHandler.Uptime(request, token);
return await validatorHandler.Uptime(request, token);
}
}
3 changes: 2 additions & 1 deletion apps/GatewayApi/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,8 @@
"dependencies": {
"JsonSubTypes": "[2.0.1, )",
"Newtonsoft.Json": "[13.0.3, )",
"Polly": "[8.3.0, )"
"Polly": "[8.3.0, )",
"RadixDlt.NetworkGateway.Abstractions": "[1.7.0-develop, )"
}
},
"radixdlt.networkgateway.postgresintegration": {
Expand Down
1 change: 1 addition & 0 deletions babylon-gateway.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=mempool/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Querier/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=radixfoundation/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=sbor/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=substate/@EntryIndexedValue">True</s:Boolean>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ namespace RadixDlt.NetworkGateway.Abstractions.Numerics;
public static readonly TokenAmount Zero;
public static readonly TokenAmount NaN;
public static readonly TokenAmount OneFullUnit;
public static readonly TokenAmount MaxValue;

private const int DecimalPrecision = 18;

Expand All @@ -83,7 +84,7 @@ namespace RadixDlt.NetworkGateway.Abstractions.Numerics;
static TokenAmount()
{
_divisor = BigInteger.Pow(10, DecimalPrecision);

MaxValue = new TokenAmount(BigInteger.Pow(2, 192), 0);
Zero = new TokenAmount(0);
NaN = new TokenAmount(true);
OneFullUnit = new TokenAmount(_divisor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,15 @@ public sealed class EndpointOptions
[ConfigurationKeyName("ValidatorsUptimePageSize")]
public int ValidatorsUptimeMaxPageSize { get; set; } = 200;

[ConfigurationKeyName("ResourceHoldersMaxPageSize")]
public int ResourceHoldersMaxPageSize { get; set; } = 1000;

[ConfigurationKeyName("TransactionStreamMaxFilterCount")]
public int TransactionStreamMaxFilterCount { get; set; } = 10;

public int ResolvePageSize(int? requestPageSize) => ResolvePageSize(requestPageSize, DefaultPageSize, MaxPageSize);

public int ResolveNonFungibleIdsPageSize(int? requestPageSize) => ResolvePageSize(requestPageSize, DefaultNonFungibleIdsPageSize, MaxPageSize);
public int ResolveResourceHoldersPageSize(int? requestPageSize) => ResolvePageSize(requestPageSize, DefaultPageSize, ResourceHoldersMaxPageSize);

public int ResolveHeavyPageSize(int? requestPageSize) => ResolvePageSize(requestPageSize, DefaultHeavyCollectionsPageSize, MaxHeavyCollectionsPageSize);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* Copyright 2021 Radix Publishing Ltd incorporated in Jersey (Channel Islands).
*
* Licensed under the Radix License, Version 1.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
*
* radixfoundation.org/licenses/LICENSE-v1
*
* The Licensor hereby grants permission for the Canonical version of the Work to be
* published, distributed and used under or by reference to the Licensor’s trademark
* Radix ® and use of any unregistered trade names, logos or get-up.
*
* The Licensor provides the Work (and each Contributor provides its Contributions) on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
* including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT,
* MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.
*
* Whilst the Work is capable of being deployed, used and adopted (instantiated) to create
* a distributed ledger it is your responsibility to test and validate the code, together
* with all logic and performance of that code under all foreseeable scenarios.
*
* The Licensor does not make or purport to make and hereby excludes liability for all
* and any representation, warranty or undertaking in any form whatsoever, whether express
* or implied, to any entity or person, including any representation, warranty or
* undertaking, as to the functionality security use, value or other characteristics of
* any distributed ledger nor in respect the functioning or value of any tokens which may
* be created stored or transferred using the Work. The Licensor does not warrant that the
* Work or any use of the Work complies with any law or regulation in any territory where
* it may be implemented or used or that it will be appropriate for any specific purpose.
*
* Neither the licensor nor any current or former employees, officers, directors, partners,
* trustees, representatives, agents, advisors, contractors, or volunteers of the Licensor
* shall be liable for any direct or indirect, special, incidental, consequential or other
* losses of any kind, in tort, contract or otherwise (including but not limited to loss
* of revenue, income or profits, or loss of use or data, or loss of reputation, or loss
* of any economic or other opportunity of whatsoever nature or howsoever arising), arising
* out of or in connection with (without limitation of any use, misuse, of any ledger system
* or use made or its functionality or any performance or operation of any code or protocol
* caused by bugs or programming or logic errors or otherwise);
*
* A. any offer, purchase, holding, use, sale, exchange or transmission of any
* cryptographic keys, tokens or assets created, exchanged, stored or arising from any
* interaction with the Work;
*
* B. any failure in a transmission or loss of any token or assets keys or other digital
* artefacts due to errors in transmission;
*
* C. bugs, hacks, logic errors or faults in the Work or any communication;
*
* D. system software or apparatus including but not limited to losses caused by errors
* in holding or transmitting tokens by any third-party;
*
* E. breaches or failure of security including hacker attacks, loss or disclosure of
* password, loss of private key, unauthorised use or misuse of such passwords or keys;
*
* F. any losses including loss of anticipated savings or other benefits resulting from
* use of the Work or any changes to the Work (however implemented).
*
* You are solely responsible for; testing, validating and evaluation of all operation
* logic, functionality, security and appropriateness of using the Work for any commercial
* or non-commercial purpose and for any reproduction or redistribution by You of the
* Work. You assume all risks associated with Your use of the Work and the exercise of
* permissions under this License.
*/

using Microsoft.Extensions.Options;
using RadixDlt.NetworkGateway.Abstractions;
using RadixDlt.NetworkGateway.GatewayApi.Configuration;
using RadixDlt.NetworkGateway.GatewayApi.Services;
using System.Threading;
using System.Threading.Tasks;
using GatewayModel = RadixDlt.NetworkGateway.GatewayApiSdk.Model;

namespace RadixDlt.NetworkGateway.GatewayApi.Handlers;

internal class DefaultExtensionsHandler(IExtensionsQuerier extensionsQuerier, IOptionsSnapshot<EndpointOptions> endpointConfiguration) : IExtensionsHandler
{
public async Task<GatewayModel.ResourceHoldersResponse> ResourceHolders(GatewayModel.ResourceHoldersRequest request, CancellationToken token)
{
var cursor = GatewayModel.ResourceHoldersCursor.FromCursorString(request.Cursor);

return await extensionsQuerier.ResourceHolders(
(EntityAddress)request.ResourceAddress,
endpointConfiguration.Value.ResolveResourceHoldersPageSize(request.LimitPerPage),
cursor,
token);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using GatewayModel = RadixDlt.NetworkGateway.GatewayApiSdk.Model;

namespace RadixDlt.NetworkGateway.GatewayApi.Handlers;

Expand All @@ -81,7 +82,7 @@ public DefaultValidatorHandler(ILedgerStateQuerier ledgerStateQuerier, IValidato
_validatorQuerier = validatorQuerier;
}

public async Task<GatewayApiSdk.Model.ValidatorsUptimeResponse> Uptime(GatewayApiSdk.Model.ValidatorsUptimeRequest request, CancellationToken token)
public async Task<GatewayModel.ValidatorsUptimeResponse> Uptime(GatewayModel.ValidatorsUptimeRequest request, CancellationToken token)
{
var ledgerState = await _ledgerStateQuerier.GetValidLedgerStateForReadRequest(request.AtLedgerState, token);
var fromLedgerState = await _ledgerStateQuerier.GetValidLedgerStateForReadForwardRequest(request.FromLedgerState, token);
Expand Down
Loading
Loading