-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
1,716 additions
and
20 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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
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,248 @@ | ||
import { Service } from 'typedi' | ||
import { QueryParams } from '../../../dto' | ||
import { GetI } from '../../../dto/GetI' | ||
import { PostI } from '../../../dto/PostI' | ||
import { | ||
AddPeerRequest, | ||
AliasOutputSearchParams, | ||
Balance, | ||
BasicOutputSearchParams, | ||
Block, | ||
BlockChildrenResponse, | ||
BlockIdentifier, | ||
BlockMetadata, | ||
BlocksByMilestoneIndexParams, | ||
BlocksByMilestoneParams, | ||
ComputedMerkleRootResult, | ||
ComputeWhiteFlagRequest, | ||
CreateSnapshotsRequest, | ||
CreateSnapshotsResponse, | ||
ErrorFormat, | ||
FoundryOutputsFilterParams, | ||
IotaRpcSuite, | ||
LedgerUpdateList, | ||
LedgerUpdatesByAddressParams, | ||
LedgerUpdatesByMilestoneParams, | ||
Milestone, | ||
MilestonePayload, | ||
MilestonesParams, | ||
NftOutputSearchParams, | ||
NodeInfo, | ||
OutputIdResponse, | ||
OutputMetadata, | ||
OutputResponse, | ||
OutputSearchParams, | ||
PagedBlockIdsByMilestone, | ||
Peer, | ||
PeerResponse, | ||
PruneDatabaseRequest, | ||
PruneDatabaseResponse, | ||
ReceiptsResponse, | ||
RichestAddressesStatistics, | ||
SubmitBlock, | ||
TipsResponse, | ||
TopRichestAddressesParams, | ||
TreasuryResponse, | ||
UTXOChanges, | ||
WealthDistributionStatistics, | ||
} from '../../../dto/rpc/IotaRpcSuite' | ||
import { Utils } from '../../../util' | ||
|
||
@Service() | ||
export abstract class AbstractIotaRpc implements IotaRpcSuite { | ||
protected abstract post<T>(post: PostI): Promise<T> | ||
protected abstract get<T>(get: GetI): Promise<T> | ||
|
||
private async sendGet<T>({ path, queryParams }: { path: string; queryParams?: QueryParams }): Promise<T> { | ||
return this.get({ path: Utils.addQueryParams({ basePath: path, queryParams: queryParams }) }) | ||
} | ||
|
||
getNodeHealth(): Promise<boolean | ErrorFormat> { | ||
return this.get({ path: '/health' }) | ||
} | ||
|
||
getAvailableRouteGroups(): Promise<string[] | ErrorFormat> { | ||
return this.get({ path: '/api/routes' }) | ||
} | ||
|
||
getNodeInfo(): Promise<NodeInfo | ErrorFormat> { | ||
return this.get({ path: '/api/core/v2/info' }) | ||
} | ||
|
||
getTips(): Promise<TipsResponse | ErrorFormat> { | ||
return this.get({ path: '/api/core/v2/tips' }) | ||
} | ||
|
||
submitBlock(params: SubmitBlock): Promise<BlockIdentifier | ErrorFormat> { | ||
return this.post({ path: '/api/core/v2/blocks', body: params }) | ||
} | ||
|
||
getBlockDataById(params: BlockIdentifier): Promise<Block | ErrorFormat> { | ||
return this.get({ path: `/api/core/v2/blocks/${params.blockId}` }) | ||
} | ||
|
||
getBlockMetadata(params: BlockIdentifier): Promise<BlockMetadata | ErrorFormat> { | ||
return this.get({ path: `/api/core/v2/blocks/${params.blockId}/metadata` }) | ||
} | ||
|
||
findOutputById(outputId: string): Promise<OutputResponse | ErrorFormat> { | ||
return this.get({ path: `/api/core/v2/outputs/${encodeURIComponent(outputId)}` }) | ||
} | ||
|
||
getOutputMetadata(outputId: string): Promise<OutputMetadata | ErrorFormat> { | ||
return this.get({ path: `/api/core/v2/outputs/${encodeURIComponent(outputId)}/metadata` }) | ||
} | ||
|
||
getAllReceipts(): Promise<ReceiptsResponse | ErrorFormat> { | ||
return this.get({ path: `/api/core/v2/receipts` }) | ||
} | ||
|
||
getReceiptsByMigrationIndex(migratedAt: number): Promise<ReceiptsResponse | ErrorFormat> { | ||
return this.get({ path: `/api/core/v2/receipts/${migratedAt}` }) | ||
} | ||
|
||
getTransactionIncludedBlock(transactionId: string): Promise<Block | ErrorFormat> { | ||
return this.get({ path: `/api/core/v2/transactions/${transactionId}/included-block` }) | ||
} | ||
|
||
findIncludedBlockMetadata(transactionId: string): Promise<BlockMetadata | ErrorFormat> { | ||
return this.get({ path: `/api/core/v2/transactions/${transactionId}/included-block/metadata` }) | ||
} | ||
|
||
getMilestoneById(milestoneId: string): Promise<MilestonePayload | ErrorFormat> { | ||
return this.get({ path: `/api/core/v2/milestones/${milestoneId}` }) | ||
} | ||
|
||
getMilestoneUtxoChangesByMilestone(milestoneId: string): Promise<UTXOChanges | ErrorFormat> { | ||
return this.get({ path: `/api/core/v2/milestones/${milestoneId}/utxo-changes` }) | ||
} | ||
|
||
lookupMilestoneByIndex(index: number): Promise<MilestonePayload | ErrorFormat> { | ||
return this.get({ path: `/api/core/v2/milestones/by-index/${index}` }) | ||
} | ||
|
||
getMilestoneUtxoChangesById(index: number): Promise<UTXOChanges | ErrorFormat> { | ||
return this.get({ path: `/api/core/v2/milestones/by-index/${index}/utxo-changes` }) | ||
} | ||
|
||
computeMerkleRouteHashes(params: ComputeWhiteFlagRequest): Promise<ComputedMerkleRootResult | ErrorFormat> { | ||
return this.post({ path: '/api/core/v2/whiteflag', body: params }) | ||
} | ||
|
||
pruneDatabase(request: PruneDatabaseRequest): Promise<PruneDatabaseResponse | ErrorFormat> { | ||
return this.post({ path: '/api/core/v2/control/database/prune', body: request }) | ||
} | ||
|
||
createSnapshot(requestData: CreateSnapshotsRequest): Promise<CreateSnapshotsResponse | ErrorFormat> { | ||
return this.post({ path: `/api/core/v2/control/snapshot/create`, body: requestData }) | ||
} | ||
|
||
getTreasuryInformation(): Promise<TreasuryResponse | ErrorFormat> { | ||
return this.get({ path: '/api/core/v2/treasury' }) | ||
} | ||
|
||
getPeerInfo(peerId: string): Promise<PeerResponse | ErrorFormat> { | ||
return this.get({ path: `api/core/v2/peers/${peerId}` }) | ||
} | ||
|
||
getPeers(): Promise<PeerResponse | ErrorFormat> { | ||
return this.get({ path: '/api/core/v2/peers' }) | ||
} | ||
|
||
addPeer(peerData: AddPeerRequest): Promise<Peer | ErrorFormat> { | ||
return this.post({ path: '/api/core/v2/peers', body: peerData }) | ||
} | ||
|
||
getOutputs(params: OutputSearchParams): Promise<OutputIdResponse> { | ||
return this.sendGet({ path: '/api/indexer/v1/outputs', queryParams: params as QueryParams }) | ||
} | ||
|
||
getBasicOutputs(params: BasicOutputSearchParams): Promise<OutputIdResponse> { | ||
return this.sendGet({ path: '/api/indexer/v1/outputs/basic', queryParams: params as QueryParams }) | ||
} | ||
|
||
getAliasOutputs(params: AliasOutputSearchParams): Promise<OutputIdResponse> { | ||
return this.sendGet({ path: '/api/indexer/v1/outputs/alias', queryParams: params as QueryParams }) | ||
} | ||
|
||
getCurrentUnspentAliasOutput(aliasId: string): Promise<OutputIdResponse> { | ||
return this.sendGet({ path: `/api/indexer/v1/outputs/alias/${aliasId}` }) | ||
} | ||
|
||
getFoundryOutputs(params: FoundryOutputsFilterParams): Promise<OutputIdResponse> { | ||
return this.sendGet({ path: '/api/indexer/v1/outputs/foundry', queryParams: params as QueryParams }) | ||
} | ||
|
||
getCurrentUnspentFoundryOutput(foundryId: string): Promise<OutputIdResponse> { | ||
return this.sendGet({ path: `/api/indexer/v1/outputs/foundry/${foundryId}` }) | ||
} | ||
|
||
getNftOutputs(params: NftOutputSearchParams): Promise<OutputIdResponse> { | ||
return this.sendGet({ path: '/api/indexer/v1/outputs/nft', queryParams: params as QueryParams }) | ||
} | ||
|
||
getCurrentNftOutput(nftId: string): Promise<OutputIdResponse> { | ||
return this.sendGet({ path: `/api/indexer/v1/outputs/nft/${nftId}` }) | ||
} | ||
|
||
async getBalanceByAddress(address: string): Promise<Balance> { | ||
return this.sendGet<Balance>({ path: `/api/explorer/v2/balance/${address}` }) | ||
} | ||
|
||
async getBlockChildren(blockId: string): Promise<BlockChildrenResponse> { | ||
return this.sendGet<BlockChildrenResponse>({ path: `/api/explorer/v2/blocks/${blockId}/children` }) | ||
} | ||
|
||
async getMilestones(params: MilestonesParams): Promise<Milestone> { | ||
return this.sendGet<Milestone>({ | ||
path: `/api/explorer/v2/milestones`, | ||
queryParams: params as QueryParams, | ||
}) | ||
} | ||
|
||
async getBlocksByMilestone(params: BlocksByMilestoneParams): Promise<PagedBlockIdsByMilestone> { | ||
const { milestoneId, ...rest } = params | ||
return this.sendGet<PagedBlockIdsByMilestone>({ | ||
path: `/api/explorer/v2/milestones/${milestoneId}/blocks`, | ||
queryParams: rest, | ||
}) | ||
} | ||
|
||
async getBlocksByMilestoneIndex(params: BlocksByMilestoneIndexParams): Promise<PagedBlockIdsByMilestone> { | ||
const { milestoneIndex, ...rest } = params | ||
return this.sendGet<PagedBlockIdsByMilestone>({ | ||
path: `/api/explorer/v2/milestones/by-index/${milestoneIndex}/blocks`, | ||
queryParams: rest, | ||
}) | ||
} | ||
|
||
async getLedgerUpdatesByAddress(params: LedgerUpdatesByAddressParams): Promise<LedgerUpdateList> { | ||
const { address, ...rest } = params | ||
return this.sendGet<LedgerUpdateList>({ | ||
path: `/api/explorer/v2/ledger/updates/by-address/${address}`, | ||
queryParams: rest, | ||
}) | ||
} | ||
|
||
async getLedgerUpdatesByMilestone(params: LedgerUpdatesByMilestoneParams): Promise<LedgerUpdateList> { | ||
const { milestoneId, ...rest } = params | ||
return this.sendGet<LedgerUpdateList>({ | ||
path: `/api/explorer/v2/ledger/updates/by-milestone/${milestoneId}`, | ||
queryParams: rest, | ||
}) | ||
} | ||
|
||
async getTopRichestAddresses(params: TopRichestAddressesParams): Promise<RichestAddressesStatistics> { | ||
return this.sendGet<RichestAddressesStatistics>({ | ||
path: `/api/explorer/v2/ledger/richest-addresses`, | ||
queryParams: params as QueryParams, | ||
}) | ||
} | ||
|
||
async getTokenDistribution(ledgerIndex: number): Promise<WealthDistributionStatistics> { | ||
return this.sendGet<WealthDistributionStatistics>({ | ||
path: `/api/explorer/v2/ledger/token-distribution`, | ||
queryParams: { ledgerIndex }, | ||
}) | ||
} | ||
} |
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
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.