Beispiel #1
0
        public bool CheckBreezeRegistration(BreezeConfiguration config, DBUtils db)
        {
            var network = Network.StratisMain;

            if (config.IsTestNet)
            {
                // TODO: Change to StratisTest when it is added to NStratis
                network = Network.TestNet;
            }

            // In order to determine if the registration sequence has been performed
            // before, and to see if a previous performance is still valid, interrogate
            // the database to see if any transactions have been recorded.

            var transactions = db.GetDictionary <string, string>("RegistrationTransactions");

            // If no transactions exist, the registration definitely needs to be done
            if (transactions == null || transactions.Count == 0)
            {
                return(false);
            }

            string highestKey = null;

            foreach (var txn in transactions)
            {
                // Find most recent transaction. Assume that the rowKeys are ordered
                // lexicographically.
                if (highestKey == null)
                {
                    highestKey = txn.Key;
                }

                if (String.Compare(txn.Key, highestKey) == 1)
                {
                    highestKey = txn.Key;
                }
            }

            var mostRecentTxn = new Transaction(transactions[highestKey]);

            // Decode transaction and check if the decoded bitstream matches the
            // current configuration

            // TODO: Check if transaction is actually confirmed on the blockchain?
            var registrationToken = new RegistrationToken();

            registrationToken.ParseTransaction(mostRecentTxn, network);

            if (!config.Ipv4Address.Equals(registrationToken.Ipv4Addr))
            {
                return(false);
            }

            if (!config.Ipv6Address.Equals(registrationToken.Ipv6Addr))
            {
                return(false);
            }

            if (config.OnionAddress != registrationToken.OnionAddress)
            {
                return(false);
            }

            if (config.Port != registrationToken.Port)
            {
                return(false);
            }

            return(true);
        }