findProgramAddress static method

Tuple<SolAddress, int> findProgramAddress({
  1. required List<List<int>> seeds,
  2. required SolAddress programId,
})

Converts a Solana value to lamports.

Implementation

static Tuple<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 MessageException("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 Tuple(addr, nonce);
    } catch (e) {
      nonce--;
      continue;
    }
  }
  throw MessageException("Unable to find a viable program address nonce");
}