Skip to content

Commit

Permalink
Merge pull request #8 from HannaAndreevna/replace-common-sql-package
Browse files Browse the repository at this point in the history
Replace Lykke.Common.MsSql package to MAVN.Common.MsSql
starkmsu authored May 14, 2020
2 parents 6f445a7 + d818cc9 commit a3e7101
Showing 14 changed files with 74 additions and 78 deletions.
23 changes: 9 additions & 14 deletions src/MAVN.Job.QuorumExplorer/Modules/JobModule.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Autofac;
using Autofac;
using Lykke.Common.Log;
using Lykke.Common.MsSql;
using MAVN.Common.MsSql;
using Lykke.Job.QuorumExplorer.Services;
using Lykke.Sdk;
using Lykke.Job.QuorumExplorer.Settings;
@@ -15,7 +15,7 @@ public class JobModule : Module
public JobModule(
IReloadingManager<AppSettings> appSettings)
{

}

protected override void Load(ContainerBuilder builder)
@@ -29,17 +29,17 @@ protected override void Load(ContainerBuilder builder)
.RegisterType<DecodingService>()
.As<IDecodingService>()
.SingleInstance();

builder
.RegisterType<TransactionInputDecodingService>()
.As<ITransactionInputDecodingService>()
.SingleInstance();

builder
.RegisterType<TransactionLogDecodingService>()
.As<ITransactionLogDecodingService>()
.SingleInstance();

builder
.Register(ctx => new BlockchainIndexingManager
(
@@ -48,7 +48,7 @@ protected override void Load(ContainerBuilder builder)
))
.AsSelf()
.SingleInstance();

builder
.Register(ctx => new TransactionInputDecodingManager
(
@@ -58,7 +58,7 @@ protected override void Load(ContainerBuilder builder)
))
.AsSelf()
.SingleInstance();

builder
.Register(ctx => new TransactionLogDecodingManager
(
@@ -68,7 +68,7 @@ protected override void Load(ContainerBuilder builder)
))
.AsSelf()
.SingleInstance();

builder
.Register(ctx => new StartupManager
(
@@ -90,11 +90,6 @@ protected override void Load(ContainerBuilder builder)
))
.As<IShutdownManager>()
.SingleInstance();

builder
.RegisterType<TransactionScopeHandler>()
.AsSelf()
.InstancePerLifetimeScope();
}
}
}
4 changes: 2 additions & 2 deletions src/MAVN.Job.QuorumExplorer/Modules/RepositoriesModule.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Autofac;
using Autofac;
using JetBrains.Annotations;
using Lykke.Common.MsSql;
using MAVN.Common.MsSql;
using Lykke.Job.QuorumExplorer.Settings;
using MAVN.Service.QuorumExplorer.Domain.Repositories;
using MAVN.Service.QuorumExplorer.MsSqlRepositories;
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>1.0.0</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Lykke.Common" Version="7.4.0" />
<PackageReference Include="MAVN.Common.MsSql" Version="3.0.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading.Tasks;
using MAVN.Common.MsSql;
using MAVN.Service.QuorumExplorer.Domain.DTOs;

namespace MAVN.Service.QuorumExplorer.Domain.Repositories
{
public interface IEventRepository
{
Task SaveAsync(IReadOnlyCollection<Event> events);
Task SaveAsync(IReadOnlyCollection<Event> events, TransactionContext txContext = null);

Task<(int total, IEnumerable<EventInfo>)> GetByBlockNumberAsync(long number, int skip, int take);

Task<(int total, IEnumerable<EventInfo>)> GetByBlockHashAsync(string hash, int skip, int take);

Task<(int total, IEnumerable<EventInfo>)> GetByTransactionAsync(string hash, int skip, int take);

Task<IEnumerable<EventInfo>> GetFilteredAsync(EventsFilter filter, int skip, int take);
}
}
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
<ProjectReference Include="..\MAVN.Service.QuorumExplorer.Domain\MAVN.Service.QuorumExplorer.Domain.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Lykke.Common.MsSql" Version="1.4.1" />
<PackageReference Include="MAVN.Common.MsSql" Version="3.0.0" />
<PackageReference Include="Nethereum.Web3" Version="3.6.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Common.Log;
using Lykke.Common.Log;
using Lykke.Common.MsSql;
using Lykke.Common.MsSql.Exceptions;
using MAVN.Common.MsSql;
using MAVN.Service.QuorumExplorer.Domain.DTOs;
using MAVN.Service.QuorumExplorer.Domain.Repositories;
using MAVN.Service.QuorumExplorer.Domain.Services;
@@ -18,22 +17,22 @@ public class TransactionLogDecodingService : ITransactionLogDecodingService
private readonly IEventRepository _eventRepository;
private readonly ILog _log;
private readonly ITransactionRepository _transactionRepository;
private readonly TransactionScopeHandler _transactionScopeHandler;
private readonly ITransactionRunner _transactionRunner;

public TransactionLogDecodingService(
IDecodingService decodingService,
IEventRepository eventRepository,
ILogFactory logFactory,
ITransactionRepository transactionRepository,
TransactionScopeHandler transactionScopeHandler)
ITransactionRepository transactionRepository,
ITransactionRunner transactionRunner)
{
_decodingService = decodingService;
_eventRepository = eventRepository;
_log = logFactory.CreateLog(this);
_transactionRepository = transactionRepository;
_transactionScopeHandler = transactionScopeHandler;
_transactionRunner = transactionRunner;
}

