assertIsBlockhash function
Asserts that putativeBlockhash is a valid base58-encoded blockhash.
A valid blockhash has the same format as an address: a string length between 32 and 44 characters that decodes to exactly 32 bytes.
Throws SolanaError with SolanaErrorCode.blockhashStringLengthOutOfRange
if the string length is outside 32, 44.
Throws SolanaError with SolanaErrorCode.invalidBlockhashByteLength if the decoded byte array is not exactly 32 bytes.
Implementation
void assertIsBlockhash(String putativeBlockhash) {
try {
assertIsAddress(putativeBlockhash);
} on SolanaError catch (error) {
if (isSolanaError(error, SolanaErrorCode.addressesStringLengthOutOfRange)) {
throw SolanaError(
SolanaErrorCode.blockhashStringLengthOutOfRange,
error.context,
);
}
if (isSolanaError(error, SolanaErrorCode.addressesInvalidByteLength)) {
throw SolanaError(
SolanaErrorCode.invalidBlockhashByteLength,
error.context,
);
}
rethrow;
}
}