예제 #1
0
        public static BlockchainProposalModel ToModel(this BlockchainProposal entity)
        {
            if (entity == null)
            {
                throw new System.ArgumentNullException(nameof(entity));
            }

            var model = new BlockchainProposalModel()
            {
                Name          = entity.Name,
                Url           = entity.Url,
                Hash          = entity.Hash,
                FeeHash       = entity.FeeHash,
                Yeas          = entity.Yeas,
                Nays          = entity.Nays,
                Abstains      = entity.Abstains,
                IsEstablished = entity.IsEstablished ? "Yes" : "No",
                IsValid       = entity.IsValid ? "Yes" : "No",
                IsValidReason = entity.IsValidReason,
                FValid        = entity.FValid ? "Yes" : "No",
                Ratio         = entity.Ratio,
                TotalPayment  = entity.TotalPayment
            };

            return(model);
        }
예제 #2
0
        public static BlockchainProposal ToEntity(this BlockchainProposalJson jsonClass)
        {
            if (jsonClass == null)
            {
                throw new System.ArgumentNullException(nameof(jsonClass));
            }

            var entity = new BlockchainProposal()
            {
                Name          = jsonClass.Name,
                Url           = jsonClass.Url,
                Hash          = jsonClass.Hash,
                FeeHash       = jsonClass.FeeHash,
                Yeas          = jsonClass.Yeas,
                Nays          = jsonClass.Nays,
                Abstains      = jsonClass.Abstains,
                IsEstablished = jsonClass.IsEstablished,
                IsValid       = jsonClass.IsValid,
                IsValidReason = jsonClass.IsValidReason,
                FValid        = jsonClass.FValid,
                Ratio         = jsonClass.Ratio
            };

            return(entity);
        }
예제 #3
0
        public static BlockchainProposal ToEntity(this BlockchainProposalJson jsonClass)
        {
            if (jsonClass == null)
            {
                throw new System.ArgumentNullException(nameof(jsonClass));
            }

            var entity = new BlockchainProposal()
            {
                Name                  = jsonClass.Name,
                Url                   = jsonClass.Url,
                Hash                  = jsonClass.Hash,
                FeeHash               = jsonClass.FeeHash,
                Yeas                  = jsonClass.Yeas,
                Nays                  = jsonClass.Nays,
                Abstains              = jsonClass.Abstains,
                IsEstablished         = jsonClass.IsEstablished,
                IsValid               = jsonClass.IsValid,
                IsValidReason         = jsonClass.IsValidReason,
                FValid                = jsonClass.FValid,
                Ratio                 = jsonClass.Ratio,
                TotalPayment          = jsonClass.TotalPayment,
                TotalPaymentCount     = jsonClass.TotalPaymentCount,
                RemainingPaymentCount = jsonClass.RemainingPaymentCount,
                MonthlyPayment        = jsonClass.MonthlyPayment,
                BlockStart            = jsonClass.BlockStart,
                BlockEnd              = jsonClass.BlockEnd,
                UpdatedAt             = DateTime.Now
            };

            return(entity);
        }
예제 #4
0
        // Builds a complete blockchain proposal with Time to store in the db
        private BlockchainProposal ConstructFullBlockchainProposal(IEnumerable <ProposalPayments> localProposals, BlockchainProposal blockchainProposal, int masternodeCount)
        {
            if (localProposals == null || blockchainProposal == null)
            {
                return(null);
            }

            var entity = new BlockchainProposal();

            entity.Time                  = !string.IsNullOrEmpty(blockchainProposal.FeeHash) ? this.BlockchainRepository.GetTime(blockchainProposal.FeeHash) : null;
            entity.Name                  = blockchainProposal.Name;
            entity.Url                   = blockchainProposal.Url;
            entity.Hash                  = blockchainProposal.Hash;
            entity.FeeHash               = blockchainProposal.FeeHash;
            entity.Yeas                  = blockchainProposal.Yeas;
            entity.Nays                  = blockchainProposal.Nays;
            entity.Abstains              = blockchainProposal.Abstains;
            entity.Ratio                 = blockchainProposal.Ratio;
            entity.IsEstablished         = blockchainProposal.IsEstablished;
            entity.IsValid               = blockchainProposal.IsValid;
            entity.IsValidReason         = blockchainProposal.IsValidReason;
            entity.IsFunded              = this.CalculateIsFunded(blockchainProposal, masternodeCount);
            entity.FValid                = blockchainProposal.FValid;
            entity.TotalPayment          = blockchainProposal.TotalPayment;
            entity.TotalPaymentCount     = blockchainProposal.TotalPaymentCount;
            entity.RemainingPaymentCount = blockchainProposal.RemainingPaymentCount;
            entity.MonthlyPayment        = blockchainProposal.MonthlyPayment;
            entity.BlockStart            = blockchainProposal.BlockStart;
            entity.BlockEnd              = blockchainProposal.BlockEnd;
            entity.UpdatedAt             = DateTime.Now;
            return(entity);
        }
