fix: improve findProgramAddress error when MAX_SEED_LENGTH is exceeded (#17151)
This commit is contained in:
committed by
GitHub
parent
82fb6712e7
commit
e511c442e6
@ -113,7 +113,7 @@ export class PublicKey {
|
|||||||
let buffer = Buffer.alloc(0);
|
let buffer = Buffer.alloc(0);
|
||||||
seeds.forEach(function (seed) {
|
seeds.forEach(function (seed) {
|
||||||
if (seed.length > MAX_SEED_LENGTH) {
|
if (seed.length > MAX_SEED_LENGTH) {
|
||||||
throw new Error(`Max seed length exceeded`);
|
throw new TypeError(`Max seed length exceeded`);
|
||||||
}
|
}
|
||||||
buffer = Buffer.concat([buffer, toBuffer(seed)]);
|
buffer = Buffer.concat([buffer, toBuffer(seed)]);
|
||||||
});
|
});
|
||||||
@ -148,6 +148,9 @@ export class PublicKey {
|
|||||||
const seedsWithNonce = seeds.concat(Buffer.from([nonce]));
|
const seedsWithNonce = seeds.concat(Buffer.from([nonce]));
|
||||||
address = await this.createProgramAddress(seedsWithNonce, programId);
|
address = await this.createProgramAddress(seedsWithNonce, programId);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (err instanceof TypeError) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
nonce--;
|
nonce--;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user