-
Notifications
You must be signed in to change notification settings - Fork 56
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
- Loading branch information
Jin
committed
Oct 17, 2023
1 parent
237e513
commit ff1b95f
Showing
8 changed files
with
186 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,29 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { GetFungibleAssetMetadataResponse, HexInput, PaginationArgs } from "../types"; | ||
import { AptosConfig } from "./aptos_config"; | ||
import { getFungibleAssetMetadata } from "../internal/fungible_asset"; | ||
|
||
/** | ||
* A class to query all `FungibleAsset` related queries on Aptos. | ||
*/ | ||
export class FungibleAsset { | ||
readonly config: AptosConfig; | ||
|
||
constructor(config: AptosConfig) { | ||
this.config = config; | ||
} | ||
|
||
async getFungibleAssetMetadata(args: { | ||
options?: { | ||
pagination?: PaginationArgs; | ||
whereCondition?: { | ||
creatorAddress?: HexInput; | ||
assetType?: string; | ||
}; | ||
}; | ||
}): 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,56 @@ | ||
// 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 { AccountAddress } from "../core"; | ||
import { GetFungibleAssetMetadataResponse, HexInput, PaginationArgs } from "../types"; | ||
import { queryIndexer } from "./general"; | ||
import { GetFungibleAssetMetadata } from "../types/generated/queries"; | ||
import { GetFungibleAssetMetadataQuery } from "../types/generated/operations"; | ||
|
||
export async function getFungibleAssetMetadata(args: { | ||
aptosConfig: AptosConfig; | ||
options?: { | ||
pagination?: PaginationArgs; | ||
whereCondition?: { | ||
creatorAddress?: HexInput; | ||
assetType?: string; | ||
}; | ||
}; | ||
}): Promise<GetFungibleAssetMetadataResponse> { | ||
const { aptosConfig, options } = args; | ||
|
||
const whereCondition: any = {}; | ||
if (options?.whereCondition?.creatorAddress) { | ||
whereCondition.creator_address = { | ||
_eq: AccountAddress.fromHexInput(options.whereCondition.creatorAddress).toString(), | ||
}; | ||
} | ||
if (options?.whereCondition?.assetType) { | ||
whereCondition.asset_type = { _eq: options.whereCondition.assetType }; | ||
} | ||
|
||
const graphqlQuery = { | ||
query: GetFungibleAssetMetadata, | ||
variables: { | ||
where_condition: whereCondition, | ||
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,22 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { Aptos, AptosConfig, Network } from "../../../src"; | ||
|
||
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: { | ||
whereCondition: { | ||
assetType: APT_COIN_TYPE, | ||
}, | ||
}, | ||
}); | ||
expect(data.length).toEqual(1); | ||
expect(data[0]).toHaveProperty("asset_type"); | ||
expect(data[0].asset_type).toEqual(APT_COIN_TYPE); | ||
}); | ||
}); |