-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into feat/nova/mark-finalized-blocks
- Loading branch information
Showing
65 changed files
with
2,401 additions
and
360 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* eslint-disable import/no-unresolved */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-argument */ | ||
import { AddressType } from "@iota/sdk-nova"; | ||
|
||
export interface IAddressDetails { | ||
bech32: string; | ||
hex?: string; | ||
type?: AddressType; | ||
label?: string; | ||
restricted: boolean; | ||
capabilities?: number[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export interface IAssociationsRequest { | ||
/** | ||
* The network to search on. | ||
*/ | ||
network: string; | ||
|
||
/** | ||
* The address to get the associated outputs for. | ||
*/ | ||
address: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { IAddressDetails } from "./IAddressDetails"; | ||
|
||
export interface IAssociationsRequestBody { | ||
/** | ||
* The address details of the address to get the associated outputs for. | ||
*/ | ||
addressDetails: IAddressDetails; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export interface ISearchRequest { | ||
/** | ||
* The network to search on. | ||
*/ | ||
network: string; | ||
|
||
/** | ||
* The query to look for. | ||
*/ | ||
query: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* eslint-disable import/no-unresolved */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-argument */ | ||
import { Block, OutputResponse } from "@iota/sdk-nova"; | ||
import { IAddressDetails } from "./IAddressDetails"; | ||
import { IResponse } from "../IResponse"; | ||
|
||
export interface ISearchResponse extends IResponse { | ||
/** | ||
* Block if it was found. | ||
*/ | ||
block?: Block; | ||
|
||
/** | ||
* Address details. | ||
*/ | ||
addressDetails?: IAddressDetails; | ||
|
||
/** | ||
* Output if it was found (block will also be populated). | ||
*/ | ||
output?: OutputResponse; | ||
|
||
/** | ||
* Account id if it was found. | ||
*/ | ||
accountId?: string; | ||
|
||
/** | ||
* Anchor id if it was found. | ||
*/ | ||
anchorId?: string; | ||
|
||
/** | ||
* Foundry id if it was found. | ||
*/ | ||
foundryId?: string; | ||
|
||
/** | ||
* Nft id if it was found. | ||
*/ | ||
nftId?: string; | ||
} |
11 changes: 11 additions & 0 deletions
11
api/src/models/api/nova/chronicle/IAddressBalanceRequest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export interface IAddressBalanceRequest { | ||
/** | ||
* The network to search on. | ||
*/ | ||
network: string; | ||
|
||
/** | ||
* The bech32 address to get the balance for. | ||
*/ | ||
address: string; | ||
} |
18 changes: 18 additions & 0 deletions
18
api/src/models/api/nova/chronicle/IAddressBalanceResponse.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { IResponse } from "../../IResponse"; | ||
|
||
export interface IAddressBalanceResponse extends IResponse { | ||
/** | ||
* The total balance (including Expiration, Timelock and StorageDepositReturn outputs) | ||
*/ | ||
totalBalance?: number; | ||
|
||
/** | ||
* The balance of all spendable outputs by the address at this time. | ||
*/ | ||
availableBalance?: number; | ||
|
||
/** | ||
* The ledger index at which this balance data was valid. | ||
*/ | ||
ledgerIndex?: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { ServiceFactory } from "../../../../../factories/serviceFactory"; | ||
import { IAddressBalanceRequest } from "../../../../../models/api/nova/chronicle/IAddressBalanceRequest"; | ||
import { IAddressBalanceResponse } from "../../../../../models/api/nova/chronicle/IAddressBalanceResponse"; | ||
import { IConfiguration } from "../../../../../models/configuration/IConfiguration"; | ||
import { NOVA } from "../../../../../models/db/protocolVersion"; | ||
import { NetworkService } from "../../../../../services/networkService"; | ||
import { ChronicleService } from "../../../../../services/nova/chronicleService"; | ||
import { ValidationHelper } from "../../../../../utils/validationHelper"; | ||
|
||
/** | ||
* Fetch the address balance from chronicle nova. | ||
* @param _ The configuration. | ||
* @param request The request. | ||
* @returns The response. | ||
*/ | ||
export async function get(_: IConfiguration, request: IAddressBalanceRequest): Promise<IAddressBalanceResponse> { | ||
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 {}; | ||
} | ||
|
||
if (!networkConfig.permaNodeEndpoint) { | ||
return {}; | ||
} | ||
|
||
const chronicleService = ServiceFactory.get<ChronicleService>(`chronicle-${networkConfig.network}`); | ||
|
||
return chronicleService.addressBalance(request.address); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { ServiceFactory } from "../../factories/serviceFactory"; | ||
import { ISearchRequest } from "../../models/api/nova/ISearchRequest"; | ||
import { ISearchResponse } from "../../models/api/nova/ISearchResponse"; | ||
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"; | ||
|
||
/** | ||
* Find the object from the network. | ||
* @param _ The configuration. | ||
* @param request The request. | ||
* @returns The response. | ||
*/ | ||
export async function search(_: IConfiguration, request: ISearchRequest): Promise<ISearchResponse> { | ||
const networkService = ServiceFactory.get<NetworkService>("network"); | ||
const networks = networkService.networkNames(); | ||
ValidationHelper.oneOf(request.network, networks, "network"); | ||
ValidationHelper.string(request.query, "query"); | ||
|
||
const networkConfig = networkService.get(request.network); | ||
|
||
if (networkConfig.protocolVersion !== NOVA) { | ||
return {}; | ||
} | ||
|
||
const novaApiService = ServiceFactory.get<NovaApiService>(`api-service-${networkConfig.network}`); | ||
return novaApiService.search(request.query); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import logger from "../../logger"; | ||
import { IAddressBalanceResponse } from "../../models/api/nova/chronicle/IAddressBalanceResponse"; | ||
import { INetwork } from "../../models/db/INetwork"; | ||
import { FetchHelper } from "../../utils/fetchHelper"; | ||
|
||
const CHRONICLE_ENDPOINTS = { | ||
balance: "/api/explorer/v3/balance/", | ||
}; | ||
|
||
export class ChronicleService { | ||
/** | ||
* The endpoint for performing communications. | ||
*/ | ||
private readonly chronicleEndpoint: string; | ||
|
||
/** | ||
* The network config in context. | ||
*/ | ||
private readonly networkConfig: INetwork; | ||
|
||
constructor(config: INetwork) { | ||
this.networkConfig = config; | ||
this.chronicleEndpoint = config.permaNodeEndpoint; | ||
} | ||
|
||
/** | ||
* Get the current address balance info. | ||
* @param address The address to fetch the balance for. | ||
* @returns The address balance response. | ||
*/ | ||
public async addressBalance(address: string): Promise<IAddressBalanceResponse | undefined> { | ||
try { | ||
return await FetchHelper.json<never, IAddressBalanceResponse>( | ||
this.chronicleEndpoint, | ||
`${CHRONICLE_ENDPOINTS.balance}${address}`, | ||
"get", | ||
); | ||
} catch (error) { | ||
const network = this.networkConfig.network; | ||
logger.warn(`[ChronicleService (Nova)] Failed fetching address balance for ${address} on ${network}. Cause: ${error}`); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.