Example #1
0
        private void CheckTransactionTypeValues(TransactionSubType expectedSubType)
        {
            var expectedName = GetAttributeName(expectedSubType);

            var actual = _getConstantsReply.TransactionTypes
                         [TransactionTypeMapper.GetMainTypeByte(expectedSubType)]
                         [TransactionTypeMapper.GetSubTypeByte(expectedSubType)];

            if (actual == null)
            {
                Logger.Fail($"Did not find expected transaction type {expectedName}");
                return;
            }
            if (!actual.Name.Equals(expectedName))
            {
                Logger.Fail($"Transaction type name mismatch, expected: {expectedName}, actual: {actual.Name}");
            }
            else
            {
                var expectedValues = _transactionTypes[expectedSubType];
                AssertEquals(expectedValues.CanHaveRecipient, actual.CanHaveRecipient, "CanHaveRecipient");
                AssertEquals(expectedValues.IsPhasingSafe, actual.IsPhasingSafe, "IsPhasingSafe");
                AssertEquals(expectedValues.MustHaveRecipient, actual.MustHaveRecipient, "MustHaveRecipient");
            }
        }
Example #2
0
        /// <summary>
        /// Gets the transactionSubType.
        /// </summary>
        /// <param name="transactionSubTypeId">The transactionSubType id.</param>
        /// <returns></returns>
        public static TransactionSubType GetTransactionSubType(int transactionSubTypeId)
        {
            TransactionSubType transactionSubType = new TransactionSubType();

            try
            {
                transactionSubType = CacheManager.Get <TransactionSubType>(transactionSubTypeId);
                if (transactionSubType == null)
                {
                    transactionSubType =
                        CBO <TransactionSubType> .FillObject(
                            DataAccessProvider.Instance().GetTransactionSubType(transactionSubTypeId));

                    if (transactionSubType != null)
                    {
                        CacheManager.Add(transactionSubType);
                    }
                }
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, "Business Logic"))
                {
                    throw;
                }
            }
            return(transactionSubType);
        }
Example #3
0
        private static bool CanBeAmendedBy(this Transaction sourceTran, TransactionBookData tranData)
        {
            TransactionSubType tranSubType = tranData.SubType;

            if (tranSubType == TransactionSubType.Amend)
            {
                Order order = sourceTran.FirstOrder;
                return(sourceTran.OrderCount == 1 &&
                       order.IsOpen &&
                       tranData.SourceOrderId != null &&
                       order.Id == tranData.SourceOrderId &&
                       sourceTran.AccountId == tranData.AccountId &&
                       sourceTran.InstrumentId == tranData.InstrumentId &&
                       sourceTran.Type == tranData.Type &&
                       sourceTran.OrderType == tranData.OrderType &&
                       sourceTran.ContractSize(null) == tranData.ContractSize &&
                       sourceTran.BeginTime == tranData.BeginTime &&
                       sourceTran.EndTime == tranData.EndTime &&
                       sourceTran.SubmitTime == tranData.SubmitTime &&
                       sourceTran.ExecuteTime == tranData.ExecuteTime &&
                       sourceTran.SubmitorId == tranData.SubmitorId &&
                       sourceTran.ApproverId == tranData.ApproverId);
            }
            else
            {
                return(false);
            }
        }
