示例#1
0
        public bool ConsumeFeeForCreateNewAccount(AccountCapsule account, TransactionTrace trace)
        {
            bool result = false;
            long fee    = this.db_manager.DynamicProperties.GetCreateAccountFee();

            if (ConsumeFee(account, fee))
            {
                trace.SetNetBill(0, fee);
                this.db_manager.DynamicProperties.AddTotalCreateAccountCost(fee);
                result = true;
            }

            return(result);
        }
示例#2
0
        private bool UseTransactionFee(AccountCapsule account, long bytes, TransactionTrace trace)
        {
            bool result = false;
            long fee    = this.db_manager.DynamicProperties.GetTransactionFee() * bytes;

            if (ConsumeFee(account, fee))
            {
                trace.SetNetBill(0, fee);
                this.db_manager.DynamicProperties.AddTotalTransactionCost(fee);
                result = true;
            }

            return(result);
        }
示例#3
0
 public abstract void Consume(TransactionCapsule tx, TransactionTrace tx_trace);
示例#4
0
        private void ConsumeForCreateNewAccount(AccountCapsule account, long bytes, long now, TransactionTrace trace)
        {
            bool ret = ConsumeBandwidthForCreateNewAccount(account, bytes, now);

            if (!ret)
            {
                ret = ConsumeFeeForCreateNewAccount(account, trace);
                if (!ret)
                {
                    throw new AccountResourceInsufficientException();
                }
            }
        }
示例#5
0
        public override void Consume(TransactionCapsule tx, TransactionTrace tx_trace)
        {
            List <Contract> contracts = new List <Contract>(tx.Instance.RawData.Contract);

            if (tx.ResultSize > DefineParameter.MAX_RESULT_SIZE_IN_TX * contracts.Count)
            {
                throw new TooBigTransactionResultException();
            }

            long size = 0;

            if (this.db_manager.DynamicProperties.SupportVM())
            {
                tx.Instance.Ret.Clear();
                size += tx.Instance.CalculateSize();
            }
            else
            {
                size += tx.Size;
            }

            foreach (Contract contract in contracts)
            {
                if (this.db_manager.DynamicProperties.SupportVM())
                {
                    size += DefineParameter.MAX_RESULT_SIZE_IN_TX;
                }

                Logger.Debug(string.Format("tx id {0}, bandwidth cost {1}",
                                           tx.Id,
                                           size));

                tx_trace.SetNetBill(size, 0);
                byte[]         address = TransactionCapsule.GetOwner(contract);
                AccountCapsule account = this.db_manager.Account.Get(address);

                if (account == null)
                {
                    throw new ContractValidateException("account not exists");
                }

                long now = this.db_manager.WitnessController.GetHeadSlot();
                if (ContractCreateNewAccount(contract))
                {
                    ConsumeForCreateNewAccount(account, size, now, tx_trace);
                    continue;
                }

                if (contract.Type == ContractType.TransferAssetContract &&
                    UseAssetAccountNet(contract, account, now, size))
                {
                    continue;
                }

                if (UseAccountNet(account, size, now))
                {
                    continue;
                }

                if (UseFreeNet(account, size, now))
                {
                    continue;
                }

                if (UseTransactionFee(account, size, tx_trace))
                {
                    continue;
                }

                long fee = this.db_manager.DynamicProperties.GetTransactionFee() * size;


                throw new AccountResourceInsufficientException(
                          "Account Insufficient bandwidth[" + size + "] and balance[" + fee + "] to create new account");
            }
        }
示例#6
0
 public override void Consume(TransactionCapsule tx, TransactionTrace tx_trace)
 {
     throw new System.Exception("Not support");
 }