paritytech / polkadot-sdk

The Parity Polkadot Blockchain SDK
https://polkadot.network/
1.81k stars 661 forks source link

api.query.identity.identityOf returns array for main Id and null for subId #4556

Closed dcolley closed 4 months ago

dcolley commented 4 months ago

Is there an existing issue?

Experiencing problems? Have you tried our Stack Exchange first?

Description of bug

Source:

https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fksm-rpc.stakeworld.io%2Fpeople#/chainstate

Accounts: Main: HyLisujX7Cr6D7xzb6qadFdedLt8hmArB6ZVGJ6xsCUHqmx Sub: JKhBBSWkr8BJKh5eFBtRux4hsDq4sAxvvmMU426qUA9aqEQ

  1. api.query.identity.identityOf returns an array. I would expect only 1 ID per account OR please document this behaviour going forward.

    [
    {
    judgements: [
      [
        0
        Reasonable
      ]
    ]
    deposit: 6,688,333,305
    info: {
      display: {
        Raw: METASPAN
      }
      legal: None
      web: None
      matrix: None
      email: {
        Raw: derek@metaspan.com
      }
      pgpFingerprint: null
      image: None
      twitter: {
        Raw: @metaspan_io
      }
      github: None
      discord: None
    }
    }
    null
    ]
  2. identityOf for subId is empty

    <none>

Steps to reproduce

Make a connection to People-kusama chain Trigger the storage call for api.query.identity.identityOf via PJS, or js

bkchr commented 4 months ago

@TarikGul sounds like some PJS issue to me?

TarikGul commented 4 months ago

@bkchr Yea this is polkadot-js/api related.

@dcolley This is totally expected as the return type of api.query.identity.identityOf is a Tuple: Option<ITuple<[PalletIdentityRegistration, Option<Bytes>]>>. This is mirrored from the chain as PJS decorates all its calls directly from the metadata.

When looking at the docs for identityOf:

    /// Information that is pertinent to identify the entity behind an account. First item is the
    /// registration, second is the account's primary username.
    ///
    /// TWOX-NOTE: OK ― `AccountId` is a secure hash.
    #[pallet::storage]
    #[pallet::getter(fn identity)]
    pub(super) type IdentityOf<T: Config> = StorageMap<
        _,
        Twox64Concat,
        T::AccountId,
        (Registration<BalanceOf<T>, T::MaxRegistrars, T::IdentityInformation>, Option<Username<T>>),
        OptionQuery,
    >;

Apps also shows what the return types is going to be via here.

Screenshot 2024-05-23 at 10 35 37 AM

TL:DR The source of truth will always be the chain you are connected to, PJS just mirrors what the chain gives it. IMO i think we can close this as its totally expected, and documented on the storage calls in the sdk but also in PJS api augmented calls.

dcolley commented 4 months ago

The spec of the call changed between 10.12.2 and 10.12.3 - no mention of this in the release notes.

10.12.2

identityOf: AugmentedQuery<ApiType, (arg: AccountId32 | string | Uint8Array) => Observable<Option<PalletIdentityRegistration>>, [AccountId32]> & QueryableStorageEntry<ApiType, [AccountId32]>;

10.12.3

identityOf: AugmentedQuery<ApiType, (arg: AccountId32 | string | Uint8Array) => Observable<Option<ITuple<[PalletIdentityRegistration, Option<Bytes>]>>>, [AccountId32]> & QueryableStorageEntry<ApiType, [AccountId32]>;

I have updated my code, thanks.