Example #4
0
        /// <summary>
        /// Saves the transactionSubType.
        /// </summary>
        /// <param name="transactionSubType">The transactionSubType.</param>
        /// <returns></returns>
        public static int SaveTransactionSubType(TransactionSubType transactionSubType)
        {
            try
            {
                if (transactionSubType.IsValid)
                {
                    // Save entity
                    transactionSubType.Id = DataAccessProvider.Instance().SaveTransactionSubType(transactionSubType);
                    if (transactionSubType.Id != -1)
                    {
                        FrameworkController.GetChecksum(transactionSubType);
                        CacheManager.Add(transactionSubType);
                    }
                }
                else
                {
                    // Entity is not valid
                    throw new InValidBusinessObjectException(transactionSubType);
                }
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, "Business Logic"))
                {
                    throw;
                }
            }

            // Done
            return(transactionSubType.Id);
        }
        public static TransactionSubType PopulateNewItem()
        {
            TransactionSubType transactionSubType = new TransactionSubType();

            transactionSubType.Code        = Guid.NewGuid().ToString().Substring(0, 9);;
            transactionSubType.Description = "Test";
            transactionSubType.UpdatedBy   = "test";
            return(transactionSubType);
        }
 public void SaveItem()
 {
     using (TransactionScope scope = new TransactionScope())
     {
         TransactionSubType transactionSubType = PopulateNewItem();
         transactionSubType.Id = SaveItem(transactionSubType);
         Assert.IsTrue(transactionSubType.Id != -1);
     }
 }
        public void SaveTransactionSubTypeTestConstraint()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                TransactionSubType transactionSubType = PopulateNewItem();

                SaveItem(transactionSubType);

                SaveItem(transactionSubType);
            }
        }
 public void DeleteItem()
 {
     using (TransactionScope scope = new TransactionScope())
     {
         int id = SaveItem(PopulateNewItem());
         if (id != -1)
         {
             TransactionSubType transactionSubTypeToDelete = new TransactionSubType();
             transactionSubTypeToDelete.Id = id;
             Assert.IsTrue(DeleteItem(transactionSubTypeToDelete));
         }
     }
 }
Example #9
0
 internal Attachment GetAttachment(TransactionSubType transactionSubType)
 {
     if (_attachments != null)
     {
         var attachment = AttachmentFuncs[transactionSubType].Invoke(_attachments);
         return(attachment);
     }
     if (_reader != null)
     {
         var attachment = BinaryAttachmentFuncs[transactionSubType].Invoke(_reader, _transactionVersion);
         return(attachment);
     }
     return(null);
 }
        public void UpdateTransactionSubType()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                TransactionSubType transactionSubType = PopulateNewItem();
                transactionSubType.Description = "Original";
                transactionSubType.Id          = SaveItem(transactionSubType);
                transactionSubType             = GetItem(transactionSubType.Id);
                //change a value
                transactionSubType.Description = "Updated";

                SaveItem(transactionSubType);
                transactionSubType = GetItem(transactionSubType.Id);
                Assert.IsTrue(transactionSubType.Description == "Updated");
            }
        }
        public long SaveTransactionSubType(TransactionSubType transactionSubType, string userId)
        {
            var transactionSubTypeDTO = new DTO.TransactionSubTypeDTO()
            {
                TransactionSubTypeId = transactionSubType.TransactionSubTypeId,
                Name = transactionSubType.Name,
                TransactionTypeId = transactionSubType.TransactionTypeId,

                Deleted   = transactionSubType.Deleted,
                CreatedBy = transactionSubType.CreatedBy,
                CreatedOn = transactionSubType.CreatedOn,
            };

            var transactionSubTypeId = this._dataService.SaveTransactionSubType(transactionSubTypeDTO, userId);

            return(transactionSubTypeId);
        }
        /// <summary>
        /// Maps TransactionSubType EF object to TransactionSubType Model Object and
        /// returns the TransactionSubType model object.
        /// </summary>
        /// <param name="result">EF TransactionSubType object to be mapped.</param>
        /// <returns>TransactionSubType Model Object.</returns>
        public TransactionSubType MapEFToModel(EF.Models.TransactionSubType data)
        {
            var transactionSubType = new TransactionSubType()
            {
                TransactionSubTypeId = data.TransactionSubTypeId,
                Name = data.Name,
                TransactionTypeName = data.TransactionType != null ? data.TransactionType.Name : "",
                TransactionTypeId   = data.TransactionTypeId,
                CreatedOn           = data.CreatedOn,
                TimeStamp           = data.TimeStamp,
                Deleted             = data.Deleted,
                CreatedBy           = _userService.GetUserFullName(data.AspNetUser),
                UpdatedBy           = _userService.GetUserFullName(data.AspNetUser1),
            };

            return(transactionSubType);
        }
 public void UpdateTransactionSubTypeConcurrencyTest()
 {
     using (TransactionScope ts = new TransactionScope())
     {
         try
         {
             TransactionSubType transactionSubType = PopulateNewItem();
             transactionSubType.Id = SaveItem(transactionSubType);
             SaveItem(transactionSubType);
         }
         catch (DiscoveryException e)
         {
             Assert.IsInstanceOfType(typeof(ConcurrencyException), e.InnerException);
             throw e;
         }
     }
 }
