Beispiel #1
0
        private Registration?TryGetDependency(Type type)
        {
            lock (SyncRoot)
            {
                if (RegistrationStore.Registrations.TryGetValue(type, out Registration parent))
                {
                    return(parent);
                }

                foreach (IDependencyResolver dependencyResolver in _resolvers)
                {
                    ServiceBinding[] serviceBindings = dependencyResolver.Resolve(this, type).ToArray();
                    if (serviceBindings.Length > 0)
                    {
                        foreach (ServiceBinding binding in serviceBindings)
                        {
                            RegistrationStore.AddBinding(binding);
                        }
                        return(TryGetDependency(type));
                    }
                }

                return(_parentPipeline?.TryGetDependency(type));
            }
        }
        public void GetDependencies_MultiDecoratorRegistration_Enumerate()
        {
            //ARRANGE
            var container = new Container(builder =>
            {
                builder.Register <IPlugin, Plugin1>();
                builder.Register <IPlugin, Plugin2>();
                builder.Register <IPlugin, Plugin3>();

                builder.Decorate(typeof(IPlugin), new[]
                {
                    typeof(PluginLogger1),
                    typeof(PluginLogger2),
                    typeof(PluginLogger3),
                });
            });

            //ACT
            RegistrationStore readOnlyBindingConfig = container.Registrations;

            //ASSERT
            Binding[] bindings = Assert.Single(readOnlyBindingConfig.Registrations).Value.Bindings.ToArray();
            Assert.Equal(typeof(Plugin1), bindings[0].Expression !.Type);
            Assert.Equal(typeof(Plugin2), bindings[1].Expression !.Type);
            Assert.Equal(typeof(Plugin3), bindings[2].Expression !.Type);

            ArrayList <Expression> decorators = Assert.Single(readOnlyBindingConfig.Decorators.Values);

            Assert.Equal(new[] { typeof(PluginLogger1), typeof(PluginLogger2), typeof(PluginLogger3) }, decorators.Select(x => x.Type));
        }
