public GenericResponse DeleteLocalChain() { try { DataServices dataService = new DataServices(); if (dataService.HasLocalChainData()) { dataService.DeleteLocalChain(); } ApplicationLog.Info("Local chain data deleted successfully."); return(new GenericResponse(null, ResponseCodes.Success, ResponseMessages.Success)); } catch (ValidationException vex) { ApplicationLog.Warn("ValidationException [" + vex.Code + "]: " + vex.Message); return(new GenericResponse(null, vex.Code, vex.Message)); } catch (Exception ex) { ApplicationLog.Exception(ex); return(new GenericResponse(null, ResponseCodes.Error, ResponseMessages.Error)); } }
public GenericResponse GetBlocks(int fromIndex, int toIndex) { try { if (toIndex < fromIndex) { return(new GenericResponse(null, ResponseCodes.ViewBlocksInvalidIndex, ResponseMessages.ViewBlocksInvalidIndex)); } if ((toIndex - fromIndex) > 100) { return(new GenericResponse(null, ResponseCodes.ViewBlocksTooMany, ResponseMessages.ViewBlocksTooMany)); } ViewerServices viewerService = new ViewerServices(); var blocks = viewerService.GetBlocks(fromIndex, toIndex); return(new GenericResponse(blocks, ResponseCodes.Success, ResponseMessages.Success)); } catch (ValidationException vex) { ApplicationLog.Warn("ValidationException [" + vex.Code + "]: " + vex.Message); return(new GenericResponse(null, vex.Code, vex.Message)); } catch (Exception ex) { ApplicationLog.Exception(ex); return(new GenericResponse(null, ResponseCodes.Error, ResponseMessages.Error)); } }
public GenericResponse GetOrders(string tradingPair) { try { IndexServices indexServices = new IndexServices(); var orders = indexServices.OrderIndex.GetByTradingPair(tradingPair); if (orders != null) { orders = orders.OrderByDescending(x => x.Price).ToList(); return(new GenericResponse(orders, ResponseCodes.Success, ResponseMessages.Success)); } else { return(new GenericResponse(null, ResponseCodes.Success, ResponseMessages.Success)); } } catch (ValidationException vex) { ApplicationLog.Warn("ValidationException [" + vex.Code + "]: " + vex.Message); return(new GenericResponse(null, vex.Code, vex.Message)); } catch (Exception ex) { ApplicationLog.Exception(ex); return(new GenericResponse(null, ResponseCodes.Error, ResponseMessages.Error)); } }
public GenericResponse CreateNewChain(string ownerAddress) { try { DataServices dataService = new DataServices(); if (dataService.HasLocalChainData()) { throw new Exception("Chain folder is not empty. Please delete the existing chain folder first before creating a new chain."); } ApplicationLog.Info("Creating new chain..."); dataService.CreateGenesisBlock( ownerAddress, Settings.NewChainSetup.NativeTokenName, Settings.NewChainSetup.NativeTokenSymbol, Settings.NewChainSetup.InitialSupply, Settings.NewChainSetup.Decimals); ApplicationLog.Info("Chain created successfully."); return(new GenericResponse("Chain created successfully.", ResponseCodes.Success, ResponseMessages.Success)); } catch (ValidationException vex) { ApplicationLog.Warn("ValidationException [" + vex.Code + "]: " + vex.Message); return(new GenericResponse(null, vex.Code, vex.Message)); } catch (Exception ex) { ApplicationLog.Exception(ex); return(new GenericResponse(null, ResponseCodes.Error, ResponseMessages.Error)); } }
public GenericResponse Transfer(TransactionTransferRequest value) { try { VerifySignature(value.Body, value.Signature, value.Body.Sender); if (!ApplicationState.IsChainUpToDate) { return(new GenericResponse(null, ResponseCodes.Success, ResponseMessages.NodeNotConsensusReady)); } //Perform transaction TransactionServices transactionService = new TransactionServices(); string txId = transactionService.AddTransfer( value.Body.Nonce, Convert.ToDecimal(value.Body.Fee), value.Body.TokenSymbol, value.Body.Sender, value.Body.ToAddress, Convert.ToDecimal(value.Body.Amount)); ApplicationLog.Info("Transaction added to queue for next block. TxId: " + txId); return(new GenericResponse(txId, ResponseCodes.Success, "Transaction added to queue for next block.")); } catch (ValidationException vex) { ApplicationLog.Warn("ValidationException [" + vex.Code + "]: " + vex.Message); return(new GenericResponse(null, vex.Code, vex.Message)); } catch (Exception ex) { ApplicationLog.Exception(ex); return(new GenericResponse(null, ResponseCodes.Error, ResponseMessages.Error)); } }
public GenericResponse AddOrderMarket(TransactionOrderMarketRequest value) { try { VerifySignature(value.Body, value.Signature, value.Body.Owner); if (!ApplicationState.IsChainUpToDate) { return(new GenericResponse(null, ResponseCodes.Success, ResponseMessages.NodeNotConsensusReady)); } //Perform transaction TransactionServices transactionService = new TransactionServices(); List <string> txIds = transactionService.AddMarketOrder( value.Body.Nonce, Convert.ToDecimal(value.Body.Fee), value.Body.PairSymbol, value.Body.Side, Convert.ToDecimal(value.Body.Amount), value.Body.Owner); ApplicationLog.Info("Transaction added to queue for next block."); return(new GenericResponse(txIds, ResponseCodes.Success, "Transaction added to queue for next block.")); } catch (ValidationException vex) { ApplicationLog.Warn("ValidationException [" + vex.Code + "]: " + vex.Message); return(new GenericResponse(null, vex.Code, vex.Message)); } catch (Exception ex) { ApplicationLog.Exception(ex); return(new GenericResponse(null, ResponseCodes.Error, ResponseMessages.Error)); } }
public void Warn(string message, Exception exception = null) { if (string.IsNullOrWhiteSpace(message)) { return; } message = string.Concat(LogPrefix, message); ApplicationLog.Warn(message, exception); }
public GenericResponse GetPending() { try { ViewerServices viewerService = new ViewerServices(); var pending = viewerService.GetPending(); return(new GenericResponse(pending, ResponseCodes.Success, ResponseMessages.Success)); } catch (ValidationException vex) { ApplicationLog.Warn("ValidationException [" + vex.Code + "]: " + vex.Message); return(new GenericResponse(null, vex.Code, vex.Message)); } catch (Exception ex) { ApplicationLog.Exception(ex); return(new GenericResponse(null, ResponseCodes.Error, ResponseMessages.Error)); } }
public GenericResponse GetWalletBalance(string address, string tokenSymbol) { try { ViewerServices viewerServices = new ViewerServices(); decimal?balance = viewerServices.GetWalletBalance(address, tokenSymbol); return(new GenericResponse(balance, ResponseCodes.Success, ResponseMessages.Success)); } catch (ValidationException vex) { ApplicationLog.Warn("ValidationException [" + vex.Code + "]: " + vex.Message); return(new GenericResponse(null, vex.Code, vex.Message)); } catch (Exception ex) { ApplicationLog.Exception(ex); return(new GenericResponse(null, ResponseCodes.Error, ResponseMessages.Error)); } }