Example #14
0
        //public TransactionSubType GetTransactionTypeIdForParticularSubType(long transactionSubTypeId)
        //{
        //    return this.UnitOfWork.Get<TransactionSubType>().AsQueryable()
        //         .FirstOrDefault(c =>
        //            c.TransactionTypeId == transactionSubTypeId &&
        //            c.Deleted == false
        //        );
        //}

        /// <summary>
        /// Saves a new TransactionSubType or updates an already existing TransactionSubType.
        /// </summary>
        /// <param name="TransactionSubType">TransactionSubType to be saved or updated.</param>
        /// <param name="TransactionSubTypeId">TransactionSubTypeId of the TransactionSubType creating or updating</param>
        /// <returns>TransactionSubTypeId</returns>
        public long SaveTransactionSubType(TransactionSubTypeDTO transactionSubTypeDTO, string userId)
        {
            long transactionSubTypeId = 0;

            if (transactionSubTypeDTO.TransactionSubTypeId == 0)
            {
                var transactionSubType = new TransactionSubType()
                {
                    TransactionSubTypeId = transactionSubTypeDTO.TransactionSubTypeId,
                    TransactionTypeId    = transactionSubTypeDTO.TransactionTypeId,
                    Name      = transactionSubTypeDTO.Name,
                    CreatedOn = DateTime.Now,
                    TimeStamp = DateTime.Now,
                    CreatedBy = userId,
                    Deleted   = false,
                };

                this.UnitOfWork.Get <TransactionSubType>().AddNew(transactionSubType);
                this.UnitOfWork.SaveChanges();
                transactionSubTypeId = transactionSubType.TransactionSubTypeId;
                return(transactionSubTypeId);
            }

            else
            {
                var result = this.UnitOfWork.Get <TransactionSubType>().AsQueryable()
                             .FirstOrDefault(e => e.TransactionSubTypeId == transactionSubTypeDTO.TransactionSubTypeId);
                if (result != null)
                {
                    result.TransactionSubTypeId = transactionSubTypeDTO.TransactionSubTypeId;
                    result.Name = transactionSubTypeDTO.Name;
                    result.TransactionTypeId = transactionSubTypeDTO.TransactionTypeId;
                    result.UpdatedBy         = userId;
                    result.TimeStamp         = DateTime.Now;
                    result.Deleted           = transactionSubTypeDTO.Deleted;
                    result.DeletedBy         = transactionSubTypeDTO.DeletedBy;
                    result.DeletedOn         = transactionSubTypeDTO.DeletedOn;

                    this.UnitOfWork.Get <TransactionSubType>().Update(result);
                    this.UnitOfWork.SaveChanges();
                }
                return(transactionSubTypeDTO.TransactionSubTypeId);
            }
        }
Example #15
0
        /// <summary>
        /// Deletes the transactionSubType.
        /// </summary>
        /// <param name="transactionSubType">The transactionSubType to delete.</param>
        /// <returns></returns>
        public static bool DeleteTransactionSubType(TransactionSubType transactionSubType)
        {
            bool success = false;

            try
            {
                if (transactionSubType != null)
                {
                    success = DataAccessProvider.Instance().DeleteTransactionSubType(transactionSubType.Id);
                    if (success)
                    {
                        CacheManager.Remove(transactionSubType);
                    }
                }
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, "Business Logic"))
                {
                    throw;
                }
            }
            return(success);
        }
