Exemplo n.º 1
0
        public async Task <IActionResult> AddCommitmentPunishmentPair([FromQuery] string commitment,
                                                                      [FromQuery] string punishment, [FromQuery] bool overwrite = false)
        {
            if (string.IsNullOrEmpty(commitment) || string.IsNullOrEmpty(punishment))
            {
                return(BadRequest("Passed parameters should not be null or empty"));
            }
            else
            {
                try
                {
                    Transaction cTx = new Transaction(commitment);
                    Transaction pTx = new Transaction(punishment);

                    using (OffchainMonitorContext context = new OffchainMonitorContext())
                    {
                        var matchedCommitment = (from c in context.Commitments
                                                 where c.CommitmentTxId == cTx.GetHash().ToString()
                                                 select c).FirstOrDefault();

                        if (matchedCommitment != null)
                        {
                            if (overwrite == false)
                            {
                                return(BadRequest("To overwrite an existing punishment for existing commitment id, the overwrite flag should bet set to true"));
                            }
                            else
                            {
                                matchedCommitment.Commitment = commitment;
                                matchedCommitment.Punishment = punishment;
                            }
                        }
                        else
                        {
                            var newlyAddedCommitment = new CommitmentEntity
                            {
                                Commitment     = commitment,
                                CommitmentTxId = cTx.GetHash().ToString(),
                                Punishment     = punishment
                            };

                            await context.Commitments.AddAsync(newlyAddedCommitment);
                        }

                        await context.SaveChangesAsync();
                    }
                }
                catch (Exception exp)
                {
                    throw exp;
                }

                return(Ok());
            }
        }
Exemplo n.º 2
0
        private void AddCommitmentDetails()
        {
            ICommitment commitment = new CommitmentEntity();

            BuildCommitmentEntity(commitment);

            if (ViewState["CommittmentDetails"] != null)
            {
                commitmentDetails = ViewState["CommittmentDetails"] as List <ICommitment>;
            }

            commitmentDetails.Add(commitment);

            gvwSalesCall.DataSource = commitmentDetails;
            gvwSalesCall.DataBind();

            ViewState["CommittmentDetails"] = commitmentDetails;
            ClearCommitmentDetail();
        }
Exemplo n.º 3
0
        public static List <ICommitment> GetCommitments(int callId)
        {
            string             strExecution  = "[common].[uspGetCommitments]";
            List <ICommitment> lstCommitment = new List <ICommitment>();

            using (DbQuery oDq = new DbQuery(strExecution))
            {
                oDq.AddIntegerParam("@CallId", callId);
                DataTableReader reader = oDq.GetTableReader();

                while (reader.Read())
                {
                    ICommitment loc = new CommitmentEntity(reader);
                    lstCommitment.Add(loc);
                }

                reader.Close();
            }

            return(lstCommitment);
        }
        private bool TransactionsMatch(CommitmentEntity c, BalanceOperation op)
        {
            var commitmentTx = new Transaction(c.Commitment);

            foreach (var input in commitmentTx.Inputs)
            {
                if (!op.SpentCoins.Select(sp => sp.Outpoint.Hash == input.PrevOut.Hash && sp.Outpoint.N == input.PrevOut.N).Any())
                {
                    return(false);
                }
            }

            foreach (var output in commitmentTx.Outputs)
            {
                if (!op.ReceivedCoins.Select(rc => rc.GetScriptCode() == output.ScriptPubKey).Any())
                {
                    return(false);
                }
            }

            return(true);
        }
 internal static void CreateCommitment(CommitmentEntity commitment, EnvironmentVariables environmentVariables)
 {
     using (var connection = new SqlConnection(environmentVariables.DedsDatabaseConnectionString))
     {
         connection.Execute("INSERT INTO DasCommitments ("
                            + "CommitmentId, "
                            + "VersionId, "
                            + "Uln, "
                            + "Ukprn, "
                            + "AccountId, "
                            + "StartDate, "
                            + "EndDate, "
                            + "AgreedCost, "
                            + "StandardCode, "
                            + "ProgrammeType, "
                            + "FrameworkCode, "
                            + "PathwayCode, "
                            + "PaymentStatus, "
                            + "PaymentStatusDescription, "
                            + "Priority, "
                            + "EffectiveFromDate, "
                            + "EffectiveToDate"
                            + ") VALUES ("
                            + "@commitmentId, "
                            + "@versionId, "
                            + "@uln, "
                            + "@ukprn, "
                            + "@accountId, "
                            + "@startDate, "
                            + "@endDate, "
                            + "@agreedCost, "
                            + "@standardCode, "
                            + "@programmeType, "
                            + "@frameworkCode, "
                            + "@pathwayCode, "
                            + "@paymentStatus, "
                            + "@paymentStatusDescription, "
                            + "@priority, "
                            + "@effectiveFromDate, "
                            + "@effectiveToDate"
                            + ")",
                            new
         {
             commitmentId             = commitment.CommitmentId,
             ukprn                    = commitment.Ukprn,
             uln                      = commitment.Uln,
             accountId                = commitment.AccountId,
             startDate                = commitment.StartDate,
             endDate                  = commitment.EndDate,
             agreedCost               = commitment.AgreedCost,
             standardCode             = commitment.StandardCode > 0 ? commitment.StandardCode : (long?)null,
             frameworkCode            = commitment.FrameworkCode > 0 ? commitment.FrameworkCode : (int?)null,
             programmeType            = commitment.ProgrammeType > 0 ? commitment.ProgrammeType : (int?)null,
             pathwayCode              = commitment.PathwayCode > 0 ? commitment.PathwayCode : (int?)null,
             priority                 = commitment.Priority,
             versionId                = commitment.VersionId,
             paymentStatus            = commitment.PaymentStatus,
             paymentStatusDescription = commitment.PaymentStatusDescription,
             effectiveFromDate        = commitment.EffectiveFrom,
             effectiveToDate          = commitment.EffectiveTo
         });
     }
 }