Beispiel #3
0
        public void RegistrationStoreGetOneTest()
        {
            var token = new RegistrationToken(255,
                                              "1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2",
                                              IPAddress.Parse("127.0.0.1"),
                                              IPAddress.Parse("2001:0db8:85a3:0000:0000:8a2e:0370:7334"),
                                              "0123456789ABCDEF",
                                              37123);

            token.RsaSignature   = Encoding.ASCII.GetBytes("xyz");
            token.EcdsaSignature = Encoding.ASCII.GetBytes("abc");

            RegistrationRecord record = new RegistrationRecord(DateTime.Now,
                                                               Guid.NewGuid(),
                                                               "137cc93a23383252348de58e53e193db471099e78ef89edf1fdea6ff340a7261",
                                                               "0100000027c16c59051604707fcfc75e7ab33decbe72e72baff44ad2b38b78a13929eb5d092df004b20200000048473044022067c3c50f13a1b68402549c6a049a9298d8de03e176909cc6b44f9fd9d9db532502203e7416233a125264aef46698b22f429f60be9ed3b2115ec24f0a05de2a4e4cd901feffffff1d92cb2776b3c3cb3e89ad84c38c72fc72646238d23312a6b1931e7980f90f590200000049483045022100d4141e26371a198fb22347e0cc64fd0563ee11640108836e5f427873e4aa0d00022012960447890e151b46a19c2d1d480f7e81e5ceb615c9566be03189108cb08ce401feffffffa23c4e0da07acb439735e6f2a3c7a1ee15521138cc3815fdbac428e1756a3976010000004948304502210083dfda6e8a7584741c79d60a8c69c372789eb28680fdf43fe15e67eb05c7628e022041cde42e79e83c5be5902c035abcde02579e1841473efbbeb5a909d4520a8ea801fefffffff3b56cf319b4b4895beae1e047d77fddcfd8b86a3964226c0d24dda83335e40802000000484730440220219623b855cd1ac0ad43cb3b76097cb52db2d37b4a6a768a5911dfa3571ff4b602203eb843072f746e225e6c7225438f4f4bf012c18f1a1572d4ead288190d8d61cb01feffffff15209f56f6f5d1246f43057ab546be192659a3c88365529667eb3aa364ed4392000000006b483045022100a5791707155d03fb6e770c0dd0924cf08a3bd3b6e0b5713d7d3e84dc5c2e18bc02200370afce15733f5139a018d3ffc5e594e646ce372274818d9780906f9fb3699101210344e875df3990bf55d7218020b09aea6e1383206ec88344847771b3bc0d72251bfeffffff0220188fba000000001976a914b88f742a0a07af27ccfe21de8a40b9f7541f3e0088ac00e87648170000001976a914db0be998354d2139b14e06459d295de03b94fadb88ac90920000",
                                                               token);
            RegistrationStore store = new RegistrationStore(Path.GetTempFileName());

            store.Add(record);

            var retrievedRecords = store.GetAll();

            Assert.Equal(retrievedRecords.Count, 1);

            var retrievedRecord = retrievedRecords[0].Record;

            Assert.Equal(retrievedRecord.ProtocolVersion, 255);
            Assert.Equal(retrievedRecord.ServerId, "1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2");
            Assert.Equal(retrievedRecord.Ipv4Addr, IPAddress.Parse("127.0.0.1"));
            Assert.Equal(retrievedRecord.Ipv6Addr, IPAddress.Parse("2001:0db8:85a3:0000:0000:8a2e:0370:7334"));
            Assert.Equal(retrievedRecord.OnionAddress, "0123456789ABCDEF");
            Assert.Equal(retrievedRecord.Port, 37123);
        }
        public void RegistrationStoreAddTest()
        {
            var privateKey = new Key();
            var token      = new RegistrationToken(255,
                                                   IPAddress.Parse("127.0.0.1"),
                                                   IPAddress.Parse("2001:0db8:85a3:0000:0000:8a2e:0370:7334"),
                                                   "",
                                                   37123,
                                                   new KeyId("dbb476190a81120928763ee8ce97e4c0bcfd6624"),
                                                   new KeyId("dbb476190a81120928763ee8ce97e4c0bcfd6624"),
                                                   privateKey.PubKey,
                                                   new Uri("https://redstone.com/test"));

            token.Signature = CryptoUtils.SignData(token.GetHeaderBytes().ToArray(), privateKey);

            RegistrationRecord record = new RegistrationRecord(DateTime.Now,
                                                               Guid.NewGuid(),
                                                               "137cc93a23383252348de58e53e193db471099e78ef89edf1fdea6ff340a7261",
                                                               "0100000027c16c59051604707fcfc75e7ab33decbe72e72baff44ad2b38b78a13929eb5d092df004b20200000048473044022067c3c50f13a1b68402549c6a049a9298d8de03e176909cc6b44f9fd9d9db532502203e7416233a125264aef46698b22f429f60be9ed3b2115ec24f0a05de2a4e4cd901feffffff1d92cb2776b3c3cb3e89ad84c38c72fc72646238d23312a6b1931e7980f90f590200000049483045022100d4141e26371a198fb22347e0cc64fd0563ee11640108836e5f427873e4aa0d00022012960447890e151b46a19c2d1d480f7e81e5ceb615c9566be03189108cb08ce401feffffffa23c4e0da07acb439735e6f2a3c7a1ee15521138cc3815fdbac428e1756a3976010000004948304502210083dfda6e8a7584741c79d60a8c69c372789eb28680fdf43fe15e67eb05c7628e022041cde42e79e83c5be5902c035abcde02579e1841473efbbeb5a909d4520a8ea801fefffffff3b56cf319b4b4895beae1e047d77fddcfd8b86a3964226c0d24dda83335e40802000000484730440220219623b855cd1ac0ad43cb3b76097cb52db2d37b4a6a768a5911dfa3571ff4b602203eb843072f746e225e6c7225438f4f4bf012c18f1a1572d4ead288190d8d61cb01feffffff15209f56f6f5d1246f43057ab546be192659a3c88365529667eb3aa364ed4392000000006b483045022100a5791707155d03fb6e770c0dd0924cf08a3bd3b6e0b5713d7d3e84dc5c2e18bc02200370afce15733f5139a018d3ffc5e594e646ce372274818d9780906f9fb3699101210344e875df3990bf55d7218020b09aea6e1383206ec88344847771b3bc0d72251bfeffffff0220188fba000000001976a914b88f742a0a07af27ccfe21de8a40b9f7541f3e0088ac00e87648170000001976a914db0be998354d2139b14e06459d295de03b94fadb88ac90920000",
                                                               token,
                                                               null);
            RegistrationStore store = new RegistrationStore(Path.GetTempFileName());

            Assert.True(store.Add(record));
        }
