Skip to content

Commit

Permalink
Merge branch 'feat/add-validation-tab' into feat/add-delegation-search
Browse files Browse the repository at this point in the history
  • Loading branch information
brancoder committed Feb 26, 2024
2 parents c44dbd7 + 2b52a49 commit 4be9765
Show file tree
Hide file tree
Showing 35 changed files with 1,178 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nova-build-temp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
TARGET_COMMIT:
description: "Target Commit Hash for the SDK"
required: false
default: "fc9f0f56bb5cfc146993e53aa9656ded220734e1"
default: "aa1b1de58731dbbf9dd0f5e2960fd11b0056b633"
environment:
type: choice
description: "Select the environment to deploy to"
Expand Down
11 changes: 11 additions & 0 deletions api/src/models/api/nova/IAccountValidatorDetailsRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface IAccountValidatorDetailsRequest {
/**
* The network to search on.
*/
network: string;

/**
* The account id to get the validator details for.
*/
accountId: string;
}
11 changes: 11 additions & 0 deletions api/src/models/api/nova/IAccountValidatorDetailsResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable import/no-unresolved */
/* eslint-disable @typescript-eslint/no-unsafe-argument */
import { ValidatorResponse } from "@iota/sdk-nova";
import { IResponse } from "./IResponse";

export interface IAccountValidatorDetailsResponse extends IResponse {
/**
* The account validator response.
*/
validatorDetails?: ValidatorResponse;
}
12 changes: 12 additions & 0 deletions api/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ export const routes: IRoute[] = [
folder: "nova/address/outputs/basic",
func: "get",
},
{
path: "/nova/address/outputs/nft/:network/:address",
method: "get",
folder: "nova/address/outputs/nft",
func: "get",
},
{
path: "/nova/output/associated/:network/:address",
method: "post",
Expand All @@ -254,6 +260,12 @@ export const routes: IRoute[] = [
folder: "nova/account/congestion",
func: "get",
},
{
path: "/nova/account/validator/:network/:accountId",
method: "get",
folder: "nova/account/validator",
func: "get",
},
{ path: "/nova/block/:network/:blockId", method: "get", folder: "nova/block", func: "get" },
{ path: "/nova/block/metadata/:network/:blockId", method: "get", folder: "nova/block/metadata", func: "get" },
{ path: "/nova/slot/:network/:slotIndex", method: "get", folder: "nova/slot", func: "get" },
Expand Down
30 changes: 30 additions & 0 deletions api/src/routes/nova/account/validator/get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { ServiceFactory } from "../../../../factories/serviceFactory";
import { IAccountValidatorDetailsRequest } from "../../../../models/api/nova/IAccountValidatorDetailsRequest";
import { IAccountValidatorDetailsResponse } from "../../../../models/api/nova/IAccountValidatorDetailsResponse";
import { IConfiguration } from "../../../../models/configuration/IConfiguration";
import { NOVA } from "../../../../models/db/protocolVersion";
import { NetworkService } from "../../../../services/networkService";
import { NovaApiService } from "../../../../services/nova/novaApiService";
import { ValidationHelper } from "../../../../utils/validationHelper";

/**
* Get validator details for Account address
* @param config The configuration.
* @param request The request.
* @returns The response.
*/
export async function get(config: IConfiguration, request: IAccountValidatorDetailsRequest): Promise<IAccountValidatorDetailsResponse> {
const networkService = ServiceFactory.get<NetworkService>("network");
const networks = networkService.networkNames();
ValidationHelper.oneOf(request.network, networks, "network");
ValidationHelper.string(request.accountId, "accountId");

const networkConfig = networkService.get(request.network);

if (networkConfig.protocolVersion !== NOVA) {
return {};
}

const novaApiService = ServiceFactory.get<NovaApiService>(`api-service-${networkConfig.network}`);
return novaApiService.getAccountValidatorDetails(request.accountId);
}
29 changes: 29 additions & 0 deletions api/src/routes/nova/address/outputs/nft/get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ServiceFactory } from "../../../../../factories/serviceFactory";
import { IAddressDetailsRequest } from "../../../../../models/api/nova/IAddressDetailsRequest";
import { IAddressDetailsResponse } from "../../../../../models/api/nova/IAddressDetailsResponse";
import { IConfiguration } from "../../../../../models/configuration/IConfiguration";
import { NOVA } from "../../../../../models/db/protocolVersion";
import { NetworkService } from "../../../../../services/networkService";
import { NovaApiService } from "../../../../../services/nova/novaApiService";
import { ValidationHelper } from "../../../../../utils/validationHelper";

