Ejemplo n.º 1
0
        public void ValidateValue(ulong commission)
        {
            var len      = (Transfers?.Count ?? 0) + (Stakes?.Count ?? 0);
            var outValue = commission * GasPrice * (ulong)len;

            if (Transfers != null)
            {
                outValue = Transfers.Aggregate(outValue, (current, txOut) =>
                                               current + txOut.Value);
            }

            if (Stakes != null)
            {
                outValue = Stakes.Aggregate(outValue, (current, txOut) =>
                                            current + txOut.Value);
            }

            if (Messages != null)
            {
                outValue = Messages.Aggregate(outValue, (current, txOut) =>
                                              current + txOut.Value + txOut.Gas * GasPrice);
            }

            var inValue = Inputs.Aggregate((ulong)0, (current, txIn) =>
                                           current + txIn.Value);

            if (inValue != outValue)
            {
                throw new Exception($"Wrong sum in transaction, inValue: {inValue}, outValue: {outValue}");
            }
        }