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); }
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); }
public abstract void Consume(TransactionCapsule tx, TransactionTrace tx_trace);
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(); } } }
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"); } }
public override void Consume(TransactionCapsule tx, TransactionTrace tx_trace) { throw new System.Exception("Not support"); }