Beispiel #5
0
        private Registration?TryGetDependency(Type type)
        {
            lock (SyncRoot)
            {
                if (RegistrationStore.Registrations.TryGetValue(type, out Registration parent))
                {
                    return(parent);
                }

                foreach (IServiceBindingGenerator dependencyResolver in _resolvers)
                {
                    if (Settings.ResolverExclusions.TryGetValue(dependencyResolver.GetType(), out var exclusions))
                    {
                        if (exclusions.Any(x => x.Match(type)))
                        {
                            continue;
                        }
                    }
                    ServiceBinding[] serviceBindings = dependencyResolver.Resolve(this, type).ToArray();
                    if (serviceBindings.Length > 0)
                    {
                        foreach (ServiceBinding binding in serviceBindings)
                        {
                            RegistrationStore.AddBinding(binding);
                        }
                        return(TryGetDependency(type));
                    }
                }

                return(_parentPipeline?.TryGetDependency(type));
            }
        }
Beispiel #6
0
        private Container(Container parentContainer, Action <ContainerBuilder>?builder)
        {
            var context = new ContainerBuilder(this);

            builder?.Invoke(context);
            _options         = parentContainer._options;
            _containerScope  = new Scoped(this);
            Registrations    = context.Registrations;
            _dependencyGraph = new DependencyGraph(context.Registrations, _containerScope, _options, parentContainer._dependencyGraph);
        }
Beispiel #7
0
        /// <summary>
        /// Creates a new container using the provided builder.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="options"></param>
        public Container(Action <ContainerBuilder>?builder = null, SingularitySettings?options = null)
        {
            var context = new ContainerBuilder(this);

            builder?.Invoke(context);
            _options         = options ?? SingularitySettings.Default;
            _containerScope  = new Scoped(this);
            Registrations    = context.Registrations;
            _dependencyGraph = new DependencyGraph(context.Registrations, _containerScope, _options);
        }
Beispiel #8
0
        public void Initialize(ILoggerFactory loggerFactory, RegistrationStore registrationStore, bool isBitcoin, Network network, IWatchOnlyWalletManager watchOnlyWalletManager)
        {
            this.loggerFactory          = loggerFactory;
            this.logger                 = loggerFactory.CreateLogger(this.GetType().FullName);
            this.registrationStore      = registrationStore;
            this.network                = network;
            this.watchOnlyWalletManager = watchOnlyWalletManager as WatchOnlyWalletManager;

            logger.LogInformation("Initialized RegistrationFeature");
        }
        public InstanceFactoryResolver(RegistrationStore registrationStore, Scoped containerScope, SingularitySettings settings, InstanceFactoryResolver?parentPipeline)
        {
            Settings          = settings ?? throw new ArgumentNullException(nameof(settings));
            _resolvers        = Settings.ServiceBindingGenerators.ToArray();
            _parentPipeline   = parentPipeline;
            SyncRoot          = parentPipeline?.SyncRoot ?? new object();
            _containerScope   = containerScope ?? throw new ArgumentNullException(nameof(containerScope));
            RegistrationStore = registrationStore ?? throw new ArgumentNullException(nameof(registrationStore));

            if (parentPipeline != null)
            {
                CheckChildRegistrations(parentPipeline.RegistrationStore.Registrations, registrationStore.Registrations, SyncRoot);
            }
        }
