public Task HandleTransactionAsync(TransactionWithReceipt transactionWithReceipt) { var addresses = string.Join(",", transactionWithReceipt.GetAllRelatedAddresses()); Log($"[Transaction] Block:{transactionWithReceipt.Transaction.BlockNumber.Value}, Index:{transactionWithReceipt.Transaction.TransactionIndex.Value}, Hash:{transactionWithReceipt.Transaction.TransactionHash}, From:{transactionWithReceipt.Transaction.From}, To:{transactionWithReceipt.Transaction.To}, All Addresses: {addresses}"); return(Task.CompletedTask); }
public Task HandleTransactionAsync(TransactionWithReceipt txnWithReceipt) { var dto = txnWithReceipt.Decode <TFunctionInput>(); FunctionsHandled.Add((txnWithReceipt, dto)); return(Task.CompletedTask); }
private async Task HandleAsync(TransactionWithReceipt transactionWithReceipt) { try { if (!transactionWithReceipt.IsForFunction <TFunctionMessage>()) { return; } var decoded = transactionWithReceipt.Decode <TFunctionMessage>(); if (decoded == null) { return; } _currentBatch.Enqueue(new FunctionCall <TFunctionMessage>(transactionWithReceipt, decoded)); if (_currentBatch.Count == _logsPerIndexBatch) { await FunctionIndexer.IndexAsync(_currentBatch); _currentBatch.Clear(); } } catch (Exception) { //Error whilst handling transaction log //expected event signature may differ from the expected event. } }
public Task HandleTransactionAsync(TransactionWithReceipt txnWithReceipt) { //we are not using conditional TransactionRouting in this example (see TransactionRouter) //therefore we need this check to avoid handling non related transactions if (!txnWithReceipt.IsForFunction <BuyApprenticeFunction>()) { return(Task.CompletedTask); } var dto = txnWithReceipt.Decode <BuyApprenticeFunction>(); FunctionsHandled.Add((txnWithReceipt, dto)); return(Task.CompletedTask); }
public async Task HandleTransactionAsync_Calls_Tx_Repo_Once_And_Address_Repo_For_Each_Associated_Address() { var tx = CreateTransaction(); var receipt = CreateReceipt(); TransactionWithReceipt txWithReceipt = CreateTransactionWithReceipt(tx, receipt); SetUpTransactionRepoUpsert(txWithReceipt); SetupAddressUpsert(txWithReceipt, tx.From, tx.To, LogAddress1, LogAddress2); await _handler.HandleTransactionAsync(txWithReceipt); Assert.Equal(1, _txRepoUpsertCount); Assert.Equal(4, _addressRepoUpsertCount); }
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 = transactionReceipt.Failed(); if (EnabledVmProcessing) { try { stackTrace = await _web3 .GetTransactionVmStack(transactionHash) .ConfigureAwait(false); } catch (Exception) { } if (stackTrace != null) { //TODO! _Remove this debug line //File.WriteAllText($"c:/Temp/StackTrace_{transactionReceipt.BlockNumber.Value}.json", stackTrace.ToString()); error = _vmStackErrorChecker.GetError(stackTrace); hasError = !string.IsNullOrEmpty(error); hasStackTrace = true; await _transactionVmStackHandler.HandleAsync (new TransactionVmStack(transactionHash, transaction.To, stackTrace)) .ConfigureAwait(false); } } var tx = new TransactionWithReceipt( transaction, transactionReceipt, hasError, blockTimestamp, error, hasStackTrace); await _transactionHandler.HandleTransactionAsync(tx) .ConfigureAwait(false); }
private void SetupAddressUpsert(TransactionWithReceipt txWithReceipt, params string[] expectedAddresses) { foreach (var address in expectedAddresses) { _addressTransactionRepository .Setup(t => t.UpsertAsync(txWithReceipt.Transaction, txWithReceipt.TransactionReceipt, txWithReceipt.HasError, txWithReceipt.BlockTimestamp, address, txWithReceipt.Error, txWithReceipt.HasVmStack, txWithReceipt.TransactionReceipt.ContractAddress)) .Returns(() => { _addressRepoUpsertCount++; return(Task.CompletedTask); }); } }
private void SetUpTransactionRepoUpsert(TransactionWithReceipt txWithReceipt) { _transactionRepository .Setup(t => t.UpsertAsync( txWithReceipt.Transaction, txWithReceipt.TransactionReceipt, txWithReceipt.HasError, txWithReceipt.BlockTimestamp, txWithReceipt.HasVmStack, txWithReceipt.Error)) .Returns(() => { _txRepoUpsertCount++; return(Task.CompletedTask); }); }
public Task HandleTransactionAsync(TransactionWithReceipt txnWithReceipt) { if (!txnWithReceipt.IsForFunction <TFunctionInput>()) { return(Task.CompletedTask); } var dto = txnWithReceipt.Decode <TFunctionInput>(); System.Console.WriteLine($"[FUNCTION]"); System.Console.WriteLine($"\t{_functionAbi.Name ?? "unknown"}"); foreach (var prop in dto.GetType().GetProperties()) { System.Console.WriteLine($"\t\t[{prop.Name}:{prop.GetValue(dto) ?? "null"}]"); } return(Task.CompletedTask); }
public async Task HandleTransactionAsync(TransactionWithReceipt tx) { await _transactionRepository.UpsertAsync( tx.Transaction, tx.TransactionReceipt, tx.HasError, tx.BlockTimestamp, tx.HasVmStack, tx.Error); await UpsertAddressTransactions( tx.Transaction, tx.TransactionReceipt, tx.HasError, tx.BlockTimestamp, tx.Error, tx.HasVmStack); }
private async Task SendToHandler(List <ITransactionHandler> handlers, string transactionHash, Transaction transaction, Hex.HexTypes.HexBigInteger blockTimestamp) { var receipt = await _blockchainProxyService.GetTransactionReceipt(transactionHash); if (transaction.IsForContractCreation(receipt)) { var code = await _blockchainProxyService.GetCode(receipt.ContractAddress); var contractCreationFailure = (code == null) || (code == "0x"); var contactCreationTransaction = new ContractCreationTransaction( receipt.ContractAddress, code, transaction, receipt, contractCreationFailure, blockTimestamp); foreach (var handler in handlers) { await handler.HandleContractCreationTransactionAsync(contactCreationTransaction); } } else { var txWithReceipt = new TransactionWithReceipt( transaction, receipt, !receipt.Succeeded(), blockTimestamp); foreach (var handler in handlers) { await handler.HandleTransactionAsync(txWithReceipt); } } }
public TransactionContext(IndexDefinition index, T dto, TransactionWithReceipt tx) : base(index) { FunctionCall = new FunctionCall <T>(tx, dto); Index = index; }
public Task HandleTransactionAsync(TransactionWithReceipt transactionWithReceipt) { TransactionsHandled.Add(transactionWithReceipt); return(Task.CompletedTask); }
public Task HandleTransactionAsync(TransactionWithReceipt txnWithReceipt) { return(Task.CompletedTask); }
public void Convenience_Properties_And_Methods() { var txn = new Transaction { BlockNumber = new HexBigInteger(100), TransactionHash = "0xc185cc7b9f7862255b82fd41be561fdc94d030567d0b41292008095bf31c39b9", From = "0x1009b29f2094457d3dba62d1953efea58176ba27", To = "0x2009b29f2094457d3dba62d1953efea58176ba27", Value = new HexBigInteger(0), Gas = new HexBigInteger(0), GasPrice = new HexBigInteger(0), Nonce = new HexBigInteger(0) }; const string logAddress = "0x4009b29f2094457d3dba62d1953efea58176ba27"; var receipt = new TransactionReceipt { ContractAddress = "0x3009b29f2094457d3dba62d1953efea58176ba27", Status = new HexBigInteger(BigInteger.One), Logs = JArray.FromObject(new [] { new{ address = logAddress } }) }; var f = new DoSomethingFunction { Gas = txn.Gas, GasPrice = txn.GasPrice, Nonce = txn.Nonce, FromAddress = txn.From, AmountToSend = txn.Value }; var txInput = f.CreateTransactionInput(receipt.ContractAddress); txn.Input = txInput.Data; // this is a workaround for a bug in FunctionCallDecoder v3.00rc3 // if sig == data it returned a null instead of the function input object // adding this zero prevents it from doing that // bug already fixed in Neth awaiting next release txn.Input = txn.Input + "0"; var txnWithReceipt = new TransactionWithReceipt(txn, receipt, false, null); Assert.Equal(txn.BlockNumber, txnWithReceipt.BlockNumber); Assert.Equal(txn.TransactionHash, txnWithReceipt.TransactionHash); Assert.True(txnWithReceipt.Succeeded); Assert.False(txnWithReceipt.Failed); Assert.True(txnWithReceipt.HasLogs()); var relatedAddresses = txnWithReceipt.GetAllRelatedAddresses(); Assert.Contains(txn.From, relatedAddresses); Assert.Contains(txn.To, relatedAddresses); Assert.Contains(receipt.ContractAddress, relatedAddresses); Assert.Contains(logAddress, relatedAddresses); receipt.Status = new HexBigInteger(BigInteger.Zero); Assert.False(txnWithReceipt.Succeeded); Assert.True(txnWithReceipt.Failed); Assert.True(txnWithReceipt.IsForFunction <DoSomethingFunction>()); Assert.NotNull(txnWithReceipt.Decode <DoSomethingFunction>()); }
public void WhenTxIsNullBlockNumberIsZero() { var txWithReceipt = new TransactionWithReceipt(); Assert.Equal(BigInteger.Zero, txWithReceipt.BlockNumber.Value); }
public FunctionCall(TransactionWithReceipt tx, TDto dto) { Tx = tx; Dto = dto; }
public static TFunctionMessage Decode <TFunctionMessage>(this TransactionWithReceipt transactionWithReceipt) where TFunctionMessage : FunctionMessage, new() { return(transactionWithReceipt.Transaction?.DecodeTransactionToFunctionMessage <TFunctionMessage>()); }
public static bool IsForFunction <TFunctionMessage>(this TransactionWithReceipt transactionWithReceipt) where TFunctionMessage : FunctionMessage, new() { return(transactionWithReceipt.Transaction?.IsTransactionForFunctionMessage <TFunctionMessage>() ?? false); }
public static TransactionContext <T> Assertions <T>(this IndexDefinition index, T dto, TransactionWithReceipt tx) where T : FunctionMessage, new() { return(new TransactionContext <T>(index, dto, tx)); }
public Task HandleTransactionAsync(TransactionWithReceipt transactionWithReceipt) => HandleAsync(transactionWithReceipt);