예제 #1
0
        public static void RunValidation(TransactionViewModel transactionViewModel, int minWeightMagnitude)
        {
            transactionViewModel.SetMetadata();
            transactionViewModel.SetAttachmentData();
            if (HasInvalidTimestamp(transactionViewModel))
            {
                throw new StaleTimestampException("Invalid transaction timestamp.");
            }

            for (int i = TransactionViewModel.ValueTrinaryOffset + TransactionViewModel.ValueUsableTrinarySize;
                 i < TransactionViewModel.ValueTrinaryOffset + TransactionViewModel.ValueTrinarySize;
                 i++)
            {
                if (transactionViewModel.Trits()[i] != 0)
                {
                    throw new Exception("Invalid transaction value");
                }
            }

            int weightMagnitude = transactionViewModel.WeightMagnitude;

            if (weightMagnitude < minWeightMagnitude)
            {
                throw new Exception("Invalid transaction hash");
            }

            if (transactionViewModel.Value() != 0 &&
                transactionViewModel.GetAddressHash().Trits()[Sponge.HashLength - 1] != 0)
            {
                throw new Exception("Invalid transaction address");
            }
        }