예제 #1
0
 public NewTransactionMatchEvent(string cryptoCode, uint256 blockId, TransactionMatch match, Repository.SavedTransaction savedTransaction)
 {
     Match            = match;
     BlockId          = blockId;
     SavedTransaction = savedTransaction;
     CryptoCode       = cryptoCode;
 }
예제 #2
0
        HttpRequestMessage PrepareRequest(TransactionMatch match, Uri callback)
        {
            HttpRequestMessage message = new HttpRequestMessage();

            message.Method     = HttpMethod.Post;
            message.RequestUri = callback;
            message.Content    = new StringContent(_Serializer.ToString(match), Encoding, "application/json");
            return(message);
        }
예제 #3
0
 internal static InsertTransaction CreateInsertTransaction(this TransactionMatch match, uint256 blockHash)
 {
     return(new InsertTransaction()
     {
         DerivationStrategy = match.DerivationStrategy,
         TrackedTransaction = new TrackedTransaction()
         {
             Transaction = match.Transaction, BlockHash = blockHash
         }
     });
 }
예제 #4
0
        public static IEnumerable <TransactionMatch> GetMatches(this Repository repository, Transaction tx)
        {
            var matches = new Dictionary <string, TransactionMatch>();
            HashSet <Script> inputScripts  = new HashSet <Script>();
            HashSet <Script> outputScripts = new HashSet <Script>();
            HashSet <Script> scripts       = new HashSet <Script>();

            foreach (var input in tx.Inputs)
            {
                var signer = input.GetSigner();
                if (signer != null)
                {
                    inputScripts.Add(signer.ScriptPubKey);
                    scripts.Add(signer.ScriptPubKey);
                }
            }

            foreach (var output in tx.Outputs)
            {
                outputScripts.Add(output.ScriptPubKey);
                scripts.Add(output.ScriptPubKey);
            }

            var keyInformations = repository.GetKeyInformations(scripts.ToArray());

            foreach (var keyInfoByScripts in keyInformations)
            {
                foreach (var keyInfo in keyInfoByScripts.Value)
                {
                    var matchesGroupingKey = keyInfo.DerivationStrategy?.ToString() ?? keyInfo.ScriptPubKey.ToHex();
                    if (!matches.TryGetValue(matchesGroupingKey, out TransactionMatch match))
                    {
                        match = new TransactionMatch();
                        matches.Add(matchesGroupingKey, match);
                        match.TrackedSource      = keyInfo.TrackedSource;
                        match.DerivationStrategy = (keyInfo.TrackedSource as DerivationSchemeTrackedSource)?.DerivationStrategy;
                        match.Transaction        = tx;
                    }

                    if (outputScripts.Contains(keyInfo.ScriptPubKey))
                    {
                        match.Outputs.Add(keyInfo);
                    }

                    if (inputScripts.Contains(keyInfo.ScriptPubKey))
                    {
                        match.Inputs.Add(keyInfo);
                    }
                }
            }
            return(matches.Values);
        }
예제 #5
0
        public static IEnumerable <TransactionMatch> GetMatches(this Repository repository, Transaction tx)
        {
            var matches = new Dictionary <DerivationStrategyBase, TransactionMatch>();
            HashSet <Script> inputScripts  = new HashSet <Script>();
            HashSet <Script> outputScripts = new HashSet <Script>();
            HashSet <Script> scripts       = new HashSet <Script>();

            foreach (var input in tx.Inputs)
            {
                var signer = input.ScriptSig.GetSigner() ?? input.WitScript.ToScript().GetSigner();
                if (signer != null)
                {
                    inputScripts.Add(signer.ScriptPubKey);
                    scripts.Add(signer.ScriptPubKey);
                }
            }

            foreach (var output in tx.Outputs)
            {
                outputScripts.Add(output.ScriptPubKey);
                scripts.Add(output.ScriptPubKey);
            }

            var keyInformations = repository.GetKeyInformations(scripts.ToArray());

            foreach (var keyInfoByScripts in keyInformations)
            {
                foreach (var keyInfo in keyInfoByScripts.Value)
                {
                    if (!matches.TryGetValue(keyInfo.DerivationStrategy, out TransactionMatch match))
                    {
                        match = new TransactionMatch();
                        matches.Add(keyInfo.DerivationStrategy, match);
                        match.DerivationStrategy = keyInfo.DerivationStrategy;
                        match.Transaction        = tx;
                    }

                    if (outputScripts.Contains(keyInfo.ScriptPubKey))
                    {
                        match.Outputs.Add(keyInfo);
                    }

                    if (inputScripts.Contains(keyInfo.ScriptPubKey))
                    {
                        match.Inputs.Add(keyInfo);
                    }
                }
            }
            return(matches.Values);
        }
예제 #6
0
        private IEnumerable <TransactionMatch> GetMatches(Transaction tx)
        {
            var matches = new Dictionary <DerivationStrategyBase, TransactionMatch>();
            HashSet <Script> scripts = new HashSet <Script>();

            foreach (var input in tx.Inputs)
            {
                var signer = input.ScriptSig.GetSigner() ?? input.WitScript.ToScript().GetSigner();
                if (signer != null)
                {
                    scripts.Add(signer.ScriptPubKey);
                }
            }

            int scriptPubKeyIndex = scripts.Count;

            foreach (var output in tx.Outputs)
            {
                scripts.Add(output.ScriptPubKey);
            }

            var keyInformations = Repository.GetKeyInformations(scripts.ToArray()).GetAwaiter().GetResult();

            for (int scriptIndex = 0; scriptIndex < keyInformations.Length; scriptIndex++)
            {
                for (int i = 0; i < keyInformations[scriptIndex].Length; i++)
                {
                    var keyInfo = keyInformations[scriptIndex][i];
                    if (!matches.TryGetValue(keyInfo.DerivationStrategy, out TransactionMatch match))
                    {
                        match = new TransactionMatch();
                        matches.Add(keyInfo.DerivationStrategy, match);
                        match.DerivationStrategy = keyInfo.DerivationStrategy;
                        match.Transaction        = tx;
                    }
                    var isOutput = scriptIndex >= scriptPubKeyIndex;
                    if (isOutput)
                    {
                        match.Outputs.Add(keyInfo);
                    }
                    else
                    {
                        match.Inputs.Add(keyInfo);
                    }
                }
            }
            return(matches.Values);
        }
예제 #7
0
        public void Notify(TransactionMatch match, bool log)
        {
            if (log)
            {
                Logs.Explorer.LogInformation($"A wallet received money");
            }
            var key = match.DerivationStrategy.GetHash();

            lock (_WaitFor)
            {
                IReadOnlyCollection <Completion> completions;
                if (_WaitFor.TryGetValue(key, out completions))
                {
                    foreach (var completion in completions.ToList())
                    {
                        completion.TrySetResult(true);
                    }
                }
            }
        }