private void ClearCoinValues() { foreach (var coin in ReceivedCoins.OfType <Coin>()) { coin.Amount = null; } }
public TrackedTransaction(TrackedTransactionKey key, TrackedSource trackedSource, IEnumerable <Coin> receivedCoins, Dictionary <Script, KeyPath> knownScriptMapping) { if (key == null) { throw new ArgumentNullException(nameof(key)); } if (!key.IsPruned) { throw new ArgumentException("The key should be pruned", nameof(key)); } if (trackedSource == null) { throw new ArgumentNullException(nameof(trackedSource)); } TrackedSource = trackedSource; Key = key; if (knownScriptMapping != null) { KnownKeyPathMapping = knownScriptMapping; } if (receivedCoins != null) { ReceivedCoins.AddRange(receivedCoins); } }
private void ClearCoinValues() { ReceivedCoins = ReceivedCoins.Select(coin => (ICoin) new Coin(coin.Outpoint.Clone(), coin.TxOut.Clone())).ToHashSet(); foreach (var coin in ReceivedCoins.OfType <Coin>()) { coin.Amount = null; } }
internal void Merge(OrderedBalanceChange other, WalletRule walletRule) { if (other.ReceivedCoins.Count != 0) { ReceivedCoins.AddRange(other.ReceivedCoins); ReceivedCoins = new CoinCollection(ReceivedCoins.Distinct <ICoin, OutPoint>(c => c.Outpoint)); if (walletRule != null) { foreach (var c in other.ReceivedCoins) { this.MatchedRules.Add(new MatchedRule() { Index = c.Outpoint.N, Rule = walletRule, MatchType = MatchLocation.Output }); } } } if (other.SpentIndices.Count != 0) { SpentIndices.AddRange(other.SpentIndices); SpentIndices = SpentIndices.Distinct().ToList(); SpentOutpoints.AddRange(other.SpentOutpoints); SpentOutpoints = SpentOutpoints.Distinct().ToList(); //Remove cached value, no longer correct UpdateToUncoloredCoins(); SpentCoins = null; if (walletRule != null) { foreach (var c in other.SpentIndices) { this.MatchedRules.Add(new MatchedRule() { Index = c, Rule = walletRule, MatchType = MatchLocation.Input }); } } } }
internal void KnownKeyPathMappingUpdated() { if (Transaction == null) { return; } var scriptPubKey = (TrackedSource as IDestination)?.ScriptPubKey; for (int i = 0; i < Transaction.Outputs.Count; i++) { var output = Transaction.Outputs[i]; if (KnownKeyPathMapping.ContainsKey(output.ScriptPubKey) || scriptPubKey == output.ScriptPubKey) { ReceivedCoins.Add(new Coin(new OutPoint(Key.TxId, i), output)); } } SpentOutpoints.AddRange(Transaction.Inputs.Select(input => input.PrevOut)); }
internal DynamicTableEntity ToEntity() { DynamicTableEntity entity = new DynamicTableEntity(); entity.ETag = "*"; entity.PartitionKey = PartitionKey; var locator = CreateBalanceLocator(); entity.RowKey = BalanceId + "-" + locator.ToString(true); entity.Properties.Add("s", new EntityProperty(SeenUtc)); Helper.SetEntityProperty(entity, "ss", Helper.SerializeList(SpentIndices.Select(e => new IntCompactVarInt(e)))); Helper.SetEntityProperty(entity, "a", Helper.SerializeList(SpentOutpoints)); if (SpentCoins != null) { Helper.SetEntityProperty(entity, "b", Helper.SerializeList(SpentCoins.Select(c => new Spendable(c.Outpoint, c.TxOut)))); } Helper.SetEntityProperty(entity, "c", Helper.SerializeList(ReceivedCoins.Select(e => new IntCompactVarInt(e.Outpoint.N)))); Helper.SetEntityProperty(entity, "d", Helper.SerializeList(ReceivedCoins.Select(e => e.TxOut))); var flags = (HasOpReturn ? "o" : "n") + (IsCoinbase ? "o" : "n"); entity.Properties.AddOrReplace("e", new EntityProperty(flags)); entity.Properties.AddOrReplace("f", new EntityProperty(Helper.Serialize(MatchedRules))); if (ColoredTransaction != null) { entity.Properties.AddOrReplace("g", new EntityProperty(ColoredTransaction.ToBytes())); } if (ScriptPubKey != null && !BalanceId.ContainsScript) { var bytes = ScriptPubKey.ToBytes(true); if (bytes.Length < 63000) { entity.Properties.Add("h", new EntityProperty(bytes)); } } if (CustomData != null) { Helper.SetEntityProperty(entity, "cu", Encoding.UTF8.GetBytes(CustomData)); } return(entity); }
internal JObject ToJson() { var obj = new JObject(); if (BlockId != null) { obj.Add("Height", Height); obj.Add("BlockId", BlockId.ToString()); obj.Add("Proof", Encoders.Hex.EncodeData(this.Proof.ToBytes())); } obj.Add("AddedDate", AddedDate); obj.Add("UnconfirmedSeen", UnconfirmedSeen); obj.Add("Transaction", Encoders.Hex.EncodeData(this.Transaction.ToBytes())); if (this.ReceivedCoins != null) { obj.Add("ReceivedCoins", new JArray(ReceivedCoins.Select(c => ToJson(c)))); } if (this.SpentCoins != null) { obj.Add("SpentCoins", new JArray(SpentCoins.Select(c => ToJson(c)))); } return(obj); }