public async Task Persist(Transaction transaction) { await SpendOutputs(transaction.Inputs); await GainOutputs(transaction.Hash, transaction.Outputs); switch (transaction) { case ContractTransaction _: case MinerTransaction _: break; case ClaimTransaction claim: await _claimTransactionPersister.Persist(claim); break; case InvocationTransaction invocation: await _invocationTransactionPersister.Persist(invocation); break; case StateTransaction state: await _stateTransactionPersister.Persist(state); break; case IssueTransaction issue: await _issueTransactionPersister.Persist(issue); break; case PublishTransaction publish: await _publishTransactionPersister.Persist(publish); break; case RegisterTransaction register: await _registerTransactionPersister.Persist(register); break; case EnrollmentTransaction enrollment: await _enrollmentTransactionPersister.Persist(enrollment); break; default: throw new ArgumentException("Unknown Transaction Type"); } await _repository.AddTransaction(transaction); _transactionPool.Remove(transaction.Hash); }
public async Task Persist(params Block[] blocks) { var height = await _blockRepository.GetTotalBlockHeight(); foreach (var block in blocks) { var blockHeader = await _blockRepository.GetBlockHeader(block.Hash); if (blockHeader != null && blockHeader.Type == HeaderType.Extended) { continue; } foreach (var transaction in block.Transactions) { await _transactionPersister.Persist(transaction); } if (block.Index > 0) { await _blockHeaderPersister.Update(block.GetBlockHeader()); } else { await _blockHeaderPersister.Persist(block.GetBlockHeader()); } if (height + 1 == block.Index) { await _blockRepository.SetTotalBlockHeight(block.Index); height = block.Index; } _blockchainContext.CurrentBlock = block; } }