public async Task<bool> DecodeNonDecodedTopicsAsync(
int batchSize)
{
@@ -44,38 +43,38 @@ public async Task<bool> DecodeNonDecodedTopicsAsync(
try
{
#region Logging

_log.Debug($"Getting up to {batchSize} non-decoded transaction logs with known ABIs.");

#endregion

nonDecodedTransactionLogs = (await _transactionRepository.GetNonDecodedTransactionLogsAsync(batchSize)).ToList();

#region Logging

_log.Debug($"Got {nonDecodedTransactionLogs.Count} non-decoded transaction logs with known ABIs.");

#endregion
}
catch (Exception e)
{
#region Logging

_log.Error(e, $"Failed to get up to {batchSize} non-decoded transaction logs with known ABIs.");

#endregion

return false;
}

if (nonDecodedTransactionLogs.Count == 0)
{
#region Logging

_log.Debug("No non-decoded transaction logs with known ABIs have been found.");

#endregion

return false;
}

@@ -84,65 +83,65 @@ public async Task<bool> DecodeNonDecodedTopicsAsync(
try
{
#region Logging

_log.Debug($"Decoding {nonDecodedTransactionLogs.Count} transaction logs.");

#endregion

decodedEvents = nonDecodedTransactionLogs.Select(x => _decodingService.DecodeTransactionLog(x)).ToList();

#region Logging

_log.Debug($"{nonDecodedTransactionLogs.Count} transaction logs have been decoded.");

#endregion
}
catch (Exception e)
{
#region Logging

_log.Error(e, "Failed to decode transaction logs.");

#endregion

return false;
}

try
{
await _transactionScopeHandler.WithTransactionAsync(async () =>
await _transactionRunner.RunWithTransactionAsync(async (txContext) =>
{
await _eventRepository.SaveAsync(decodedEvents);
await _eventRepository.SaveAsync(decodedEvents, txContext);

await _transactionRepository.SaveDecodedAsync(
nonDecodedTransactionLogs.Select(t => Tuple.Create(t.LogIndex, t.TransactionHash)));
});
}
catch (CommitTransactionException e)
catch (InvalidOperationException e)
{
#region Logging

_log.Error(e, "Failed to commit transaction.");

#endregion

return false;
}
catch (Exception e)
{
#region Logging

_log.Error(e, "Failed to save decoded transaction logs.");

#endregion

return false;
}

#region Logging

_log.Info($"{nonDecodedTransactionLogs.Count} transaction logs have been decoded.");

#endregion

return true;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Common;
using Lykke.Common.MsSql;
using MAVN.Common.MsSql;
using MAVN.Service.QuorumExplorer.Domain.DTOs;
using MAVN.Service.QuorumExplorer.Domain.Repositories;
using MAVN.Service.QuorumExplorer.MsSqlRepositories.Contexts;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using JetBrains.Annotations;
using Lykke.Common.MsSql;
using JetBrains.Annotations;
using MAVN.Common.MsSql;
using MAVN.Service.QuorumExplorer.MsSqlRepositories.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Lykke.Common.MsSql;
using MAVN.Common.MsSql;
using MAVN.Service.QuorumExplorer.Domain;
using MAVN.Service.QuorumExplorer.Domain.DTOs;
using MAVN.Service.QuorumExplorer.Domain.Repositories;
@@ -25,9 +25,9 @@ public EventRepository(
}

public async Task SaveAsync(
IReadOnlyCollection<Event> events)
IReadOnlyCollection<Event> events, TransactionContext txContext = null)
{
using (var context = _contextFactory.CreateDataContext())
using (var context = _contextFactory.CreateDataContext(txContext))
{
var hasher = Sha3Keccack.Current;

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Lykke.Common.MsSql;
using MAVN.Common.MsSql;
using MAVN.Service.QuorumExplorer.Domain.DTOs;
using MAVN.Service.QuorumExplorer.Domain.Repositories;
using MAVN.Service.QuorumExplorer.MsSqlRepositories.Contexts;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Threading.Tasks;
using Lykke.Common.MsSql;
using System.Threading.Tasks;
using MAVN.Common.MsSql;
using MAVN.Service.QuorumExplorer.Domain.Repositories;
using MAVN.Service.QuorumExplorer.MsSqlRepositories.Constants;
using MAVN.Service.QuorumExplorer.MsSqlRepositories.Contexts;
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
<Version>1.0.0</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Lykke.Common.MsSql" Version="1.4.1" />
<PackageReference Include="MAVN.Common.MsSql" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.2.0" />
<PackageReference Include="Nethereum.Util" Version="3.6.0" />
<PackageReference Include="Z.EntityFramework.Plus.EFCore" Version="2.0.3" />
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Lykke.Common.MsSql;
using MAVN.Common.MsSql;
using MAVN.Service.QuorumExplorer.Domain;
using MAVN.Service.QuorumExplorer.Domain.DTOs;
using MAVN.Service.QuorumExplorer.Domain.Extensions;
6 changes: 3 additions & 3 deletions src/MAVN.Service.QuorumExplorer/Modules/RepositoriesModule.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Autofac;
using Autofac;
using JetBrains.Annotations;
using Lykke.Common.MsSql;
using MAVN.Service.QuorumExplorer.Domain.Repositories;
using MAVN.Service.QuorumExplorer.MsSqlRepositories;
using MAVN.Service.QuorumExplorer.MsSqlRepositories.Contexts;
using MAVN.Service.QuorumExplorer.Settings;
using Lykke.SettingsReader;
using MAVN.Common.MsSql;

namespace MAVN.Service.QuorumExplorer.Modules
{
@@ -35,7 +35,7 @@ protected override void Load(
.RegisterType<TransactionRepository>()
.As<ITransactionRepository>()
.SingleInstance();

builder
.RegisterType<EventRepository>()
.As<IEventRepository>()

0 comments on commit a3e7101

Please sign in to comment.