+
Skip to content

We should accept Address as Base58EncodedBytes #950

@mcintyre94

Description

@mcintyre94

Overview

From twitter:

Transitioning to gill and understanding the conventions. Things like converting an Address to Base58EncodedString to pass into a memcmp filter. I can get it to work but would like to know more best practices.

https://x.com/fzzyyti/status/1975327247231033718

Steps to reproduce

Add this typetest in rpc-api:

{
    // address in memcmp
    const rpc = null as unknown as Rpc<GetProgramAccountsApi>;
    const programAddress = null as unknown as Address;
    const filterAddress = null as unknown as Address;

    rpc.getProgramAccounts(programAddress, {
        filters: [
            {
                memcmp: {
                    bytes: filterAddress,
                    encoding: 'base58',
                    offset: 0n,
                }
            }
        ]
    })
}

Type error on bytes: filterAddress. The only way to resolve this is to use filterAddress as unknown as Base58EncodedBytes

Description of bug

I think we should allow Address to be used in the base58 memcmp type:

type ProgramNotificationsMemcmpFilterBase58 = Readonly<{
    /**
     * The bytes to match, as a base-58 encoded string.
     *
     * Data is limited to a maximum of 128 decoded bytes.
     */
    bytes: Base58EncodedBytes | Address; // add Address here
    /** The encoding to use when decoding the supplied byte string */
    encoding: 'base58';
    /** The byte offset into the account data from which to start the comparison */
    offset: bigint;
}>;

The docstring mentions the requirements: base58 encoded, max of 128 bytes. Address satisfies these. And since there's base64 support, addresses are probably the only common reason to use base58 memcmp at all.

Note that rpc-types already has a dependency on addresses and it's widely used in RPC requests, so this doesn't add a new dependency between packages.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载