TransactionInstruction.fromBytes constructor

TransactionInstruction.fromBytes({
  1. required SolAddress programId,
  2. required List<AccountMeta> keys,
  3. required List<int> instructionBytes,
})

Implementation

factory TransactionInstruction.fromBytes({
  required SolAddress programId,
  required List<AccountMeta> keys,
  required List<int> instructionBytes,
}) {
  try {
    if (programId == AddressLookupTableProgramConst.programId) {
      return AddressLookupTableProgram.fromBytes(
          programId: programId,
          keys: keys,
          instructionBytes: instructionBytes);
    } else if (programId == ComputeBudgetConst.programId) {
      return ComputeBudgetProgram.fromBytes(
          keys: keys, instructionBytes: instructionBytes);
    } else if (programId == Ed25519ProgramConst.programId) {
      return Ed25519Program.fromBytes(
          instructionBytes: instructionBytes, keys: keys);
    } else if (programId == MemoProgramConst.programId) {
      return MemoProgram.fromBytes(
          keys: keys, instructionBytes: instructionBytes);
    } else if (programId == NameServiceProgramConst.programId) {
      return NameServiceProgram.fromBytes(
          keys: keys, instructionBytes: instructionBytes);
    } else if (programId == Secp256k1ProgramConst.programId) {
      return Secp256k1Program.fromBytes(
          keys: keys, instructionBytes: instructionBytes);
    } else if (programId == SPLTokenProgramConst.tokenProgramId ||
        programId == SPLTokenProgramConst.token2022ProgramId) {
      return SPLTokenProgram.fromBytes(
          keys: keys,
          instructionBytes: instructionBytes,
          programId: programId);
    } else if (programId == SPLTokenSwapConst.oldTokenSwapProgramId ||
        programId == SPLTokenSwapConst.tokenSwapProgramId) {
      return SPLTokenSwapProgram.fromBytes(
          keys: keys,
          instructionBytes: instructionBytes,
          programId: programId);
    } else if (programId == StakeProgramConst.programId) {
      return StakeProgram.fromBytes(
          keys: keys, instructionBytes: instructionBytes);
    } else if (programId == StakePoolProgramConst.programId) {
      return StakePoolProgram.fromBytes(
          keys: keys, instructionBytes: instructionBytes);
    } else if (programId == SystemProgramConst.programId) {
      return SystemProgram.fromBytes(
          keys: keys, instructionBytes: instructionBytes);
    } else if (programId == VoteProgramConst.programId) {
      return VoteProgram.fromBytes(
          keys: keys, instructionBytes: instructionBytes);
    } else if (programId == TokenLendingProgramConst.lendingProgramId) {
      return TokenLendingProgram.fromBytes(
          keys: keys, instructionBytes: instructionBytes);
    } else if (programId ==
        AssociatedTokenAccountProgramConst.associatedTokenProgramId) {
      return AssociatedTokenAccountProgram.fromBytes(
          keys: keys, instructionBytes: instructionBytes);
    }
    return SPLTokenMetaDataProgram.fromBytes(
        keys: keys, instructionBytes: instructionBytes, programId: programId);
  } catch (e) {
    return CustomProgram(
        keys: keys,
        programId: programId,
        layout: UnknownProgramLayout(instructionBytes));
  }
}