Skip to content

Commit

Permalink
Merge pull request tronprotocol#3615 from tronprotocol/remove-blackho…
Browse files Browse the repository at this point in the history
…le-account

add the query burn trx interface
  • Loading branch information
lvs007 authored Jan 13, 2021
2 parents 2d4a7f9 + 6bf2ebb commit f09bedb
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 15 deletions.
40 changes: 31 additions & 9 deletions framework/src/main/java/org/tron/core/services/RpcApiService.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.tron.core.services;

import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;

import com.google.common.base.Preconditions;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
Expand Down Expand Up @@ -142,7 +140,6 @@
import org.tron.protos.contract.AssetIssueContractOuterClass.TransferAssetContract;
import org.tron.protos.contract.AssetIssueContractOuterClass.UnfreezeAssetContract;
import org.tron.protos.contract.AssetIssueContractOuterClass.UpdateAssetContract;
import org.tron.protos.contract.BalanceContract;
import org.tron.protos.contract.BalanceContract.AccountBalanceRequest;
import org.tron.protos.contract.BalanceContract.AccountBalanceResponse;
import org.tron.protos.contract.BalanceContract.BlockBalanceTrace;
Expand Down Expand Up @@ -672,6 +669,11 @@ public void getBrokerageInfo(BytesMessage request,
getBrokerageInfoCommon(request, responseObserver);
}

@Override
public void getBurnTrx(EmptyMessage request, StreamObserver<NumberMessage> responseObserver) {
getBurnTrxCommon(request, responseObserver);
}