Exemplo n.º 6
0
        public async Task <IActionResult> AddCommitmentPunishmentPairOldDesign([FromQuery] string commitment,
                                                                               [FromQuery] string punishment)
        {
            if (string.IsNullOrEmpty(commitment) || string.IsNullOrEmpty(punishment))
            {
                return(BadRequest("Passed parameters should not be null or empty"));
            }
            else
            {
                Transaction cTx = new Transaction(commitment);
                Transaction pTx = new Transaction(punishment);

                try
                {
                    using (OffchainMonitorContext context = new OffchainMonitorContext())
                    {
                        var newlyAddedCommitment = new CommitmentEntity
                        {
                            Commitment = commitment,
                            Punishment = punishment
                        };

                        bool found    = false;
                        var  multisig = await settingsRepository.Get <string>("multisig");

                        var netwok = await Helper.GetNetwork(settingsRepository);

                        for (int i = 0; i < cTx.Inputs.Count; i++)
                        {
                            var prevHash = cTx.Inputs[i].PrevOut.Hash.ToString();
                            var prevTx   = await bitcoinTransactionService.GetTransaction(prevHash);

                            var prevOut = cTx.Inputs[i].PrevOut;
                            if (prevTx.Outputs[prevOut.N].ScriptPubKey.GetDestinationAddress(netwok).ToString()
                                == multisig)
                            {
                                found = true;

                                var existingMultisigOutput = (from o in context.MultisigOutputs
                                                              where o.TransactionId == prevOut.Hash.ToString() && o.OutputNumber == prevOut.N
                                                              select o).FirstOrDefault();
                                if (existingMultisigOutput == null)
                                {
                                    var newMultisigOutput = new MultisigOutputEntity();
                                    newMultisigOutput.TransactionId = prevOut.Hash.ToString();
                                    newMultisigOutput.OutputNumber  = (int)prevOut.N;
                                    newMultisigOutput.LastSeen      = DateTime.UtcNow;
                                    await context.MultisigOutputs.AddAsync(newMultisigOutput);

                                    existingMultisigOutput = newMultisigOutput;
                                }

                                existingMultisigOutput.LastSeen = DateTime.UtcNow;
                                existingMultisigOutput.Commitments.Add(newlyAddedCommitment);

                                newlyAddedCommitment.CommitmentOutput = existingMultisigOutput;
                                await context.Commitments.AddAsync(newlyAddedCommitment);
                            }
                        }

                        if (!found)
                        {
                            return(BadRequest(string.Format("The provide transaction does not pay to multisig:{0}", multisig)));
                        }

                        await context.SaveChangesAsync();
                    }
                    return(Ok());
                }
                catch (Exception exp)
                {
                    throw exp;
                }
            }
        }