Skip to content

Commit f5e5c61

Browse files
authored
Merge pull request #694 from tronprotocol/feature/modify_transfer_asset_bandwidth
Feature/modify transfer asset bandwidth
2 parents f24d35b + 9301c0a commit f5e5c61

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

src/main/java/org/tron/core/actuator/TransferAssetActuator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,17 @@ public boolean execute(TransactionResultCapsule ret) throws ContractExeException
5454
AccountStore accountStore = this.dbManager.getAccountStore();
5555
byte[] ownerKey = transferAssetContract.getOwnerAddress().toByteArray();
5656
byte[] toKey = transferAssetContract.getToAddress().toByteArray();
57-
ByteString assertName = transferAssetContract.getAssetName();
57+
ByteString assetName = transferAssetContract.getAssetName();
5858
long amount = transferAssetContract.getAmount();
5959

6060
AccountCapsule ownerAccountCapsule = accountStore.get(ownerKey);
61-
if (!ownerAccountCapsule.reduceAssetAmount(assertName, amount)) {
61+
if (!ownerAccountCapsule.reduceAssetAmount(assetName, amount)) {
6262
throw new ContractExeException("reduceAssetAmount failed !");
6363
}
6464
accountStore.put(ownerKey, ownerAccountCapsule);
6565

6666
AccountCapsule toAccountCapsule = accountStore.get(toKey);
67-
toAccountCapsule.addAssetAmount(assertName, amount);
67+
toAccountCapsule.addAssetAmount(assetName, amount);
6868
accountStore.put(toKey, toAccountCapsule);
6969

7070
ret.setStatus(fee, code.SUCESS);

src/main/java/org/tron/core/db/Manager.java

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.tron.core.actuator.Actuator;
3434
import org.tron.core.actuator.ActuatorFactory;
3535
import org.tron.core.capsule.AccountCapsule;
36+
import org.tron.core.capsule.AssetIssueCapsule;
3637
import org.tron.core.capsule.BlockCapsule;
3738
import org.tron.core.capsule.BlockCapsule.BlockId;
3839
import org.tron.core.capsule.BytesCapsule;
@@ -59,6 +60,7 @@
5960
import org.tron.core.exception.ValidateScheduleException;
6061
import org.tron.core.exception.ValidateSignatureException;
6162
import org.tron.core.witness.WitnessController;
63+
import org.tron.protos.Contract.TransferAssetContract;
6264
import org.tron.protos.Protocol.AccountType;
6365
import org.tron.protos.Protocol.Transaction;
6466

@@ -453,7 +455,7 @@ public boolean pushTransactions(final TransactionCapsule trx)
453455
}
454456

455457

456-
public void consumeBandwidth(TransactionCapsule trx) throws ValidateBandwidthException {
458+
private void consumeBandwidth(TransactionCapsule trx) throws ValidateBandwidthException {
457459
List<org.tron.protos.Protocol.Transaction.Contract> contracts =
458460
trx.getInstance().getRawData().getContractList();
459461
for (Transaction.Contract contract : contracts) {
@@ -462,7 +464,6 @@ public void consumeBandwidth(TransactionCapsule trx) throws ValidateBandwidthExc
462464
if (accountCapsule == null) {
463465
throw new ValidateBandwidthException("account not exists");
464466
}
465-
long bandwidth = accountCapsule.getBandwidth();
466467
long now = getHeadBlockTimeStamp();
467468
long latestOperationTime = accountCapsule.getLatestOperationTime();
468469
//10 * 1000
@@ -472,10 +473,32 @@ public void consumeBandwidth(TransactionCapsule trx) throws ValidateBandwidthExc
472473
return;
473474
}
474475
long bandwidthPerTransaction = getDynamicPropertiesStore().getBandwidthPerTransaction();
475-
if (bandwidth < bandwidthPerTransaction) {
476-
throw new ValidateBandwidthException("bandwidth is not enough");
476+
long bandwidth;
477+
if (contract.getType() == TransferAssetContract) {
478+
AccountCapsule issuerAccountCapsule;
479+
try {
480+
ByteString assetName
481+
= contract.getParameter().unpack(TransferAssetContract.class).getAssetName();
482+
AssetIssueCapsule assetIssueCapsule
483+
= this.getAssetIssueStore().get(assetName.toByteArray());
484+
issuerAccountCapsule = this.getAccountStore()
485+
.get(assetIssueCapsule.getOwnerAddress().toByteArray());
486+
bandwidth = issuerAccountCapsule.getBandwidth();
487+
} catch (Exception ex) {
488+
throw new ValidateBandwidthException(ex.getMessage());
489+
}
490+
if (bandwidth < bandwidthPerTransaction) {
491+
throw new ValidateBandwidthException("bandwidth is not enough");
492+
}
493+
issuerAccountCapsule.setBandwidth(bandwidth - bandwidthPerTransaction);
494+
this.getAccountStore().put(issuerAccountCapsule.createDbKey(), issuerAccountCapsule);
495+
} else {
496+
bandwidth = accountCapsule.getBandwidth();
497+
if (bandwidth < bandwidthPerTransaction) {
498+
throw new ValidateBandwidthException("bandwidth is not enough");
499+
}
500+
accountCapsule.setBandwidth(bandwidth - bandwidthPerTransaction);
477501
}
478-
accountCapsule.setBandwidth(bandwidth - bandwidthPerTransaction);
479502
accountCapsule.setLatestOperationTime(now);
480503
this.getAccountStore().put(accountCapsule.createDbKey(), accountCapsule);
481504
}

0 commit comments

Comments
 (0)