File tree 2 files changed +13
-13
lines changed
main/java/org/tron/core/services/event
test/java/org/tron/core/event 2 files changed +13
-13
lines changed Original file line number Diff line number Diff line change 39
39
import org .tron .core .exception .BadItemException ;
40
40
import org .tron .core .services .event .bo .BlockEvent ;
41
41
import org .tron .core .services .event .bo .SmartContractTrigger ;
42
+ import org .tron .core .services .jsonrpc .JsonRpcApiUtil ;
42
43
import org .tron .core .store .StoreFactory ;
43
44
import org .tron .protos .Protocol ;
44
45
import org .tron .protos .contract .SmartContractOuterClass ;
@@ -373,19 +374,7 @@ public List<TransactionLogTriggerCapsule> getTransactionLogTrigger(BlockCapsule
373
374
374
375
public long getEnergyPrice (long blockTime ) {
375
376
String energyPriceHistory = manager .getDynamicPropertiesStore ().getEnergyPriceHistory ();
376
-
377
- String [] energyPrices = energyPriceHistory .split ("," );
378
- String [] lastPrice = energyPrices [energyPrices .length - 1 ].split (":" );
379
- long energyPrice = Long .parseLong (lastPrice [1 ]);
380
-
381
- for (int i = 1 ; i < energyPrices .length ; i ++) {
382
- long effectiveTime = Long .parseLong (energyPrices [i ].split (":" )[0 ]);
383
- if (blockTime < effectiveTime ) {
384
- energyPrice = Long .parseLong (energyPrices [i - 1 ].split (":" )[1 ]);
385
- break ;
386
- }
387
- }
388
- return energyPrice ;
377
+ return JsonRpcApiUtil .parseEnergyFee (blockTime , energyPriceHistory );
389
378
}
390
379
391
380
public List <TransactionLogTriggerCapsule > getTransactionTriggers (BlockCapsule block ,
Original file line number Diff line number Diff line change @@ -150,6 +150,11 @@ public void test() throws Exception {
150
150
});
151
151
manager .pushBlock (blockCapsule );
152
152
153
+ // Set energy price history to test boundary cases
154
+ manager .getDynamicPropertiesStore ().saveEnergyPriceHistory (
155
+ manager .getDynamicPropertiesStore ().getEnergyPriceHistory ()
156
+ + "," + time + ":210" );
157
+
153
158
EventPluginConfig config = new EventPluginConfig ();
154
159
config .setSendQueueLength (1000 );
155
160
config .setBindPort (5555 );
@@ -187,6 +192,12 @@ public void test() throws Exception {
187
192
try {
188
193
BlockEvent blockEvent = blockEventGet .getBlockEvent (1 );
189
194
Assert .assertNotNull (blockEvent );
195
+ Assert .assertEquals (1 , blockEvent .getTransactionLogTriggerCapsules ().size ());
196
+
197
+ // Here energy unit price should be 100 not 210,
198
+ // cause block time is equal to 210`s effective time
199
+ Assert .assertEquals (100 , blockEvent .getTransactionLogTriggerCapsules ()
200
+ .get (0 ).getTransactionLogTrigger ().getEnergyUnitPrice ());
190
201
} catch (Exception e ) {
191
202
Assert .fail ();
192
203
}
You can’t perform that action at this time.
0 commit comments