Beispiel #10
0
        public ResolverPipeline(RegistrationStore registrationStore, IDependencyResolver[] resolvers, Scoped containerScope, SingularitySettings settings, IResolverPipeline?parentPipeline)
        {
            _settings         = settings ?? throw new ArgumentNullException(nameof(settings));
            _resolvers        = resolvers ?? throw new ArgumentNullException(nameof(resolvers));
            _parentPipeline   = parentPipeline;
            SyncRoot          = parentPipeline?.SyncRoot ?? new object();
            _containerScope   = containerScope ?? throw new ArgumentNullException(nameof(containerScope));
            RegistrationStore = registrationStore ?? throw new ArgumentNullException(nameof(registrationStore));

            if (parentPipeline != null)
            {
                CheckChildRegistrations(parentPipeline, registrationStore.Registrations, SyncRoot);
            }
        }
        public void GetDependencies_MultiDecoratorRegistration_Enumerate()
        {
            //ARRANGE
            var builder = new ContainerBuilder(cb =>
            {
                cb.Register <IPlugin, Plugin1>();
                cb.Register <IPlugin, Plugin2>();
                cb.Register <IPlugin, Plugin3>();

                cb.Decorate(typeof(IPlugin), new[]
                {
                    typeof(PluginLogger1),
                    typeof(PluginLogger2),
                    typeof(PluginLogger3),
                });
            });

            //ACT
            RegistrationStore readOnlyBindingConfig = builder.Registrations;

            //ASSERT

            Assert.Equal(4, readOnlyBindingConfig.Registrations.Count());

            var multiServiceBinding = readOnlyBindingConfig.Registrations[typeof(IPlugin)];

            ServiceBinding[] serviceBindings = multiServiceBinding.Bindings.ToArray();
            Assert.Equal(typeof(Plugin1), serviceBindings[0].Expression?.Type);
            Assert.Equal(typeof(Plugin2), serviceBindings[1].Expression?.Type);
            Assert.Equal(typeof(Plugin3), serviceBindings[2].Expression?.Type);

            var plugin1Binding = readOnlyBindingConfig.Registrations[typeof(Plugin1)];

            Assert.Single(plugin1Binding.Bindings);

            var plugin2Binding = readOnlyBindingConfig.Registrations[typeof(Plugin2)];

            Assert.Single(plugin2Binding.Bindings);

            var plugin3Binding = readOnlyBindingConfig.Registrations[typeof(Plugin3)];

            Assert.Single(plugin3Binding.Bindings);

            ArrayList <Expression> decorators = Assert.Single(readOnlyBindingConfig.Decorators.Values);

            Assert.Equal(new[] { typeof(PluginLogger1), typeof(PluginLogger2), typeof(PluginLogger3) }, decorators.Select(x => x.Type));
        }
Beispiel #12
0
        public void RegisterServices()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddTransient <IRepositoryTransient1, RepositoryTransient1>();

            var builder = new ContainerBuilder(builder =>
            {
                builder.RegisterServices(serviceCollection);
            });

            RegistrationStore registrationStore = builder.Registrations;

            KeyValuePair <Type, Registration> registration = Assert.Single(registrationStore.Registrations);

            Assert.Empty(registrationStore.Decorators);
            ServiceBinding serviceBinding = Assert.Single(registration.Value.Bindings);

            Assert.Equal(typeof(IRepositoryTransient1), registration.Key);
            Assert.Equal(typeof(RepositoryTransient1), serviceBinding.Expression?.Type);
        }
        public void RegisterServices()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddTransient <IRepositoryTransient1, RepositoryTransient1>();

            var container = new Container(builder =>
            {
                builder.RegisterServices(serviceCollection);
            });

            RegistrationStore registrationStore = container.Registrations;

            Registration registration = Assert.Single(registrationStore.Registrations.Values);

            Assert.Empty(registrationStore.Decorators);
            Binding binding = Assert.Single(registration.Bindings);

            Assert.Equal(typeof(IRepositoryTransient1), registration.DependencyType);
            Assert.Equal(typeof(RepositoryTransient1), binding.Expression?.Type);
        }