Example #16
0
        static internal TDCShipment PopulateItem()
        {
            TDCShipment  tdcShipment  = new TDCShipment();
            OpCoShipment opCoShipment = OpcoShipmentTests.PopulateNewItem();

            try
            {
                tdcShipment.OpCoShipmentId = OpCoShipmentController.SaveShipment(opCoShipment);
            }
            catch (InValidBusinessObjectException e)
            {
                Console.Write(e.ValidatableObject.ValidationMessages);
            }

            tdcShipment.OpCoCode           = opCoShipment.OpCoCode;
            tdcShipment.OpCoSequenceNumber = 1;

            tdcShipment.OpCoContact.Email        = "Email";
            tdcShipment.OpCoContact.Name         = "Name";
            tdcShipment.DespatchNumber           = "Number";
            tdcShipment.RequiredShipmentDate     = DateTime.Now;
            tdcShipment.CustomerNumber           = "CustNo";
            tdcShipment.CustomerName             = "CustomerName";
            tdcShipment.CustomerReference        = "ref";
            tdcShipment.CustomerAddress.Line1    = "Line1";
            tdcShipment.CustomerAddress.PostCode = "NN8 1NB";
            tdcShipment.ShipmentNumber           = "ShipNo";
            tdcShipment.ShipmentName             = "ShipmentName";
            tdcShipment.ShipmentAddress.Line1    = "Line1";
            tdcShipment.ShipmentAddress.PostCode = "NN8 1NB";
            tdcShipment.SalesBranchCode          = "BranchCode";
            tdcShipment.AfterTime           = "11:11";
            tdcShipment.BeforeTime          = "10:10";
            tdcShipment.TailLiftRequired    = false;
            tdcShipment.CheckInTime         = 1;
            tdcShipment.DivisionCode        = "Div";
            tdcShipment.GeneratedDateTime   = DateTime.Now;
            tdcShipment.Status              = Shipment.StatusEnum.Mapped;
            tdcShipment.IsRecurring         = false;
            tdcShipment.IsValidAddress      = false;
            tdcShipment.PAFAddress.Line1    = "Line1";
            tdcShipment.PAFAddress.PostCode = "PostCode";
            tdcShipment.UpdatedBy           = "UpdatedBy";
            tdcShipment.Instructions        = "Instructions";
            tdcShipment.VehicleMaxWeight    = (decimal)1.1;
            OpCoDivision division = OpcoDivisionTests.PopulateNewItem();

            OpcoDivisionTests.SaveItem(division);
            tdcShipment.DivisionCode = division.Code;

            Warehouse deliveryWarehouse = WarehouseTests.PopulateNewItem();

            WarehouseTests.SaveItem(deliveryWarehouse);
            tdcShipment.DeliveryWarehouseCode = deliveryWarehouse.Code;

            Warehouse stockWarehouse = WarehouseTests.PopulateNewItem();

            WarehouseTests.SaveItem(stockWarehouse);
            tdcShipment.StockWarehouseCode = stockWarehouse.Code;

            Route route = RouteTests.PopulateNewItem();

            RouteTests.SaveItem(route);
            tdcShipment.RouteCode = route.Code;

            TransactionType transactionType = TransactionTypeTests.PopulateNewItem();

            TransactionTypeTests.SaveItem(transactionType);
            tdcShipment.TransactionTypeCode = transactionType.Code;

            TransactionSubType transactionSubType = TransactionSubTypeTests.PopulateNewItem();

            TransactionSubTypeTests.SaveItem(transactionSubType);
            tdcShipment.TransactionSubTypeCode = transactionSubType.Code;

            return(tdcShipment);
        }
