Skip to content

Commit

Permalink
Merge pull request #47 from tronprotocol/featture-optimize-construction
Browse files Browse the repository at this point in the history
remove useless operations
  • Loading branch information
lvs007 authored Aug 6, 2021
2 parents 8a398c9 + 4b5d937 commit e2279c6
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/main/java/org/tron/api/BlockApiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,15 @@ public Pair<Integer, String> handlerBlockTransaction(BlockTransactionRequest blo
}


private List<TransactionBalanceTrace.Operation> removeBlackHole(List<TransactionBalanceTrace.Operation> operations){
private List<TransactionBalanceTrace.Operation> removeUselessOperations(List<TransactionBalanceTrace.Operation> operations){
List<TransactionBalanceTrace.Operation> result = new LinkedList<>();
for (BalanceContract.TransactionBalanceTrace.Operation op : operations) {
if (Arrays.equals(op.getAddress().toByteArray(),chainBaseManager.getAccountStore().getBlackholeAddress())) {
continue;
}
if (op.getAmount()==0) {
continue;
}
result.add(op);
}
return result;
Expand Down Expand Up @@ -454,23 +457,23 @@ private org.tron.model.Transaction toRosettaVmTx(BalanceContract.TransactionBala
.transactionIdentifier(new org.tron.model.TransactionIdentifier()
.hash(ByteArray.toHexString(transactionBalanceTrace.getTransactionIdentifier().toByteArray())));
//2. set operations
List<BalanceContract.TransactionBalanceTrace.Operation> operations = removeBlackHole(transactionBalanceTrace.getOperationList());
List<BalanceContract.TransactionBalanceTrace.Operation> operations = removeUselessOperations(transactionBalanceTrace.getOperationList());

String feeAddress = "";
for (BalanceContract.TransactionBalanceTrace.Operation op : operations) {
if (op.getAmount() == -1 * energyFee) {
if (energyFee != 0 && op.getAmount() == -1 * energyFee) {
feeAddress = encode58Check(op.getAddress().toByteArray());
fee += op.getAmount();
energyFee = 0;
continue;
}
if (op.getAmount() == -1 * netFee) {
if (netFee != 0 && op.getAmount() == -1 * netFee) {
feeAddress = encode58Check(op.getAddress().toByteArray());
fee += op.getAmount();
netFee = 0;
continue;
}
if (op.getAmount() == -1 * multiSignFee) {
if (multiSignFee != 0 && op.getAmount() == -1 * multiSignFee) {
feeAddress = encode58Check(op.getAddress().toByteArray());
fee += op.getAmount();
multiSignFee = 0;
Expand Down Expand Up @@ -501,7 +504,7 @@ private org.tron.model.Transaction toRosettaOtherTx(BalanceContract.TransactionB
.transactionIdentifier(new org.tron.model.TransactionIdentifier()
.hash(ByteArray.toHexString(transactionBalanceTrace.getTransactionIdentifier().toByteArray())));

List<BalanceContract.TransactionBalanceTrace.Operation> operations = removeBlackHole(transactionBalanceTrace.getOperationList());
List<BalanceContract.TransactionBalanceTrace.Operation> operations = removeUselessOperations(transactionBalanceTrace.getOperationList());
int transactionCount = getTransOperationCount(transaction.getInstance().getRawData().getContract(0));
int feeOperationCount = operations.size() - transactionCount;
if (transactionBalanceTrace.getType().equals(ContractType.MarketSellAssetContract.name()) ||
Expand Down

0 comments on commit e2279c6

Please sign in to comment.