Skip to content

patchedSubscription --> patch not enough information returned. #28

@AdrianKBL

Description

@AdrianKBL

Good morning,

I'm currently testing the new patchedSubscriptions to implement them in our DApps to improve performance, and I'm encountering a few issues:

  1. Balance updated at patch: /data/entity_by_pk/token_account/39/token/total_supply - New value: 27282926759423626. What does the 39 after token_account refer to? How can I determine which token this new value belongs to? Given that we have numerous tokens, different balances, various public keys for each token, and different supplies for each token, I need each value to clearly identify a specific token. For instance, if a key changes, it should indicate what type of key it is.
{
    "op": "replace",
    "path": "/data/entity_by_pk/balance",
    "value": 570062825537
}
  1. Is there a way to subscribe to a specific field? For example, there are too many different burns and mints on Hedera concerning FTs. I don't want to keep receiving notifications for each burn that occurs for each token ID, but I do want to get notifications when the balance changes.

  2. Regarding NFTs, the value being returned includes the Token ID and Serial Number, which is great. However, for NFTs, the path should ideally be something like /data/tokenId/serialNumber instead of /data/nft/5, as I don't know what the 5 refers to.

{
    "op": "remove",
    "path": "/data/nft/5",
    "value": {
        "token_id": 3958582,
        "metadata": "\\x697066733a2f2f62616679626569666c77696935637965686c666f79357a6b37347a626e686d7433716e7073706f357a6a3764727733746b6f6f6e6c76626d6879692f6d657461646174615f3132322e6a736f6e",
        "serial_number": 122,
        "spender": null,
        "modified_timestamp": "1723910081709934947"
    }
}
  1. Regarding Nft_Aggregate, same problem, how do I determine which collection has been modified If TokenId is not being returned?
{
    "op": "replace",
    "path": "/data/account/collections/167/nft_aggregate/aggregate/count",
    "value": 69
}

I didn't test other operations, but I guess we will have these problems in many different operations.

Example of a subscription:

Query

export function subFtsBalances(accountId: number, extraArgs?: string[]) {
  return `
  subscription AccountTokenBalances {
    entity_by_pk(id: ${accountId}) {
          balance
          token_account(
            where: {token: {type: {_eq: "FUNGIBLE_COMMON"}}}
          ) {
        balance
        associated
        }
      }
    }
  }`;
}

patchedSubscription

  patchedSubscribe(
    query: any,
    onNext: <T>(data: T) => void,
    onError?: (data: any) => void,
    onComplete?: () => void
  ): () => ObservableSubscription {
    const subscription = this.client.patchedSubscribe(query, {
      next: ({ data }, patches) => {
        console.log('data', data);
        onNext(data);
        patches.forEach((patch) => {
          console.log('patch', patch);
          switch (patch.op) {
            case 'add':
              console.log('New balance received:', patch.value);
              break;
            case 'remove':
              console.log('Balance removed:', patch.path);
              break;
            case 'replace':
              console.log(`Balance updated at patch: ${patch.path} - new value:  ${patch.value}`);
              break;
          }
        });
      },
      error: (error) => {
        if (onError) onError(error);
      },
      complete: () => {
        if (onComplete) onComplete();
      }
    });
    return () => subscription;
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions