예제 #1
0
 public AccountManager() 
     {
     unitOfWork = new UnitOfWork();
     addressRepository = new AddressRepository(unitOfWork);
     userRepository = new UserRepository(unitOfWork);
     statesRepository = new StatesRepository(unitOfWork);
     webMembershipRepository = new WebMembershipRepository(unitOfWork);
     userSecQuestionRepository = new UserSecQuestionRepository(unitOfWork);
 }        
예제 #2
0
 public SynchronizationConfirmedVerifier(IStatesRepository statesRepository, IHashCalculationsRepository proofOfWorkCalculationRepository, ICryptoService cryptoService, ILoggerService loggerService)
 {
     _synchronizationContext = statesRepository.GetInstance <ISynchronizationContext>();
 }
예제 #3
0
 public SynchronizationGroupParticipationService(ISynchronizationProducer synchronizationProducer, IStatesRepository statesRepository,
                                                 INodesRatingProviderFactory nodesRatingProvidersFactory, ILoggerService loggerService)
 {
     _synchronizationProducer   = synchronizationProducer;
     _nodesRatingProvider       = nodesRatingProvidersFactory.GetInstance(PacketType.Transactional);
     _synchronizationContext    = statesRepository.GetInstance <ISynchronizationContext>();
     _accountState              = statesRepository.GetInstance <IAccountState>();
     _synchronizationGroupState = statesRepository.GetInstance <ISynchronizationGroupState>();
     _synchronizationGroupParticipationCheckAction = new TransformBlock <string, string>((Func <string, string>)SynchronizationGroupParticipationCheckAction, new ExecutionDataflowBlockOptions {
         MaxDegreeOfParallelism = 1
     });
     _synchronizationGroupLeaderCheckAction = new ActionBlock <string>((Action <string>)SynchronizationGroupLeaderCheckAction, new ExecutionDataflowBlockOptions {
         MaxDegreeOfParallelism = 1
     });
     _logger = loggerService.GetLogger(nameof(SynchronizationGroupParticipationService));
 }