Beispiel #14
0
        public ResolverPipeline(RegistrationStore registrationStore, Scoped containerScope, SingularitySettings settings, ResolverPipeline?parentPipeline)
        {
            _settings  = settings ?? throw new ArgumentNullException(nameof(settings));
            _resolvers = new IDependencyResolver[]
            {
                new EnumerableDependencyResolver(),
                new ExpressionDependencyResolver(),
                new LazyDependencyResolver(),
                new FactoryDependencyResolver(),
                new ConcreteDependencyResolver(),
                new OpenGenericResolver()
            };
            _parentPipeline   = parentPipeline;
            SyncRoot          = parentPipeline?.SyncRoot ?? new object();
            _containerScope   = containerScope ?? throw new ArgumentNullException(nameof(containerScope));
            RegistrationStore = registrationStore ?? throw new ArgumentNullException(nameof(registrationStore));

            if (parentPipeline != null)
            {
                CheckChildRegistrations(parentPipeline.RegistrationStore.Registrations, registrationStore.Registrations, SyncRoot);
            }
        }
        public RegistrationFeature(ILoggerFactory loggerFactory,
                                   NodeSettings nodeSettings,
                                   RegistrationManager registrationManager,
                                   RegistrationStore registrationStore,
                                   ConcurrentChain chain,
                                   Signals signals,
                                   IWatchOnlyWalletManager watchOnlyWalletManager,
                                   IBlockNotification blockNotification,
                                   IWalletSyncManager walletSyncManager)
        {
            this.loggerFactory       = loggerFactory;
            this.logger              = loggerFactory.CreateLogger(this.GetType().FullName);
            this.nodeSettings        = nodeSettings;
            this.registrationManager = registrationManager;
            this.registrationStore   = registrationStore;
            this.chain   = chain;
            this.signals = signals;
            this.network = nodeSettings.Network;
            this.watchOnlyWalletManager = watchOnlyWalletManager;
            this.blockNotification      = blockNotification as BlockNotification;
            this.walletSyncManager      = walletSyncManager;

            if (nodeSettings.Network == Network.Main || nodeSettings.Network == Network.TestNet || nodeSettings.Network == Network.RegTest)
            {
                // Bitcoin networks - these currently only interrogate the registration store for initial masternode selection
                this.isBitcoin = true;
            }
            else
            {
                // Stratis networks - these write to the registration store as new registrations come in via blocks
                this.isBitcoin = false;

                // Force registration store to be kept in same folder as other node data
                this.registrationStore.SetStorePath(this.nodeSettings.DataDir);
            }
        }
