public IEnumerable <Label> GetLabels(WalletTransactionInfo transactionInfo) { foreach (var label in transactionInfo.Labels) { if (LabelColors.TryGetValue(label, out var color)) { yield return(new Label(label, color)); } } }
public void SetBlobInfo(WalletTransactionInfo blobInfo) { if (blobInfo == null) { Labels = string.Empty; Blob = Array.Empty <byte>(); return; } Labels = String.Join(',', blobInfo.Labels); Blob = ZipUtils.Zip(JsonConvert.SerializeObject(blobInfo)); }
public void SetBlobInfo(WalletTransactionInfo blobInfo) { if (blobInfo == null) { Labels = string.Empty; Blob = Array.Empty <byte>(); return; } if (blobInfo.Labels.Any(l => l.Contains(',', StringComparison.OrdinalIgnoreCase))) { throw new ArgumentException(paramName: nameof(blobInfo), message: "Labels must not contains ','"); } Labels = String.Join(',', blobInfo.Labels); Blob = ZipUtils.Zip(JsonConvert.SerializeObject(blobInfo)); }
public static WalletTransactionInfo GetBlobInfo(this WalletTransactionData walletTransactionData) { WalletTransactionInfo blobInfo; if (walletTransactionData.Blob == null || walletTransactionData.Blob.Length == 0) { blobInfo = new WalletTransactionInfo(); } else { blobInfo = JsonConvert.DeserializeObject <WalletTransactionInfo>(ZipUtils.Unzip(walletTransactionData.Blob)); } if (!string.IsNullOrEmpty(walletTransactionData.Labels)) { if (walletTransactionData.Labels.StartsWith('[')) { foreach (var jtoken in JArray.Parse(walletTransactionData.Labels)) { var l = jtoken.Type == JTokenType.String ? Label.Parse(jtoken.Value <string>()) : Label.Parse(jtoken.ToString()); blobInfo.Labels.TryAdd(l.Text, l); } } else { // Legacy path foreach (var token in walletTransactionData.Labels.Split(',', StringSplitOptions.RemoveEmptyEntries)) { var l = Label.Parse(token); blobInfo.Labels.TryAdd(l.Text, l); } } } return(blobInfo); }
public static void SetBlobInfo(this WalletTransactionData walletTransactionData, WalletTransactionInfo blobInfo) { if (blobInfo == null) { walletTransactionData.Labels = string.Empty; walletTransactionData.Blob = Array.Empty <byte>(); return; } walletTransactionData.Labels = new JArray( blobInfo.Labels.Select(l => JsonConvert.SerializeObject(l.Value, LabelSerializerSettings)) .Select(l => JObject.Parse(l)) .OfType <JToken>() .ToArray()).ToString(); walletTransactionData.Blob = ZipUtils.Zip(JsonConvert.SerializeObject(blobInfo)); }
public static void SetBlobInfo(this WalletTransactionData walletTransactionData, WalletTransactionInfo blobInfo) { if (blobInfo == null) { walletTransactionData.Labels = string.Empty; walletTransactionData.Blob = Array.Empty <byte>(); return; } walletTransactionData.Labels = JArray.FromObject(blobInfo.Labels).ToString(); walletTransactionData.Blob = ZipUtils.Zip(JsonConvert.SerializeObject(blobInfo)); }