33
33
import org .tron .core .actuator .Actuator ;
34
34
import org .tron .core .actuator .ActuatorFactory ;
35
35
import org .tron .core .capsule .AccountCapsule ;
36
+ import org .tron .core .capsule .AssetIssueCapsule ;
36
37
import org .tron .core .capsule .BlockCapsule ;
37
38
import org .tron .core .capsule .BlockCapsule .BlockId ;
38
39
import org .tron .core .capsule .BytesCapsule ;
59
60
import org .tron .core .exception .ValidateScheduleException ;
60
61
import org .tron .core .exception .ValidateSignatureException ;
61
62
import org .tron .core .witness .WitnessController ;
63
+ import org .tron .protos .Contract .TransferAssetContract ;
62
64
import org .tron .protos .Protocol .AccountType ;
63
65
import org .tron .protos .Protocol .Transaction ;
64
66
@@ -453,7 +455,7 @@ public boolean pushTransactions(final TransactionCapsule trx)
453
455
}
454
456
455
457
456
- public void consumeBandwidth (TransactionCapsule trx ) throws ValidateBandwidthException {
458
+ private void consumeBandwidth (TransactionCapsule trx ) throws ValidateBandwidthException {
457
459
List <org .tron .protos .Protocol .Transaction .Contract > contracts =
458
460
trx .getInstance ().getRawData ().getContractList ();
459
461
for (Transaction .Contract contract : contracts ) {
@@ -462,7 +464,6 @@ public void consumeBandwidth(TransactionCapsule trx) throws ValidateBandwidthExc
462
464
if (accountCapsule == null ) {
463
465
throw new ValidateBandwidthException ("account not exists" );
464
466
}
465
- long bandwidth = accountCapsule .getBandwidth ();
466
467
long now = getHeadBlockTimeStamp ();
467
468
long latestOperationTime = accountCapsule .getLatestOperationTime ();
468
469
//10 * 1000
@@ -472,10 +473,32 @@ public void consumeBandwidth(TransactionCapsule trx) throws ValidateBandwidthExc
472
473
return ;
473
474
}
474
475
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 );
477
501
}
478
- accountCapsule .setBandwidth (bandwidth - bandwidthPerTransaction );
479
502
accountCapsule .setLatestOperationTime (now );
480
503
this .getAccountStore ().put (accountCapsule .createDbKey (), accountCapsule );
481
504
}
0 commit comments