Beispiel #16
0
        public bool CheckBreezeRegistration(BreezeConfiguration config, string regStorePath, string configurationHash, string onionAddress, RsaKey tumblerKey)
        {
            // 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.

            RegistrationStore regStore = new RegistrationStore(regStorePath);

            List <RegistrationRecord> transactions = regStore.GetByServerId(config.TumblerEcdsaKeyAddress);

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

            RegistrationRecord mostRecent = null;

            foreach (RegistrationRecord record in transactions)
            {
                // Find most recent transaction
                if (mostRecent == null)
                {
                    mostRecent = record;
                }

                if (record.RecordTimestamp > mostRecent.RecordTimestamp)
                {
                    mostRecent = record;
                }
            }

            // Check if the stored record matches the current configuration

            RegistrationToken registrationToken;

            try
            {
                registrationToken = mostRecent.Record;
            }
            catch (NullReferenceException e)
            {
                Console.WriteLine(e);
                return(false);
            }

            // IPv4
            if (config.Ipv4Address == null && registrationToken.Ipv4Addr != null)
            {
                return(false);
            }

            if (config.Ipv4Address != null && registrationToken.Ipv4Addr == null)
            {
                return(false);
            }

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

            // IPv6
            if (config.Ipv6Address == null && registrationToken.Ipv6Addr != null)
            {
                return(false);
            }

            if (config.Ipv6Address != null && registrationToken.Ipv6Addr == null)
            {
                return(false);
            }

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

            // Onion
            if (onionAddress != registrationToken.OnionAddress)
            {
                return(false);
            }

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

            // This verifies that the tumbler parameters are unchanged
            if (configurationHash != registrationToken.ConfigurationHash)
            {
                return(false);
            }

            // TODO: Check if transaction is actually confirmed on the blockchain?

            return(true);
        }
        public TumbleBitManager(
            ILoggerFactory loggerFactory,
            NodeSettings nodeSettings,
            IWalletManager walletManager,
            IWatchOnlyWalletManager watchOnlyWalletManager,
            ConcurrentChain chain,
            Network network,
            Signals signals,
            IWalletTransactionHandler walletTransactionHandler,
            IWalletSyncManager walletSyncManager,
            IWalletFeePolicy walletFeePolicy,
            IBroadcasterManager broadcasterManager,
            FullNode fullNode,
            ConfigurationOptionWrapper <string>[] configurationOptions)
        {
            this.walletManager            = walletManager as WalletManager;
            this.watchOnlyWalletManager   = watchOnlyWalletManager;
            this.walletSyncManager        = walletSyncManager as WalletSyncManager;
            this.walletTransactionHandler = walletTransactionHandler as WalletTransactionHandler;
            this.chain              = chain;
            this.signals            = signals;
            this.network            = network;
            this.nodeSettings       = nodeSettings;
            this.loggerFactory      = loggerFactory;
            this.logger             = loggerFactory.CreateLogger(this.GetType().FullName);
            this.walletFeePolicy    = walletFeePolicy;
            this.broadcasterManager = broadcasterManager;
            this.connectionManager  = fullNode.ConnectionManager as ConnectionManager;
            this.fullNode           = fullNode;

            foreach (var option in configurationOptions)
            {
                if (option.Name.Equals("RegistrationStoreDirectory"))
                {
                    if (option.Value != null)
                    {
                        this.registrationStore = new RegistrationStore(option.Value);
                    }
                    else
                    {
                        this.registrationStore = new RegistrationStore(this.nodeSettings.DataDir);
                    }
                }

                if (option.Name.Equals("MasterNodeUri"))
                {
                    if (option.Value != null)
                    {
                        this.TumblerAddress = option.Value;
                    }
                }
            }

            this.tumblingState = new TumblingState(
                this.loggerFactory,
                this.chain,
                this.walletManager,
                this.watchOnlyWalletManager,
                this.network,
                this.walletTransactionHandler,
                this.walletSyncManager,
                this.walletFeePolicy,
                this.nodeSettings,
                this.broadcasterManager,
                this.connectionManager);

            // Load saved state e.g. previously selected server
            if (File.Exists(this.tumblingState.GetStateFilePath()))
            {
                try
                {
                    this.tumblingState.LoadStateFromMemory();
                }
                catch (NullReferenceException)
                {
                    // The file appears to get corrupted sometimes, not clear why
                    // May be if the node is not shut down correctly
                }
            }

            this.tumblingState.Save();

            // If there was a server address saved, that means we were previously
            // connected to it, and should try to reconnect to it by default when
            // the connect method is invoked by the UI
            if ((this.TumblerAddress == null) && (this.tumblingState.TumblerUri != null))
            {
                this.TumblerAddress = this.tumblingState.TumblerUri.ToString();
            }

            // Remove the progress file from previous session as it is now stale
            ProgressInfo.RemoveProgressFile();
        }
Beispiel #18
0
        public Transaction PerformBreezeRegistration(BreezeConfiguration config, string regStorePath, string configurationHash, string onionAddress, RsaKey tumblerKey)
        {
            Network network = Network.ImpleumMain;

            if (config.TumblerNetwork == Network.TestNet || config.TumblerNetwork == Network.RegTest)
            {
                network = Network.ImpleumTest;
            }

            RPCHelper     stratisHelper   = null;
            RPCClient     stratisRpc      = null;
            BitcoinSecret privateKeyEcdsa = null;

            try {
                stratisHelper   = new RPCHelper(network);
                stratisRpc      = stratisHelper.GetClient(config.RpcUser, config.RpcPassword, config.RpcUrl);
                privateKeyEcdsa = stratisRpc.DumpPrivKey(BitcoinAddress.Create(config.TumblerEcdsaKeyAddress));
            }
            catch (Exception e) {
                Console.WriteLine("ERROR: Unable to retrieve private key to fund registration transaction");
                Console.WriteLine("Is the Stratis wallet unlocked & RPC enabled?");
                Console.WriteLine(e);
                Environment.Exit(0);
            }

            RegistrationToken registrationToken = new RegistrationToken(PROTOCOL_VERSION_TO_USE, config.TumblerEcdsaKeyAddress, config.Ipv4Address, config.Ipv6Address, onionAddress, configurationHash, config.Port, privateKeyEcdsa.PubKey);

            byte[] msgBytes = registrationToken.GetRegistrationTokenBytes(tumblerKey, privateKeyEcdsa);

            // Create the registration transaction using the bytes generated above
            Transaction rawTx = CreateBreezeRegistrationTx(network, msgBytes, config.TxOutputValueSetting);

            TransactionUtils  txUtils  = new TransactionUtils();
            RegistrationStore regStore = new RegistrationStore(regStorePath);

            try {
                // Replace fundrawtransaction with C# implementation. The legacy wallet
                // software does not support the RPC call.
                Transaction fundedTx = txUtils.FundRawTx(stratisRpc, rawTx, config.TxFeeValueSetting, BitcoinAddress.Create(config.TumblerEcdsaKeyAddress));
                RPCResponse signedTx = stratisRpc.SendCommand("signrawtransaction", fundedTx.ToHex());
                Transaction txToSend = new Transaction(((JObject)signedTx.Result)["hex"].Value <string>());

                RegistrationRecord regRecord = new RegistrationRecord(DateTime.Now,
                                                                      Guid.NewGuid(),
                                                                      txToSend.GetHash().ToString(),
                                                                      txToSend.ToHex(),
                                                                      registrationToken,
                                                                      null);

                regStore.Add(regRecord);

                stratisRpc.SendRawTransaction(txToSend);

                return(txToSend);
            }
            catch (Exception e)
            {
                Console.WriteLine("ERROR: Unable to broadcast registration transaction");
                Console.WriteLine(e);
            }

            return(null);
        }