예제 #4
0
        public void GetMostConfidentFullBlockTest()
        {
            List <RegistryFullBlock>  registryFullBlocks    = new List <RegistryFullBlock>();
            List <RegistryShortBlock> registryShortBlocks   = new List <RegistryShortBlock>();
            Dictionary <IKey, int>    votesPerShortBlockKey = new Dictionary <IKey, int>();

            int   fullBlockCount  = 10;
            int   votersCount     = 100;
            ulong syncBlockHeight = 1;
            ulong blockHeight     = 12;
            uint  nonce           = 0;

            byte[]           powHash = BinaryHelper.GetPowHash(1234);
            IHashCalculation hashCalculationTransactionKey = new MurMurHashCalculation();

            IHashCalculation              hashCalculationDefault            = new Keccak256HashCalculation();
            IHashCalculation              hashCalculationMurMur             = new MurMurHashCalculation();
            ISerializersFactory           serializersFactory                = Substitute.For <ISerializersFactory>();
            IHashCalculationsRepository   hashCalculationsRepository        = Substitute.For <IHashCalculationsRepository>();
            IIdentityKeyProvider          identityKeyProviderTransactionKey = Substitute.For <IIdentityKeyProvider>();
            IIdentityKeyProvidersRegistry identityKeyProvidersRegistry      = Substitute.For <IIdentityKeyProvidersRegistry>();
            ISigningService         signingService         = GetRandomCryptoService();
            ILoggerService          loggerService          = Substitute.For <ILoggerService>();
            IStatesRepository       statesRepository       = Substitute.For <IStatesRepository>();
            ISynchronizationContext synchronizationContext = new Wist.Core.Synchronization.SynchronizationContext(loggerService);

            statesRepository.GetInstance <ISynchronizationContext>().ReturnsForAnyArgs(synchronizationContext);

            identityKeyProviderTransactionKey.GetKey(null).ReturnsForAnyArgs(c => new Key16(c.ArgAt <Memory <byte> >(0)));

            identityKeyProvidersRegistry.GetInstance("DefaultHash").Returns(new DefaultHashKeyProvider());
            identityKeyProvidersRegistry.GetTransactionsIdenityKeyProvider().Returns(identityKeyProviderTransactionKey);

            hashCalculationsRepository.Create(HashType.Keccak256).Returns(hashCalculationDefault);
            hashCalculationsRepository.Create(HashType.MurMur).Returns(hashCalculationMurMur);

            serializersFactory.Create(null).ReturnsForAnyArgs(c =>
            {
                RegistryShortBlockSerializer registryShortBlockSerializer = new RegistryShortBlockSerializer();
                registryShortBlockSerializer.Initialize(c.Arg <SignedPacketBase>());
                return(registryShortBlockSerializer);
            });

            SyncRegistryMemPool syncRegistryMemPool = new SyncRegistryMemPool(loggerService, hashCalculationsRepository);

            for (int i = 0; i < fullBlockCount; i++)
            {
                ISigningService signingService1 = GetRandomCryptoService();
                ushort          expectedCount   = 1000;

                SortedList <ushort, RegistryRegisterBlock> transactionHeaders = GetTransactionHeaders(syncBlockHeight, blockHeight, nonce, expectedCount);
                WitnessStateKey[] transactionHeaderKeys = GetTransactionHeaderKeys(transactionHeaders);

                RegistryShortBlock registryShortBlock = new RegistryShortBlock
                {
                    SyncBlockHeight  = syncBlockHeight,
                    BlockHeight      = blockHeight,
                    Nonce            = nonce,
                    PowHash          = powHash,
                    WitnessStateKeys = transactionHeaderKeys
                };

                RegistryShortBlockSerializer registryShortBlockSerializer = new RegistryShortBlockSerializer();
                registryShortBlockSerializer.Initialize(registryShortBlock);
                registryShortBlockSerializer.SerializeBody();
                signingService1.Sign(registryShortBlock);
                registryShortBlockSerializer.SerializeFully();

                RegistryFullBlock registryFullBlock = new RegistryFullBlock
                {
                    SyncBlockHeight = syncBlockHeight,
                    BlockHeight     = blockHeight,
                    Nonce           = nonce,
                    PowHash         = powHash,
                    StateWitnesses  = transactionHeaders.Values.ToArray(),
                    ShortBlockHash  = hashCalculationDefault.CalculateHash(registryShortBlock.RawData)
                };

                RegistryFullBlockSerializer serializer = new RegistryFullBlockSerializer();
                serializer.Initialize(registryFullBlock);
                serializer.SerializeBody();
                signingService.Sign(registryFullBlock);
                serializer.SerializeFully();

                registryFullBlocks.Add(registryFullBlock);
                registryShortBlocks.Add(registryShortBlock);
            }

            foreach (RegistryFullBlock fullBlock in registryFullBlocks)
            {
                syncRegistryMemPool.AddCandidateBlock(fullBlock);
            }

            IKey expectedMostConfidentKey = votesPerShortBlockKey.OrderByDescending(kv => kv.Value).Select(kv => kv.Key).First();

            IEnumerable <RegistryFullBlock> actualFullBlocks = syncRegistryMemPool.GetRegistryBlocks();
        }
예제 #5
0
 public SyncConfirmedLoadModule(ILoggerService loggerService, IClientCommunicationServiceRepository clientCommunicationServiceRepository, IConfigurationService configurationService, IIdentityKeyProvidersRegistry identityKeyProvidersRegistry, ISerializersFactory signatureSupportSerializersFactory, INodesDataService nodesDataService, ISigningService cryptoService, IPerformanceCountersRepository performanceCountersRepository, IStatesRepository statesRepository, IHashCalculationsRepository hashCalculationRepository)
     : base(loggerService, clientCommunicationServiceRepository, configurationService, identityKeyProvidersRegistry, signatureSupportSerializersFactory, nodesDataService, cryptoService, performanceCountersRepository, hashCalculationRepository)
 {
     _synchronizationContext = statesRepository.GetInstance <ISynchronizationContext>();
 }
 public StatesController(IStatesRepository statesRepository)
 {
     this.statesRepository = statesRepository;
 }
