Skip to content

JS Client - typed fetch? #153

@fedorerd

Description

@fedorerd

Default kit methods fetchMaybeRecord / fetchRecord decode base account layout - which is version + authority and also crop out remaining data. So regardless if I store any data I will get only version and authority from default fetch methods. Which is slightly inconvenient, since forces to use rpc.getAccountInfo instead of package methods in most cases.

I wonder if that would make sense to actually add custom fetch methods, which will accept optional data layout from user and will always return remaining data.

So, something like that:

    // user can specify his data layout
    fetchRecordDataExtended(rpc, addressWithSeed, [
        ['value', getU64Decoder({ endian: Endian.Little })]
    ])

This function will fetch account info, try decode first 33 bytes into RecordData, then take remaining bytes and try decode them with user provided layout. And also return remaining data (so if user's layout was 8 bytes, but total account space was 65 bytes, remaining 24 bytes will be also returned)

    // or just fetch without specifying anything
    fetchRecordDataExtended(rpc, addressWithSeed)

If user didn't specify layout at all - we just return remaining bytes.

so the return type will be something like:

type RecordDataExtended<T> = RecordData & T & { remainingData?: Uint8Array }

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