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

feat: add assets to account check utility #3417

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions .changeset/grumpy-geese-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/account": patch
---

feat: add assets to account checking utility
12 changes: 12 additions & 0 deletions packages/account/src/providers/fuel-core-schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ scalar Address

scalar AssetId

type AssetInfoDetails {
contractId: HexString!
subId: HexString!
totalSupply: U64!
}

type Balance {
owner: Address!
amount: U64!
Expand Down Expand Up @@ -921,6 +927,12 @@ type ProgramState {
}

type Query {
assetDetails(
"""
ID of the Asset
"""
id: AssetId!
): AssetInfoDetails
"""
Read register value by index.
"""
Expand Down
4 changes: 4 additions & 0 deletions packages/account/src/providers/operations.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@ query isUserAccount(
$blobId: BlobId!
$contractId: ContractId!
$transactionId: TransactionId!
$assetId: AssetId!
) {
blob(id: $blobId) {
id
Expand All @@ -810,6 +811,9 @@ query isUserAccount(
transaction(id: $transactionId) {
id
}
assetDetails(id: $assetId) {
subId
}
}

query getConsensusParametersVersion {
Expand Down
16 changes: 12 additions & 4 deletions packages/account/src/providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
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) {
Expand All @@ -2038,6 +2042,10 @@ Supported fuel-core version: ${supportedVersion}.`
return 'Transaction';
}

if (assetDetails) {
return 'Asset';
}

return 'Account';
}

Expand Down
Loading