Example #1
0
 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));
     }
 }
Example #2
0
        public GenericResponse GetAllTokens()
        {
            try
            {
                IndexServices indexService = new IndexServices();
                var           index        = indexService.TokenIndex.GetAll();

                return(new GenericResponse(index, ResponseCodes.Success, ResponseMessages.Success));
            }
            catch (Exception ex)
            {
                ApplicationLog.Exception(ex);
                return(new GenericResponse(null, ResponseCodes.Error, ResponseMessages.Error));
            }
        }
Example #3
0
        public GenericResponse RebuildIndex()
        {
            try
            {
                IndexServices indexServices = new IndexServices();
                indexServices.DeleteIndexForAllBlocks();
                indexServices.UpdateIndexForAllBlocks();

                return(new GenericResponse(null, ResponseCodes.Success, ResponseMessages.Success));
            }
            catch (Exception ex)
            {
                ApplicationLog.Exception(ex);
                return(new GenericResponse(null, ResponseCodes.Error, ResponseMessages.Error));
            }
        }
Example #4
0
        public GenericResponse RegisterNodeAnnouncement(string serverAddress, string walletAddress, string signature)
        {
            try
            {
                VerifySignature(walletAddress, signature, walletAddress);

                //Get wallet balance
                decimal       walletBalance = 0;
                IndexServices indexServices = new IndexServices();
                var           nativeToken   = indexServices.TokenIndex.GetNative();
                if (nativeToken != null) //Native token would be null if chain has not yet been sync / no local chain
                {
                    var walletIndex = indexServices.BalanceIndex.Get(walletAddress, indexServices.TokenIndex.GetNative().Symbol);
                    if (walletIndex != null)
                    {
                        walletBalance = walletIndex.Balance;
                    }
                }

                //Add node to consensus
                Node node = new Node()
                {
                    ServerAddress = serverAddress,
                    WalletAddress = walletAddress,
                    Signature     = signature,
                    Balance       = walletBalance
                };

                ConsensusServices consensusService = new ConsensusServices();
                consensusService.AddConsensusNode(node);

                ApplicationLog.Info("Registered node: " + node.ServerAddress);

                return(new GenericResponse(null, ResponseCodes.Success, ResponseMessages.Success));
            }
            catch (Exception ex)
            {
                ApplicationLog.Exception(ex);
                return(new GenericResponse(null, ResponseCodes.Error, ResponseMessages.Error));
            }
        }