mirrored_repositories/espresso-cash-public/packages/solana/lib/src/rpc
import 'package:json_annotation/json_annotation.dart';
import 'package:solana/src/rpc/dto/account.dart';
import 'package:solana/src/rpc/dto/context.dart';
import 'package:solana/src/rpc/dto/return_data.dart';

part 'transaction_status.g.dart';

/// The status of a transaction
@JsonSerializable()
class TransactionStatus {
  const TransactionStatus({
    required this.err,
    required this.logs,
    required this.accounts,
    required this.unitsConsumed,
    this.returnData,
  });

  factory TransactionStatus.fromJson(Map<String, dynamic> json) =>
      _$TransactionStatusFromJson(json);

  /// Error if transaction failed, null if transaction succeeded.
  final dynamic err;

  /// Array of log messages the transaction instructions output during
  /// execution, null if simulation failed before the transaction was able to
  /// execute (for example due to an invalid blockhash or signature verification
  /// failure).
  final List<String>? logs;

  /// Array of accounts with the same length as the `accounts.addresses` array
  /// in the request.
  final List<Account>? accounts;

  /// The number of compute budget units consumed during the processing of this
  /// transaction.
  final int? unitsConsumed;

  /// The most-recent return data generated by an instruction in the transaction
  final ReturnData? returnData;

  Map<String, dynamic> toJson() => _$TransactionStatusToJson(this);
}

@JsonSerializable()
class TransactionStatusResult extends ContextResult<TransactionStatus> {
  const TransactionStatusResult({required super.context, required super.value});

  factory TransactionStatusResult.fromJson(Map<String, dynamic> json) =>
      _$TransactionStatusResultFromJson(json);

  Map<String, dynamic> toJson() => _$TransactionStatusResultToJson(this);
}