/**
* Fetch the nft output details by address.
* @param config The configuration.
* @param request The request.
* @returns The response.
*/
export async function get(config: IConfiguration, request: IAddressDetailsRequest): Promise<IAddressDetailsResponse> {
const networkService = ServiceFactory.get<NetworkService>("network");
const networks = networkService.networkNames();
ValidationHelper.oneOf(request.network, networks, "network");

const networkConfig = networkService.get(request.network);

if (networkConfig.protocolVersion !== NOVA) {
return {};
}

const novaApiService = ServiceFactory.get<NovaApiService>(`api-service-${networkConfig.network}`);
return novaApiService.nftOutputDetailsByAddress(request.address);
}
46 changes: 46 additions & 0 deletions api/src/services/nova/novaApiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import logger from "../../logger";
import { IFoundriesResponse } from "../../models/api/nova/foundry/IFoundriesResponse";
import { IFoundryResponse } from "../../models/api/nova/foundry/IFoundryResponse";
import { IAccountDetailsResponse } from "../../models/api/nova/IAccountDetailsResponse";
import { IAccountValidatorDetailsResponse } from "../../models/api/nova/IAccountValidatorDetailsResponse";
import { IAddressDetailsResponse } from "../../models/api/nova/IAddressDetailsResponse";
import { IAnchorDetailsResponse } from "../../models/api/nova/IAnchorDetailsResponse";
import { IBlockDetailsResponse } from "../../models/api/nova/IBlockDetailsResponse";
Expand Down Expand Up @@ -296,6 +297,32 @@ export class NovaApiService {
};
}

/**
* Get the relevant nft output details for an address.
* @param addressBech32 The address in bech32 format.
* @returns The alias output details.
*/
public async nftOutputDetailsByAddress(addressBech32: string): Promise<IAddressDetailsResponse> {
let cursor: string | undefined;
let outputIds: string[] = [];

do {
try {
const outputIdsResponse = await this.client.nftOutputIds({ address: addressBech32, cursor: cursor ?? "" });

outputIds = outputIds.concat(outputIdsResponse.items);
cursor = outputIdsResponse.cursor;
} catch (e) {
logger.error(`Fetching nft output ids failed. Cause: ${e}`);
}
} while (cursor);

const outputResponses = await this.outputsDetails(outputIds);
return {
outputs: outputResponses,
};
}

/**
* Get Congestion for Account
* @param accountId The account address to get the congestion for.
Expand All @@ -315,6 +342,25 @@ export class NovaApiService {
}
}

/**
* Get validator details for Account
* @param accountId The account id to get the validator details for.
* @returns The Congestion.
*/
public async getAccountValidatorDetails(accountId: string): Promise<IAccountValidatorDetailsResponse | undefined> {
try {
const response = await this.client.getValidator(accountId);

if (response) {
return {
validatorDetails: response,
};
}
} catch {
return { message: "Validator details not found" };
}
}

/**
* Get the output mana rewards.
* @param outputId The outputId to get the rewards for.
Expand Down
9 changes: 8 additions & 1 deletion client/src/app/components/nova/FeaturesView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ const FeatureView: React.FC<FeatureViewProps> = ({ feature, isImmutable, isPreEx
{feature.type === FeatureType.Issuer && <AddressView address={(feature as IssuerFeature).address} />}
{feature.type === FeatureType.Metadata && (
<div className="card--value row">
<DataToggle sourceData={(feature as MetadataFeature).data} withSpacedHex={true} />
{Object.entries((feature as MetadataFeature).entries).map(([key, value], index) => (
<div key={index}>
<div className="label margin-t-m">{key}</div>
<div className="value row middle margin-t-t">
<DataToggle sourceData={value} withSpacedHex={true} />
</div>
</div>
))}
</div>
)}
{feature.type === FeatureType.StateMetadata && <div className="card--value row">State metadata unimplemented</div>}
Expand Down
Loading

0 comments on commit 4be9765

Please sign in to comment.