Skip to content

Commit

Permalink
Merge pull request #46 from tronprotocol/featture-optimize-construction
Browse files Browse the repository at this point in the history
optimize vm contract fee
  • Loading branch information
zhang0125 authored Aug 5, 2021
2 parents 92e53df + e53baa4 commit 8a398c9
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/main/java/org/tron/api/BlockApiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ private org.tron.model.Transaction toRosettaTx(BalanceContract.TransactionBalanc
}
if (transactionBalanceTrace.getType().equals(ContractType.CreateSmartContract.name()) ||
transactionBalanceTrace.getType().equals(ContractType.TriggerSmartContract.name())) {
return toRosettaVmTx(transactionBalanceTrace);
return toRosettaVmTx(transactionBalanceTrace,transaction);
}
return toRosettaOtherTx(transactionBalanceTrace,transaction);
}
Expand Down Expand Up @@ -415,7 +415,7 @@ private org.tron.model.Transaction toRosettaTransferTx(BalanceContract.Transacti
.operationIdentifier(new OperationIdentifier().index(0L))
.type("TransferContract")
.status(transactionBalanceTrace.getStatus())
.amount(new Amount().currency(Default.CURRENCY).value(Long.toString(transferContract.getAmount())))
.amount(new Amount().currency(Default.CURRENCY).value(Long.toString(-transferContract.getAmount())))
.account(new AccountIdentifier().address(encode58Check(transferContract.getOwnerAddress().toByteArray()))));
rstTx.addOperationsItem(new org.tron.model.Operation()
.operationIdentifier(new OperationIdentifier().index(1L))
Expand All @@ -436,16 +436,18 @@ private org.tron.model.Transaction toRosettaTransferTx(BalanceContract.Transacti
return rstTx;
}

private org.tron.model.Transaction toRosettaVmTx(BalanceContract.TransactionBalanceTrace transactionBalanceTrace){
private org.tron.model.Transaction toRosettaVmTx(BalanceContract.TransactionBalanceTrace transactionBalanceTrace,
TransactionCapsule transaction){
long energyFee = 0;
long netFee = 0;
long multiSignFee = 0;
long fee = 0;
String txid = ByteArray.toHexString(transactionBalanceTrace.getTransactionIdentifier().toByteArray());
Protocol.TransactionInfo reply = wallet.getTransactionInfoById(transactionBalanceTrace.getTransactionIdentifier());
if (reply != null) {
energyFee = reply.getReceipt().getEnergyFee();
netFee = reply.getReceipt().getNetFee();
fee = -reply.getFee();
multiSignFee = reply.getFee()- energyFee - netFee - transaction.getInstance().getRet(0).getFee();
}
//1. set tx
org.tron.model.Transaction rstTx = new org.tron.model.Transaction()
Expand All @@ -456,8 +458,22 @@ private org.tron.model.Transaction toRosettaVmTx(BalanceContract.TransactionBala

String feeAddress = "";
for (BalanceContract.TransactionBalanceTrace.Operation op : operations) {
if (op.getAmount() == -1 * energyFee || op.getAmount() == -1 * netFee) {
if (op.getAmount() == -1 * energyFee) {
feeAddress = encode58Check(op.getAddress().toByteArray());
fee += op.getAmount();
energyFee = 0;
continue;
}
if (op.getAmount() == -1 * netFee) {
feeAddress = encode58Check(op.getAddress().toByteArray());
fee += op.getAmount();
netFee = 0;
continue;
}
if (op.getAmount() == -1 * multiSignFee) {
feeAddress = encode58Check(op.getAddress().toByteArray());
fee += op.getAmount();
multiSignFee = 0;
continue;
}
long curIndex = rstTx.getOperations().size();
Expand Down

0 comments on commit 8a398c9

Please sign in to comment.