private void AddTxrVO(TransactionReceiptVO txr) { lock (transactions) { transactions.Add(txr); } }
public async Task UpsertAsync() { var transaction = CreateDummyTransaction(); var receipt = CreateDummyReceipt(); var blockTimestamp = CreateBlockTimestamp(); var address = "0x9209b29f2094457d3dba62d1953efea58176ba27"; var error = (string)null; var hasVmStack = false; var failure = false; var vo = new TransactionReceiptVO(new RPC.Eth.DTOs.Block { Timestamp = blockTimestamp }, transaction, receipt, failure, error, hasVmStack); await _repo.UpsertAsync(vo, address, error); var storedTransaction = await _repo.FindByAddressBlockNumberAndHashAsync(address, transaction.BlockNumber, transaction.TransactionHash); Assert.NotNull(storedTransaction); EnsureCorrectStoredValues(transaction, receipt, blockTimestamp, address, error, null, hasVmStack, storedTransaction); var txView = await _repo.FindAsync(address, transaction.BlockNumber, transaction.TransactionHash); Assert.Equal(address, txView.Address); Assert.Equal(storedTransaction.BlockNumber, txView.BlockNumber); Assert.Equal(storedTransaction.Hash, txView.Hash); }
public async Task UpsertAsync(TransactionReceiptVO transactionReceiptVO, string address, string error = null, string newContractAddress = null) { var tx = transactionReceiptVO.MapToStorageEntityForUpsert <MongoDbAddressTransaction>(address); tx.UpdateRowDates(); await UpsertDocumentAsync(tx).ConfigureAwait(false); }
public async Task UpsertAsync_2() { var transaction = CreateDummyTransaction(); var receipt = CreateDummyReceipt(); var blockTimestamp = CreateBlockTimestamp(); var address = "0x9209b29f2094457d3dba62d1953efea58176ba27"; var error = (string)null; var newContractAddress = "0xbb0ee65f8bb24c5c1ed0f5e65184a4a77e9ffc26"; var hasVmStack = false; var code = ""; var failure = false; receipt.ContractAddress = newContractAddress; var transactionReceiptVO = new TransactionReceiptVO( block: new RPC.Eth.DTOs.Block { Timestamp = blockTimestamp }, transaction: transaction, transactionReceipt: receipt, hasError: failure, error: error, hasVmStack: hasVmStack); await _repo.UpsertAsync(transactionReceiptVO, code, failure); var storedTransaction = await _repo.FindByBlockNumberAndHashAsync(transaction.BlockNumber, transaction.TransactionHash); Assert.NotNull(storedTransaction); EnsureCorrectStoredValues(transaction, receipt, blockTimestamp, address, error, newContractAddress, hasVmStack, storedTransaction); }
public async Task UpsertAsync(TransactionReceiptVO transactionReceiptVO, string code, bool failedCreatingContract) { var transactionEntity = Entities.Transaction.CreateTransaction( transactionReceiptVO.Transaction, transactionReceiptVO.TransactionReceipt, failedCreatingContract, transactionReceiptVO.BlockTimestamp, transactionReceiptVO.TransactionReceipt.ContractAddress); await UpsertAsync(transactionEntity).ConfigureAwait(false); }
public async Task UpsertAsync(TransactionReceiptVO transactionReceiptVO, string address, string error = null, string newContractAddress = null) { var entity = AzureEntities.AddressTransaction.CreateAddressTransaction(transactionReceiptVO.Transaction, transactionReceiptVO.TransactionReceipt, transactionReceiptVO.HasError, transactionReceiptVO.BlockTimestamp, address, error, transactionReceiptVO.HasVmStack, newContractAddress); await UpsertAsync(entity).ConfigureAwait(false); }
public async Task UpsertAsync(TransactionReceiptVO transactionReceiptVO, string code, bool failedCreatingContract) { var record = await FindByBlockNumberAndHashAsync(transactionReceiptVO.BlockNumber, transactionReceiptVO.TransactionHash); if (record != null) { Records.Remove(record); } Records.Add(transactionReceiptVO.MapToStorageEntityForUpsert(code, failedCreatingContract)); }
public async Task UpsertAsync(TransactionReceiptVO transactionReceiptVO) { var record = await FindByBlockNumberAndHashAsync(transactionReceiptVO.BlockNumber, transactionReceiptVO.TransactionHash); if (record != null) { Records.Remove(record); } Records.Add(transactionReceiptVO.MapToStorageEntityForUpsert()); }
public async Task UpsertAsync(TransactionReceiptVO transactionReceiptVO, string address, string error = null, string newContractAddress = null) { var entity = await FindAsync(address, transactionReceiptVO.Transaction.BlockNumber, transactionReceiptVO.TransactionHash).ConfigureAwait(false); if (entity != null) { Records.Remove(entity); } Records.Add(transactionReceiptVO.MapToStorageEntityForUpsert(address)); }
public async Task UpsertAsync(TransactionReceiptVO transactionReceiptVO) { var transactionEntity = Entities.Transaction.CreateTransaction(transactionReceiptVO.Transaction, transactionReceiptVO.TransactionReceipt, transactionReceiptVO.HasError, transactionReceiptVO.BlockTimestamp, transactionReceiptVO.HasVmStack, transactionReceiptVO.Error); await UpsertAsync(transactionEntity).ConfigureAwait(false); }
private TransactionDto MapReceiptToTransactionDto(TransactionReceiptVO r) { return(new TransactionDto { BlockHeight = (long)r.Transaction.BlockNumber.Value, From = r.Transaction.From, To = r.Transaction.To, Quantity = r.Transaction.Value.Value.ToString(), Status = r.Failed ? "0" : "1", TimeStamp = r.Block.Timestamp.ToString(), TransactionHash = r.TransactionHash }); }
public static TEntity MapToStorageEntityForUpsert <TEntity>(this TEntity tx, TransactionReceiptVO transactionReceiptVO) where TEntity : Transaction, new() { tx.Map(transactionReceiptVO.Transaction); tx.Map(transactionReceiptVO.TransactionReceipt); tx.Failed = transactionReceiptVO.TransactionReceipt.HasErrors() ?? false; tx.TimeStamp = transactionReceiptVO.BlockTimestamp?.Value.ToString(); tx.Error = transactionReceiptVO.Error ?? string.Empty; tx.HasVmStack = transactionReceiptVO.HasVmStack; tx.UpdateRowDates(); return(tx); }
public static TEntity MapToStorageEntityForUpsert <TEntity>(this TEntity tx, TransactionReceiptVO transactionReceiptVO, string code, bool failedCreatingContract) where TEntity : Transaction, new() { tx.Map(transactionReceiptVO.Transaction); tx.Map(transactionReceiptVO.TransactionReceipt); tx.NewContractAddress = transactionReceiptVO.TransactionReceipt.ContractAddress; tx.Failed = failedCreatingContract; tx.TimeStamp = transactionReceiptVO.BlockTimestamp.Value.ToString(); tx.Error = string.Empty; tx.HasVmStack = transactionReceiptVO.HasVmStack; tx.UpdateRowDates(); return(tx); }
public async Task MapsTransactionToSearchDocument() { var mockElasticClient = new MockElasticClient(); var indexer = new ElasticTransactionReceiptVOIndexer <SearchDocument>("my-index", mockElasticClient.ElasticClient, (tx) => new SearchDocument(tx)); TransactionReceiptVO transaction = IndexerTestData.CreateSampleTransaction(); await indexer.IndexAsync(transaction); Assert.Single(mockElasticClient.BulkRequests); var indexedDocument = mockElasticClient.GetFirstBulkOperation().GetBody() as SearchDocument; //check mapping Assert.Same(transaction, indexedDocument.TransactionReceiptVO); }
public async Task MapsTransactionToGenericSearchDocument() { var indexDefinition = new TransactionReceiptVOIndexDefinition("my-transactions"); var mockElasticClient = new MockElasticClient(); var indexer = new ElasticTransactionReceiptVOIndexer("my-index", mockElasticClient.ElasticClient, indexDefinition); TransactionReceiptVO transaction = IndexerTestData.CreateSampleTransaction(); await indexer.IndexAsync(transaction); Assert.Single(mockElasticClient.BulkRequests); var indexedDoc = mockElasticClient.GetFirstBulkOperation().GetBody() as GenericSearchDocument; //check generic mapping Assert.Equal(transaction.Transaction.BlockNumber.ToString(), indexedDoc[PresetSearchFieldName.tx_block_number.ToString()]); }
public async Task MapsTransactionToSearchDocument() { var index = new Index(); var mockSearchIndexClient = new SearchIndexClientMock <SearchDocument>(); var indexer = new AzureTransactionReceiptVOIndexer <SearchDocument>( mockSearchIndexClient.SearchIndexClient, (tx) => new SearchDocument(tx)); TransactionReceiptVO transaction = IndexerTestData.CreateSampleTransaction(); await indexer.IndexAsync(transaction); Assert.Single(mockSearchIndexClient.IndexedBatches); var firstIndexAction = mockSearchIndexClient.IndexedBatches[0].Actions.First(); var document = firstIndexAction.Document; //check mapping Assert.Same(transaction, document.TransactionReceiptVO); }
public async Task UpsertAsync(TransactionReceiptVO transactionReceiptVO, string address, string error = null, string newContractAddress = null) { using (var context = _contextFactory.CreateContext()) { var tx = await FindOrCreate(transactionReceiptVO.Transaction, address, context).ConfigureAwait(false); tx.MapToStorageEntityForUpsert(transactionReceiptVO, address); if (tx.IsNew()) { context.AddressTransactions.Add(tx); } else { context.AddressTransactions.Update(tx); } await context.SaveChangesAsync().ConfigureAwait(false); } }
public async Task UpsertAsync(TransactionReceiptVO transactionReceiptVO, string code, bool failedCreatingContract) { using (var context = _contextFactory.CreateContext()) { var tx = await FindOrCreate(transactionReceiptVO.Transaction, context).ConfigureAwait(false); tx.MapToStorageEntityForUpsert(transactionReceiptVO, code, failedCreatingContract); if (tx.IsNew()) { context.Transactions.Add(tx); } else { context.Transactions.Update(tx); } await context.SaveChangesAsync().ConfigureAwait(false); } }
public async Task MapsTransactionToGenericSearchDocument() { var indexDefinition = new TransactionReceiptVOIndexDefinition("my-transactions"); var index = indexDefinition.ToAzureIndex(); var mockSearchIndexClient = new SearchIndexClientMock <GenericSearchDocument>(); var indexer = new AzureTransactionReceiptVOIndexer( mockSearchIndexClient.SearchIndexClient, indexDefinition); TransactionReceiptVO transaction = IndexerTestData.CreateSampleTransaction(); await indexer.IndexAsync(transaction); Assert.Single(mockSearchIndexClient.IndexedBatches); var firstIndexAction = mockSearchIndexClient.IndexedBatches[0].Actions.First(); var document = firstIndexAction.Document; //check generic mapping Assert.Equal(transaction.Transaction.BlockNumber.ToString(), document[PresetSearchFieldName.tx_block_number.ToString()]); }
public static GenericSearchDocument ToGenericElasticSearchDoc( this TransactionReceiptVO transactionReceiptVO, TransactionReceiptVOIndexDefinition indexDefinition) { var dictionary = new GenericSearchDocument(); foreach (var field in indexDefinition.Fields) { var val = field.GetTransactionReceiptValue(transactionReceiptVO)?.ToElasticSearchFieldValue(); if (val != null) { dictionary.Add(field.Name.ToElasticName(), val); } } var id = transactionReceiptVO.TransactionHash; dictionary.SetId(id.ToString()); return(dictionary); }
public async Task UpsertAsync(TransactionReceiptVO transactionReceiptVO, string address, string error = null, string newContractAddress = null) { await _lock.WaitAsync(); try { using (var context = _contextFactory.CreateContext()) { var tx = await FindOrCreate(transactionReceiptVO.Transaction, address, context).ConfigureAwait(false); tx.MapToStorageEntityForUpsert(transactionReceiptVO, address); context.AddressTransactions.AddOrUpdate(tx); await context.SaveChangesAsync().ConfigureAwait(false); } } finally { _lock.Release(); } }
public async Task UpsertAsync(TransactionReceiptVO transactionReceiptVO, string code, bool failedCreatingContract) { await _lock.WaitAsync(); try { using (var context = _contextFactory.CreateContext()) { var tx = await FindOrCreate(transactionReceiptVO.Transaction, context).ConfigureAwait(false); tx.MapToStorageEntityForUpsert(transactionReceiptVO, code, failedCreatingContract); context.Transactions.AddOrUpdate(tx); await context.SaveChangesAsync().ConfigureAwait(false); } } finally { _lock.Release(); } }
public async Task UpsertAsync() { var contractAddress = "0x26bc47888b7bfdf77db41ec0a2fb4db00af1c92a"; var code = "0x6080604052600436106053576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680635589f21d14605857806388a6f572146076578063ddca3f4314609e575b600080fd5b60746004803603810190808035906020019092919050505060c6565b005b348015608157600080fd5b50608860d0565b6040518082815260200191505060405180910390f35b34801560a957600080fd5b5060b060d9565b6040518082815260200191505060405180910390f35b8060008190555050565b60008054905090565b600054815600a165627a7a723058205345477b840b4fb7b6401abdcd3ab98ae1db0d342e6c6b4b45a4e2b10f6ae1f80029"; var transaction = new Nethereum.RPC.Eth.DTOs.Transaction { From = "0xe6de16a66e5cd7270cc36a851818bc092884fe64", TransactionHash = "0xcb00b69d2594a3583309f332ada97d0df48bae00170e36a4f7bbdad7783fc7e5" }; var block = new Block { }; var receipt = new TransactionReceipt { ContractAddress = contractAddress }; var transactionReceiptVO = new TransactionReceiptVO(block, transaction, receipt, false); var contractCreationVO = new ContractCreationVO(transactionReceiptVO, code, false); Assert.False(await _repo.ExistsAsync(contractAddress)); Assert.False(_repo.IsCached(contractAddress)); await _repo.UpsertAsync(contractCreationVO); Assert.True(await _repo.ExistsAsync(contractAddress)); Assert.True(_repo.IsCached(contractAddress)); var storedContract = await _repo.FindByAddressAsync(contractAddress); Assert.NotNull(storedContract); Assert.Equal(contractAddress, storedContract.Address); Assert.Equal(code, storedContract.Code); Assert.Equal(transaction.From, storedContract.Creator); Assert.Equal(transaction.TransactionHash, storedContract.TransactionHash); }
public static TransactionForFunctionVO <TransferFunction> CreateSampleTransactionForFunction() { Block block = new Block { Number = new HexBigInteger(new BigInteger(10)) }; var tx = new Transaction { BlockNumber = block.Number, TransactionHash = "0x19ce02e0b4fdf5cfee0ed21141b38c2d88113c58828c771e813ce2624af127cd", TransactionIndex = new HexBigInteger(new BigInteger(0)) }; var receipt = new TransactionReceipt { }; var txWithReceipt = new TransactionReceiptVO(block, tx, receipt, false); var functionMessage = new TransferFunction { FromAddress = "0x12890d2cce102216644c59dae5baed380d84830c", To = "0x22890d2cce102216644c59dae5baed380d84830c", Value = new BigInteger(101) }; return(new TransactionForFunctionVO <TransferFunction>(txWithReceipt, functionMessage)); }
public object GetTransactionReceiptValue(TransactionReceiptVO transactionReceiptVO) => TxValueCallback?.Invoke(transactionReceiptVO);
public static GenericSearchDocument ToAzureDocument( this TransactionReceiptVO transactionReceiptVO, TransactionReceiptVOIndexDefinition indexDefinition) { return(CreateFieldWithValueDictionary(transactionReceiptVO, indexDefinition.Fields, (field) => field.GetTransactionReceiptValue(transactionReceiptVO))); }
public static Transaction MapToStorageEntityForUpsert(this TransactionReceiptVO transactionReceiptVO) { return(transactionReceiptVO.MapToStorageEntityForUpsert <Transaction>()); }
public static TEntity MapToStorageEntityForUpsert <TEntity>(this TransactionReceiptVO transactionReceiptVO, string code, bool failedCreatingContract) where TEntity : Transaction, new() { return(new TEntity().MapToStorageEntityForUpsert(transactionReceiptVO, code, failedCreatingContract)); }
public static Transaction MapToStorageEntityForUpsert(this TransactionReceiptVO transactionReceiptVO, string code, bool failedCreatingContract) { return(transactionReceiptVO.MapToStorageEntityForUpsert <Transaction>(code, failedCreatingContract)); }
public static TEntity MapToStorageEntityForUpsert <TEntity>(this TransactionReceiptVO transactionReceiptVO) where TEntity : Transaction, new() { return(new TEntity().MapToStorageEntityForUpsert(transactionReceiptVO)); }