3333import org .tron .core .actuator .Actuator ;
3434import org .tron .core .actuator .ActuatorFactory ;
3535import org .tron .core .capsule .AccountCapsule ;
36+ import org .tron .core .capsule .AssetIssueCapsule ;
3637import org .tron .core .capsule .BlockCapsule ;
3738import org .tron .core .capsule .BlockCapsule .BlockId ;
3839import org .tron .core .capsule .BytesCapsule ;
5960import org .tron .core .exception .ValidateScheduleException ;
6061import org .tron .core .exception .ValidateSignatureException ;
6162import org .tron .core .witness .WitnessController ;
63+ import org .tron .protos .Contract .TransferAssetContract ;
6264import org .tron .protos .Protocol .AccountType ;
6365import 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