-
Notifications
You must be signed in to change notification settings - Fork 110
Description
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.