Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ public boolean execute(TransactionResultCapsule ret) throws ContractExeException
AccountStore accountStore = this.dbManager.getAccountStore();
byte[] ownerKey = transferAssetContract.getOwnerAddress().toByteArray();
byte[] toKey = transferAssetContract.getToAddress().toByteArray();
ByteString assertName = transferAssetContract.getAssetName();
ByteString assetName = transferAssetContract.getAssetName();
long amount = transferAssetContract.getAmount();

AccountCapsule ownerAccountCapsule = accountStore.get(ownerKey);
if (!ownerAccountCapsule.reduceAssetAmount(assertName, amount)) {
if (!ownerAccountCapsule.reduceAssetAmount(assetName, amount)) {
throw new ContractExeException("reduceAssetAmount failed !");
}
accountStore.put(ownerKey, ownerAccountCapsule);

AccountCapsule toAccountCapsule = accountStore.get(toKey);
toAccountCapsule.addAssetAmount(assertName, amount);
toAccountCapsule.addAssetAmount(assetName, amount);
accountStore.put(toKey, toAccountCapsule);

ret.setStatus(fee, code.SUCESS);
Expand Down
33 changes: 28 additions & 5 deletions src/main/java/org/tron/core/db/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.tron.core.actuator.Actuator;
import org.tron.core.actuator.ActuatorFactory;
import org.tron.core.capsule.AccountCapsule;
import org.tron.core.capsule.AssetIssueCapsule;
import org.tron.core.capsule.BlockCapsule;
import org.tron.core.capsule.BlockCapsule.BlockId;
import org.tron.core.capsule.BytesCapsule;
Expand All @@ -59,6 +60,7 @@
import org.tron.core.exception.ValidateScheduleException;
import org.tron.core.exception.ValidateSignatureException;
import org.tron.core.witness.WitnessController;
import org.tron.protos.Contract.TransferAssetContract;
import org.tron.protos.Protocol.AccountType;
import org.tron.protos.Protocol.Transaction;

Expand Down Expand Up @@ -453,7 +455,7 @@ public boolean pushTransactions(final TransactionCapsule trx)
}


public void consumeBandwidth(TransactionCapsule trx) throws ValidateBandwidthException {
private void consumeBandwidth(TransactionCapsule trx) throws ValidateBandwidthException {
List<org.tron.protos.Protocol.Transaction.Contract> contracts =
trx.getInstance().getRawData().getContractList();
for (Transaction.Contract contract : contracts) {
Expand All @@ -462,7 +464,6 @@ public void consumeBandwidth(TransactionCapsule trx) throws ValidateBandwidthExc
if (accountCapsule == null) {
throw new ValidateBandwidthException("account not exists");
}
long bandwidth = accountCapsule.getBandwidth();
long now = getHeadBlockTimeStamp();
long latestOperationTime = accountCapsule.getLatestOperationTime();
//10 * 1000
Expand All @@ -472,10 +473,32 @@ public void consumeBandwidth(TransactionCapsule trx) throws ValidateBandwidthExc
return;
}
long bandwidthPerTransaction = getDynamicPropertiesStore().getBandwidthPerTransaction();
if (bandwidth < bandwidthPerTransaction) {
throw new ValidateBandwidthException("bandwidth is not enough");
long bandwidth;
if (contract.getType() == TransferAssetContract) {
AccountCapsule issuerAccountCapsule;
try {
ByteString assetName
= contract.getParameter().unpack(TransferAssetContract.class).getAssetName();
AssetIssueCapsule assetIssueCapsule
= this.getAssetIssueStore().get(assetName.toByteArray());
issuerAccountCapsule = this.getAccountStore()
.get(assetIssueCapsule.getOwnerAddress().toByteArray());
bandwidth = issuerAccountCapsule.getBandwidth();
} catch (Exception ex) {
throw new ValidateBandwidthException(ex.getMessage());
}
if (bandwidth < bandwidthPerTransaction) {
throw new ValidateBandwidthException("bandwidth is not enough");
}
issuerAccountCapsule.setBandwidth(bandwidth - bandwidthPerTransaction);
this.getAccountStore().put(issuerAccountCapsule.createDbKey(), issuerAccountCapsule);
} else {
bandwidth = accountCapsule.getBandwidth();
if (bandwidth < bandwidthPerTransaction) {
throw new ValidateBandwidthException("bandwidth is not enough");
}
accountCapsule.setBandwidth(bandwidth - bandwidthPerTransaction);
}
accountCapsule.setBandwidth(bandwidth - bandwidthPerTransaction);
accountCapsule.setLatestOperationTime(now);
this.getAccountStore().put(accountCapsule.createDbKey(), accountCapsule);
}
Expand Down