示例#1
0
        Witness.Size;                   //Witnesses

        public void CalculateFees()
        {
            if (Sender is null)
            {
                Sender = UInt160.Zero;
            }
            if (Attributes is null)
            {
                Attributes = new TransactionAttribute[0];
            }
            if (Witness is null)
            {
                Witness = new Witness
                {
                    InvocationScript   = new byte[65],
                    VerificationScript = new byte[39]
                }
            }
            ;
            _hash = null;
            long consumed;

            using (ApplicationEngine engine = ApplicationEngine.Run(Script, this))
            {
                if (engine.State.HasFlag(VMState.FAULT))
                {
                    throw new InvalidOperationException();
                }
                consumed = engine.GasConsumed;
            }
            _hash = null;
            long d = (long)NativeContract.GAS.Factor;

            Gas = consumed - ApplicationEngine.GasFree;
            if (Gas <= 0)
            {
                Gas = 0;
            }
            else
            {
                long remainder = Gas % d;
                if (remainder == 0)
                {
                    return;
                }
                if (remainder > 0)
                {
                    Gas += d - remainder;
                }
                else
                {
                    Gas -= remainder;
                }
            }
            using (Snapshot snapshot = Blockchain.Singleton.GetSnapshot())
            {
                long feeperbyte = NativeContract.Policy.GetFeePerByte(snapshot);
                long fee        = feeperbyte * Size;
                if (fee > NetworkFee)
                {
                    NetworkFee = fee;
                }
            }
        }

        void ISerializable.Deserialize(BinaryReader reader)
        {
            DeserializeUnsigned(reader);
            Witness = reader.ReadSerializable <Witness>();
        }