Open FredoNook opened 1 month ago
To me, the behavior is expected, but the comment "Accounts not found or with wrong discriminator are returned as null." is half correct. Having different discriminator is an error in all cases, and null
is only returned if the account doesn't exist.
What is benefit to get error in this case? Why not exist account less critical than account with different discriminator? Says we have program instruction that take bunch of same type accounts as input and that accounts isn't PDA so in this use case we have to fetch one by one to check that account exists and have expected type right? Why not to check them in one RPC request utilizing #fetchMultiple
?
Greetings
When in
AccountClient#fetchMultiple
method passed Pubkeys with account not matching to AccountClient's account discriminator,BorschAccountDecoder
throw error and that error not catched, so in this case any wrong Pubkey breakAccountClient#fetchMultiple
instead of return null for wrong Pubkey account as discribed in JSDoc to methodAccountClient#fetchMultiple
.Method:
AccountClient#fetchMultipleAndContext
In line
data: this._coder.accounts.decode(this._idlAccount.name, account.data),
calledBorschAccountDecoder#decode
which throw error ifdiscriminator.compare(data.slice(0, DISCRIMINATOR_SIZE))
:And this error not catched in
AccountClient#fetchMultipleAndContext
, so in this case this account not mapped as null but break execution with error.