예제 #5
0
        private bool CalculateIsFunded(BlockchainProposal blockchainProposal, int masternodeCount)
        {
            if (masternodeCount <= 0)
            {
                return(false);
            }

            var fundedThreshold = this.IConfiguration.GetValue <int>("FundedThreshold");

            return((blockchainProposal.Yeas - blockchainProposal.Nays) / masternodeCount > fundedThreshold ? true : false);
        }
예제 #6
0
        // Builds a complete blockchain proposal
        // with local, manually-entered payment amount and time (for ui)
        private async Task <BlockchainProposalModel> ConstructBlockchainProposalModel(IQueryable <ProposalPayments> localProposals, BlockchainProposal blockchainProposal)
        {
            if (localProposals == null || blockchainProposal == null)
            {
                return(null);
            }

            var model = new BlockchainProposalModel();

            var blockLocalProposalMatch = await localProposals.OrderByDescending(x => x.CreatedAt).FirstOrDefaultAsync(x => x.Hash == blockchainProposal.Hash);

            var masternodeCount = await this.MasternodeCountRepository.GetLatestLocalMasternodeCount();

            if (masternodeCount == null)
            {
                return(null);
            }

            if (blockLocalProposalMatch != null)
            {
                model.Amount = blockchainProposal.TotalPayment == 0.0m ? blockLocalProposalMatch.Amount : Convert.ToInt32(blockchainProposal.TotalPayment) + blockLocalProposalMatch.Amount;
            }

            model.Time          = blockchainProposal.Time.ToString();
            model.Name          = blockchainProposal.Name;
            model.Url           = blockchainProposal.Url;
            model.Hash          = blockchainProposal.Hash;
            model.FeeHash       = blockchainProposal.FeeHash;
            model.Yeas          = blockchainProposal.Yeas;
            model.Nays          = blockchainProposal.Nays;
            model.Abstains      = blockchainProposal.Abstains;
            model.Ratio         = blockchainProposal.Ratio;
            model.IsEstablished = blockchainProposal.IsEstablished ? "Yes" : "No";
            model.IsValid       = blockchainProposal.IsValid ? "Yes" : "No";
            model.IsFunded      = blockchainProposal.IsFunded ? "Yes" : "No";
            model.IsValidReason = blockchainProposal.IsValidReason;
            model.FValid        = blockchainProposal.FValid ? "Yes" : "No";
            model.TotalPayment  = blockchainProposal.TotalPayment;
            return(model);
        }
예제 #7
0
        private BlockchainProposalModel CreateBlockchainProposalModel(IEnumerable <ProposalPaymentsModel> localProposals, BlockchainProposal blockchainProposal)
        {
            if (localProposals == null || blockchainProposal == null)
            {
                return(null);
            }

            var model = new BlockchainProposalModel();
            var blockLocalProposalMatch = localProposals.OrderByDescending(x => x.DateCreated).FirstOrDefault(x => x.Hash == blockchainProposal.Hash);

            if (blockLocalProposalMatch != null)
            {
                model.Amount = blockLocalProposalMatch.Amount;
            }

            model.Time          = !string.IsNullOrEmpty(blockchainProposal.FeeHash) ? this.BlockchainRepository.GetTime(blockchainProposal.FeeHash) : null;
            model.Name          = blockchainProposal.Name;
            model.Url           = blockchainProposal.Url;
            model.Hash          = blockchainProposal.Hash;
            model.FeeHash       = blockchainProposal.FeeHash;
            model.Yeas          = blockchainProposal.Yeas;
            model.Nays          = blockchainProposal.Nays;
            model.Abstains      = blockchainProposal.Abstains;
            model.Ratio         = Math.Round(blockchainProposal.Ratio, 2);
            model.IsEstablished = blockchainProposal.IsEstablished ? "Yes" : "No";
            model.IsValid       = blockchainProposal.IsValid ? "Yes" : "No";
            model.IsValidReason = blockchainProposal.IsValidReason;
            model.FValid        = blockchainProposal.FValid ? "Yes" : "No";
            return(model);
        }