Skip to content

Commit

Permalink
Merge pull request #2141 from tronprotocol/feature/fix_http_2
Browse files Browse the repository at this point in the history
Feature/fix http 2
  • Loading branch information
renchenchang authored Apr 18, 2019
2 parents 5f13542 + 459f2e2 commit 335f525
Show file tree
Hide file tree
Showing 84 changed files with 1,201 additions and 374 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import org.tron.protos.Protocol.Transaction;
import org.tron.protos.Protocol.Transaction.Contract.ContractType;

import static org.tron.core.services.http.Util.getVisible;
import static org.tron.core.services.http.Util.getVisiblePost;


@Component
@Slf4j(topic = "API")
Expand All @@ -30,13 +33,14 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
String contract = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(contract);
boolean visible = getVisiblePost(contract);
AccountPermissionUpdateContract.Builder build = AccountPermissionUpdateContract.newBuilder();
JsonFormat.merge(contract, build);
JsonFormat.merge(contract, build, visible);

Transaction tx = wallet
.createTransactionCapsule(build.build(), ContractType.AccountPermissionUpdateContract)
.getInstance();
response.getWriter().println(Util.printTransaction(tx));
response.getWriter().println(Util.printTransaction(tx, visible));
} catch (Exception e) {
logger.debug("Exception: {}", e.getMessage());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import org.tron.protos.Protocol.Transaction;
import org.tron.protos.Protocol.TransactionSign;

import static org.tron.core.services.http.Util.getVisible;
import static org.tron.core.services.http.Util.getVisiblePost;


@Component
@Slf4j(topic = "API")
Expand All @@ -31,16 +34,17 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
String contract = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(contract);
boolean visible = getVisiblePost(contract);
JSONObject input = JSONObject.parseObject(contract);
String strTransaction = input.getJSONObject("transaction").toJSONString();
Transaction transaction = Util.packTransaction(strTransaction);
JSONObject jsonTransaction = JSONObject.parseObject(JsonFormat.printToString(transaction));
Transaction transaction = Util.packTransaction(strTransaction, visible);
JSONObject jsonTransaction = JSONObject.parseObject(JsonFormat.printToString(transaction, visible));
input.put("transaction", jsonTransaction);
TransactionSign.Builder build = TransactionSign.newBuilder();
JsonFormat.merge(input.toJSONString(), build);
JsonFormat.merge(input.toJSONString(), build, visible);
TransactionCapsule reply = wallet.addSign(build.build());
if (reply != null) {
response.getWriter().println(Util.printTransaction(reply.getInstance()));
response.getWriter().println(Util.printTransaction(reply.getInstance(), visible));
} else {
response.getWriter().println("{}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import org.tron.core.Wallet;
import org.tron.protos.Protocol.Transaction;

import static org.tron.core.services.http.Util.getVisible;
import static org.tron.core.services.http.Util.getVisiblePost;

@Component
@Slf4j(topic = "API")
public class BroadcastServlet extends HttpServlet {
Expand All @@ -24,9 +27,10 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
String input = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(input);
Transaction transaction = Util.packTransaction(input);
boolean visible = getVisiblePost(input);
Transaction transaction = Util.packTransaction(input, visible );
GrpcAPI.Return retur = wallet.broadcastTransaction(transaction);
response.getWriter().println(JsonFormat.printToString(retur));
response.getWriter().println(JsonFormat.printToString(retur, visible));
} catch (Exception e) {
logger.debug("Exception: {}", e.getMessage());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.tron.protos.Protocol.Transaction;
import org.tron.protos.Protocol.Transaction.Contract.ContractType;

import static org.tron.core.services.http.Util.getVisiblePost;

@Component
@Slf4j(topic = "API")
public class CancelDeferredTransactionByIdServlet extends HttpServlet {
Expand All @@ -27,13 +29,14 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
String contract = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(contract);
boolean visible = getVisiblePost( contract );
CancelDeferredTransactionContract.Builder build = CancelDeferredTransactionContract.newBuilder();
JsonFormat.merge(contract, build);
JsonFormat.merge(contract, build, visible );
Transaction tx = wallet
.createTransactionCapsule(build.build(), ContractType.CancelDeferredTransactionContract)
.getInstance();

response.getWriter().println(Util.printTransaction(tx));
response.getWriter().println(Util.printTransaction(tx, visible ));
} catch (Exception e) {
logger.debug("Exception: {}", e.getMessage());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.tron.protos.Protocol.Transaction;
import org.tron.protos.Protocol.Transaction.Contract.ContractType;

import static org.tron.core.services.http.Util.getVisiblePost;

@Component
@Slf4j(topic = "API")
Expand All @@ -33,19 +34,18 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
String contract = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(contract);
boolean visible = getVisiblePost( contract );
ClearABIContract.Builder build = ClearABIContract.newBuilder();
JsonFormat.merge(contract, build);
JsonFormat.merge(contract, build, visible );
Transaction tx = wallet
.createTransactionCapsule(build.build(), ContractType.ClearABIContract)
.getInstance();

JSONObject jsonObject = JSONObject.parseObject(contract);
if (jsonObject.containsKey(Constant.DELAY_SECONDS)) {
long delaySeconds = jsonObject.getLong(Constant.DELAY_SECONDS);
tx = TransactionUtil.setTransactionDelaySeconds(tx, delaySeconds);
}

response.getWriter().println(Util.printTransaction(tx));
response.getWriter().println(Util.printTransaction(tx, visible ));
} catch (Exception e) {
logger.debug("Exception: {}", e.getMessage());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
import org.tron.protos.Protocol.Transaction;
import org.tron.protos.Protocol.Transaction.Contract.ContractType;

import static org.tron.core.services.http.Util.getVisible;
import static org.tron.core.services.http.Util.getVisiblePost;


@Component
@Slf4j(topic = "API")
Expand All @@ -30,20 +33,20 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
String contract = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(contract);
boolean visible = getVisiblePost(contract);
AccountCreateContract.Builder build = AccountCreateContract.newBuilder();
JsonFormat.merge(contract, build);
JsonFormat.merge(contract, build, visible);
Transaction tx = wallet
.createTransactionCapsule(build.build(), ContractType.AccountCreateContract)
.getInstance();

JSONObject input = JSONObject.parseObject(contract);

if (input.containsKey(Constant.DELAY_SECONDS)) {
long delaySeconds = input.getLong(Constant.DELAY_SECONDS);
tx = TransactionUtil.setTransactionDelaySeconds(tx, delaySeconds);
}

response.getWriter().println(Util.printTransaction(tx));
response.getWriter().println(Util.printTransaction(tx, visible));
} catch (Exception e) {
logger.debug("Exception: {}", e.getMessage());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
import org.tron.common.utils.ByteArray;
import org.tron.core.Wallet;

import static org.tron.core.services.http.Util.getHexString;
import static org.tron.core.services.http.Util.getVisible;
import static org.tron.core.services.http.Util.getVisiblePost;


@Component
@Slf4j(topic = "API")
Expand All @@ -23,11 +27,15 @@ public class CreateAddressServlet extends HttpServlet {

protected void doGet(HttpServletRequest request, HttpServletResponse response) {
try {
boolean visible = getVisible(request);
String input = request.getParameter("value");
if ( visible ) {
input = getHexString( input );
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("value", input);
BytesMessage.Builder build = BytesMessage.newBuilder();
JsonFormat.merge(jsonObject.toJSONString(), build);
JsonFormat.merge(jsonObject.toJSONString(), build, visible);
byte[] address = wallet.createAdresss(build.getValue().toByteArray());
String base58check = Wallet.encode58Check(address);
String hexString = ByteArray.toHexString(address);
Expand All @@ -45,13 +53,24 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) {
}
}

private String CovertStringToHex(String input ) {
JSONObject jsonObject = JSONObject.parseObject(input);
String value = jsonObject.getString("value");
jsonObject.put("value", getHexString(value) );
return jsonObject.toJSONString();
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) {
try {
String input = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(input);
boolean visible = getVisiblePost(input);
if ( visible ) {
input = CovertStringToHex( input );
}
BytesMessage.Builder build = BytesMessage.newBuilder();
JsonFormat.merge(input, build);
JsonFormat.merge(input, build, visible);
byte[] address = wallet.createAdresss(build.getValue().toByteArray());
String base58check = Wallet.encode58Check(address);
String hexString = ByteArray.toHexString(address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import org.tron.protos.Protocol.Transaction;
import org.tron.protos.Protocol.Transaction.Contract.ContractType;

import static org.tron.core.services.http.Util.getVisible;
import static org.tron.core.services.http.Util.getVisiblePost;


@Component
@Slf4j(topic = "API")
Expand All @@ -30,11 +33,12 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
String contract = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(contract);
boolean visible = getVisiblePost(contract);
AssetIssueContract.Builder build = AssetIssueContract.newBuilder();
JsonFormat.merge(contract, build);
JsonFormat.merge(contract, build, visible );
Transaction tx = wallet
.createTransactionCapsule(build.build(), ContractType.AssetIssueContract).getInstance();
response.getWriter().println(Util.printTransaction(tx));
response.getWriter().println(Util.printTransaction(tx, visible));
} catch (Exception e) {
logger.debug("Exception: {}", e.getMessage());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import org.tron.protos.Protocol.Transaction;
import org.tron.protos.Protocol.Transaction.Contract.ContractType;

import static org.tron.core.services.http.Util.getVisible;
import static org.tron.core.services.http.Util.getVisiblePost;


@Component
@Slf4j(topic = "API")
Expand All @@ -30,12 +33,13 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
String contract = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(contract);
boolean visible = getVisiblePost(contract);
WitnessCreateContract.Builder build = WitnessCreateContract.newBuilder();
JsonFormat.merge(contract, build);
JsonFormat.merge(contract, build, visible );
Transaction tx = wallet
.createTransactionCapsule(build.build(), ContractType.WitnessCreateContract)
.getInstance();
response.getWriter().println(Util.printTransaction(tx));
response.getWriter().println(Util.printTransaction(tx, visible));
} catch (Exception e) {
logger.debug("Exception: {}", e.getMessage());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import org.tron.protos.Protocol.Transaction;
import org.tron.protos.Protocol.Transaction.Contract.ContractType;

import static org.tron.core.services.http.Util.getVisible;
import static org.tron.core.services.http.Util.getVisiblePost;


@Component
@Slf4j(topic = "API")
Expand All @@ -36,6 +39,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
String contract = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(contract);
boolean visible = getVisiblePost(contract);
CreateSmartContract.Builder build = CreateSmartContract.newBuilder();
JSONObject jsonObject = JSONObject.parseObject(contract);
byte[] ownerAddress = ByteArray.fromHexString(jsonObject.getString("owner_address"));
Expand All @@ -50,7 +54,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
abiSB.append(abi);
abiSB.append("}");
ABI.Builder abiBuilder = ABI.newBuilder();
JsonFormat.merge(abiSB.toString(), abiBuilder);
JsonFormat.merge(abiSB.toString(), abiBuilder, visible);

long feeLimit = jsonObject.getLongValue("fee_limit");

Expand Down Expand Up @@ -84,7 +88,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
Transaction.raw.Builder rawBuilder = tx.getRawData().toBuilder();
rawBuilder.setFeeLimit(feeLimit);
txBuilder.setRawData(rawBuilder);
response.getWriter().println(Util.printTransaction(txBuilder.build()));
response.getWriter().println(Util.printTransaction(txBuilder.build(), visible));
} catch (Exception e) {
logger.debug("Exception: {}", e.getMessage());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import org.tron.protos.Contract.TransferAssetContract;
import org.tron.protos.Protocol.Transaction.Contract.ContractType;

import static org.tron.core.services.http.Util.getVisible;
import static org.tron.core.services.http.Util.getVisiblePost;


@Component
@Slf4j
Expand All @@ -34,12 +37,14 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) {
protected void doPost(HttpServletRequest request, HttpServletResponse response) {
GrpcAPI.Return.Builder returnBuilder = GrpcAPI.Return.newBuilder();
EasyTransferResponse.Builder responseBuild = EasyTransferResponse.newBuilder();
boolean visible = false;
try {
String input = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
visible = getVisiblePost(input);
EasyTransferAssetByPrivateMessage.Builder build = EasyTransferAssetByPrivateMessage
.newBuilder();
JsonFormat.merge(input, build);
JsonFormat.merge(input, build, visible);
byte[] privateKey = build.getPrivateKey().toByteArray();
ECKey ecKey = ECKey.fromPrivate(privateKey);
byte[] owner = ecKey.getAddress();
Expand All @@ -56,13 +61,13 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
GrpcAPI.Return retur = wallet.broadcastTransaction(transactionCapsule.getInstance());
responseBuild.setTransaction(transactionCapsule.getInstance());
responseBuild.setResult(retur);
response.getWriter().println(Util.printEasyTransferResponse(responseBuild.build()));
response.getWriter().println(Util.printEasyTransferResponse(responseBuild.build(), visible));
} catch (Exception e) {
returnBuilder.setResult(false).setCode(response_code.CONTRACT_VALIDATE_ERROR)
.setMessage(ByteString.copyFromUtf8(e.getMessage()));
responseBuild.setResult(returnBuilder.build());
try {
response.getWriter().println(JsonFormat.printToString(responseBuild.build()));
response.getWriter().println(JsonFormat.printToString(responseBuild.build(), visible));
} catch (IOException ioe) {
logger.debug("IOException: {}", ioe.getMessage());
}
Expand Down
Loading

0 comments on commit 335f525

Please sign in to comment.