Example #17
0
        private static Transaction VerifyCommonProperties(TransactionCreatedReply transactionCreatedReply, CreateTransactionByPublicKey parameters,
                                                          Account recipient, Amount amount, TransactionSubType transactionType)
        {
            var byteArray = transactionCreatedReply.UnsignedTransactionBytes.ToBytes().ToArray();

            using (var stream = new MemoryStream(byteArray))
                using (var reader = new BinaryReader(stream))
                {
                    var transaction = new Transaction();
                    var type        = reader.ReadByte(); // 1
                    var subtype     = reader.ReadByte(); // 2
                    transaction.SubType         = TransactionTypeMapper.GetSubType(type, (byte)(subtype & 0x0F));
                    transaction.Version         = (subtype & 0xF0) >> 4;
                    transaction.Timestamp       = new DateTimeConverter().GetFromNxtTime(reader.ReadInt32()); // 6
                    transaction.Deadline        = reader.ReadInt16();                                         // 8
                    transaction.SenderPublicKey = new BinaryHexString(reader.ReadBytes(32));                  // 40
                    transaction.Recipient       = reader.ReadUInt64();                                        // 48
                    transaction.Amount          = Amount.CreateAmountFromNqt(reader.ReadInt64());             // 56
                    transaction.Fee             = Amount.CreateAmountFromNqt(reader.ReadInt64());             // 64
                    transaction.ReferencedTransactionFullHash = new BinaryHexString(reader.ReadBytes(32));    // 96

                    if (transaction.ReferencedTransactionFullHash.ToBytes().All(b => b == 0))
                    {
                        transaction.ReferencedTransactionFullHash = "";
                    }

                    reader.ReadBytes(64); // signature, 160

                    var flags = 0;

                    if (transaction.Version > 0)
                    {
                        flags = reader.ReadInt32();                      // 164
                        transaction.EcBlockHeight = reader.ReadInt32();  // 168
                        transaction.EcBlockId     = reader.ReadUInt64(); // 176
                    }

                    if (!transaction.SenderPublicKey.Equals(parameters.PublicKey))
                    {
                        throw new ValidationException(nameof(transaction.SenderPublicKey), parameters.PublicKey, transaction.SenderPublicKey);
                    }

                    if (parameters.Deadline != transaction.Deadline)
                    {
                        throw new ValidationException(nameof(transaction.Deadline), parameters.Deadline, transaction.Deadline);
                    }

                    if ((recipient?.AccountId ?? 0) != (transaction?.Recipient ?? 0))
                    {
                        throw new ValidationException(nameof(transaction.Recipient), recipient?.AccountId, transaction.Recipient);
                    }

                    if (!amount.Equals(transaction.Amount))
                    {
                        throw new ValidationException(nameof(transaction.Amount), amount, transaction.Amount);
                    }

                    if (parameters.ReferencedTransactionFullHash != null)
                    {
                        if (!parameters.ReferencedTransactionFullHash.Equals(transaction.ReferencedTransactionFullHash))
                        {
                            throw new ValidationException(nameof(transaction.ReferencedTransactionFullHash), parameters.ReferencedTransactionFullHash, transaction.ReferencedTransactionFullHash);
                        }
                    }
                    else if (transaction.ReferencedTransactionFullHash.ToHexString() != "")
                    {
                        throw new ValidationException(nameof(transaction.ReferencedTransactionFullHash), parameters.ReferencedTransactionFullHash, transaction.ReferencedTransactionFullHash);
                    }

                    var attachmentConverter = new AttachmentConverter(reader, (byte)transaction.Version);
                    transaction.Attachment = attachmentConverter.GetAttachment(transactionType);

                    var position = 1;
                    if ((flags & position) != 0 || (transaction.Version == 0 && transactionType == TransactionSubType.MessagingArbitraryMessage))
                    {
                        transaction.Message = new Message(reader, (byte)transaction.Version);

                        if (parameters.Message.MessageIsText != transaction.Message.IsText)
                        {
                            throw new ValidationException(nameof(transaction.Message.IsText), parameters.Message.MessageIsText, transaction.Message.IsText);
                        }
                        if (parameters.Message.MessageIsText && parameters.Message.Message != transaction.Message.MessageText)
                        {
                            throw new ValidationException(nameof(transaction.Message.MessageText), parameters.Message.Message, transaction.Message.MessageText);
                        }
                        if (!parameters.Message.MessageIsText && !transaction.Message.Data.Equals(parameters.Message.Message))
                        {
                            throw new ValidationException(nameof(transaction.Message.Data), parameters.Message.Message, transaction.Message.Data);
                        }
                    }
                    else if (parameters.Message != null && !parameters.Message.IsPrunable)
                    {
                        throw new ValidationException("Expected a message, but got null");
                    }

                    position <<= 1;
                    if ((flags & position) != 0)
                    {
                        transaction.EncryptedMessage = new EncryptedMessage(reader, (byte)transaction.Version);
                        var encryptedMessage = parameters.EncryptedMessage;

                        if (encryptedMessage.MessageIsText != transaction.EncryptedMessage.IsText)
                        {
                            throw new ValidationException(nameof(transaction.EncryptedMessage.IsText), encryptedMessage.MessageIsText, transaction.EncryptedMessage.IsText);
                        }
                        if (encryptedMessage.CompressMessage != transaction.EncryptedMessage.IsCompressed)
                        {
                            throw new ValidationException(nameof(transaction.EncryptedMessage.IsCompressed), encryptedMessage.CompressMessage, transaction.EncryptedMessage.IsCompressed);
                        }
                        if (!encryptedMessage.Message.Equals(transaction.EncryptedMessage.Data))
                        {
                            throw new ValidationException(nameof(transaction.EncryptedMessage.MessageToEncrypt), encryptedMessage.Message, transaction.EncryptedMessage.MessageToEncrypt);
                        }
                        if (encryptedMessage is AlreadyEncryptedMessage)
                        {
                            var alreadyEncryptedMessage = (AlreadyEncryptedMessage)parameters.EncryptedMessage;
                            if (!alreadyEncryptedMessage.Nonce.Equals(transaction.EncryptedMessage.Nonce))
                            {
                                throw new ValidationException(nameof(transaction.EncryptedMessage.Nonce), alreadyEncryptedMessage.Nonce, transaction.EncryptedMessage.Nonce);
                            }
                        }
                    }
                    else if (parameters.EncryptedMessage != null && !parameters.EncryptedMessage.IsPrunable)
                    {
                        throw new ValidationException("Expected an encrypted message, but got null");
                    }

                    position <<= 1;
                    if ((flags & position) != 0)
                    {
                        transaction.PublicKeyAnnouncement = new PublicKeyAnnouncement(reader, (byte)transaction.Version);
                        if (parameters.RecipientPublicKey != null && !parameters.RecipientPublicKey.Equals(transaction.PublicKeyAnnouncement.RecipientPublicKey))
                        {
                            throw new ValidationException(nameof(transaction.PublicKeyAnnouncement.RecipientPublicKey), parameters.RecipientPublicKey, transaction.PublicKeyAnnouncement.RecipientPublicKey);
                        }
                    }

                    position <<= 1;
                    if ((flags & position) != 0)
                    {
                        transaction.EncryptToSelfMessage = new EncryptToSelfMessage(reader, (byte)transaction.Version);
                        var encryptedMessage = parameters.EncryptedMessageToSelf;

                        if (encryptedMessage.MessageIsText != transaction.EncryptToSelfMessage.IsText)
                        {
                            throw new ValidationException(nameof(transaction.EncryptToSelfMessage.IsText), encryptedMessage.MessageIsText, transaction.EncryptToSelfMessage.IsText);
                        }
                        if (encryptedMessage.CompressMessage != transaction.EncryptToSelfMessage.IsCompressed)
                        {
                            throw new ValidationException(nameof(transaction.EncryptToSelfMessage.IsCompressed), encryptedMessage.CompressMessage, transaction.EncryptToSelfMessage.IsCompressed);
                        }
                        if (!encryptedMessage.Message.Equals(transaction.EncryptToSelfMessage.Data))
                        {
                            throw new ValidationException(nameof(transaction.EncryptToSelfMessage.MessageToEncrypt), encryptedMessage.Message, transaction.EncryptToSelfMessage.MessageToEncrypt);
                        }
                        if (encryptedMessage is AlreadyEncryptedMessageToSelf)
                        {
                            var alreadyEncryptedMessage = (AlreadyEncryptedMessageToSelf)parameters.EncryptedMessageToSelf;
                            if (!alreadyEncryptedMessage.Nonce.Equals(transaction.EncryptToSelfMessage.Nonce))
                            {
                                throw new ValidationException(nameof(transaction.EncryptToSelfMessage.Nonce), alreadyEncryptedMessage.Nonce, transaction.EncryptToSelfMessage.Nonce);
                            }
                        }
                    }
                    else if (parameters.EncryptedMessageToSelf != null)
                    {
                        throw new ValidationException("Expected an encrypted to self message, but got null");
                    }

                    position <<= 1;
                    if ((flags & position) != 0)
                    {
                        transaction.Phasing = new TransactionPhasing(reader, (byte)transaction.Version);

                        if (parameters.Phasing.FinishHeight != transaction.Phasing.FinishHeight)
                        {
                            throw new ValidationException(nameof(transaction.Phasing.FinishHeight), parameters.Phasing.FinishHeight, transaction.Phasing.FinishHeight);
                        }
                        if (parameters.Phasing.HashedSecret != null && !parameters.Phasing.HashedSecret.Equals(transaction.Phasing.HashedSecret))
                        {
                            throw new ValidationException(nameof(transaction.Phasing.HashedSecret), parameters.Phasing.HashedSecret, transaction.Phasing.HashedSecret);
                        }
                        if (parameters.Phasing.HashedSecretAlgorithm != transaction.Phasing.HashedSecretAlgorithm)
                        {
                            throw new ValidationException(nameof(transaction.Phasing.HashedSecretAlgorithm), parameters.Phasing.HashedSecretAlgorithm, transaction.Phasing.HashedSecretAlgorithm);
                        }
                        if (parameters.Phasing.HoldingId != transaction.Phasing.HoldingId)
                        {
                            throw new ValidationException(nameof(transaction.Phasing.HoldingId), parameters.Phasing.HoldingId, transaction.Phasing.HoldingId);
                        }
                        if (!Enumerable.SequenceEqual(parameters.Phasing.LinkedFullHash, transaction.Phasing.LinkedFullHashes))
                        {
                            throw new ValidationException(nameof(transaction.Phasing.LinkedFullHashes), parameters.Phasing.LinkedFullHash, transaction.Phasing.LinkedFullHashes);
                        }
                        if (parameters.Phasing.MinBalance != transaction.Phasing.MinBalance)
                        {
                            throw new ValidationException(nameof(transaction.Phasing.MinBalance), parameters.Phasing.MinBalance, transaction.Phasing.MinBalance);
                        }
                        if (parameters.Phasing.MinBalanceModel != transaction.Phasing.MinBalanceModel)
                        {
                            throw new ValidationException(nameof(transaction.Phasing.MinBalanceModel), parameters.Phasing.MinBalanceModel, transaction.Phasing.MinBalanceModel);
                        }
                        //if (parameters.Phasing.Phased != transaction.Phased)
                        //{
                        //    throw new ValidationException(nameof(transaction.Phased), parameters.Phasing.Phased, transaction.Phased);
                        //}
                        if (parameters.Phasing.Quorum != transaction.Phasing.Quorum)
                        {
                            throw new ValidationException(nameof(transaction.Phasing.Quorum), parameters.Phasing.Quorum, transaction.Phasing.Quorum);
                        }
                        if (parameters.Phasing.VotingModel != transaction.Phasing.VotingModel)
                        {
                            throw new ValidationException(nameof(transaction.Phasing.VotingModel), parameters.Phasing.VotingModel, transaction.Phasing.VotingModel);
                        }
                        if (!Enumerable.SequenceEqual(parameters.Phasing.WhiteListed, transaction.Phasing.WhiteList))
                        {
                            throw new ValidationException(nameof(transaction.Phasing.WhiteList), parameters.Phasing.WhiteListed, transaction.Phasing.WhiteList);
                        }
                    }
                    else if (parameters.Phasing != null)
                    {
                        throw new ValidationException("Expected phasing, but got null");
                    }

                    position <<= 1;
                    if ((flags & position) != 0)
                    {
                        transaction.Message = new Message(reader, (byte)transaction.Version, true);
                        var expectedHash = HashPrunableMessage(parameters.Message.MessageIsText, parameters.Message.Message);

                        if (!expectedHash.Equals(transaction.Message.MessageHash))
                        {
                            throw new ValidationException(nameof(transaction.Message.MessageHash), expectedHash, transaction.Message.MessageHash);
                        }
                    }
                    else if (parameters.Message != null && parameters.Message.IsPrunable)
                    {
                        throw new ValidationException("Expected prunable message, but got null");
                    }

                    position <<= 1;
                    if ((flags & position) != 0)
                    {
                        var alreadyEncrypted = (AlreadyEncryptedMessage)parameters.EncryptedMessage;
                        transaction.EncryptedMessage = new EncryptedMessage(reader, (byte)transaction.Version, true);

                        var isText       = new byte[] { (byte)(alreadyEncrypted.MessageIsText ? 1 : 0) };
                        var isCompressed = new byte[] { (byte)(alreadyEncrypted.CompressMessage ? 1 : 0) };
                        var messageBytes = alreadyEncrypted.Message.ToBytes().ToArray();
                        var nonceBytes   = alreadyEncrypted.Nonce.ToBytes().ToArray();

                        var expectedHash = HashPrunableMessage(isText, isCompressed, messageBytes, nonceBytes);

                        if (!expectedHash.Equals(transaction.EncryptedMessage.EncryptedMessageHash))
                        {
                            throw new ValidationException(nameof(transaction.EncryptedMessage.EncryptedMessageHash), expectedHash, transaction.EncryptedMessage.EncryptedMessageHash);
                        }
                    }
                    else if (parameters.EncryptedMessage != null && parameters.EncryptedMessage.IsPrunable)
                    {
                        throw new ValidationException("Expected encrypted prunable message, but got null");
                    }

                    if (transaction.SubType != transactionType)
                    {
                        throw new ValidationException(nameof(transaction.SubType), transactionType, transaction.SubType);
                    }

                    return(transaction);
                }
        }
Example #18
0
        public long Save(TransactionSubType model)
        {
            var transactionSubTypeId = _transactionSubTypeService.SaveTransactionSubType(model, userId);

            return(transactionSubTypeId);
        }
 public TransactionLine(AccountID accountId, decimal balance, TransactionType type, TransactionSubType subType) : this(accountId, balance, type)
 {
     SubType = subType;
 }
 public static byte GetMainTypeByte(TransactionSubType type)
 {
     return(SubTypes.Single(st => st.Value.ContainsValue(type)).Key);
 }
 public static byte GetSubTypeByte(TransactionSubType type)
 {
     return(SubTypesToByte[type]);
 }
 public static int SaveItem(TransactionSubType transactionSubType)
 {
     return(TransactionSubTypeController.SaveTransactionSubType(transactionSubType));
 }
 internal bool DeleteItem(TransactionSubType transactionSubType)
 {
     return(TransactionSubTypeController.DeleteTransactionSubType(transactionSubType));
 }