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 <BlockchainEvent> ImportValidatorRewardEvent( decimal reward, long blockId, string blockchainAddress) { using (var uow = NewUnitOfWork(UnitOfWorkMode.Writable)) { var eventRepo = NewRepository <BlockchainEvent>(uow); var blockchainEvent = new BlockchainEvent { Amount = reward, BlockId = blockId, EventType = EventType.ValidatorReward.ToString() }; var addressId = NewRepository <Address>(uow) .GetAs(a => a.BlockchainAddress == blockchainAddress, a => a.AddressId) .SingleOrDefault(); if (addressId == default(long)) { return(Result.Failure <BlockchainEvent>("Address {0} does not exist.".F(blockchainAddress))); } blockchainEvent.AddressId = addressId; eventRepo.Insert(blockchainEvent); uow.Commit(); return(Result.Success(blockchainEvent)); } }
public BlockchainEventFilterParams(BlockchainEvent eventType, UInt256[] txHashes) { EventType = eventType; // sorting the tx hashes for further optimization Array.Sort(txHashes, (x, y) => UInt256Utils.Compare(x, y)); PendingTransactionList = new List <UInt256>(txHashes.ToList()); PollingTime = TimeUtils.CurrentTimeMillis(); }
public BlockchainEventFilterParams(BlockchainEvent eventType, ulong?fromBlock, ulong?toBlock, List <UInt160> addresses, List <List <UInt256> > topics) { EventType = eventType; FromBlock = fromBlock; ToBlock = toBlock; AddressList = new List <UInt160>(addresses); TopicLists = new List <List <UInt256> >(topics); PollingTime = TimeUtils.CurrentTimeMillis(); }
public ulong Create(BlockchainEvent eventType, ulong?fromBlock, ulong?toBlock, List <UInt160> addresses, List <List <UInt256> > topics) { RemoveUnusedFilters(); _currentId++; if (eventType == BlockchainEvent.Logs) { _filters[_currentId] = new BlockchainEventFilterParams( eventType, fromBlock, toBlock, addresses, topics ); } else { Logger.LogError($"Implementation not found for filter type: {eventType}"); } return(_currentId); }
public ulong Create(BlockchainEvent eventType) { RemoveUnusedFilters(); _currentId++; if (eventType == BlockchainEvent.Block) { _filters[_currentId] = new BlockchainEventFilterParams( eventType, _stateManager.LastApprovedSnapshot.Blocks.GetTotalBlockHeight() ); } else if (eventType == BlockchainEvent.Transaction) { _filters[_currentId] = new BlockchainEventFilterParams( eventType, _transactionPool.Transactions.Keys.ToArray() ); } else { Logger.LogError($"Implementation not found for filter type: {eventType}"); } return(_currentId); }
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())); } }
public BlockchainEventFilterParams(BlockchainEvent eventType, ulong lastSyncedBlock) { EventType = eventType; LastSyncedBlock = lastSyncedBlock; PollingTime = TimeUtils.CurrentTimeMillis(); }