@Override
public void getMerkleTreeVoucherInfo(OutputPointInfo request,
StreamObserver<IncrementalMerkleVoucherInfo> responseObserver) {
Expand Down Expand Up @@ -959,9 +961,10 @@ public void getAccountById(Account req, StreamObserver<Account> responseObserver
}

/**
*
*/
public void getAccountBalance(AccountBalanceRequest request,
StreamObserver<AccountBalanceResponse> responseObserver) {
StreamObserver<AccountBalanceResponse> responseObserver) {
try {
AccountBalanceResponse accountBalanceResponse = wallet.getAccountBalance(request);
responseObserver.onNext(accountBalanceResponse);
Expand All @@ -972,9 +975,10 @@ public void getAccountBalance(AccountBalanceRequest request,
}

/**
*
*/
public void getBlockBalanceTrace(BlockBalanceTrace.BlockIdentifier request,
StreamObserver<BlockBalanceTrace> responseObserver) {
StreamObserver<BlockBalanceTrace> responseObserver) {
try {
BlockBalanceTrace blockBalanceTrace = wallet.getBlockBalance(request);
responseObserver.onNext(blockBalanceTrace);
Expand Down Expand Up @@ -1017,7 +1021,7 @@ private void createTransactionExtention(Message request, ContractType contractTy
} catch (ContractValidateException e) {
retBuilder.setResult(false).setCode(response_code.CONTRACT_VALIDATE_ERROR)
.setMessage(ByteString
.copyFromUtf8(Wallet.CONTRACT_VALIDATE_ERROR + e.getMessage()));
.copyFromUtf8(Wallet.CONTRACT_VALIDATE_ERROR + e.getMessage()));
logger.debug(CONTRACT_VALIDATE_EXCEPTION, e.getMessage());
} catch (Exception e) {
retBuilder.setResult(false).setCode(response_code.OTHER_ERROR)
Expand Down Expand Up @@ -1895,7 +1899,7 @@ private void callContract(TriggerSmartContract request,
} catch (ContractValidateException | VMIllegalException e) {
retBuilder.setResult(false).setCode(response_code.CONTRACT_VALIDATE_ERROR)
.setMessage(ByteString.copyFromUtf8(Wallet
.CONTRACT_VALIDATE_ERROR + e.getMessage()));
.CONTRACT_VALIDATE_ERROR + e.getMessage()));
trxExtBuilder.setResult(retBuilder);
logger.warn(CONTRACT_VALIDATE_EXCEPTION, e.getMessage());
} catch (RuntimeException e) {
Expand Down Expand Up @@ -2069,7 +2073,7 @@ public void createShieldedTransaction(PrivateParameters request,
} catch (ContractValidateException | ZksnarkException e) {
retBuilder.setResult(false).setCode(response_code.CONTRACT_VALIDATE_ERROR)
.setMessage(ByteString
.copyFromUtf8(Wallet.CONTRACT_VALIDATE_ERROR + e.getMessage()));
.copyFromUtf8(Wallet.CONTRACT_VALIDATE_ERROR + e.getMessage()));
logger.debug(CONTRACT_VALIDATE_EXCEPTION, e.getMessage());
} catch (Exception e) {
retBuilder.setResult(false).setCode(response_code.OTHER_ERROR)
Expand Down Expand Up @@ -2100,7 +2104,7 @@ public void createShieldedTransactionWithoutSpendAuthSig(PrivateParametersWithou
} catch (ContractValidateException | ZksnarkException e) {
retBuilder.setResult(false).setCode(response_code.CONTRACT_VALIDATE_ERROR)
.setMessage(ByteString
.copyFromUtf8(Wallet.CONTRACT_VALIDATE_ERROR + e.getMessage()));
.copyFromUtf8(Wallet.CONTRACT_VALIDATE_ERROR + e.getMessage()));
logger.debug(CONTRACT_VALIDATE_EXCEPTION, e.getMessage());
} catch (Exception e) {
retBuilder.setResult(false).setCode(response_code.OTHER_ERROR)
Expand Down Expand Up @@ -2510,6 +2514,11 @@ public void getBrokerageInfo(BytesMessage request,
getBrokerageInfoCommon(request, responseObserver);
}

@Override
public void getBurnTrx(EmptyMessage request, StreamObserver<NumberMessage> responseObserver) {
getBurnTrxCommon(request, responseObserver);
}

@Override
public void updateBrokerage(UpdateBrokerageContract request,
StreamObserver<TransactionExtention> responseObserver) {
Expand Down Expand Up @@ -2659,6 +2668,19 @@ public void getRewardInfoCommon(BytesMessage request,
responseObserver.onCompleted();
}

public void getBurnTrxCommon(EmptyMessage request,
StreamObserver<NumberMessage> responseObserver) {
try {
long value = dbManager.getDynamicPropertiesStore().getBurnTrxAmount();
NumberMessage.Builder builder = NumberMessage.newBuilder();
builder.setNum(value);
responseObserver.onNext(builder.build());
} catch (Exception e) {
responseObserver.onError(e);
}
responseObserver.onCompleted();
}

public void getBrokerageInfoCommon(BytesMessage request,
StreamObserver<NumberMessage> responseObserver) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ public class FullNodeHttpApiService implements Service {
@Autowired
private BroadcastHexServlet broadcastHexServlet;
@Autowired
private GetBurnTrxServlet getBurnTrxServlet;
@Autowired
private GetBrokerageServlet getBrokerageServlet;
@Autowired
private GetRewardServlet getRewardServlet;
Expand Down Expand Up @@ -515,6 +517,7 @@ public void start() {
"/wallet/getaccountbalance");
context.addServlet(new ServletHolder(getBlockBalanceServlet),
"/wallet/getblockbalance");
context.addServlet(new ServletHolder(getBurnTrxServlet), "/wallet/getburntrx");

int maxHttpConnectNumber = Args.getInstance().getMaxHttpConnectNumber();
if (maxHttpConnectNumber > 0) {
Expand All @@ -524,7 +527,7 @@ public void start() {
// filters the specified APIs
// when node is lite fullnode and openHistoryQueryWhenLiteFN is false
context.addFilter(new FilterHolder(liteFnQueryHttpFilter), "/*",
EnumSet.allOf(DispatcherType.class));
EnumSet.allOf(DispatcherType.class));

// filter
ServletHandler handler = new ServletHandler();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.tron.core.services.http;

import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.tron.core.db.Manager;


@Component
@Slf4j(topic = "API")
public class GetBurnTrxServlet extends RateLimiterServlet {

@Autowired
private Manager manager;

protected void doGet(HttpServletRequest request, HttpServletResponse response) {
try {
long value = manager.getDynamicPropertiesStore().getBurnTrxAmount();
response.getWriter().println("{\"burnTrxAmount\": " + value + "}");
} catch (Exception e) {
logger.error("", e);
try {
response.getWriter().println(Util.printErrorMsg(e));
} catch (IOException ioe) {
logger.debug("IOException: {}", ioe.getMessage());
}
}
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) {
doGet(request, response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.tron.core.services.http.GetBlockByLimitNextServlet;
import org.tron.core.services.http.GetBlockByNumServlet;
import org.tron.core.services.http.GetBrokerageServlet;
import org.tron.core.services.http.GetBurnTrxServlet;
import org.tron.core.services.http.GetDelegatedResourceAccountIndexServlet;
import org.tron.core.services.http.GetDelegatedResourceServlet;
import org.tron.core.services.http.GetExchangeByIdServlet;
Expand Down Expand Up @@ -127,7 +128,8 @@ public class SolidityNodeHttpApiService implements Service {
private GetMarketOrderListByPairServlet getMarketOrderListByPairServlet;
@Autowired
private GetMarketPairListServlet getMarketPairListServlet;

@Autowired
private GetBurnTrxServlet getBurnTrxServlet;
@Autowired
private GetBrokerageServlet getBrokerageServlet;
@Autowired
Expand Down Expand Up @@ -237,6 +239,7 @@ public void start() {
context.addServlet(new ServletHolder(getNodeInfoServlet), "/wallet/getnodeinfo");
context.addServlet(new ServletHolder(getBrokerageServlet), "/walletsolidity/getBrokerage");
context.addServlet(new ServletHolder(getRewardServlet), "/walletsolidity/getReward");
context.addServlet(new ServletHolder(getBurnTrxServlet), "/walletsolidity/getburntrx");

int maxHttpConnectNumber = Args.getInstance().getMaxHttpConnectNumber();
if (maxHttpConnectNumber > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ public void scanShieldedTRC20NotesByIvk(IvkDecryptTRC20Parameters request,
StreamObserver<DecryptNotesTRC20> responseObserver) {
walletOnPBFT.futureGet(
() -> rpcApiService.getWalletSolidityApi()
.scanShieldedTRC20NotesByIvk(request, responseObserver)
.scanShieldedTRC20NotesByIvk(request, responseObserver)
);
}

Expand All @@ -476,7 +476,7 @@ public void scanShieldedTRC20NotesByOvk(OvkDecryptTRC20Parameters request,
StreamObserver<DecryptNotesTRC20> responseObserver) {
walletOnPBFT.futureGet(
() -> rpcApiService.getWalletSolidityApi()
.scanShieldedTRC20NotesByOvk(request, responseObserver)
.scanShieldedTRC20NotesByOvk(request, responseObserver)
);
}

Expand All @@ -485,7 +485,14 @@ public void isShieldedTRC20ContractNoteSpent(NfTRC20Parameters request,
StreamObserver<NullifierResult> responseObserver) {
walletOnPBFT.futureGet(
() -> rpcApiService.getWalletSolidityApi()
.isShieldedTRC20ContractNoteSpent(request, responseObserver)
.isShieldedTRC20ContractNoteSpent(request, responseObserver)
);
}

@Override
public void getBurnTrx(EmptyMessage request, StreamObserver<NumberMessage> responseObserver) {
walletOnPBFT.futureGet(
() -> rpcApiService.getWalletSolidityApi().getBurnTrx(request, responseObserver)
);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.tron.core.services.interfaceOnPBFT.http;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.tron.core.services.http.GetBurnTrxServlet;
import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT;


@Component
@Slf4j(topic = "API")
public class GetBurnTrxOnPBFTServlet extends GetBurnTrxServlet {

@Autowired
private WalletOnPBFT walletOnPBFT;

protected void doGet(HttpServletRequest request, HttpServletResponse response) {
walletOnPBFT.futureGet(() -> super.doGet(request, response));
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) {
walletOnPBFT.futureGet(() -> super.doPost(request, response));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -485,5 +485,11 @@ public void getMarketPairList(EmptyMessage request,
);
}

@Override
public void getBurnTrx(EmptyMessage request, StreamObserver<NumberMessage> responseObserver) {
walletOnSolidity.futureGet(
() -> rpcApiService.getWalletSolidityApi().getBurnTrx(request, responseObserver)
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.tron.core.services.interfaceOnSolidity.http;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.tron.core.services.http.GetBurnTrxServlet;
import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity;


@Component
@Slf4j(topic = "API")
public class GetBurnTrxOnSolidityServlet extends GetBurnTrxServlet {

@Autowired
private WalletOnSolidity walletOnSolidity;

protected void doGet(HttpServletRequest request, HttpServletResponse response) {
walletOnSolidity.futureGet(() -> super.doGet(request, response));
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) {
walletOnSolidity.futureGet(() -> super.doPost(request, response));
}
}
7 changes: 6 additions & 1 deletion protocol/src/main/protos/api/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ service Wallet {
};

rpc GetAccountBalance (AccountBalanceRequest) returns (AccountBalanceResponse) {
option (google.api.http) = {
option (google.api.http) = {
post: "/wallet/getaccountbalance"
body: "*"
additional_bindings {
Expand Down Expand Up @@ -777,6 +777,9 @@ service Wallet {

rpc GetTransactionInfoByBlockNum (NumberMessage) returns (TransactionInfoList) {
}

rpc GetBurnTrx (EmptyMessage) returns (NumberMessage) {
}
};

service WalletSolidity {
Expand Down Expand Up @@ -960,6 +963,8 @@ service WalletSolidity {
rpc GetMarketPairList (EmptyMessage) returns (MarketOrderPairList) {
}

rpc GetBurnTrx (EmptyMessage) returns (NumberMessage) {
}
};

service WalletExtension {
Expand Down

0 comments on commit f09bedb

Please sign in to comment.