示例#1
0
        public void AddServiceNode(IServiceNode serviceNode)
        {
            lock (this.locker)
            {
                if (this.ServiceNodes.Contains(serviceNode))
                {
                    this.Logger.LogTrace("(-)[ALREADY_EXISTS]");
                    return;
                }

                // Remove any that have a matching collateral address
                BitcoinAddress serviceNodeCollateralAddress = serviceNode.GetCollateralAddress(this.network);
                var            nodesWithMatchingPubKeys     = this.ServiceNodes.Where(sn => sn.GetCollateralAddress(this.network) == serviceNodeCollateralAddress).ToList();
                foreach (IServiceNode matchingNode in nodesWithMatchingPubKeys)
                {
                    this.ServiceNodes.Remove(matchingNode);
                }

                // Add new one
                this.ServiceNodes.Add(serviceNode);

                SaveServiceNodes();
                SetIsServiceNode();

                this.Logger.LogInformation("Federation member '{0}' was added!", serviceNode);

                // Publish events
                foreach (IServiceNode node in nodesWithMatchingPubKeys)
                {
                    this.signals.Publish(new ServiceNodeRemoved(serviceNode));
                }

                this.signals.Publish(new ServiceNodeAdded(serviceNode));
            }
        }