예제 #7
0
 public StatesApiController(IStatesRepository statesRepo, ILoggerFactory loggerFactory)
 {
     _StatesRepository = statesRepo;
     _Logger           = loggerFactory.CreateLogger(nameof(StatesApiController));
 }
예제 #8
0
 public InteractionModule(ILoggerService loggerService, IConfigurationService configurationService, IStatesRepository statesRepository,
                          IChainDataServicesManager chainDataServicesManager, IIdentityKeyProvidersRegistry identityKeyProvidersRegistry,
                          IHashCalculationsRepository hashCalculationsRepository)
     : base(loggerService)
 {
     _synchronizationContext       = statesRepository.GetInstance <ISynchronizationContext>();
     _configurationService         = configurationService;
     _chainDataServicesManager     = chainDataServicesManager;
     _identityKeyProvidersRegistry = identityKeyProvidersRegistry;
     _hashCalculationsRepository   = hashCalculationsRepository;
 }
예제 #9
0
 public WalletManager(INetworkAdapter networkAdapter, IBlockCreator blockCreator, IDataAccessService dataAccessService, IHashCalculationsRepository hashCalculationsRepository,
                      IIdentityKeyProvidersRegistry identityKeyProvidersRegistry, IStatesRepository statesRepository, ISerializersFactory signatureSupportSerializersFactory,
                      IBlockParsersRepositoriesRepository blockParsersRepositoriesRepository)
 {
     _networkAdapter    = networkAdapter;
     _blockCreator      = blockCreator;
     _dataAccessService = dataAccessService;
     _signatureSupportSerializersFactory = signatureSupportSerializersFactory;
     _blockParsersRepositoriesRepository = blockParsersRepositoriesRepository;
     _heightsDictionary      = new Dictionary <byte[], ulong>();
     _hashCalculation        = hashCalculationsRepository.Create(Globals.DEFAULT_HASH);
     _proofOfWorkCalculation = hashCalculationsRepository.Create(Globals.POW_TYPE);
     _identityKeyProvider    = identityKeyProvidersRegistry.GetInstance();
     _clientState            = statesRepository.GetInstance <IClientState>();
 }
예제 #10
0
 public CartController(IProductsRepository repo, IOrderProcessor proc, IStatesRepository state)
 {
     repository     = repo;
     orderProcessor = proc;
     stateRepo      = state;
 }
예제 #11
0
 public States(IUnitOfWork unitOfWork, IStatesRepository _statesRepository)
 {
     this.unitOfWork        = unitOfWork;
     this._statesRepository = _statesRepository;
 }
예제 #12
0
 public StateFilteringProvider(ITasksSourceJiraCacheAdapter jiraCacheAdapter, IStatesRepository statesRepository)
 {
     _stateFiltering = new StateFiltering(jiraCacheAdapter, statesRepository);
 }
예제 #13
0
 public StatesController(IStatesRepository statesRepository, ILoggerFactory loggerFactory)
 {
     _statesRepository = statesRepository;
     _logger           = loggerFactory.CreateLogger(nameof(StatesController));
 }
