@@ -83,6 +83,7 @@ public boolean execute(Object result) throws ContractExeException {
8383 byte [] receiverAddress = unfreezeBalanceContract .getReceiverAddress ().toByteArray ();
8484 //If the receiver is not included in the contract, unfreeze frozen balance for this account.
8585 //otherwise,unfreeze delegated frozen balance provided this account.
86+ long decrease = 0 ;
8687 if (!ArrayUtils .isEmpty (receiverAddress ) && dynamicStore .supportDR ()) {
8788 byte [] key = DelegatedResourceCapsule
8889 .createDbKey (unfreezeBalanceContract .getOwnerAddress ().toByteArray (),
@@ -107,25 +108,38 @@ public boolean execute(Object result) throws ContractExeException {
107108 }
108109
109110 AccountCapsule receiverCapsule = accountStore .get (receiverAddress );
111+
110112 if (dynamicStore .getAllowTvmConstantinople () == 0 ||
111113 (receiverCapsule != null && receiverCapsule .getType () != AccountType .Contract )) {
112114 switch (unfreezeBalanceContract .getResource ()) {
113115 case BANDWIDTH :
116+ long oldNetWeight = receiverCapsule .getAcquiredDelegatedFrozenBalanceForBandwidth () /
117+ TRX_PRECISION ;
114118 if (dynamicStore .getAllowTvmSolidity059 () == 1
115119 && receiverCapsule .getAcquiredDelegatedFrozenBalanceForBandwidth ()
116120 < unfreezeBalance ) {
121+ oldNetWeight = unfreezeBalance / TRX_PRECISION ;
117122 receiverCapsule .setAcquiredDelegatedFrozenBalanceForBandwidth (0 );
118123 } else {
119124 receiverCapsule .addAcquiredDelegatedFrozenBalanceForBandwidth (-unfreezeBalance );
120125 }
126+ long newNetWeight = receiverCapsule .getAcquiredDelegatedFrozenBalanceForBandwidth () /
127+ TRX_PRECISION ;
128+ decrease = newNetWeight - oldNetWeight ;
121129 break ;
122130 case ENERGY :
131+ long oldEnergyWeight = receiverCapsule .getAcquiredDelegatedFrozenBalanceForEnergy () /
132+ TRX_PRECISION ;
123133 if (dynamicStore .getAllowTvmSolidity059 () == 1
124134 && receiverCapsule .getAcquiredDelegatedFrozenBalanceForEnergy () < unfreezeBalance ) {
135+ oldEnergyWeight = unfreezeBalance / TRX_PRECISION ;
125136 receiverCapsule .setAcquiredDelegatedFrozenBalanceForEnergy (0 );
126137 } else {
127138 receiverCapsule .addAcquiredDelegatedFrozenBalanceForEnergy (-unfreezeBalance );
128139 }
140+ long newEnergyWeight = receiverCapsule .getAcquiredDelegatedFrozenBalanceForEnergy () /
141+ TRX_PRECISION ;
142+ decrease = newEnergyWeight - oldEnergyWeight ;
129143 break ;
130144 default :
131145 //this should never happen
@@ -213,19 +227,20 @@ public boolean execute(Object result) throws ContractExeException {
213227 }
214228
215229 }
216-
230+
231+ long weight = dynamicStore .allowNewRewardEnable () ? decrease : -unfreezeBalance / TRX_PRECISION ;
217232 switch (unfreezeBalanceContract .getResource ()) {
218233 case BANDWIDTH :
219234 dynamicStore
220- .addTotalNetWeight (- unfreezeBalance / TRX_PRECISION );
235+ .addTotalNetWeight (weight );
221236 break ;
222237 case ENERGY :
223238 dynamicStore
224- .addTotalEnergyWeight (- unfreezeBalance / TRX_PRECISION );
239+ .addTotalEnergyWeight (weight );
225240 break ;
226241 case TRON_POWER :
227242 dynamicStore
228- .addTotalTronPowerWeight (- unfreezeBalance / TRX_PRECISION );
243+ .addTotalTronPowerWeight (weight );
229244 break ;
230245 default :
231246 //this should never happen
0 commit comments