getResultValue method Null safety

XdrSCVal? getResultValue()

Extracts the result value from the first entry on success

Implementation

XdrSCVal? getResultValue() {
  if (error != null || status != STATUS_SUCCESS || resultMetaXdr == null) {
    return null;
  }

  XdrTransactionMeta meta =
      XdrTransactionMeta.fromBase64EncodedXdrString(resultMetaXdr!);

  List<XdrOperationResult>? results = meta.v3?.txResult.result.results; // :)
  if (results == null || results.length == 0) {
    return null;
  }

  List<XdrSCVal>? success = results[0].tr?.invokeHostFunctionResult?.success;
  if (success != null && success.length > 0) {
    return success[0];
  }
  return null;
}