예제 #14
0
        public void GetMostConfidentFullBlockTest()
        {
            List <RegistryFullBlock>  registryFullBlocks    = new List <RegistryFullBlock>();
            List <RegistryShortBlock> registryShortBlocks   = new List <RegistryShortBlock>();
            Dictionary <IKey, int>    votesPerShortBlockKey = new Dictionary <IKey, int>();

            int   fullBlockCount  = 10;
            int   votersCount     = 100;
            ulong syncBlockHeight = 1;
            ulong blockHeight     = 12;
            uint  nonce           = 0;

            byte[]           powHash = BinaryBuilder.GetPowHash(1234);
            IHashCalculation hashCalculationTransactionKey = new MurMurHashCalculation();

            IHashCalculation              hashCalculationDefault             = new Keccak256HashCalculation();
            IHashCalculation              hashCalculationMurMur              = new MurMurHashCalculation();
            ISerializersFactory           signatureSupportSerializersFactory = Substitute.For <ISerializersFactory>();
            IHashCalculationsRepository   hashCalculationsRepository         = Substitute.For <IHashCalculationsRepository>();
            IIdentityKeyProvider          identityKeyProviderTransactionKey  = Substitute.For <IIdentityKeyProvider>();
            IIdentityKeyProvidersRegistry identityKeyProvidersRegistry       = Substitute.For <IIdentityKeyProvidersRegistry>();
            ICryptoService          cryptoService          = GetRandomCryptoService();
            ILoggerService          loggerService          = Substitute.For <ILoggerService>();
            IStatesRepository       statesRepository       = Substitute.For <IStatesRepository>();
            ISynchronizationContext synchronizationContext = new Wist.Core.Synchronization.SynchronizationContext(loggerService);

            statesRepository.GetInstance <ISynchronizationContext>().ReturnsForAnyArgs(synchronizationContext);

            identityKeyProviderTransactionKey.GetKey(null).ReturnsForAnyArgs(c => new Key16(c.ArgAt <Memory <byte> >(0)));

            identityKeyProvidersRegistry.GetInstance("DefaultHash").Returns(new DefaultHashKeyProvider());
            identityKeyProvidersRegistry.GetTransactionsIdenityKeyProvider().Returns(identityKeyProviderTransactionKey);

            hashCalculationsRepository.Create(HashType.Keccak256).Returns(hashCalculationDefault);
            hashCalculationsRepository.Create(HashType.MurMur).Returns(hashCalculationMurMur);

            signatureSupportSerializersFactory.Create(null).ReturnsForAnyArgs(c =>
            {
                RegistryShortBlockSerializer registryShortBlockSerializer = new RegistryShortBlockSerializer(cryptoService, identityKeyProvidersRegistry, hashCalculationsRepository);
                registryShortBlockSerializer.Initialize(c.Arg <SignedBlockBase>());
                return(registryShortBlockSerializer);
            });

            SyncRegistryMemPool syncRegistryMemPool = new SyncRegistryMemPool(signatureSupportSerializersFactory, hashCalculationsRepository, identityKeyProvidersRegistry, cryptoService, statesRepository, loggerService);

            for (int i = 0; i < fullBlockCount; i++)
            {
                ICryptoService cryptoService1 = GetRandomCryptoService();
                ushort         expectedCount  = 1000;

                SortedList <ushort, ITransactionRegistryBlock> transactionHeaders = GetTransactionHeaders(syncBlockHeight, blockHeight, nonce, expectedCount);
                SortedList <ushort, IKey> transactionHeaderKeys = GetTransactionHeaderKeys(hashCalculationTransactionKey, transactionHeaders);

                RegistryShortBlock registryShortBlock = new RegistryShortBlock
                {
                    SyncBlockHeight         = syncBlockHeight,
                    BlockHeight             = blockHeight,
                    Nonce                   = nonce,
                    PowHash                 = powHash,
                    TransactionHeaderHashes = transactionHeaderKeys
                };

                RegistryShortBlockSerializer registryShortBlockSerializer = new RegistryShortBlockSerializer(cryptoService1, identityKeyProvidersRegistry, hashCalculationsRepository);
                registryShortBlockSerializer.Initialize(registryShortBlock);
                registryShortBlockSerializer.FillBodyAndRowBytes();

                RegistryFullBlock registryFullBlock = new RegistryFullBlock
                {
                    SyncBlockHeight    = syncBlockHeight,
                    BlockHeight        = blockHeight,
                    Nonce              = nonce,
                    PowHash            = powHash,
                    TransactionHeaders = transactionHeaders,
                    ShortBlockHash     = hashCalculationDefault.CalculateHash(registryShortBlock.RawData)
                };

                RegistryFullBlockSerializer serializer = new RegistryFullBlockSerializer(cryptoService1, identityKeyProvidersRegistry, hashCalculationsRepository);
                serializer.Initialize(registryFullBlock);
                serializer.FillBodyAndRowBytes();

                registryFullBlocks.Add(registryFullBlock);
                registryShortBlocks.Add(registryShortBlock);
            }

            foreach (RegistryFullBlock fullBlock in registryFullBlocks)
            {
                syncRegistryMemPool.AddCandidateBlock(fullBlock);
            }

            Random random = new Random();

            for (int i = 0; i < votersCount; i++)
            {
                ICryptoService cryptoService2 = GetRandomCryptoService();

                foreach (var registryShortBlock in registryShortBlocks)
                {
                    byte[] hashBytes     = hashCalculationDefault.CalculateHash(registryShortBlock.RawData);
                    Random randNum       = new Random();
                    byte[] bitMask       = Enumerable.Repeat(0, registryShortBlock.TransactionHeaderHashes.Count).Select(j => (byte)randNum.Next(0, 255)).ToArray();
                    byte[] expectedProof = Enumerable.Repeat(0, 16).Select(j => (byte)randNum.Next(0, 255)).ToArray();
                    IKey   shortBlockKey = new Key32(hashBytes);
                    long   vote          = GetConfidence(bitMask);
                    if (!votesPerShortBlockKey.ContainsKey(shortBlockKey))
                    {
                        votesPerShortBlockKey.Add(shortBlockKey, (ushort)vote);
                    }
                    else
                    {
                        votesPerShortBlockKey[shortBlockKey] += (ushort)vote;
                    }

                    RegistryConfidenceBlock registryConfidenceBlock = new RegistryConfidenceBlock
                    {
                        SyncBlockHeight     = syncBlockHeight,
                        BlockHeight         = blockHeight,
                        Nonce               = nonce,
                        PowHash             = powHash,
                        ReferencedBlockHash = hashBytes,
                        BitMask             = bitMask,
                        ConfidenceProof     = expectedProof
                    };

                    RegistryConfidenceBlockSerializer registryConfidenceBlockSerializer = new RegistryConfidenceBlockSerializer(cryptoService2, identityKeyProvidersRegistry, hashCalculationsRepository);
                    registryConfidenceBlockSerializer.Initialize(registryConfidenceBlock);
                    registryConfidenceBlockSerializer.FillBodyAndRowBytes();

                    syncRegistryMemPool.AddVotingBlock(registryConfidenceBlock);
                }
            }

            IKey expectedMostConfidentKey = votesPerShortBlockKey.OrderByDescending(kv => kv.Value).Select(kv => kv.Key).First();

            RegistryFullBlock actualFullBlock = syncRegistryMemPool.GetMostConfidentFullBlock(blockHeight);
            IKey actualMostConfidentKey       = new Key32(actualFullBlock.ShortBlockHash);

            Assert.Equal(expectedMostConfidentKey, actualMostConfidentKey);
        }
