public static string StackItemAsString(StackItem item, bool addQuotes = false, Emulator.Type hintType = Emulator.Type.Unknown) { if (item is ICollection) { var bytes = item.GetByteArray(); if (bytes != null && bytes.Length == 20) { var signatureHash = new UInt160(bytes); return(Crypto.Default.ToAddress(signatureHash)); } var s = new StringBuilder(); var items = (ICollection)item; s.Append('['); int i = 0; foreach (StackItem element in items) { if (i > 0) { s.Append(','); } s.Append(StackItemAsString(element)); i++; } s.Append(']'); return(s.ToString()); } if (item is Neo.VM.Types.Boolean && hintType == Emulator.Type.Unknown) { return(item.GetBoolean().ToString()); } if (item is Neo.VM.Types.Integer && hintType == Emulator.Type.Unknown) { return(item.GetBigInteger().ToString()); } if (item is Neo.VM.Types.InteropInterface) { return("{InteropInterface}"); } byte[] data = null; try { data = item.GetByteArray(); } catch { } if ((data == null || data.Length == 0) && hintType == Emulator.Type.Unknown) { return("Null"); } return(FormattingUtils.OutputData(data, addQuotes, hintType)); }
public static string StackItemAsString(StackItem item, bool addQuotes = false, Emulator.Type hintType = Emulator.Type.Unknown) { if (item is ICollection && !(item is Map)) { var bytes = item.GetByteArray(); if (bytes != null && bytes.Length == 20) { var signatureHash = new UInt160(bytes); return(CryptoUtils.ToAddress(signatureHash)); } var s = new StringBuilder(); var items = (ICollection)item; s.Append('['); int i = 0; foreach (StackItem element in items) { if (i > 0) { s.Append(','); } s.Append(StackItemAsString(element)); i++; } s.Append(']'); return(s.ToString()); } else if (item is Map) { Map mapItem = (Map)item; var builder = new StringBuilder(); builder.Append("{\n"); foreach (var key in mapItem.Keys) { builder.Append(StackItemAsString(key)); builder.Append(" : "); builder.Append(StackItemAsString(mapItem[key])); builder.Append("\n"); } builder.Append("}"); return(builder.ToString()); } if (item is Neo.VM.Types.Boolean && hintType == Emulator.Type.Unknown) { return(item.GetBoolean().ToString()); } if (item is Neo.VM.Types.Integer && hintType == Emulator.Type.Unknown) { return(item.GetBigInteger().ToString()); } if (item is Neo.VM.Types.InteropInterface) { return("{InteropInterface}"); } byte[] data = null; try { data = item.GetByteArray(); } catch { } if ((data == null || data.Length == 0) && hintType == Emulator.Type.Unknown) { return("Null"); } if (hintType == Emulator.Type.Array) { var s = new StringBuilder(); s.Append('['); int count = 0; if (data.Length > 0) { var array = (VM.Types.Array)item; foreach (var entry in array) { if (count > 0) { s.Append(", "); } count++; s.Append(StackItemAsString(entry, addQuotes, Emulator.Type.Unknown)); } } s.Append(']'); return(s.ToString()); } return(FormattingUtils.OutputData(data, addQuotes, hintType)); }