public Result <BlockchainEvent> ImportDepositTakenEvent( EquivocationDto equivocationDto, long blockId, long equivocationId) { using (var uow = NewUnitOfWork(UnitOfWorkMode.Writable)) { var eventRepo = NewRepository <BlockchainEvent>(uow); var depositTakenEvent = new BlockchainEvent { EventType = EventType.DepositTaken.ToString(), Amount = equivocationDto.DepositTaken * -1, EquivocationId = equivocationId, BlockId = blockId }; var addressId = NewRepository <Address>(uow) .GetAs(a => a.BlockchainAddress == equivocationDto.ValidatorAddress, a => a.AddressId) .SingleOrDefault(); if (addressId == default(long)) { return(Result.Failure <BlockchainEvent>("Address {0} does not exist.".F(equivocationDto.ValidatorAddress))); } depositTakenEvent.AddressId = addressId; eventRepo.Insert(depositTakenEvent); uow.Commit(); return(Result.Success(depositTakenEvent)); } }
public Result <Equivocation> ImportEquivocation(EquivocationDto equivocationDto, long blockId) { using (var uow = NewUnitOfWork(UnitOfWorkMode.Writable)) { var equivocationRepo = NewRepository <Equivocation>(uow); if (equivocationRepo.Exists(e => e.EquivocationProofHash == equivocationDto.EquivocationProofHash)) { return(Result.Failure <Equivocation>( "Equivocation {0} already exists.".F(equivocationDto.EquivocationProofHash))); } var equivocation = new Equivocation { EquivocationProofHash = equivocationDto.EquivocationProofHash, BlockNumber = equivocationDto.BlockNumber, ConsensusRound = equivocationDto.ConsensusRound, ConsensusStep = equivocationDto.ConsensusStep, EquivocationValue1 = equivocationDto.EquivocationValue1, EquivocationValue2 = equivocationDto.EquivocationValue2, Signature1 = equivocationDto.Signature1, Signature2 = equivocationDto.Signature2, BlockId = blockId }; equivocationRepo.Insert(equivocation); uow.Commit(); return(Result.Success(equivocation)); } }
public Result <IEnumerable <BlockchainEvent> > ImportDepositGivenEvents( EquivocationDto equivocationDto, long blockId, long equivocationId) { using (var uow = NewUnitOfWork(UnitOfWorkMode.Writable)) { var eventRepo = NewRepository <BlockchainEvent>(uow); var addressRepo = NewRepository <Address>(uow); var events = new List <BlockchainEvent>(); foreach (var depositDto in equivocationDto.DepositDistribution) { var depositGivenEvent = new BlockchainEvent { EventType = EventType.DepositGiven.ToString(), Amount = depositDto.Amount, EquivocationId = equivocationId, BlockId = blockId }; var addressId = addressRepo .GetAs(a => a.BlockchainAddress == depositDto.ValidatorAddress, a => a.AddressId) .SingleOrDefault(); if (addressId == default(long)) { return(Result.Failure <IEnumerable <BlockchainEvent> >("Address {0} does not exist.".F(depositDto.ValidatorAddress))); } depositGivenEvent.AddressId = addressId; } eventRepo.Insert(events); uow.Commit(); return(Result.Success(events.AsEnumerable())); } }