@@ -855,6 +855,42 @@ public void consumeMultiSignFee(TransactionCapsule trx, TransactionTrace trace)
855855 }
856856 }
857857
858+ public void consumeMemoFee (TransactionCapsule trx , TransactionTrace trace )
859+ throws AccountResourceInsufficientException {
860+ if (trx .getInstance ().getRawData ().getData ().isEmpty ()) {
861+ // no memo
862+ return ;
863+ }
864+
865+ long fee = getDynamicPropertiesStore ().getMemoFee ();
866+ if (fee == 0 ) {
867+ return ;
868+ }
869+
870+ List <Contract > contracts = trx .getInstance ().getRawData ().getContractList ();
871+ for (Contract contract : contracts ) {
872+ byte [] address = TransactionCapsule .getOwner (contract );
873+ AccountCapsule accountCapsule = getAccountStore ().get (address );
874+ try {
875+ if (accountCapsule != null ) {
876+ adjustBalance (getAccountStore (), accountCapsule , -fee );
877+
878+ if (getDynamicPropertiesStore ().supportBlackHoleOptimization ()) {
879+ getDynamicPropertiesStore ().burnTrx (fee );
880+ } else {
881+ adjustBalance (getAccountStore (), this .getAccountStore ().getBlackhole (), +fee );
882+ }
883+ }
884+ } catch (BalanceInsufficientException e ) {
885+ throw new AccountResourceInsufficientException (
886+ String .format ("account %s insufficient balance[%d] to memo fee" ,
887+ StringUtil .encode58Check (address ), fee ));
888+ }
889+ }
890+
891+ trace .getReceipt ().setMemoFee (fee );
892+ }
893+
858894 public void consumeBandwidth (TransactionCapsule trx , TransactionTrace trace )
859895 throws ContractValidateException , AccountResourceInsufficientException ,
860896 TooBigTransactionResultException {
@@ -1338,6 +1374,7 @@ public TransactionInfo processTransaction(final TransactionCapsule trxCap, Block
13381374
13391375 consumeBandwidth (trxCap , trace );
13401376 consumeMultiSignFee (trxCap , trace );
1377+ consumeMemoFee (trxCap , trace );
13411378
13421379 trace .init (blockCap , eventPluginLoaded );
13431380 trace .checkIsConstant ();
0 commit comments