public async Task UpsertAsync() { var contractAddress = "0x26bc47888b7bfdf77db41ec0a2fb4db00af1c92a"; var code = "0x6080604052600436106053576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680635589f21d14605857806388a6f572146076578063ddca3f4314609e575b600080fd5b60746004803603810190808035906020019092919050505060c6565b005b348015608157600080fd5b50608860d0565b6040518082815260200191505060405180910390f35b34801560a957600080fd5b5060b060d9565b6040518082815260200191505060405180910390f35b8060008190555050565b60008054905090565b600054815600a165627a7a723058205345477b840b4fb7b6401abdcd3ab98ae1db0d342e6c6b4b45a4e2b10f6ae1f80029"; var transaction = new Nethereum.RPC.Eth.DTOs.Transaction { From = "0xe6de16a66e5cd7270cc36a851818bc092884fe64", TransactionHash = "0xcb00b69d2594a3583309f332ada97d0df48bae00170e36a4f7bbdad7783fc7e5" }; Assert.False(await _repo.ExistsAsync(contractAddress)); Assert.False(_repo.IsCached(contractAddress)); await _repo.UpsertAsync(contractAddress, code, transaction); 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 async Task UpsertAsync(string contractAddress, string code, Transaction transaction) { using (var context = _contextFactory.CreateContext()) { var contract = await context.Contracts.FindByContractAddressAsync(contractAddress).ConfigureAwait(false) ?? new Contract(); contract.Map(contractAddress, code, transaction); contract.UpdateRowDates(); if (contract.IsNew()) { context.Contracts.Add(contract); } else { context.Contracts.Update(contract); } await context.SaveChangesAsync().ConfigureAwait(false); _cachedContracts.AddOrUpdate(contract.Address, contract, (s, existingContract) => contract); } }
public async Task UpsertAsync(string contractAddress, string code, Transaction transaction) { var contract = Contract.CreateContract(contractAddress, code, transaction); await UpsertAsync(contract).ConfigureAwait(false); CachedContracts.AddOrUpdate(contract.Address, contract, (s, existingContract) => contract); }
public static void Map(this AddressTransaction to, Nethereum.RPC.Eth.DTOs.Transaction @from, string address) { to.BlockNumber = @from.BlockNumber.Value.ToString(); to.Hash = @from.TransactionHash; to.Address = address; }
public async Task UpsertAsync(string contractAddress, string code, Transaction transaction) { var contract = Contract.CreateContract(Table, contractAddress, code, transaction); await contract.InsertOrReplaceAsync().ConfigureAwait(false); }
public static void Map(this Contract contract, string contractAddress, string code, Nethereum.RPC.Eth.DTOs.Transaction transaction) { contract.Address = contractAddress; contract.Code = code; contract.TransactionHash = transaction.TransactionHash; contract.Creator = transaction.From; }