findProgramAddress static method
(SolAddress, int)
findProgramAddress({
- required List<
List< seeds,int> > - required SolAddress programId,
Converts a Solana value to lamports.
Implementation
static (SolAddress, int) findProgramAddress({
required List<List<int>> seeds,
required SolAddress programId,
}) {
int nonce = 255;
List<int> seedBytes = [];
for (final i in seeds) {
if (i.length > maxSeedLength) {
throw const SolanaPluginException('Max seed length exceeded');
}
seedBytes = [...seedBytes, ...i];
}
while (nonce != 0) {
try {
final List<int> seedsWithNonce = [...seedBytes, nonce];
final addr = createProgramAddress(
seedBytes: seedsWithNonce,
programId: programId,
);
return (addr, nonce);
} catch (e) {
nonce--;
continue;
}
}
throw const SolanaPluginException(
'Unable to find a viable program address nonce',
);
}