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 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'; }