예제 #15
0
 public UtxoConfidentialStorageHandler(IStatesRepository statesRepository, IServerCommunicationServicesRegistry communicationServicesRegistry, IRawPacketProvidersFactory rawPacketProvidersFactory, IRegistryMemPool registryMemPool, IConfigurationService configurationService, IHashCalculationsRepository hashCalculationRepository, IChainDataServicesManager chainDataServicesManager) : base(statesRepository, communicationServicesRegistry, rawPacketProvidersFactory, registryMemPool, configurationService, hashCalculationRepository, chainDataServicesManager)
 {
 }
예제 #16
0
 public ResultsViewModel(IDataAccessService dataAccessService, IWalletManager walletManager,
                         IBlockParsersRepositoriesRepository blockParsersRepositoriesRepository, IStatesRepository statesRepository)
 {
     _dataAccessService = dataAccessService;
     _walletManager     = walletManager;
     _blockParsersRepositoriesRepository = blockParsersRepositoriesRepository;
     _clientState = statesRepository.GetInstance <IClientState>();
     Utxos        = new ObservableCollection <UtxoIncomingBlockDesc>();
 }
예제 #17
0
 public SyncRegistryMemPool(ISerializersFactory signatureSupportSerializersFactory, IHashCalculationsRepository hashCalculationsRepository,
                            IIdentityKeyProvidersRegistry identityKeyProvidersRegistry, ICryptoService cryptoService, IStatesRepository statesRepository, ILoggerService loggerService)
 {
     _synchronizationContext             = statesRepository.GetInstance <ISynchronizationContext>();
     _roundDescriptors                   = new Dictionary <ulong, RoundDescriptor>();
     _signatureSupportSerializersFactory = signatureSupportSerializersFactory;
     _cryptoService = cryptoService;
     _defaultTransactionHashCalculation = hashCalculationsRepository.Create(Globals.DEFAULT_HASH);
     _transactionHashKey = identityKeyProvidersRegistry.GetInstance("DefaultHash");
     _logger             = loggerService.GetLogger(nameof(SyncRegistryMemPool));
 }
