-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new api getFungibleAssetMetadata (#73)
- Loading branch information
Showing
8 changed files
with
180 additions
and
0 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
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,35 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { GetFungibleAssetMetadataResponse, PaginationArgs } from "../types"; | ||
import { AptosConfig } from "./aptos_config"; | ||
import { getFungibleAssetMetadata } from "../internal/fungible_asset"; | ||
import { FungibleAssetMetadataBoolExp } from "../types/generated/types"; | ||
|
||
/** | ||
* A class to query all `FungibleAsset` related queries on Aptos. | ||
*/ | ||
export class FungibleAsset { | ||
readonly config: AptosConfig; | ||
|
||
constructor(config: AptosConfig) { | ||
this.config = config; | ||
} | ||
|
||
/** | ||
* Queries the current fungible asset metadata. | ||
* | ||
* This query returns the fungible asset metadata for all fungible assets. | ||
* It can be filtered by creator address and asset type. | ||
* | ||
* @returns getFungibleAssetMetadata A list of fungible asset metadata | ||
*/ | ||
async getFungibleAssetMetadata(args: { | ||
options?: { | ||
pagination?: PaginationArgs; | ||
where?: FungibleAssetMetadataBoolExp; | ||
}; | ||
}): Promise<GetFungibleAssetMetadataResponse> { | ||
return getFungibleAssetMetadata({ aptosConfig: this.config, ...args }); | ||
} | ||
} |
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 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
/** | ||
* This file contains the underlying implementations for exposed API surface in | ||
* the {@link api/fungible_asset}. By moving the methods out into a separate file, | ||
* other namespaces and processes can access these methods without depending on the entire | ||
* fungible_asset namespace and without having a dependency cycle error. | ||
*/ | ||
|
||
import { AptosConfig } from "../api/aptos_config"; | ||
import { GetFungibleAssetMetadataResponse, PaginationArgs } from "../types"; | ||
import { queryIndexer } from "./general"; | ||
import { GetFungibleAssetMetadata } from "../types/generated/queries"; | ||
import { GetFungibleAssetMetadataQuery } from "../types/generated/operations"; | ||
import { FungibleAssetMetadataBoolExp } from "../types/generated/types"; | ||
|
||
export async function getFungibleAssetMetadata(args: { | ||
aptosConfig: AptosConfig; | ||
options?: { | ||
pagination?: PaginationArgs; | ||
where?: FungibleAssetMetadataBoolExp; | ||
}; | ||
}): Promise<GetFungibleAssetMetadataResponse> { | ||
const { aptosConfig, options } = args; | ||
|
||
const graphqlQuery = { | ||
query: GetFungibleAssetMetadata, | ||
variables: { | ||
where_condition: options?.where, | ||
limit: options?.pagination?.limit, | ||
offset: options?.pagination?.offset, | ||
}, | ||
}; | ||
|
||
const data = await queryIndexer<GetFungibleAssetMetadataQuery>({ | ||
aptosConfig, | ||
query: graphqlQuery, | ||
originMethod: "getFungibleAssetMetadata", | ||
}); | ||
|
||
return data.fungible_asset_metadata; | ||
} |
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,16 @@ | ||
query getFungibleAssetMetadata($where_condition: fungible_asset_metadata_bool_exp, $offset: Int, $limit: Int) { | ||
fungible_asset_metadata(where: $where_condition, offset: $offset, limit: $limit) { | ||
icon_uri | ||
project_uri | ||
supply_aggregator_table_handle_v1 | ||
supply_aggregator_table_key_v1 | ||
creator_address | ||
asset_type | ||
decimals | ||
last_transaction_timestamp | ||
last_transaction_version | ||
name | ||
symbol | ||
token_standard | ||
} | ||
} |
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,23 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { Aptos, AptosConfig, Network } from "../../../src"; | ||
import { FungibleAssetMetadataBoolExp } from "../../../src/types/generated/types"; | ||
|
||
describe("FungibleAsset", () => { | ||
test("it should fetch fungible asset metadata", async () => { | ||
const config = new AptosConfig({ network: Network.LOCAL }); | ||
const aptos = new Aptos(config); | ||
const APT_COIN_TYPE = "0x1::aptos_coin::AptosCoin"; | ||
const data = await aptos.getFungibleAssetMetadata({ | ||
options: { | ||
where: { | ||
asset_type: { _eq: APT_COIN_TYPE }, | ||
} as FungibleAssetMetadataBoolExp, | ||
}, | ||
}); | ||
expect(data.length).toEqual(1); | ||
expect(data[0]).toHaveProperty("asset_type"); | ||
expect(data[0].asset_type).toEqual(APT_COIN_TYPE); | ||
}); | ||
}); |