From b92a8b93f56475fd198ad065d7ee6010d1c2ee1a Mon Sep 17 00:00:00 2001 From: chad Date: Fri, 22 Nov 2024 16:26:03 -0500 Subject: [PATCH 1/2] feat: add assets to account check utility --- .../src/providers/fuel-core-schema.graphql | 12 ++++++++++++ .../account/src/providers/operations.graphql | 4 ++++ packages/account/src/providers/provider.ts | 16 ++++++++++++---- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/packages/account/src/providers/fuel-core-schema.graphql b/packages/account/src/providers/fuel-core-schema.graphql index 8a4f2db83cd..56654b29016 100644 --- a/packages/account/src/providers/fuel-core-schema.graphql +++ b/packages/account/src/providers/fuel-core-schema.graphql @@ -18,6 +18,12 @@ scalar Address scalar AssetId +type AssetInfoDetails { + contractId: HexString! + subId: HexString! + totalSupply: U64! +} + type Balance { owner: Address! amount: U64! @@ -921,6 +927,12 @@ type ProgramState { } type Query { + assetDetails( + """ + ID of the Asset + """ + id: AssetId! + ): AssetInfoDetails """ Read register value by index. """ diff --git a/packages/account/src/providers/operations.graphql b/packages/account/src/providers/operations.graphql index 97f5bb2916c..5d824f82c49 100644 --- a/packages/account/src/providers/operations.graphql +++ b/packages/account/src/providers/operations.graphql @@ -800,6 +800,7 @@ query isUserAccount( $blobId: BlobId! $contractId: ContractId! $transactionId: TransactionId! + $assetId: AssetId! ) { blob(id: $blobId) { id @@ -810,6 +811,9 @@ query isUserAccount( transaction(id: $transactionId) { id } + assetDetails(id: $assetId) { + subId + } } query getConsensusParametersVersion { diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index 6350737c0a6..daf52534520 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -2009,23 +2009,27 @@ Supported fuel-core version: ${supportedVersion}.` * @returns A promise that resolves to the result of the check. */ async isUserAccount(id: string): Promise { - const { contract, blob, transaction } = await this.operations.isUserAccount({ + const { contract, blob, transaction, assetDetails } = await this.operations.isUserAccount({ blobId: id, contractId: id, transactionId: id, + assetId: id, }); - if (contract || blob || transaction) { + if (contract || blob || transaction || assetDetails) { return false; } return true; } - async getAddressType(id: string): Promise<'Account' | 'Contract' | 'Transaction' | 'Blob'> { - const { contract, blob, transaction } = await this.operations.isUserAccount({ + async getAddressType( + id: string + ): Promise<'Account' | 'Contract' | 'Transaction' | 'Blob' | 'Asset'> { + const { contract, blob, transaction, assetDetails } = await this.operations.isUserAccount({ blobId: id, contractId: id, transactionId: id, + assetId: id, }); if (contract) { @@ -2038,6 +2042,10 @@ Supported fuel-core version: ${supportedVersion}.` return 'Transaction'; } + if (assetDetails) { + return 'Asset'; + } + return 'Account'; } From fc5347d216ff43fb2f4f6f6a0e8efaa4e0cd78c4 Mon Sep 17 00:00:00 2001 From: chad Date: Fri, 22 Nov 2024 16:26:39 -0500 Subject: [PATCH 2/2] docs: add changeset --- .changeset/grumpy-geese-move.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/grumpy-geese-move.md diff --git a/.changeset/grumpy-geese-move.md b/.changeset/grumpy-geese-move.md new file mode 100644 index 00000000000..c10bc68b69d --- /dev/null +++ b/.changeset/grumpy-geese-move.md @@ -0,0 +1,5 @@ +--- +"@fuel-ts/account": patch +--- + +feat: add assets to account checking utility