Beispiel #19
0
        public TumbleBitManager(
            ILoggerFactory loggerFactory,
            NodeSettings nodeSettings,
            IWalletManager walletManager,
            IWatchOnlyWalletManager watchOnlyWalletManager,
            ConcurrentChain chain,
            Network network,
            Signals signals,
            IWalletTransactionHandler walletTransactionHandler,
            IWalletSyncManager walletSyncManager,
            IWalletFeePolicy walletFeePolicy,
            IBroadcasterManager broadcasterManager,
            FullNode fullNode,
            ConfigurationOptionWrapper <string> registrationStoreDirectory)
        {
            this.walletManager            = walletManager as WalletManager;
            this.watchOnlyWalletManager   = watchOnlyWalletManager;
            this.walletSyncManager        = walletSyncManager as WalletSyncManager;
            this.walletTransactionHandler = walletTransactionHandler as WalletTransactionHandler;
            this.chain              = chain;
            this.signals            = signals;
            this.network            = network;
            this.nodeSettings       = nodeSettings;
            this.loggerFactory      = loggerFactory;
            this.logger             = loggerFactory.CreateLogger(this.GetType().FullName);
            this.walletFeePolicy    = walletFeePolicy;
            this.broadcasterManager = broadcasterManager;
            this.fullNode           = fullNode;

            if (registrationStoreDirectory.Value != null)
            {
                this.registrationStore = new RegistrationStore(registrationStoreDirectory.Value);
            }
            else
            {
                this.registrationStore = new RegistrationStore(this.nodeSettings.DataDir);
            }

            this.tumblingState = new TumblingState(
                this.loggerFactory,
                this.chain,
                this.walletManager,
                this.watchOnlyWalletManager,
                this.network,
                this.walletTransactionHandler,
                this.walletSyncManager,
                this.walletFeePolicy,
                this.nodeSettings,
                this.broadcasterManager);

            // Load saved state e.g. previously selected server
            if (File.Exists(this.tumblingState.GetStateFilePath()))
            {
                try
                {
                    this.tumblingState.LoadStateFromMemory();
                }
                catch (NullReferenceException)
                {
                    // The file appears to get corrupted sometimes, not clear why
                    // May be if the node is not shut down correctly
                }
            }

            this.tumblingState.Save();

            // Remove the progress file from previous session as it is now stale
            ProgressInfo.RemoveProgressFile();
        }
Beispiel #20
0
        public DependencyGraph(RegistrationStore registrations, Scoped scope, SingularitySettings settings, DependencyGraph?parentDependencyGraph = null)
        {
            var resolvers = new IDependencyResolver[] { new EnumerableDependencyResolver(), new ExpressionDependencyResolver(), new LazyDependencyResolver(), new FactoryDependencyResolver(), new ConcreteDependencyResolver(), new OpenGenericResolver() };

            _resolverPipeline = new ResolverPipeline(registrations, resolvers, scope, settings, parentDependencyGraph?._resolverPipeline);
        }