Example #1
0
        public async Task Test(ulong start, ulong end, ulong batchSize, ulong batchHitTimes, ulong adjustedBatchSizeResult)
        {
            var batch = BlockBatcher.Start(start, end, batchSize, ExecuteBatch);

            await batch.Execute();

            Assert.Equal(batchHitTimes, _counter);
            Assert.Equal(adjustedBatchSizeResult, batch.BatchSize);
            Assert.Equal(end, batch.CurrentEnd);
        }
        public override async Task <bool> Execute(Source source, BlockchainType blockchain, BlockchainNetwork network)
        {
            ClientBase.ConnectionTimeout = new TimeSpan(0, 0, 5, 0);

            await using (var connection =
                             new MySqlConnection(OTHubSettings.Instance.MariaDB.ConnectionString))
            {
                int blockchainID = await GetBlockchainID(connection, blockchain, network);

                var cl = await GetWeb3(connection, blockchainID, blockchain);

                var eth = new EthApiService(cl.Client);

                foreach (var contract in await OTContract.GetByTypeAndBlockchain(connection,
                                                                                 (int)ContractTypeEnum.Litigation, blockchainID))
                {
                    if (contract.IsArchived && contract.LastSyncedTimestamp.HasValue &&
                        (DateTime.Now - contract.LastSyncedTimestamp.Value).TotalDays <= 5)
                    {
#if DEBUG
                        Logger.WriteLine(source, "     Skipping contract: " + contract.Address);
#endif
                        continue;
                    }

                    Logger.WriteLine(source, "     Using contract: " + contract.Address);

                    var holdingContract = new Contract(eth,
                                                       AbiHelper.GetContractAbi(ContractTypeEnum.Litigation, blockchain, network), contract.Address);

                    var litigationInitiatedEvent = holdingContract.GetEvent("LitigationInitiated");
                    var litigationAnsweredEvent  = holdingContract.GetEvent("LitigationAnswered");
                    var litigationTimedOutEvent  = holdingContract.GetEvent("LitigationTimedOut");
                    var litigationCompletedEvent = holdingContract.GetEvent("LitigationCompleted");
                    var replacementStartedEvent  = holdingContract.GetEvent("ReplacementStarted");

                    ulong size = (ulong)10000;

                    BlockBatcher batcher = BlockBatcher.Start(contract.SyncBlockNumber, (ulong)LatestBlockNumber.Value, size,
                                                              async delegate(ulong start, ulong end)
                    {
                        await Sync(connection, litigationInitiatedEvent, litigationAnsweredEvent,
                                   litigationTimedOutEvent,
                                   litigationCompletedEvent,
                                   replacementStartedEvent,
                                   contract, source, start,
                                   end, blockchainID, cl);
                    });

                    await batcher.Execute();
                }
            }

            return(true);
        }
Example #3
0
        public override async Task <bool> Execute(Source source, BlockchainType blockchain, BlockchainNetwork network)
        {
            ClientBase.ConnectionTimeout = new TimeSpan(0, 0, 5, 0);


            await using (var connection =
                             new MySqlConnection(OTHubSettings.Instance.MariaDB.ConnectionString))
            {
                int blockchainID = await GetBlockchainID(connection, blockchain, network);

                var cl = await GetWeb3(connection, blockchainID, blockchain);

                var eth = new EthApiService(cl.Client);

                foreach (var contract in await OTContract.GetByTypeAndBlockchain(connection, (int)ContractTypeEnum.Profile, blockchainID))
                {
                    if (contract.IsArchived && contract.LastSyncedTimestamp.HasValue &&
                        (DateTime.Now - contract.LastSyncedTimestamp.Value).TotalDays <= 5)
                    {
#if DEBUG
                        Logger.WriteLine(source, "     Skipping contract: " + contract.Address);
#endif
                        continue;
                    }

                    Logger.WriteLine(source, "     Using contract: " + contract.Address);

                    string abi = AbiHelper.GetContractAbi(ContractTypeEnum.Profile, blockchain, network);


                    var profileContract = new Contract(eth, abi, contract.Address);

                    var      profileCreatedEvent      = profileContract.GetEvent("ProfileCreated");
                    var      identityCreatedEvent     = profileContract.GetEvent("IdentityCreated");
                    var      identityTransferredEvent = profileContract.GetEvent("IdentityTransferred");
                    var      tokensDepositedEvent     = profileContract.GetEvent("TokensDeposited");
                    var      tokensReleasedEvent      = profileContract.GetEvent("TokensReleased");
                    var      tokensWithdrawnEvent     = profileContract.GetEvent("TokensWithdrawn");
                    var      tokensTransferredEvent   = profileContract.GetEvent("TokensTransferred");
                    var      tokensReservedEvent      = profileContract.GetEvent("TokensReserved");
                    Function createProfileFunction    = profileContract.GetFunction("createProfile");
                    Function transferProfileFunction  = profileContract.GetFunction("transferProfile");

                    ulong size = (ulong)10000;

                    BlockBatcher batcher = BlockBatcher.Start(contract.SyncBlockNumber, (ulong)LatestBlockNumber.Value, size,
                                                              async delegate(ulong start, ulong end)
                    {
                        await Sync(connection, profileCreatedEvent, identityCreatedEvent,
                                   identityTransferredEvent,
                                   tokensDepositedEvent,
                                   tokensReleasedEvent, tokensWithdrawnEvent, tokensTransferredEvent,
                                   tokensReservedEvent,
                                   contract, source, createProfileFunction, transferProfileFunction, start,
                                   end, blockchainID, cl);
                    });

                    await batcher.Execute();
                }

                await CreateMissingIdentities(connection, cl, blockchainID, blockchain, network);
            }

            return(true);
        }