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

Add: pro-apis #4

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
23 changes: 23 additions & 0 deletions src/apis/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,26 @@ export async function getAssetsByAddress(
});
return response.data;
}

export async function getAssetHoldersByPolicyId(
instance: AxiosInstance,
params: reqTypes.GetAssetHoldersByPolicyIdParams
): Promise<resTypes.PaginatedAssetHoldersByPolicy> {
const response = await instance.get<resTypes.PaginatedAssetHoldersByPolicy>(
"/asset/holders/byPolicyId",
{
params,
}
);
return response.data;
}

export async function getAssetsMetadata(
instance: AxiosInstance,
params: reqTypes.GetAssetsMetadataParams
): Promise<resTypes.PaginatedAssetsMetadata> {
const response = await instance.get<resTypes.PaginatedAssetsMetadata>("/asset/metadata", {
params,
});
return response.data;
}
10 changes: 10 additions & 0 deletions src/apis/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ export async function getTransactionListByAddress(
});
return response.data;
}

export async function getTransactionSummary(
instance: AxiosInstance,
params: reqTypes.GetTransactionSummaryParams
): Promise<resTypes.TransactionSummary> {
const response = await instance.get<resTypes.TransactionSummary>("/transaction/summary", {
params,
});
return response.data;
}
12 changes: 12 additions & 0 deletions src/apis/utxo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { AxiosInstance } from "axios";
import * as reqTypes from "../types/reqTypes";
import * as resTypes from "../types/resTypes";

// eslint-disable-next-line import/prefer-default-export
export async function getUTXOList(
instance: AxiosInstance,
params: reqTypes.GetUtxoListParams
): Promise<resTypes.PaginatedUtxos> {
const response = await instance.get<resTypes.PaginatedUtxos>("/utxo/list", { params });
return response.data;
}
38 changes: 36 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import * as reqTypes from "./types/reqTypes";
import * as resTypes from "./types/resTypes";

import { getAddressBalance } from "./apis/address";
import { getAssetDetails, getAssetsByPolicyId, getAssetsByAddress } from "./apis/asset";
import {
getAssetDetails,
getAssetsByPolicyId,
getAssetsByAddress,
getAssetHoldersByPolicyId,
getAssetsMetadata,
} from "./apis/asset";
import { getBlockDetails, getLatestBlockDetails } from "./apis/block";
import {
getPoolDetails,
Expand All @@ -14,8 +20,13 @@ import {
getExpiredPools,
} from "./apis/pools";
import { getStakeKeyDetails, getAddressesByStakeKey } from "./apis/rewardAccount";
import { getTransactionDetails, getTransactionListByAddress } from "./apis/transaction";
import {
getTransactionDetails,
getTransactionListByAddress,
getTransactionSummary,
} from "./apis/transaction";
import { getNetworkDetails, getNetworkProtocolDetails } from "./apis/network";
import { getUTXOList } from "./apis/utxo";

// eslint-disable-next-line import/prefer-default-export
export class CardanoscanAPI {
Expand Down Expand Up @@ -51,6 +62,18 @@ export class CardanoscanAPI {
return getAssetsByAddress(this.instance, params);
}

getAssetHoldersByPolicyId(
params: reqTypes.GetAssetHoldersByPolicyIdParams
): Promise<resTypes.PaginatedAssetHoldersByPolicy> {
return getAssetHoldersByPolicyId(this.instance, params);
}

getAssetsMetadata(
params: reqTypes.GetAssetsMetadataParams
): Promise<resTypes.PaginatedAssetsMetadata> {
return getAssetsMetadata(this.instance, params);
}

/* Blocks */
getBlockDetails(params: reqTypes.GetBlockDetailsParams): Promise<resTypes.Block> {
return getBlockDetails(this.instance, params);
Expand Down Expand Up @@ -107,6 +130,12 @@ export class CardanoscanAPI {
return getTransactionListByAddress(this.instance, params);
}

getTransactionSummary(
params: reqTypes.GetTransactionSummaryParams
): Promise<resTypes.TransactionSummary> {
return getTransactionSummary(this.instance, params);
}

/* Network */
getNetworkDetails(): Promise<resTypes.NetworkState> {
return getNetworkDetails(this.instance);
Expand All @@ -115,4 +144,9 @@ export class CardanoscanAPI {
getNetworkProtocolDetails(): Promise<resTypes.NetworkProtocol> {
return getNetworkProtocolDetails(this.instance);
}

/* UTXO */
getUTXOList(params: reqTypes.GetUtxoListParams): Promise<resTypes.PaginatedUtxos> {
return getUTXOList(this.instance, params);
}
}
19 changes: 19 additions & 0 deletions src/types/reqTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ export type GetAssetByAddressParams = {
limit?: number;
};

export type GetAssetHoldersByPolicyIdParams = {
policyId: string;
pageNo: number;
limit?: number;
};

export type GetAssetsMetadataParams = {
assetIds: Array<string>;
};

export type GetPoolDetails = {
poolId: string;
};
Expand Down Expand Up @@ -69,3 +79,12 @@ export type GetTransactionListByAddressParams = {
limit?: number;
order?: "asc" | "desc";
};

export type GetTransactionSummaryParams = {
hash: string;
};

export type GetUtxoListParams = { pageNo: number; limit?: number } & (
| { paymentAddress: string }
| { rewardAddress: string }
);
83 changes: 83 additions & 0 deletions src/types/resTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,86 @@ export type NetworkProtocol = {
PlutusScriptV1: Types.LanguageView;
};
};

export type AssetHoldersByPolicy = {
address: string;
policyId: string;
assetName: string;
fingerprint: string;
assetId: string;
balance: string;
};

export type PaginatedAssetHoldersByPolicy = {
holders: Array<AssetHoldersByPolicy>;
count: number;
pageNo: number;
limit: number;
};

export type AssetMetadata = {
assetId: string;
policyId: string;
assetName: string;
decimals: number;
name?: string;
description?: string;
image?: {
src: string;
type: string;
};
ticker?: string;
url?: string;
logo?: {
src: string;
type: string;
};
};

export type PaginatedAssetsMetadata = {
metadataList: Array<AssetMetadata>;
};

export type TransactionSummary = {
hash: string;
summary: Array<{
wallet: string;
amount: string;
sentTokens: Array<{
policyId: string;
assetName: string;
fingerprint: string;
assetId: string;
value: string;
}>;
receivedTokens: Array<{
policyId: string;
assetName: string;
fingerprint: string;
assetId: string;
value: string;
}>;
}>;
};

export type Utxo = {
address: string;
amount: string;
assets?: Array<{
policyId: string;
assetName: string;
fingerprint: string;
assetId: string;
value: string;
}>;
data?: { hash: string; value?: string };
txId: string;
index: number;
};

export type PaginatedUtxos = {
utxos: Array<Utxo>;
count: number;
pageNo: number;
limit: number;
};