예제 #18
0
 public LoginViewModel(IStatesRepository statesRepository, ICryptoService cryptoService)
 {
     _clientState   = statesRepository.GetInstance <IClientState>();
     _cryptoService = cryptoService;
 }
예제 #19
0
 public StorageHandlerBase(IStatesRepository statesRepository, IServerCommunicationServicesRegistry communicationServicesRegistry, IRawPacketProvidersFactory rawPacketProvidersFactory, IRegistryMemPool registryMemPool, IConfigurationService configurationService, IHashCalculationsRepository hashCalculationRepository, IChainDataServicesManager chainDataServicesManager)
 {
     _nodeContext = statesRepository.GetInstance <INodeContext>();
     _communicationServicesRegistry = communicationServicesRegistry;
     _chainDataServicesManager      = chainDataServicesManager;
 }
예제 #20
0
        //private read-only IBlocksProcessor _blocksProcessor

        public NodeMain(IServerCommunicationServicesRepository communicationServicesFactory, IServerCommunicationServicesRegistry communicationServicesRegistry, IConfigurationService configurationService, IModulesRepository modulesRepository, IPacketsHandler packetsHandler, IBlocksHandlersRegistry blocksProcessorFactory, ILoggerService loggerService, ICryptoService cryptoService, IStatesRepository statesRepository)
        {
            _log = loggerService.GetLogger(GetType().Name);
            _communicationServicesFactory  = communicationServicesFactory;
            _communicationServicesRegistry = communicationServicesRegistry;
            _configurationService          = configurationService;
            _modulesRepository             = modulesRepository;
            _packetsHandler          = packetsHandler;
            _cryptoService           = cryptoService;
            _nodeContext             = statesRepository.GetInstance <INodeContext>();
            _accountState            = statesRepository.GetInstance <IAccountState>();
            _cancellationTokenSource = new CancellationTokenSource();
        }
예제 #21
0
 public CommonTopologyInitializer(IStatesRepository statesRepository, INodesDataService nodesDataService, ILoggerService loggerService)
 {
     _neighborhoodState = statesRepository.GetInstance <INeighborhoodState>();
     _nodesDataService  = nodesDataService;
     _logger            = loggerService.GetLogger(nameof(CommonTopologyInitializer));
 }
