Exemplo n.º 1
0
 public ContractTransactionProcessor(
     Web3.Web3 web3, IContractRepository contractRepository,
     ITransactionRepository transactionRepository,
     IAddressTransactionRepository addressTransactionRepository,
     ITransactionVMStackRepository transactionVmStackRepository,
     ITransactionLogRepository transactionLogRepository)
 {
     Web3 = web3;
     _contractRepository           = contractRepository;
     _transactionRepository        = transactionRepository;
     _addressTransactionRepository = addressTransactionRepository;
     _transactionVmStackRepository = transactionVmStackRepository;
     _transactionLogRepository     = transactionLogRepository;
     VmStackErrorChecker           = new VmStackErrorChecker();
 }
Exemplo n.º 2
0
        public async Task ProcessTransactionAsync(Transaction transaction, TransactionReceipt transactionReceipt, HexBigInteger blockTimestamp)
        {
            var     transactionHash = transaction.TransactionHash;
            var     hasStackTrace   = false;
            JObject stackTrace      = null;
            var     error           = string.Empty;
            var     hasError        = false;

            if (EnabledVmProcessing)
            {
                try
                {
                    stackTrace = await GetTransactionVmStack(transactionHash).ConfigureAwait(false);
                }
                catch
                {
                    if (transaction.Gas == transactionReceipt.GasUsed)
                    {
                        hasError = true;
                    }
                }

                if (stackTrace != null)
                {
                    error         = VmStackErrorChecker.GetError(stackTrace);
                    hasError      = !string.IsNullOrEmpty(error);
                    hasStackTrace = true;
                    await _transactionVmStackRepository.UpsertAsync(transactionHash, transaction.To, stackTrace);
                }
            }

            var logs = transactionReceipt.Logs;

            await _transactionRepository.UpsertAsync(transaction,
                                                     transactionReceipt,
                                                     hasError, blockTimestamp, hasStackTrace, error);

            await
            _addressTransactionRepository.UpsertAsync(transaction, transactionReceipt, hasError, blockTimestamp,
                                                      transaction.To, error, hasStackTrace);

            var addressesAdded = new List <string> {
                transaction.To
            };

            for (var i = 0; i < logs.Count; i++)
            {
                var log = logs[i] as JObject;
                if (log != null)
                {
                    var logAddress = log["address"].Value <string>();

                    if (!addressesAdded.Exists(x => x == logAddress))
                    {
                        addressesAdded.Add(logAddress);

                        await
                        _addressTransactionRepository.UpsertAsync(transaction, transactionReceipt, hasError,
                                                                  blockTimestamp,
                                                                  logAddress, error, hasStackTrace);
                    }

                    await _transactionLogRepository.UpsertAsync(transactionHash,
                                                                i, log);
                }
            }
        }
Exemplo n.º 3
0
        public void ShouldReturnErrorFromStackTrace()
        {
            var error = new VmStackErrorChecker().GetError(JObject.Parse(StackWithError));

            Assert.Equal("oops", error);
        }
Exemplo n.º 4
0
        public void ShouldReturnNullWhenStackDoesNotContainAnError()
        {
            var error = new VmStackErrorChecker().GetError(JObject.Parse(StackWithoutError));

            Assert.Null(error);
        }