Пример #1
0
        public Transaction[] TryBroadcast(ref uint256[] knownBroadcasted)
        {
            var startTime    = DateTimeOffset.UtcNow;
            int totalEntries = 0;
            List <Transaction> broadcasted = new List <Transaction>();

            HashSet <uint256> knownBroadcastedSet = new HashSet <uint256>(knownBroadcasted ?? new uint256[0]);
            int height = _Cache.BlockCount;

            foreach (var obj in _Cache.GetEntries())
            {
                if (obj.Confirmations > 0)
                {
                    knownBroadcastedSet.Add(obj.TransactionId);
                }
            }

            foreach (var tx in GetTransactions())
            {
                totalEntries++;
                if (!knownBroadcastedSet.Contains(tx.Transaction.GetHash()) &&
                    TryBroadcastCore(tx, height))
                {
                    broadcasted.Add(tx.Transaction);
                }
                knownBroadcastedSet.Add(tx.Transaction.GetHash());
            }
            knownBroadcasted = knownBroadcastedSet.ToArray();
            Logs.Broadcasters.LogInformation($"Broadcasted {broadcasted.Count} transaction(s), monitoring {totalEntries} entries in {(long)(DateTimeOffset.UtcNow - startTime).TotalSeconds} seconds");
            return(broadcasted.ToArray());
        }
Пример #2
0
        public TransactionInformation[] GetTransactions(Script scriptPubKey, bool withProof)
        {
            if (scriptPubKey == null)
            {
                throw new ArgumentNullException(nameof(scriptPubKey));
            }

            var address = scriptPubKey.GetDestinationAddress(this.tumblingState.TumblerNetwork);

            if (address == null)
            {
                return(new TransactionInformation[0]);
            }

            var walletTransactions = _Cache.GetEntries();
            List <TransactionInformation> results = Filter(walletTransactions, !withProof, address);

            if (withProof)
            {
                bool found;
                foreach (var tx in results.ToList())
                {
                    found = false;
                    MerkleBlock proof = null;

                    // TODO: Not efficient

                    foreach (var walletName in this.tumblingState.walletManager.GetWallets())
                    {
                        if (found)
                        {
                            break;
                        }

                        var wallet = this.tumblingState.walletManager.GetWallet(walletName);

                        foreach (var account in wallet.GetAccountsByCoinType(this.tumblingState.coinType))
                        {
                            var txData = account.GetTransactionsById(tx.Transaction.GetHash());
                            if (txData != null)
                            {
                                found = true;

                                // TODO: Is it possible for GetTransactionsById to return multiple results?
                                var trx = txData.First <Stratis.Bitcoin.Features.Wallet.TransactionData>();

                                proof = new MerkleBlock();
                                proof.ReadWrite(Encoders.Hex.DecodeData(trx.MerkleProof.ToHex()));

                                tx.MerkleProof = proof;

                                break;
                            }
                        }
                    }

                    if (!found)
                    {
                        results.Remove(tx);
                        continue;
                    }
                }
            }
            return(results.ToArray());
        }