Skip to content

Commit

Permalink
ALL-5089 Add IOTA rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
Hathoriel committed Apr 10, 2024
1 parent 9190d43 commit c8ca7a5
Show file tree
Hide file tree
Showing 9 changed files with 1,716 additions and 20 deletions.
1,396 changes: 1,396 additions & 0 deletions src/dto/rpc/IotaRpcSuite.ts

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/service/rpc/evm/AbstractBeaconV1EvmRpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export abstract class AbstractBeaconV1EvmRpc implements EvmBeaconV1Interface {
protected abstract get<T>(get: GetI): Promise<T>

private sendGet<T>(path: string, params: QueryParams, prefix?: string): Promise<T> {
const fullPath = Utils.addQueryParams(
`${prefix ?? Constant.BEACON_PREFIX}/${path}`,
Utils.camelToSnakeCase,
params,
)
const fullPath = Utils.addQueryParams({
basePath: `${prefix ?? Constant.BEACON_PREFIX}/${path}`,
strategy: Utils.camelToSnakeCase,
queryParams: params,
})
return this.get({ path: fullPath })
}

Expand Down
14 changes: 12 additions & 2 deletions src/service/rpc/other/AbstractAlgorandAlgodRpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ export abstract class AbstractAlgorandAlgodRpc implements AlgorandAlgodRpcSuite
queryParams?: QueryParams
}): Promise<T> {
const post: PostI = {
path: Utils.addQueryParams(path, Utils.camelToDashCase, queryParams),
path: Utils.addQueryParams({
basePath: path,
strategy: Utils.camelToDashCase,
queryParams: queryParams,
}),
}

if (body) {
Expand All @@ -64,7 +68,13 @@ export abstract class AbstractAlgorandAlgodRpc implements AlgorandAlgodRpcSuite
}

private async sendGet<T>({ path, queryParams }: { path: string; queryParams?: QueryParams }): Promise<T> {
return this.get({ path: Utils.addQueryParams(path, Utils.camelToDashCase, queryParams) })
return this.get({
path: Utils.addQueryParams({
basePath: path,
strategy: Utils.camelToDashCase,
queryParams: queryParams,
}),
})
}

broadcastTransaction(params: TransactionBroadcastRequest): Promise<TransactionBroadcastResponse> {
Expand Down
8 changes: 7 additions & 1 deletion src/service/rpc/other/AbstractAlgorandIndexerRpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ export abstract class AbstractAlgorandIndexerRpc implements AlgorandIndexerRpcSu
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(path, Utils.camelToDashCase, queryParams) })
return this.get({
path: Utils.addQueryParams({
basePath: path,
strategy: Utils.camelToDashCase,
queryParams: queryParams,
}),
})
}

getAccount(params: AccountInformationRequest): Promise<AccountResponse> {
Expand Down
248 changes: 248 additions & 0 deletions src/service/rpc/other/AbstractIotaRpc.ts
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 {

Check failure on line 52 in src/service/rpc/other/AbstractIotaRpc.ts

View workflow job for this annotation

GitHub Actions / build (18)

Class 'AbstractIotaRpc' incorrectly implements interface '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 },
})
}
}
12 changes: 10 additions & 2 deletions src/service/rpc/other/AbstractKadenaRpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ export abstract class AbstractKadenaRpc implements KadenaRpcInterface {

private prepareRequest({ path, body, queryParams, network }: RequestI): PostI {
return {
path: Utils.addQueryParams(path, Utils.camelToDashCase, queryParams),
path: Utils.addQueryParams({
basePath: path,
strategy: Utils.camelToDashCase,
queryParams: queryParams,
}),
prefix: network ? this.urlWithPrefix(network) : undefined,
body,
}
Expand All @@ -80,7 +84,11 @@ export abstract class AbstractKadenaRpc implements KadenaRpcInterface {
network?: NetworkParams | ApiParams
}): Promise<T> {
return this.get({
path: Utils.addQueryParams(path, Utils.camelToDashCase, queryParams),
path: Utils.addQueryParams({
basePath: path,
strategy: Utils.camelToDashCase,
queryParams: queryParams,
}),
prefix: network ? this.urlWithPrefix(network) : undefined,
})
}
Expand Down
14 changes: 12 additions & 2 deletions src/service/rpc/other/AbstractStellarRpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ export abstract class AbstractStellarRpc implements StellarRpcSuite {

private async sendGet<T>({ path, queryParams }: { path: string; queryParams?: QueryParams }): Promise<T> {
if (queryParams && Object.keys(queryParams).length > 0) {
return this.get({ path: Utils.addQueryParams(path, Utils.camelToSnakeCase, queryParams) })
return this.get({
path: Utils.addQueryParams({
basePath: path,
strategy: Utils.camelToSnakeCase,
queryParams: queryParams,
}),
})
}

return this.get({ path })
Expand All @@ -102,7 +108,11 @@ export abstract class AbstractStellarRpc implements StellarRpcSuite {
}

if (queryParams && Object.keys(queryParams).length > 0) {
post.path = Utils.addQueryParams(path, Utils.camelToSnakeCase, queryParams)
post.path = Utils.addQueryParams({
basePath: path,
strategy: Utils.camelToSnakeCase,
queryParams: queryParams,
})
}

if (body) {
Expand Down
14 changes: 12 additions & 2 deletions src/service/rpc/other/AbstractTezosRpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ export abstract class AbstractTezosRpc implements TezosRpcInterface {

private async sendGet<T>({ path, queryParams }: { path: string; queryParams?: QueryParams }): Promise<T> {
if (queryParams && Object.keys(queryParams).length > 0) {
return this.get({ path: Utils.addQueryParams(path, Utils.camelToSnakeCase, queryParams) })
return this.get({
path: Utils.addQueryParams({
basePath: path,
strategy: Utils.camelToSnakeCase,
queryParams: queryParams,
}),
})
}

return this.get({ path })
Expand All @@ -50,7 +56,11 @@ export abstract class AbstractTezosRpc implements TezosRpcInterface {
}

if (queryParams && Object.keys(queryParams).length > 0) {
post.path = Utils.addQueryParams(path, Utils.camelToSnakeCase, queryParams)
post.path = Utils.addQueryParams({
basePath: path,
strategy: Utils.camelToSnakeCase,
queryParams: queryParams,
})
}

if (body) {
Expand Down
Loading

0 comments on commit c8ca7a5

Please sign in to comment.