예제 #22
0
        public void MemPool_AddedNonUniqueTransactions_NotAllContained()
        {
            SynchronizationDescriptor synchronizationDescriptor = new SynchronizationDescriptor(1, new byte[Globals.DEFAULT_HASH_SIZE], DateTime.Now, DateTime.Now, 1);
            IHash                         transactionKeyHash    = HashFactory.Hash128.CreateMurmur3_128();
            ILogger                       logger                       = Substitute.For <ILogger>();
            ILoggerService                loggerService                = Substitute.For <ILoggerService>();
            IIdentityKeyProvider          identityKeyProvider          = new TransactionRegistryKeyProvider();
            IIdentityKeyProvidersRegistry identityKeyProvidersRegistry = Substitute.For <IIdentityKeyProvidersRegistry>();
            IHashCalculationsRepository   hashCalculationsRepository   = Substitute.For <IHashCalculationsRepository>();
            ICryptoService                cryptoService                = Substitute.For <ICryptoService>();
            SynchronizationContext        synchronizationContext       = new SynchronizationContext(loggerService);

            synchronizationContext.UpdateLastSyncBlockDescriptor(synchronizationDescriptor);
            IStatesRepository statesRepository = Substitute.For <IStatesRepository>();

            hashCalculationsRepository.Create(HashType.MurMur).Returns(new MurMurHashCalculation());

            logger.WhenForAnyArgs(l => l.Error(null)).DoNotCallBase();
            logger.WhenForAnyArgs(l => l.Warning(null)).DoNotCallBase();
            logger.WhenForAnyArgs(l => l.Info(null)).DoNotCallBase();
            loggerService.GetLogger(null).Returns(logger);

            identityKeyProvidersRegistry.GetTransactionsIdenityKeyProvider().ReturnsForAnyArgs(identityKeyProvider);
            //identityKeyProvider.GetKey(null).ReturnsForAnyArgs(c => new Key16() { Value = c.Arg<Memory<byte>>() });

            statesRepository.GetInstance <ISynchronizationContext>().Returns(synchronizationContext);

            byte[] privateKey = CryptoHelper.GetRandomSeed();
            Ed25519.KeyPairFromSeed(out byte[] publicKey, out byte[] expandedPrivateKey, privateKey);

            cryptoService.ComputeTransactionKey(new Memory <byte>()).ReturnsForAnyArgs(c => transactionKeyHash.ComputeBytes(c.Arg <Memory <byte> >().ToArray()).GetBytes());
            cryptoService.ComputeTransactionKey(new byte[0]).ReturnsForAnyArgs(c => transactionKeyHash.ComputeBytes(c.Arg <byte[]>()).GetBytes());
            cryptoService.Sign(null).ReturnsForAnyArgs(c => Ed25519.Sign(c.Arg <byte[]>(), expandedPrivateKey));
            cryptoService.PublicKey.ReturnsForAnyArgs(new Key32(publicKey));

            TransactionRegistryMemPool transactionRegistryMemPool = new TransactionRegistryMemPool(loggerService, identityKeyProvidersRegistry, cryptoService, statesRepository, new TransactionsRegistryHelper(cryptoService, identityKeyProvidersRegistry), hashCalculationsRepository);

            SortedList <ushort, RegistryRegisterBlock> expectedBlocks = new SortedList <ushort, RegistryRegisterBlock>();

            ulong[] heights = new ulong[] { 1, 2, 2, 5, 4, 3, 4, 3, 4, 5, 3 };

            HashSet <ulong> addedHeights = new HashSet <ulong>();
            ushort          order        = 0;

            for (ulong i = 0; i < (ulong)heights.Length; i++)
            {
                RegistryRegisterBlock transactionRegisterBlock = PacketsBuilder.GetTransactionRegisterBlock(synchronizationContext.LastBlockDescriptor.BlockHeight, 1, null,
                                                                                                            heights[i], PacketType.Transactional, BlockTypes.Transaction_TransferFunds, new byte[Globals.POW_HASH_SIZE], new byte[Globals.DEFAULT_HASH_SIZE], privateKey);

                RegistryRegisterBlockSerializer serializer = new RegistryRegisterBlockSerializer(cryptoService, identityKeyProvidersRegistry, hashCalculationsRepository);
                serializer.Initialize(transactionRegisterBlock);
                serializer.FillBodyAndRowBytes();

                if (!addedHeights.Contains(heights[i]))
                {
                    expectedBlocks.Add(order++, transactionRegisterBlock);
                    addedHeights.Add(heights[i]);
                }

                transactionRegistryMemPool.EnqueueTransactionRegisterBlock(transactionRegisterBlock);
            }

            SortedList <ushort, ITransactionRegistryBlock> actualBlocks = transactionRegistryMemPool.DequeueBulk(-1);

            Assert.Equal(expectedBlocks.Count, actualBlocks.Count);
            for (ushort i = 0; i < (ushort)expectedBlocks.Count; i++)
            {
                Assert.Equal(expectedBlocks[i].BlockHeight, ((RegistryRegisterBlock)actualBlocks[i]).BlockHeight);
            }
        }
