private async Task <IResponse <NoValue> > TestConnection(CryptoAdapterModel cryptoAdapter) { var response = new Response <NoValue>(); var nodeType = cryptoAdapter.NodeType; switch (nodeType) { case AdapterTypeItemEnum.Ethereum: var adapter = new EthereumAdapter(_logger); if (cryptoAdapter.Direction == DirectionEnum.Destination) { response = await adapter.TestConnectionDestination(cryptoAdapter); } else { response = await adapter.TestConnectionSource(cryptoAdapter); } break; case AdapterTypeItemEnum.Cardano: break; case AdapterTypeItemEnum.EOS: break; case AdapterTypeItemEnum.NEO: var neoAdapter = new NEOAdapter(_logger); response = await neoAdapter.TestConnectionSource(cryptoAdapter); break; case AdapterTypeItemEnum.Bitcoin: var btcAdapter = new BitcoinAdapter(_logger); var btcUsername = cryptoAdapter.Properties.SelectMany(p => p.SourceProperties).FirstOrDefault(sp => sp.Id == (long)PropertyEnum.RpcUsername).Value; var btcPassword = cryptoAdapter.Properties.SelectMany(p => p.SourceProperties).FirstOrDefault(sp => sp.Id == (long)PropertyEnum.RpcPassword).Value; response = btcAdapter.TestConnectionSource(cryptoAdapter, btcUsername, btcPassword); break; case AdapterTypeItemEnum.Litecoin: var ltcAdapter = new LitecoinAdapter(_logger); var ltcUsername = cryptoAdapter.Properties.SelectMany(p => p.SourceProperties).FirstOrDefault(sp => sp.Id == (long)PropertyEnum.RpcUsername).Value; var ltcPassword = cryptoAdapter.Properties.SelectMany(p => p.SourceProperties).FirstOrDefault(sp => sp.Id == (long)PropertyEnum.RpcPassword).Value; response = ltcAdapter.TestConnectionSource(cryptoAdapter, ltcUsername, ltcPassword); break; } return(response); }
public async Task <Response <List <T> > > GetBlocksWithTransactions <T>(long adapterId, int fromBlock, int toBlock, string address) { var response = new Response <List <T> >() { Value = new List <T>() }; try { var cryptoAdapter = _entities.Adapter.Find(adapterId).CryptoAdapter.FirstOrDefault(); var cryptoAdapterModel = new CryptoAdapterModel { Id = cryptoAdapter.Id, RpcAddr = cryptoAdapter.RpcAddr, RpcPort = Convert.ToUInt16(cryptoAdapter.RpcPort) }; if (typeof(T) == typeof(EthereumBlockModel)) { var ethereumResponse = new Response <List <EthereumBlockModel> >() { Value = new List <EthereumBlockModel>() }; var adapter = new EthereumAdapter(_logger); ethereumResponse = await adapter.GetBlocksWithTransactions(cryptoAdapterModel, fromBlock, toBlock, address); response = (Response <List <T> >)Convert.ChangeType(ethereumResponse, typeof(Response <List <T> >)); } else if (typeof(T) == typeof(BitcoinBlockModel)) { var bitcoinResponse = new Response <List <BitcoinBlockModel> >() { Value = new List <BitcoinBlockModel>() }; var username = cryptoAdapter.CryptoAdapterProperty.FirstOrDefault(cap => cap.PropertyId == (long)PropertyEnum.RpcUsername).Value; var password = cryptoAdapter.CryptoAdapterProperty.FirstOrDefault(cap => cap.PropertyId == (long)PropertyEnum.RpcPassword).Value; var adapter = new BitcoinAdapter(_logger); bitcoinResponse = adapter.GetBlocksWithTransactions(cryptoAdapterModel, username, password, fromBlock, toBlock, address); response = (Response <List <T> >)Convert.ChangeType(bitcoinResponse, typeof(Response <List <T> >)); } else if (typeof(T) == typeof(LitecoinBlockModel)) { var litecoinResponse = new Response <List <LitecoinBlockModel> >() { Value = new List <LitecoinBlockModel>() }; var username = cryptoAdapter.CryptoAdapterProperty.FirstOrDefault(cap => cap.PropertyId == (long)PropertyEnum.RpcUsername).Value; var password = cryptoAdapter.CryptoAdapterProperty.FirstOrDefault(cap => cap.PropertyId == (long)PropertyEnum.RpcPassword).Value; var adapter = new LitecoinAdapter(_logger); litecoinResponse = adapter.GetBlocksWithTransactions(cryptoAdapterModel, username, password, fromBlock, toBlock, address); response = (Response <List <T> >)Convert.ChangeType(litecoinResponse, typeof(Response <List <T> >)); } else if (typeof(T) == typeof(NeoBlockModel)) { var neoResponse = new Response <List <NeoBlockModel> >() { Value = new List <NeoBlockModel>() }; var adapter = new NEOAdapter(_logger); neoResponse = await adapter.GetBlocksWithTransactions(cryptoAdapterModel, fromBlock, toBlock, address); response = (Response <List <T> >)Convert.ChangeType(neoResponse, typeof(Response <List <T> >)); } } catch (Exception ex) { response.Status = StatusEnum.Error; response.Message = Message.SomethingWentWrong; _logger.Information($"BlockchainService.GetBlocksWithTransactions(adapterId: {adapterId}, fromBlock: {fromBlock}), toBlock: {toBlock}, address: {address}"); _logger.Error(ex.Message); } return(response); }
public async Task <Response <int> > GetCurrentBlockNumber(long adapterId, AdapterTypeItemEnum adapterType) { var response = new Response <int>(); try { var cryptoAdapter = _entities.Adapter.Find(adapterId).CryptoAdapter.FirstOrDefault(); var cryptoAdapterModel = new CryptoAdapterModel { RpcAddr = cryptoAdapter.RpcAddr }; if (cryptoAdapter.RpcPort != null) { cryptoAdapterModel.RpcPort = UInt16.Parse(cryptoAdapter.RpcPort); } switch (adapterType) { case AdapterTypeItemEnum.Ethereum: var ethAdapter = new EthereumAdapter(_logger); response = await ethAdapter.GetCurrentBlockNumber(cryptoAdapterModel); break; case AdapterTypeItemEnum.Bitcoin: var btcUsername = cryptoAdapter.CryptoAdapterProperty.FirstOrDefault(cap => cap.PropertyId == (long)PropertyEnum.RpcUsername).Value; var btcPassword = cryptoAdapter.CryptoAdapterProperty.FirstOrDefault(cap => cap.PropertyId == (long)PropertyEnum.RpcPassword).Value; var btcAdapter = new BitcoinAdapter(_logger); response = btcAdapter.GetCurrentBlockNumber(cryptoAdapterModel, btcUsername, btcPassword); break; case AdapterTypeItemEnum.NEO: var neoAdapter = new NEOAdapter(_logger); response = await neoAdapter.GetCurrentBlockNumber(cryptoAdapterModel); break; case AdapterTypeItemEnum.Litecoin: var ltcUsername = cryptoAdapter.CryptoAdapterProperty.FirstOrDefault(cap => cap.PropertyId == (long)PropertyEnum.RpcUsername).Value; var ltcPassword = cryptoAdapter.CryptoAdapterProperty.FirstOrDefault(cap => cap.PropertyId == (long)PropertyEnum.RpcPassword).Value; var ltcAdapter = new LitecoinAdapter(_logger); response = ltcAdapter.GetCurrentBlockNumber(cryptoAdapterModel, ltcUsername, ltcPassword); break; default: break; } } catch (Exception ex) { response.Status = StatusEnum.Error; response.Message = Message.SomethingWentWrong; _logger.Information($"BlockchainService.GetCurrentBlockNumber(adapterId: {adapterId}, adapterType: {adapterType}"); _logger.Error(ex.Message); } return(response); }