예제 #23
0
 public RegistryTopologyInitializer(IStatesRepository statesRepository, INodesDataService nodesDataService, ILoggerService loggerService)
 {
     _registryGroupState = statesRepository.GetInstance <IRegistryGroupState>();
     _nodesDataService   = nodesDataService;
     _logger             = loggerService.GetLogger(nameof(RegistryTopologyInitializer));
 }
예제 #24
0
 public StatesController(IStatesRepository repo)
 {
     _repo = repo;
 }
예제 #25
0
 public SyncHeightVerifier(IStatesRepository statesRepository, IHashCalculationsRepository hashCalculationsRepository, ILoggerService loggerService)
 {
     _log = loggerService.GetLogger(GetType().Name);
     _synchronizationContext = statesRepository.GetInstance <ISynchronizationContext>();
     _proofOfWorkCalculation = hashCalculationsRepository.Create(Globals.POW_TYPE);
 }
예제 #26
0
 public TransactionRegistrationLoadModule(ILoggerService loggerService, IClientCommunicationServiceRepository clientCommunicationServiceRepository, IConfigurationService configurationService, IIdentityKeyProvidersRegistry identityKeyProvidersRegistry, ISerializersFactory signatureSupportSerializersFactory, INodesDataService nodesDataService, ICryptoService cryptoService, IPerformanceCountersRepository performanceCountersRepository, IStatesRepository statesRepository, IHashCalculationsRepository proofOfWorkCalculationRepository, IHashCalculationsRepository hashCalculationRepository)
     : base(loggerService, clientCommunicationServiceRepository, configurationService, identityKeyProvidersRegistry, signatureSupportSerializersFactory, nodesDataService, cryptoService, performanceCountersRepository, hashCalculationRepository)
 {
     _synchronizationContext = statesRepository.GetInstance <ISynchronizationContext>();
     _proofOfWorkCalculation = proofOfWorkCalculationRepository.Create(Globals.POW_TYPE);
 }
예제 #27
0
 public SynchronizationProducer(ISerializersFactory signatureSupportSerializersFactory, IStatesRepository statesRepository,
                                IServerCommunicationServicesRegistry communicationServicesRegistry, IConfigurationService configurationService,
                                IHashCalculationsRepository hashCalculationsRepository)
 {
     _signatureSupportSerializersFactory = signatureSupportSerializersFactory;
     _nodeContext                   = statesRepository.GetInstance <INodeContext>();
     _synchronizationContext        = statesRepository.GetInstance <ISynchronizationContext>();
     _synchronizationGroupState     = statesRepository.GetInstance <ISynchronizationGroupState>();
     _communicationServicesRegistry = communicationServicesRegistry;
     _configurationService          = configurationService;
     _proofOfWorkCalculation        = hashCalculationsRepository.Create(Globals.POW_TYPE);
 }
예제 #28
0
 public ShardsManager(IStatesRepository statesRepository, INodesDataService nodesDataService)
 {
     _synchronizationContext         = statesRepository.GetInstance <ISynchronizationContext>();
     _syncContextChangedUnsibscriber = _synchronizationContext.SubscribeOnStateChange(new ActionBlock <string>((Action <string>)OnSyncContextChanged));
     _nodesDataService = nodesDataService;
 }