diff --git a/actuator/src/main/java/org/tron/core/utils/TransactionUtil.java b/actuator/src/main/java/org/tron/core/utils/TransactionUtil.java index 496af641cde..e5cffa49790 100644 --- a/actuator/src/main/java/org/tron/core/utils/TransactionUtil.java +++ b/actuator/src/main/java/org/tron/core/utils/TransactionUtil.java @@ -49,7 +49,6 @@ import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract; import org.tron.protos.Protocol.Transaction.Result.contractResult; -import org.tron.protos.Protocol.TransactionSign; import org.tron.protos.contract.SmartContractOuterClass.CreateSmartContract; import org.tron.protos.contract.SmartContractOuterClass.TriggerSmartContract; import org.tron.protos.Protocol.Transaction.Contract.ContractType; @@ -184,21 +183,6 @@ public static String makeUpperCamelMethod(String originName) { .replace("_", ""); } - public static TransactionCapsule getTransactionSign(TransactionSign transactionSign) { - byte[] privateKey = transactionSign.getPrivateKey().toByteArray(); - TransactionCapsule trx = new TransactionCapsule(transactionSign.getTransaction()); - trx.sign(privateKey); - return trx; - } - - public TransactionCapsule addSign(TransactionSign transactionSign) - throws PermissionException, SignatureException, SignatureFormatException { - byte[] privateKey = transactionSign.getPrivateKey().toByteArray(); - TransactionCapsule trx = new TransactionCapsule(transactionSign.getTransaction()); - trx.addSign(privateKey, chainBaseManager.getAccountStore()); - return trx; - } - public TransactionSignWeight getTransactionSignWeight(Transaction trx) { TransactionSignWeight.Builder tswBuilder = TransactionSignWeight.newBuilder(); TransactionExtention.Builder trxExBuilder = TransactionExtention.newBuilder(); diff --git a/framework/src/main/java/org/tron/core/Wallet.java b/framework/src/main/java/org/tron/core/Wallet.java index 86429b65fe0..8fd966384e3 100755 --- a/framework/src/main/java/org/tron/core/Wallet.java +++ b/framework/src/main/java/org/tron/core/Wallet.java @@ -648,18 +648,6 @@ public TransactionApprovedList getTransactionApprovedList(Transaction trx) { return tswBuilder.build(); } - public byte[] pass2Key(byte[] passPhrase) { - return Sha256Hash.hash(CommonParameter - .getInstance().isECKeyCryptoEngine(), passPhrase); - } - - public byte[] createAddress(byte[] passPhrase) { - byte[] privateKey = pass2Key(passPhrase); - SignInterface ecKey = SignUtils.fromPrivate(privateKey, - Args.getInstance().isECKeyCryptoEngine()); - return ecKey.getAddress(); - } - public Block getNowBlock() { List blockList = chainBaseManager.getBlockStore().getBlockByLatestNum(1); if (CollectionUtils.isEmpty(blockList)) { diff --git a/framework/src/main/java/org/tron/core/services/RpcApiService.java b/framework/src/main/java/org/tron/core/services/RpcApiService.java index a81be8f7728..1f767eeb237 100755 --- a/framework/src/main/java/org/tron/core/services/RpcApiService.java +++ b/framework/src/main/java/org/tron/core/services/RpcApiService.java @@ -16,15 +16,12 @@ import java.util.concurrent.TimeUnit; import lombok.Getter; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.codec.binary.Hex; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.api.DatabaseGrpc.DatabaseImplBase; import org.tron.api.GrpcAPI; import org.tron.api.GrpcAPI.AccountNetMessage; import org.tron.api.GrpcAPI.AccountResourceMessage; -import org.tron.api.GrpcAPI.Address; -import org.tron.api.GrpcAPI.AddressPrKeyPairMessage; import org.tron.api.GrpcAPI.AssetIssueList; import org.tron.api.GrpcAPI.BlockExtention; import org.tron.api.GrpcAPI.BlockLimit; @@ -39,11 +36,6 @@ import org.tron.api.GrpcAPI.DelegatedResourceList; import org.tron.api.GrpcAPI.DelegatedResourceMessage; import org.tron.api.GrpcAPI.DiversifierMessage; -import org.tron.api.GrpcAPI.EasyTransferAssetByPrivateMessage; -import org.tron.api.GrpcAPI.EasyTransferAssetMessage; -import org.tron.api.GrpcAPI.EasyTransferByPrivateMessage; -import org.tron.api.GrpcAPI.EasyTransferMessage; -import org.tron.api.GrpcAPI.EasyTransferResponse; import org.tron.api.GrpcAPI.EmptyMessage; import org.tron.api.GrpcAPI.EstimateEnergyMessage; import org.tron.api.GrpcAPI.ExchangeList; @@ -52,7 +44,6 @@ import org.tron.api.GrpcAPI.IncomingViewingKeyMessage; import org.tron.api.GrpcAPI.IvkDecryptTRC20Parameters; import org.tron.api.GrpcAPI.NfTRC20Parameters; -import org.tron.api.GrpcAPI.Node; import org.tron.api.GrpcAPI.NodeList; import org.tron.api.GrpcAPI.NoteParameters; import org.tron.api.GrpcAPI.NumberMessage; @@ -85,13 +76,10 @@ import org.tron.api.WalletGrpc.WalletImplBase; import org.tron.api.WalletSolidityGrpc.WalletSolidityImplBase; import org.tron.common.application.Service; -import org.tron.common.crypto.SignInterface; -import org.tron.common.crypto.SignUtils; import org.tron.common.parameter.CommonParameter; import org.tron.common.utils.ByteArray; import org.tron.common.utils.Sha256Hash; import org.tron.common.utils.StringUtil; -import org.tron.common.utils.Utils; import org.tron.core.ChainBaseManager; import org.tron.core.Wallet; import org.tron.core.capsule.AccountCapsule; @@ -108,7 +96,6 @@ import org.tron.core.exception.VMIllegalException; import org.tron.core.exception.ZksnarkException; import org.tron.core.metrics.MetricsApiService; -import org.tron.core.net.TronNetService; import org.tron.core.services.filter.LiteFnQueryGrpcInterceptor; import org.tron.core.services.ratelimiter.RateLimiterInterceptor; import org.tron.core.services.ratelimiter.RpcApiAccessInterceptor; @@ -130,7 +117,6 @@ import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.Protocol.TransactionInfo; -import org.tron.protos.Protocol.TransactionSign; import org.tron.protos.contract.AccountContract.AccountCreateContract; import org.tron.protos.contract.AccountContract.AccountPermissionUpdateContract; import org.tron.protos.contract.AccountContract.AccountUpdateContract; @@ -726,12 +712,6 @@ public void getTransactionInfoById(BytesMessage request, responseObserver.onCompleted(); } - @Override - public void generateAddress(EmptyMessage request, - StreamObserver responseObserver) { - generateAddressCommon(request, responseObserver); - } - @Override public void getRewardInfo(BytesMessage request, StreamObserver responseObserver) { @@ -1145,55 +1125,6 @@ private void createTransactionExtention(Message request, ContractType contractTy responseObserver.onCompleted(); } - - @Override - public void getTransactionSign(TransactionSign req, - StreamObserver responseObserver) { - TransactionCapsule result = TransactionUtil.getTransactionSign(req); - responseObserver.onNext(result.getInstance()); - responseObserver.onCompleted(); - } - - @Override - public void getTransactionSign2(TransactionSign req, - StreamObserver responseObserver) { - TransactionExtention.Builder trxExtBuilder = TransactionExtention.newBuilder(); - Return.Builder retBuilder = Return.newBuilder(); - try { - TransactionCapsule trx = TransactionUtil.getTransactionSign(req); - trxExtBuilder.setTransaction(trx.getInstance()); - trxExtBuilder.setTxid(trx.getTransactionId().getByteString()); - retBuilder.setResult(true).setCode(response_code.SUCCESS); - } catch (Exception e) { - retBuilder.setResult(false).setCode(response_code.OTHER_ERROR) - .setMessage(ByteString.copyFromUtf8(e.getClass() + " : " + e.getMessage())); - logger.info(EXCEPTION_CAUGHT + e.getMessage()); - } - trxExtBuilder.setResult(retBuilder); - responseObserver.onNext(trxExtBuilder.build()); - responseObserver.onCompleted(); - } - - @Override - public void addSign(TransactionSign req, - StreamObserver responseObserver) { - TransactionExtention.Builder trxExtBuilder = TransactionExtention.newBuilder(); - Return.Builder retBuilder = Return.newBuilder(); - try { - TransactionCapsule trx = transactionUtil.addSign(req); - trxExtBuilder.setTransaction(trx.getInstance()); - trxExtBuilder.setTxid(trx.getTransactionId().getByteString()); - retBuilder.setResult(true).setCode(response_code.SUCCESS); - } catch (Exception e) { - retBuilder.setResult(false).setCode(response_code.OTHER_ERROR) - .setMessage(ByteString.copyFromUtf8(e.getClass() + " : " + e.getMessage())); - logger.info(EXCEPTION_CAUGHT + e.getMessage()); - } - trxExtBuilder.setResult(retBuilder); - responseObserver.onNext(trxExtBuilder.build()); - responseObserver.onCompleted(); - } - @Override public void getTransactionSignWeight(Transaction req, StreamObserver responseObserver) { @@ -1210,121 +1141,6 @@ public void getTransactionApprovedList(Transaction req, responseObserver.onCompleted(); } - @Override - public void createAddress(BytesMessage req, - StreamObserver responseObserver) { - byte[] address = wallet.createAddress(req.getValue().toByteArray()); - BytesMessage.Builder builder = BytesMessage.newBuilder(); - builder.setValue(ByteString.copyFrom(address)); - responseObserver.onNext(builder.build()); - responseObserver.onCompleted(); - } - - private EasyTransferResponse easyTransfer(byte[] privateKey, ByteString toAddress, - long amount) { - TransactionCapsule transactionCapsule; - GrpcAPI.Return.Builder returnBuilder = GrpcAPI.Return.newBuilder(); - EasyTransferResponse.Builder responseBuild = EasyTransferResponse.newBuilder(); - try { - SignInterface cryptoEngine = SignUtils.fromPrivate(privateKey, Args.getInstance() - .isECKeyCryptoEngine()); - byte[] owner = cryptoEngine.getAddress(); - TransferContract.Builder builder = TransferContract.newBuilder(); - builder.setOwnerAddress(ByteString.copyFrom(owner)); - builder.setToAddress(toAddress); - builder.setAmount(amount); - transactionCapsule = createTransactionCapsule(builder.build(), - ContractType.TransferContract); - transactionCapsule.sign(privateKey); - GrpcAPI.Return result = wallet.broadcastTransaction(transactionCapsule.getInstance()); - responseBuild.setTransaction(transactionCapsule.getInstance()); - responseBuild.setTxid(transactionCapsule.getTransactionId().getByteString()); - responseBuild.setResult(result); - } catch (ContractValidateException e) { - returnBuilder.setResult(false).setCode(response_code.CONTRACT_VALIDATE_ERROR) - .setMessage(ByteString.copyFromUtf8(e.getMessage())); - responseBuild.setResult(returnBuilder.build()); - } catch (Exception e) { - returnBuilder.setResult(false).setCode(response_code.OTHER_ERROR) - .setMessage(ByteString.copyFromUtf8(e.getClass() + " : " + e.getMessage())); - responseBuild.setResult(returnBuilder.build()); - } - - return responseBuild.build(); - } - - @Override - public void easyTransfer(EasyTransferMessage req, - StreamObserver responseObserver) { - byte[] privateKey = wallet.pass2Key(req.getPassPhrase().toByteArray()); - EasyTransferResponse response = easyTransfer(privateKey, req.getToAddress(), req.getAmount()); - responseObserver.onNext(response); - responseObserver.onCompleted(); - } - - @Override - public void easyTransferAsset(EasyTransferAssetMessage req, - StreamObserver responseObserver) { - byte[] privateKey = wallet.pass2Key(req.getPassPhrase().toByteArray()); - EasyTransferResponse response = easyTransferAsset(privateKey, req.getToAddress(), - req.getAssetId(), req.getAmount()); - responseObserver.onNext(response); - responseObserver.onCompleted(); - } - - private EasyTransferResponse easyTransferAsset(byte[] privateKey, ByteString toAddress, - String assetId, long amount) { - TransactionCapsule transactionCapsule; - GrpcAPI.Return.Builder returnBuilder = GrpcAPI.Return.newBuilder(); - EasyTransferResponse.Builder responseBuild = EasyTransferResponse.newBuilder(); - try { - SignInterface cryptoEngine = SignUtils.fromPrivate(privateKey, - Args.getInstance().isECKeyCryptoEngine()); - byte[] owner = cryptoEngine.getAddress(); - TransferAssetContract.Builder builder = TransferAssetContract.newBuilder(); - builder.setOwnerAddress(ByteString.copyFrom(owner)); - builder.setToAddress(toAddress); - builder.setAssetName(ByteString.copyFrom(assetId.getBytes())); - builder.setAmount(amount); - transactionCapsule = createTransactionCapsule(builder.build(), - ContractType.TransferAssetContract); - transactionCapsule.sign(privateKey); - GrpcAPI.Return result = wallet.broadcastTransaction(transactionCapsule.getInstance()); - responseBuild.setTransaction(transactionCapsule.getInstance()); - responseBuild.setTxid(transactionCapsule.getTransactionId().getByteString()); - responseBuild.setResult(result); - } catch (ContractValidateException e) { - returnBuilder.setResult(false).setCode(response_code.CONTRACT_VALIDATE_ERROR) - .setMessage(ByteString.copyFromUtf8(e.getMessage())); - responseBuild.setResult(returnBuilder.build()); - } catch (Exception e) { - returnBuilder.setResult(false).setCode(response_code.OTHER_ERROR) - .setMessage(ByteString.copyFromUtf8(e.getClass() + " : " + e.getMessage())); - responseBuild.setResult(returnBuilder.build()); - } - - return responseBuild.build(); - } - - @Override - public void easyTransferByPrivate(EasyTransferByPrivateMessage req, - StreamObserver responseObserver) { - byte[] privateKey = req.getPrivateKey().toByteArray(); - EasyTransferResponse response = easyTransfer(privateKey, req.getToAddress(), req.getAmount()); - responseObserver.onNext(response); - responseObserver.onCompleted(); - } - - @Override - public void easyTransferAssetByPrivate(EasyTransferAssetByPrivateMessage req, - StreamObserver responseObserver) { - byte[] privateKey = req.getPrivateKey().toByteArray(); - EasyTransferResponse response = easyTransferAsset(privateKey, req.getToAddress(), - req.getAssetId(), req.getAmount()); - responseObserver.onNext(response); - responseObserver.onCompleted(); - } - @Override public void broadcastTransaction(Transaction req, StreamObserver responseObserver) { @@ -2235,12 +2051,6 @@ public void getChainParameters(EmptyMessage request, responseObserver.onCompleted(); } - @Override - public void generateAddress(EmptyMessage request, - StreamObserver responseObserver) { - generateAddressCommon(request, responseObserver); - } - @Override public void getTransactionInfoById(BytesMessage request, StreamObserver responseObserver) { @@ -2899,21 +2709,6 @@ public void getStatsInfo(EmptyMessage request, } } - public void generateAddressCommon(EmptyMessage request, - StreamObserver responseObserver) { - SignInterface cryptoEngine = SignUtils.getGeneratedRandomSign(Utils.getRandom(), - Args.getInstance().isECKeyCryptoEngine()); - byte[] priKey = cryptoEngine.getPrivateKey(); - byte[] address = cryptoEngine.getAddress(); - String addressStr = StringUtil.encode58Check(address); - String priKeyStr = Hex.encodeHexString(priKey); - AddressPrKeyPairMessage.Builder builder = AddressPrKeyPairMessage.newBuilder(); - builder.setAddress(addressStr); - builder.setPrivateKey(priKeyStr); - responseObserver.onNext(builder.build()); - responseObserver.onCompleted(); - } - public void getRewardInfoCommon(BytesMessage request, StreamObserver responseObserver) { try { diff --git a/framework/src/main/java/org/tron/core/services/http/AddTransactionSignServlet.java b/framework/src/main/java/org/tron/core/services/http/AddTransactionSignServlet.java deleted file mode 100644 index f9fd1fa4936..00000000000 --- a/framework/src/main/java/org/tron/core/services/http/AddTransactionSignServlet.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.tron.core.services.http; - -import com.alibaba.fastjson.JSONObject; -import java.util.stream.Collectors; -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.capsule.TransactionCapsule; -import org.tron.core.utils.TransactionUtil; -import org.tron.protos.Protocol.Transaction; -import org.tron.protos.Protocol.TransactionSign; - - -@Component -@Slf4j(topic = "API") -public class AddTransactionSignServlet extends RateLimiterServlet { - - @Autowired - private TransactionUtil transactionUtil; - - protected void doGet(HttpServletRequest request, HttpServletResponse response) { - - } - - protected void doPost(HttpServletRequest request, HttpServletResponse response) { - try { - String contract = request.getReader().lines() - .collect(Collectors.joining(System.lineSeparator())); - Util.checkBodySize(contract); - JSONObject input = JSONObject.parseObject(contract); - boolean visible = Util.getVisibleOnlyForSign(input); - String strTransaction = input.getJSONObject("transaction").toJSONString(); - 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, visible); - TransactionCapsule reply = transactionUtil.addSign(build.build()); - if (reply != null) { - response.getWriter().println(Util.printCreateTransaction(reply.getInstance(), visible)); - } else { - response.getWriter().println("{}"); - } - } catch (Exception e) { - Util.processError(e, response); - } - } -} diff --git a/framework/src/main/java/org/tron/core/services/http/CreateAddressServlet.java b/framework/src/main/java/org/tron/core/services/http/CreateAddressServlet.java deleted file mode 100644 index 7e52abddf6a..00000000000 --- a/framework/src/main/java/org/tron/core/services/http/CreateAddressServlet.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.tron.core.services.http; - -import static org.tron.core.services.http.PostParams.S_VALUE; - -import com.alibaba.fastjson.JSONObject; -import com.google.protobuf.ByteString; -import java.io.IOException; -import java.util.stream.Collectors; -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.api.GrpcAPI.BytesMessage; -import org.tron.common.utils.ByteArray; -import org.tron.common.utils.StringUtil; -import org.tron.core.Wallet; - - -@Component -@Slf4j(topic = "API") -public class CreateAddressServlet extends RateLimiterServlet { - - @Autowired - private Wallet wallet; - - protected void doGet(HttpServletRequest request, HttpServletResponse response) { - try { - boolean visible = Util.getVisible(request); - String input = request.getParameter(S_VALUE); - if (visible) { - input = Util.getHexString(input); - } - JSONObject jsonObject = new JSONObject(); - jsonObject.put(S_VALUE, input); - BytesMessage.Builder build = BytesMessage.newBuilder(); - JsonFormat.merge(jsonObject.toJSONString(), build, visible); - fillResponse(build.getValue(), response); - } catch (Exception e) { - Util.processError(e, response); - } - } - - protected void doPost(HttpServletRequest request, HttpServletResponse response) { - try { - PostParams params = PostParams.getPostParams(request); - boolean visible = params.isVisible(); - String input = params.getParams(); - if (visible) { - input = covertStringToHex(input); - } - BytesMessage.Builder build = BytesMessage.newBuilder(); - JsonFormat.merge(input, build, visible); - fillResponse(build.getValue(), response); - } catch (Exception e) { - Util.processError(e, response); - } - } - - private String covertStringToHex(String input) { - JSONObject jsonObject = JSONObject.parseObject(input); - String value = jsonObject.getString(S_VALUE); - jsonObject.put(S_VALUE, Util.getHexString(value)); - return jsonObject.toJSONString(); - } - - private void fillResponse(ByteString value, HttpServletResponse response) throws IOException { - byte[] address = wallet.createAddress(value.toByteArray()); - String base58check = StringUtil.encode58Check(address); - String hexString = ByteArray.toHexString(address); - JSONObject jsonAddress = new JSONObject(); - jsonAddress.put("base58checkAddress", base58check); - jsonAddress.put(S_VALUE, hexString); - response.getWriter().println(jsonAddress.toJSONString()); - } -} diff --git a/framework/src/main/java/org/tron/core/services/http/EasyTransferAssetByPrivateServlet.java b/framework/src/main/java/org/tron/core/services/http/EasyTransferAssetByPrivateServlet.java deleted file mode 100644 index 2739df81387..00000000000 --- a/framework/src/main/java/org/tron/core/services/http/EasyTransferAssetByPrivateServlet.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.tron.core.services.http; - -import com.google.protobuf.ByteString; -import java.io.IOException; -import java.util.stream.Collectors; -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.api.GrpcAPI; -import org.tron.api.GrpcAPI.EasyTransferAssetByPrivateMessage; -import org.tron.api.GrpcAPI.EasyTransferResponse; -import org.tron.api.GrpcAPI.Return.response_code; -import org.tron.common.crypto.SignInterface; -import org.tron.common.crypto.SignUtils; -import org.tron.core.Wallet; -import org.tron.core.capsule.TransactionCapsule; -import org.tron.core.config.args.Args; -import org.tron.protos.Protocol.Transaction.Contract.ContractType; -import org.tron.protos.contract.AssetIssueContractOuterClass.TransferAssetContract; - - -@Component -@Slf4j -public class EasyTransferAssetByPrivateServlet extends RateLimiterServlet { - - @Autowired - private Wallet wallet; - - 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 = Util.getVisiblePost(input); - EasyTransferAssetByPrivateMessage.Builder build = EasyTransferAssetByPrivateMessage - .newBuilder(); - JsonFormat.merge(input, build, visible); - byte[] privateKey = build.getPrivateKey().toByteArray(); - SignInterface ecKey = SignUtils.fromPrivate(privateKey, Args.getInstance() - .isECKeyCryptoEngine()); - byte[] owner = ecKey.getAddress(); - TransferAssetContract.Builder builder = TransferAssetContract.newBuilder(); - builder.setOwnerAddress(ByteString.copyFrom(owner)); - builder.setToAddress(build.getToAddress()); - builder.setAssetName(ByteString.copyFrom(build.getAssetId().getBytes())); - builder.setAmount(build.getAmount()); - - TransactionCapsule transactionCapsule; - transactionCapsule = wallet - .createTransactionCapsule(builder.build(), ContractType.TransferAssetContract); - transactionCapsule.sign(privateKey); - GrpcAPI.Return result = wallet.broadcastTransaction(transactionCapsule.getInstance()); - responseBuild.setTransaction(transactionCapsule.getInstance()); - responseBuild.setResult(result); - 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(), visible)); - } catch (IOException ioe) { - logger.debug("IOException: {}", ioe.getMessage()); - } - } - } -} diff --git a/framework/src/main/java/org/tron/core/services/http/EasyTransferAssetServlet.java b/framework/src/main/java/org/tron/core/services/http/EasyTransferAssetServlet.java deleted file mode 100644 index b6939570bac..00000000000 --- a/framework/src/main/java/org/tron/core/services/http/EasyTransferAssetServlet.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.tron.core.services.http; - -import com.google.protobuf.ByteString; -import java.io.IOException; -import java.util.stream.Collectors; -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.api.GrpcAPI; -import org.tron.api.GrpcAPI.EasyTransferAssetMessage; -import org.tron.api.GrpcAPI.EasyTransferResponse; -import org.tron.api.GrpcAPI.Return.response_code; -import org.tron.common.crypto.SignInterface; -import org.tron.common.crypto.SignUtils; -import org.tron.core.Wallet; -import org.tron.core.capsule.TransactionCapsule; -import org.tron.core.config.args.Args; -import org.tron.core.exception.ContractValidateException; -import org.tron.core.services.http.JsonFormat.ParseException; -import org.tron.protos.Protocol.Transaction.Contract.ContractType; -import org.tron.protos.contract.AssetIssueContractOuterClass.TransferAssetContract; - - -@Component -@Slf4j -public class EasyTransferAssetServlet extends RateLimiterServlet { - - private static final String S_IOEXCEPTION = "IOException: {}"; - - @Autowired - private Wallet wallet; - - 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 = Util.getVisiblePost(input); - EasyTransferAssetMessage.Builder build = EasyTransferAssetMessage.newBuilder(); - JsonFormat.merge(input, build, visible); - byte[] privateKey = wallet.pass2Key(build.getPassPhrase().toByteArray()); - SignInterface ecKey = SignUtils.fromPrivate(privateKey, Args.getInstance() - .isECKeyCryptoEngine()); - byte[] owner = ecKey.getAddress(); - TransferAssetContract.Builder builder = TransferAssetContract.newBuilder(); - builder.setOwnerAddress(ByteString.copyFrom(owner)); - builder.setToAddress(build.getToAddress()); - builder.setAssetName(ByteString.copyFrom(build.getAssetId().getBytes())); - builder.setAmount(build.getAmount()); - - TransactionCapsule transactionCapsule; - transactionCapsule = wallet - .createTransactionCapsule(builder.build(), ContractType.TransferAssetContract); - transactionCapsule.sign(privateKey); - GrpcAPI.Return result = wallet.broadcastTransaction(transactionCapsule.getInstance()); - responseBuild.setTransaction(transactionCapsule.getInstance()); - responseBuild.setResult(result); - response.getWriter().println(Util.printEasyTransferResponse(responseBuild.build(), visible)); - } catch (ParseException e) { - logger.debug("ParseException: {}", e.getMessage()); - returnBuilder.setResult(false).setCode(response_code.OTHER_ERROR) - .setMessage(ByteString.copyFromUtf8(e.getMessage())); - responseBuild.setResult(returnBuilder.build()); - try { - response.getWriter().println(JsonFormat.printToString(responseBuild.build(), visible)); - } catch (IOException ioe) { - logger.debug(S_IOEXCEPTION, ioe.getMessage()); - } - return; - } catch (IOException e) { - logger.debug(S_IOEXCEPTION, e.getMessage()); - returnBuilder.setResult(false).setCode(response_code.OTHER_ERROR) - .setMessage(ByteString.copyFromUtf8(e.getMessage())); - responseBuild.setResult(returnBuilder.build()); - try { - response.getWriter().println(JsonFormat.printToString(responseBuild.build(), visible)); - } catch (IOException ioe) { - logger.debug(S_IOEXCEPTION, ioe.getMessage()); - } - return; - } catch (ContractValidateException 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(), visible)); - } catch (IOException ioe) { - logger.debug(S_IOEXCEPTION, ioe.getMessage()); - } - return; - } - } -} diff --git a/framework/src/main/java/org/tron/core/services/http/EasyTransferByPrivateServlet.java b/framework/src/main/java/org/tron/core/services/http/EasyTransferByPrivateServlet.java deleted file mode 100644 index aa6574dc66f..00000000000 --- a/framework/src/main/java/org/tron/core/services/http/EasyTransferByPrivateServlet.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.tron.core.services.http; - -import com.google.protobuf.ByteString; -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.api.GrpcAPI; -import org.tron.api.GrpcAPI.EasyTransferByPrivateMessage; -import org.tron.api.GrpcAPI.EasyTransferResponse; -import org.tron.api.GrpcAPI.Return.response_code; -import org.tron.common.crypto.SignInterface; -import org.tron.common.crypto.SignUtils; -import org.tron.core.Wallet; -import org.tron.core.capsule.TransactionCapsule; -import org.tron.core.config.args.Args; -import org.tron.protos.Protocol.Transaction.Contract.ContractType; -import org.tron.protos.contract.BalanceContract.TransferContract; - - -@Component -@Slf4j(topic = "API") -public class EasyTransferByPrivateServlet extends RateLimiterServlet { - - @Autowired - private Wallet wallet; - - 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 { - PostParams params = PostParams.getPostParams(request); - visible = params.isVisible(); - EasyTransferByPrivateMessage.Builder build = EasyTransferByPrivateMessage.newBuilder(); - JsonFormat.merge(params.getParams(), build, visible); - byte[] privateKey = build.getPrivateKey().toByteArray(); - SignInterface ecKey = SignUtils.fromPrivate(privateKey, Args.getInstance() - .isECKeyCryptoEngine()); - byte[] owner = ecKey.getAddress(); - TransferContract.Builder builder = TransferContract.newBuilder(); - builder.setOwnerAddress(ByteString.copyFrom(owner)); - builder.setToAddress(build.getToAddress()); - builder.setAmount(build.getAmount()); - - TransactionCapsule transactionCapsule; - transactionCapsule = wallet - .createTransactionCapsule(builder.build(), ContractType.TransferContract); - transactionCapsule.sign(privateKey); - GrpcAPI.Return result = wallet.broadcastTransaction(transactionCapsule.getInstance()); - responseBuild.setTransaction(transactionCapsule.getInstance()); - responseBuild.setResult(result); - 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(), visible)); - } catch (IOException ioe) { - logger.debug("IOException: {}", ioe.getMessage()); - } - return; - } - } -} diff --git a/framework/src/main/java/org/tron/core/services/http/EasyTransferServlet.java b/framework/src/main/java/org/tron/core/services/http/EasyTransferServlet.java deleted file mode 100644 index 6c80153044e..00000000000 --- a/framework/src/main/java/org/tron/core/services/http/EasyTransferServlet.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.tron.core.services.http; - -import com.google.protobuf.ByteString; -import java.io.IOException; -import java.util.stream.Collectors; -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.api.GrpcAPI; -import org.tron.api.GrpcAPI.EasyTransferMessage; -import org.tron.api.GrpcAPI.EasyTransferResponse; -import org.tron.api.GrpcAPI.Return.response_code; -import org.tron.common.crypto.SignInterface; -import org.tron.common.crypto.SignUtils; -import org.tron.core.Wallet; -import org.tron.core.capsule.TransactionCapsule; -import org.tron.core.config.args.Args; -import org.tron.core.exception.ContractValidateException; -import org.tron.core.services.http.JsonFormat.ParseException; -import org.tron.protos.Protocol.Transaction.Contract.ContractType; -import org.tron.protos.contract.BalanceContract.TransferContract; - - -@Component -@Slf4j(topic = "API") -public class EasyTransferServlet extends RateLimiterServlet { - - @Autowired - private Wallet wallet; - - 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())); - Util.checkBodySize(input); - visible = Util.getVisiblePost(input); - EasyTransferMessage.Builder build = EasyTransferMessage.newBuilder(); - JsonFormat.merge(input, build, visible); - byte[] privateKey = wallet.pass2Key(build.getPassPhrase().toByteArray()); - SignInterface ecKey = SignUtils.fromPrivate(privateKey, Args.getInstance() - .isECKeyCryptoEngine()); - byte[] owner = ecKey.getAddress(); - TransferContract.Builder builder = TransferContract.newBuilder(); - builder.setOwnerAddress(ByteString.copyFrom(owner)); - builder.setToAddress(build.getToAddress()); - builder.setAmount(build.getAmount()); - - TransactionCapsule transactionCapsule; - transactionCapsule = wallet - .createTransactionCapsule(builder.build(), ContractType.TransferContract); - transactionCapsule.sign(privateKey); - GrpcAPI.Return result = wallet.broadcastTransaction(transactionCapsule.getInstance()); - responseBuild.setTransaction(transactionCapsule.getInstance()); - responseBuild.setResult(result); - response.getWriter().println(Util.printEasyTransferResponse(responseBuild.build(), visible)); - } catch (ParseException e) { - logger.debug("ParseException: {}", e.getMessage()); - } catch (IOException e) { - logger.debug("IOException: {}", e.getMessage()); - } catch (ContractValidateException 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(), visible)); - } catch (IOException ioe) { - logger.debug("IOException: {}", ioe.getMessage()); - } - } catch (Exception e) { - logger.debug("Exception: {}", e.getMessage()); - } - } -} diff --git a/framework/src/main/java/org/tron/core/services/http/FullNodeHttpApiService.java b/framework/src/main/java/org/tron/core/services/http/FullNodeHttpApiService.java index 43f00454fd3..030adc489ed 100644 --- a/framework/src/main/java/org/tron/core/services/http/FullNodeHttpApiService.java +++ b/framework/src/main/java/org/tron/core/services/http/FullNodeHttpApiService.java @@ -42,8 +42,6 @@ public class FullNodeHttpApiService implements Service { @Autowired private BroadcastServlet broadcastServlet; @Autowired - private TransactionSignServlet transactionSignServlet; - @Autowired private UpdateAccountServlet updateAccountServlet; @Autowired private VoteWitnessAccountServlet voteWitnessAccountServlet; @@ -114,18 +112,6 @@ public class FullNodeHttpApiService implements Service { @Autowired private GetNextMaintenanceTimeServlet getNextMaintenanceTimeServlet; @Autowired - private EasyTransferServlet easyTransferServlet; - @Autowired - private EasyTransferByPrivateServlet easyTransferByPrivateServlet; - @Autowired - private EasyTransferAssetServlet easyTransferAssetServlet; - @Autowired - private EasyTransferAssetByPrivateServlet easyTransferAssetByPrivateServlet; - @Autowired - private CreateAddressServlet createAddressServlet; - @Autowired - private GenerateAddressServlet generateAddressServlet; - @Autowired private ValidateAddressServlet validateAddressServlet; @Autowired private DeployContractServlet deployContractServlet; @@ -170,8 +156,6 @@ public class FullNodeHttpApiService implements Service { @Autowired private GetNodeInfoServlet getNodeInfoServlet; @Autowired - private AddTransactionSignServlet addTransactionSignServlet; - @Autowired private GetTransactionSignWeightServlet getTransactionSignWeightServlet; @Autowired private GetTransactionApprovedListServlet getTransactionApprovedListServlet; @@ -377,7 +361,6 @@ public void start() { context.addServlet(new ServletHolder(getAccountServlet), "/wallet/getaccount"); context.addServlet(new ServletHolder(transferServlet), "/wallet/createtransaction"); context.addServlet(new ServletHolder(broadcastServlet), "/wallet/broadcasttransaction"); - context.addServlet(new ServletHolder(transactionSignServlet), "/wallet/gettransactionsign"); context.addServlet(new ServletHolder(updateAccountServlet), "/wallet/updateaccount"); context.addServlet(new ServletHolder(voteWitnessAccountServlet), "/wallet/votewitnessaccount"); @@ -430,14 +413,6 @@ public void start() { context.addServlet(new ServletHolder(totalTransactionServlet), "/wallet/totaltransaction"); context.addServlet( new ServletHolder(getNextMaintenanceTimeServlet), "/wallet/getnextmaintenancetime"); - context.addServlet(new ServletHolder(createAddressServlet), "/wallet/createaddress"); - context.addServlet(new ServletHolder(easyTransferServlet), "/wallet/easytransfer"); - context.addServlet(new ServletHolder(easyTransferByPrivateServlet), - "/wallet/easytransferbyprivate"); - context.addServlet(new ServletHolder(easyTransferAssetServlet), "/wallet/easytransferasset"); - context.addServlet(new ServletHolder(easyTransferAssetByPrivateServlet), - "/wallet/easytransferassetbyprivate"); - context.addServlet(new ServletHolder(generateAddressServlet), "/wallet/generateaddress"); context.addServlet(new ServletHolder(validateAddressServlet), "/wallet/validateaddress"); context.addServlet(new ServletHolder(deployContractServlet), "/wallet/deploycontract"); context.addServlet(new ServletHolder(triggerSmartContractServlet), @@ -464,8 +439,6 @@ public void start() { "/wallet/getchainparameters"); context.addServlet(new ServletHolder(getAccountResourceServlet), "/wallet/getaccountresource"); - context.addServlet(new ServletHolder(addTransactionSignServlet), - "/wallet/addtransactionsign"); context.addServlet(new ServletHolder(getTransactionSignWeightServlet), "/wallet/getsignweight"); context.addServlet(new ServletHolder(getTransactionApprovedListServlet), diff --git a/framework/src/main/java/org/tron/core/services/http/GenerateAddressServlet.java b/framework/src/main/java/org/tron/core/services/http/GenerateAddressServlet.java deleted file mode 100644 index 1814b34c322..00000000000 --- a/framework/src/main/java/org/tron/core/services/http/GenerateAddressServlet.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.tron.core.services.http; - -import com.alibaba.fastjson.JSONObject; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.codec.binary.Hex; -import org.springframework.stereotype.Component; -import org.tron.common.crypto.SignInterface; -import org.tron.common.crypto.SignUtils; -import org.tron.common.utils.ByteArray; -import org.tron.common.utils.StringUtil; -import org.tron.common.utils.Utils; -import org.tron.core.config.args.Args; - - -@Component -@Slf4j(topic = "API") -public class GenerateAddressServlet extends RateLimiterServlet { - - protected void doGet(HttpServletRequest request, HttpServletResponse response) { - try { - SignInterface sign = SignUtils.getGeneratedRandomSign(Utils.getRandom(), - Args.getInstance().isECKeyCryptoEngine()); - byte[] priKey = sign.getPrivateKey(); - byte[] address = sign.getAddress(); - String priKeyStr = Hex.encodeHexString(priKey); - String base58check = StringUtil.encode58Check(address); - String hexString = ByteArray.toHexString(address); - JSONObject jsonAddress = new JSONObject(); - jsonAddress.put("address", base58check); - jsonAddress.put("hexAddress", hexString); - jsonAddress.put("privateKey", priKeyStr); - response.getWriter().println(jsonAddress.toJSONString()); - } catch (Exception e) { - Util.processError(e, response); - } - } - - protected void doPost(HttpServletRequest request, HttpServletResponse response) { - doGet(request, response); - } -} \ No newline at end of file diff --git a/framework/src/main/java/org/tron/core/services/http/HttpSelfFormatFieldName.java b/framework/src/main/java/org/tron/core/services/http/HttpSelfFormatFieldName.java index 3d3f73468bd..93b726bb0e5 100644 --- a/framework/src/main/java/org/tron/core/services/http/HttpSelfFormatFieldName.java +++ b/framework/src/main/java/org/tron/core/services/http/HttpSelfFormatFieldName.java @@ -13,14 +13,6 @@ public class HttpSelfFormatFieldName { //DelegatedResourceMessage AddressFieldNameMap.put("protocol.DelegatedResourceMessage.fromAddress", 1); AddressFieldNameMap.put("protocol.DelegatedResourceMessage.toAddress", 1); - //EasyTransferMessage - AddressFieldNameMap.put("protocol.EasyTransferMessage.toAddress", 1); - //EasyTransferAssetMessage - AddressFieldNameMap.put("protocol.EasyTransferAssetMessage.toAddress", 1); - //EasyTransferByPrivateMessage - AddressFieldNameMap.put("protocol.EasyTransferByPrivateMessage.toAddress", 1); - //EasyTransferAssetByPrivateMessage - AddressFieldNameMap.put("protocol.EasyTransferAssetByPrivateMessage.toAddress", 1); //TransactionSignWeight AddressFieldNameMap.put("protocol.TransactionSignWeight.approved_list", 1); //TransactionApprovedList @@ -140,8 +132,6 @@ public class HttpSelfFormatFieldName { //ShieldedTransferContract AddressFieldNameMap.put("protocol.ShieldedTransferContract.transparent_from_address", 1); AddressFieldNameMap.put("protocol.ShieldedTransferContract.transparent_to_address", 1); - //UpdateBrokerageContract - AddressFieldNameMap.put("protocol.UpdateBrokerageContract.owner_address", 1); //FreezeBalanceV2Contract AddressFieldNameMap.put("protocol.FreezeBalanceV2Contract.owner_address", 1); //UnfreezeBalanceV2Contract @@ -206,10 +196,6 @@ public class HttpSelfFormatFieldName { NameFieldNameMap.put("protocol.Return.message", 1); //Address NameFieldNameMap.put("protocol.Address.host", 1); - //EasyTransferMessage - NameFieldNameMap.put("protocol.EasyTransferMessage.passPhrase", 1); - //EasyTransferAssetMessage - NameFieldNameMap.put("protocol.EasyTransferAssetMessage.passPhrase", 1); //Note NameFieldNameMap.put("protocol.Note.memo", 1); diff --git a/framework/src/main/java/org/tron/core/services/http/TransactionSignServlet.java b/framework/src/main/java/org/tron/core/services/http/TransactionSignServlet.java deleted file mode 100644 index 86d1b07f457..00000000000 --- a/framework/src/main/java/org/tron/core/services/http/TransactionSignServlet.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.tron.core.services.http; - -import com.alibaba.fastjson.JSONObject; -import java.util.stream.Collectors; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; -import org.tron.core.capsule.TransactionCapsule; -import org.tron.core.utils.TransactionUtil; -import org.tron.protos.Protocol.Transaction; -import org.tron.protos.Protocol.TransactionSign; - - -@Component -@Slf4j(topic = "API") -public class TransactionSignServlet extends RateLimiterServlet { - - protected void doGet(HttpServletRequest request, HttpServletResponse response) { - - } - - protected void doPost(HttpServletRequest request, HttpServletResponse response) { - try { - String contract = request.getReader().lines() - .collect(Collectors.joining(System.lineSeparator())); - Util.checkBodySize(contract); - JSONObject input = JSONObject.parseObject(contract); - boolean visible = Util.getVisibleOnlyForSign(input); - String strTransaction = input.getJSONObject("transaction").toJSONString(); - 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, visible); - TransactionCapsule reply = TransactionUtil.getTransactionSign(build.build()); - if (reply != null) { - response.getWriter().println(Util.printCreateTransaction(reply.getInstance(), visible)); - } else { - response.getWriter().println("{}"); - } - } catch (Exception e) { - Util.processError(e, response); - } - } -} diff --git a/framework/src/main/java/org/tron/core/services/http/Util.java b/framework/src/main/java/org/tron/core/services/http/Util.java index 6c8ce0b832c..28ec18b59ac 100644 --- a/framework/src/main/java/org/tron/core/services/http/Util.java +++ b/framework/src/main/java/org/tron/core/services/http/Util.java @@ -27,7 +27,6 @@ import org.eclipse.jetty.util.StringUtil; import org.tron.api.GrpcAPI; import org.tron.api.GrpcAPI.BlockList; -import org.tron.api.GrpcAPI.EasyTransferResponse; import org.tron.api.GrpcAPI.TransactionApprovedList; import org.tron.api.GrpcAPI.TransactionExtention; import org.tron.api.GrpcAPI.TransactionIdList; @@ -129,12 +128,6 @@ public static JSONArray printTransactionListToJSON(List list return transactions; } - public static String printEasyTransferResponse(EasyTransferResponse response, boolean selfType) { - JSONObject jsonResponse = JSONObject.parseObject(JsonFormat.printToString(response, selfType)); - jsonResponse.put(TRANSACTION, printTransactionToJSON(response.getTransaction(), selfType)); - return jsonResponse.toJSONString(); - } - public static String printTransaction(Transaction transaction, boolean selfType) { return printTransactionToJSON(transaction, selfType).toJSONString(); } diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/RpcApiServiceOnPBFT.java b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/RpcApiServiceOnPBFT.java index 7232ba01ce5..c003f9d3994 100755 --- a/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/RpcApiServiceOnPBFT.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnPBFT/RpcApiServiceOnPBFT.java @@ -7,11 +7,9 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.codec.binary.Hex; import org.springframework.beans.factory.annotation.Autowired; import org.tron.api.DatabaseGrpc.DatabaseImplBase; import org.tron.api.GrpcAPI; -import org.tron.api.GrpcAPI.AddressPrKeyPairMessage; import org.tron.api.GrpcAPI.AssetIssueList; import org.tron.api.GrpcAPI.BlockExtention; import org.tron.api.GrpcAPI.BlockReference; @@ -414,22 +412,6 @@ public void estimateEnergy(TriggerSmartContract request, ); } - - @Override - public void generateAddress(EmptyMessage request, - StreamObserver responseObserver) { - ECKey ecKey = new ECKey(Utils.getRandom()); - byte[] priKey = ecKey.getPrivKeyBytes(); - byte[] address = ecKey.getAddress(); - String addressStr = StringUtil.encode58Check(address); - String priKeyStr = Hex.encodeHexString(priKey); - AddressPrKeyPairMessage.Builder builder = AddressPrKeyPairMessage.newBuilder(); - builder.setAddress(addressStr); - builder.setPrivateKey(priKeyStr); - responseObserver.onNext(builder.build()); - responseObserver.onCompleted(); - } - @Override public void getRewardInfo(BytesMessage request, StreamObserver responseObserver) { diff --git a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/RpcApiServiceOnSolidity.java b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/RpcApiServiceOnSolidity.java index 254c5227929..3f4bfeda731 100755 --- a/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/RpcApiServiceOnSolidity.java +++ b/framework/src/main/java/org/tron/core/services/interfaceOnSolidity/RpcApiServiceOnSolidity.java @@ -8,11 +8,9 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.codec.binary.Hex; import org.springframework.beans.factory.annotation.Autowired; import org.tron.api.DatabaseGrpc.DatabaseImplBase; import org.tron.api.GrpcAPI; -import org.tron.api.GrpcAPI.AddressPrKeyPairMessage; import org.tron.api.GrpcAPI.AssetIssueList; import org.tron.api.GrpcAPI.BlockExtention; import org.tron.api.GrpcAPI.BlockReference; @@ -398,23 +396,6 @@ public void estimateEnergy(TriggerSmartContract request, .estimateEnergy(request, responseObserver)); } - - @Override - public void generateAddress(EmptyMessage request, - StreamObserver responseObserver) { - SignInterface cryptoEngine = SignUtils - .getGeneratedRandomSign(Utils.getRandom(), Args.getInstance().isECKeyCryptoEngine()); - byte[] priKey = cryptoEngine.getPrivateKey(); - byte[] address = cryptoEngine.getAddress(); - String addressStr = StringUtil.encode58Check(address); - String priKeyStr = Hex.encodeHexString(priKey); - AddressPrKeyPairMessage.Builder builder = AddressPrKeyPairMessage.newBuilder(); - builder.setAddress(addressStr); - builder.setPrivateKey(priKeyStr); - responseObserver.onNext(builder.build()); - responseObserver.onCompleted(); - } - @Override public void getRewardInfo(BytesMessage request, StreamObserver responseObserver) { diff --git a/framework/src/test/java/org/tron/core/actuator/ShieldedTransferActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/ShieldedTransferActuatorTest.java index 3042a745d94..5bac3effbef 100755 --- a/framework/src/test/java/org/tron/core/actuator/ShieldedTransferActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/ShieldedTransferActuatorTest.java @@ -41,10 +41,10 @@ import org.tron.core.zen.note.Note; import org.tron.protos.Protocol.AccountType; import org.tron.protos.Protocol.Transaction.Contract; -import org.tron.protos.Protocol.TransactionSign; import org.tron.protos.contract.AssetIssueContractOuterClass.AssetIssueContract; import org.tron.protos.contract.ShieldContract.PedersenHash; import org.tron.protos.contract.ShieldContract.ShieldedTransferContract; +import stest.tron.wallet.common.client.utils.TransactionUtils; @Slf4j public class ShieldedTransferActuatorTest { @@ -232,11 +232,8 @@ public void publicAddressToShieldedAddressSuccess() { TransactionCapsule transactionCap = getPublicToShieldedTransaction(); //Add public address sign - TransactionSign.Builder transactionSignBuild = TransactionSign.newBuilder(); - transactionSignBuild.setTransaction(transactionCap.getInstance()); - transactionSignBuild.setPrivateKey(ByteString.copyFrom( - ByteArray.fromHexString(ADDRESS_ONE_PRIVATE_KEY))); - transactionCap = transactionUtil.addSign(transactionSignBuild.build()); + transactionCap = TransactionUtils.addTransactionSign(transactionCap.getInstance(), + ADDRESS_ONE_PRIVATE_KEY, dbManager.getAccountStore()); Assert.assertTrue(dbManager.pushTransaction(transactionCap)); } catch (Exception e) { @@ -263,11 +260,8 @@ public void publicAddressToPublicAddressAndZereValueOutputSuccess() { TransactionCapsule transactionCap = builder.build(); //Add public address sign - TransactionSign.Builder transactionSignBuild = TransactionSign.newBuilder(); - transactionSignBuild.setTransaction(transactionCap.getInstance()); - transactionSignBuild.setPrivateKey(ByteString.copyFrom( - ByteArray.fromHexString(ADDRESS_ONE_PRIVATE_KEY))); - transactionCap = transactionUtil.addSign(transactionSignBuild.build()); + transactionCap = TransactionUtils.addTransactionSign(transactionCap.getInstance(), + ADDRESS_ONE_PRIVATE_KEY, dbManager.getAccountStore()); Assert.assertTrue(dbManager.pushTransaction(transactionCap)); } catch (Exception e) { @@ -286,11 +280,8 @@ public void publicAddressToShieldedAddressInvalidSign() { TransactionCapsule transactionCap = getPublicToShieldedTransaction(); //Add public address sign - TransactionSign.Builder transactionSignBuild = TransactionSign.newBuilder(); - transactionSignBuild.setTransaction(transactionCap.getInstance()); - transactionSignBuild.setPrivateKey(ByteString.copyFrom( - ByteArray.fromHexString(ADDRESS_TWO_PRIVATE_KEY))); - transactionUtil.addSign(transactionSignBuild.build()); + TransactionUtils.addTransactionSign(transactionCap.getInstance(), ADDRESS_TWO_PRIVATE_KEY, + dbManager.getAccountStore()); Assert.assertTrue(false); } catch (PermissionException e) { Assert.assertTrue(e instanceof PermissionException); @@ -429,11 +420,8 @@ public void publicAddressToShieldedAddressNotConsumeBandwidth() { try { TransactionCapsule transactionCap = getPublicToShieldedTransaction(); //Add public address sign - TransactionSign.Builder transactionSignBuild = TransactionSign.newBuilder(); - transactionSignBuild.setTransaction(transactionCap.getInstance()); - transactionSignBuild.setPrivateKey(ByteString.copyFrom( - ByteArray.fromHexString(ADDRESS_ONE_PRIVATE_KEY))); - transactionCap = transactionUtil.addSign(transactionSignBuild.build()); + transactionCap = TransactionUtils.addTransactionSign(transactionCap.getInstance(), + ADDRESS_ONE_PRIVATE_KEY, dbManager.getAccountStore()); AccountCapsule accountCapsule = dbManager.getAccountStore().get(ByteArray.fromHexString(PUBLIC_ADDRESS_ONE)); @@ -1020,11 +1008,8 @@ public void publicToShieldAddressAndShieldToPublicAddressWithZoreValueSuccess() TransactionCapsule transactionCapOne = builderOne.build(); //Add public address sign - TransactionSign.Builder transactionSignBuild = TransactionSign.newBuilder(); - transactionSignBuild.setTransaction(transactionCapOne.getInstance()); - transactionSignBuild.setPrivateKey(ByteString.copyFrom( - ByteArray.fromHexString(ADDRESS_ONE_PRIVATE_KEY))); - transactionCapOne = transactionUtil.addSign(transactionSignBuild.build()); + transactionCapOne = TransactionUtils.addTransactionSign(transactionCapOne.getInstance(), + ADDRESS_ONE_PRIVATE_KEY, dbManager.getAccountStore()); Assert.assertTrue(dbManager.pushTransaction(transactionCapOne)); AccountCapsule accountCapsuleOne = diff --git a/framework/src/test/java/org/tron/core/zksnark/ShieldedReceiveTest.java b/framework/src/test/java/org/tron/core/zksnark/ShieldedReceiveTest.java index d3cbdb71e95..71501d68a41 100755 --- a/framework/src/test/java/org/tron/core/zksnark/ShieldedReceiveTest.java +++ b/framework/src/test/java/org/tron/core/zksnark/ShieldedReceiveTest.java @@ -93,7 +93,6 @@ import org.tron.protos.Protocol.Block; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract.ContractType; -import org.tron.protos.Protocol.TransactionSign; import org.tron.protos.contract.AssetIssueContractOuterClass.AssetIssueContract; import org.tron.protos.contract.ShieldContract.IncrementalMerkleVoucherInfo; import org.tron.protos.contract.ShieldContract.OutputPoint; @@ -102,6 +101,7 @@ import org.tron.protos.contract.ShieldContract.ReceiveDescription; import org.tron.protos.contract.ShieldContract.ShieldedTransferContract; import org.tron.protos.contract.ShieldContract.SpendDescription; +import stest.tron.wallet.common.client.utils.TransactionUtils; @Slf4j public class ShieldedReceiveTest extends BlockGenerate { @@ -329,13 +329,8 @@ public void testBroadcastBeforeAllowZksnark() TransactionCapsule transactionCap = builder.build(); //Add public address sign - TransactionSign.Builder transactionSignBuild = TransactionSign.newBuilder(); - transactionSignBuild.setTransaction(transactionCap.getInstance()); - transactionSignBuild.setPrivateKey(ByteString.copyFrom( - ByteArray.fromHexString(ADDRESS_ONE_PRIVATE_KEY))); - - transactionCap = transactionUtil.addSign(transactionSignBuild.build()); - + transactionCap = TransactionUtils.addTransactionSign(transactionCap.getInstance(), + ADDRESS_ONE_PRIVATE_KEY, chainBaseManager.getAccountStore()); try { dbManager.pushTransaction(transactionCap); Assert.assertFalse(true); diff --git a/framework/src/test/java/stest/tron/wallet/account/WalletTestAccount011.java b/framework/src/test/java/stest/tron/wallet/account/WalletTestAccount011.java index d50783f72c1..8d829424643 100644 --- a/framework/src/test/java/stest/tron/wallet/account/WalletTestAccount011.java +++ b/framework/src/test/java/stest/tron/wallet/account/WalletTestAccount011.java @@ -58,13 +58,6 @@ public void beforeClass() { } - @Test(enabled = true) - public void testgenerateAddress() { - EmptyMessage.Builder builder = EmptyMessage.newBuilder(); - blockingStubFull.generateAddress(builder.build()); - blockingStubSolidity.generateAddress(builder.build()); - } - /** * constructor. */ diff --git a/framework/src/test/java/stest/tron/wallet/common/client/utils/HttpMethed.java b/framework/src/test/java/stest/tron/wallet/common/client/utils/HttpMethed.java index 8ef8fecbd8e..adb7c0e54a0 100644 --- a/framework/src/test/java/stest/tron/wallet/common/client/utils/HttpMethed.java +++ b/framework/src/test/java/stest/tron/wallet/common/client/utils/HttpMethed.java @@ -1174,12 +1174,8 @@ public static HttpResponse unFreezeBalance( public static String gettransactionsign( String httpNode, String transactionString, String privateKey) { try { - String requestUrl = "http://" + httpNode + "/wallet/gettransactionsign"; - JsonObject userBaseObj2 = new JsonObject(); - userBaseObj2.addProperty("transaction", transactionString); - userBaseObj2.addProperty("privateKey", privateKey); - response = createConnect(requestUrl, userBaseObj2); - transactionSignString = EntityUtils.toString(response.getEntity()); + transactionSignString = TransactionUtils.getTransactionSign(transactionString, privateKey, + false); } catch (Exception e) { e.printStackTrace(); httppost.releaseConnection(); @@ -2968,36 +2964,6 @@ public static HttpResponse updateEnergyLimit( return response; } - /** constructor. */ - public static HttpResponse createAddress(String httpNode, String value) { - try { - final String requestUrl = "http://" + httpNode + "/wallet/createaddress"; - JsonObject userBaseObj2 = new JsonObject(); - userBaseObj2.addProperty("value", str2hex(value)); - response = createConnect(requestUrl, userBaseObj2); - logger.info(userBaseObj2.toString()); - } catch (Exception e) { - e.printStackTrace(); - httppost.releaseConnection(); - return null; - } - return response; - } - - /** constructor. */ - public static HttpResponse generateAddress(String httpNode) { - try { - final String requestUrl = "http://" + httpNode + "/wallet/generateaddress"; - JsonObject userBaseObj2 = new JsonObject(); - response = createConnect(requestUrl, userBaseObj2); - } catch (Exception e) { - e.printStackTrace(); - httppost.releaseConnection(); - return null; - } - return response; - } - /** constructor. */ public static HttpResponse getTransactionCountByBlocknum(String httpNode, long blocknum) { try { @@ -3029,92 +2995,6 @@ public static HttpResponse validateAddress(String httpNode, String address) { return response; } - /** constructor. */ - public static HttpResponse easyTransfer( - String httpNode, String value, byte[] toAddress, Long amount) { - try { - final String requestUrl = "http://" + httpNode + "/wallet/easytransfer"; - JsonObject userBaseObj2 = new JsonObject(); - userBaseObj2.addProperty("toAddress", ByteArray.toHexString(toAddress)); - userBaseObj2.addProperty("passPhrase", str2hex(value)); - userBaseObj2.addProperty("amount", amount); - response = createConnect(requestUrl, userBaseObj2); - logger.info(userBaseObj2.toString()); - transactionString = EntityUtils.toString(response.getEntity()); - logger.info(transactionString); - } catch (Exception e) { - e.printStackTrace(); - httppost.releaseConnection(); - return null; - } - return response; - } - - /** constructor. */ - public static HttpResponse easyTransferByPrivate( - String httpNode, String privateKey, byte[] toAddress, Long amount) { - try { - final String requestUrl = "http://" + httpNode + "/wallet/easytransferbyprivate"; - JsonObject userBaseObj2 = new JsonObject(); - userBaseObj2.addProperty("privateKey", privateKey); - userBaseObj2.addProperty("toAddress", ByteArray.toHexString(toAddress)); - userBaseObj2.addProperty("amount", amount); - response = createConnect(requestUrl, userBaseObj2); - logger.info(userBaseObj2.toString()); - transactionString = EntityUtils.toString(response.getEntity()); - logger.info(transactionString); - } catch (Exception e) { - e.printStackTrace(); - httppost.releaseConnection(); - return null; - } - return response; - } - - /** constructor. */ - public static HttpResponse easyTransferAsset( - String httpNode, String value, byte[] toAddress, Long amount, String assetId) { - try { - final String requestUrl = "http://" + httpNode + "/wallet/easytransferasset"; - JsonObject userBaseObj2 = new JsonObject(); - userBaseObj2.addProperty("toAddress", ByteArray.toHexString(toAddress)); - userBaseObj2.addProperty("passPhrase", str2hex(value)); - userBaseObj2.addProperty("amount", amount); - userBaseObj2.addProperty("assetId", assetId); - response = createConnect(requestUrl, userBaseObj2); - logger.info(userBaseObj2.toString()); - transactionString = EntityUtils.toString(response.getEntity()); - logger.info(transactionString); - } catch (Exception e) { - e.printStackTrace(); - httppost.releaseConnection(); - return null; - } - return response; - } - - /** constructor. */ - public static HttpResponse easyTransferAssetByPrivate( - String httpNode, String privateKey, byte[] toAddress, Long amount, String assetId) { - try { - final String requestUrl = "http://" + httpNode + "/wallet/easytransferassetbyprivate"; - JsonObject userBaseObj2 = new JsonObject(); - userBaseObj2.addProperty("privateKey", privateKey); - userBaseObj2.addProperty("toAddress", ByteArray.toHexString(toAddress)); - userBaseObj2.addProperty("amount", amount); - userBaseObj2.addProperty("assetId", assetId); - response = createConnect(requestUrl, userBaseObj2); - logger.info(userBaseObj2.toString()); - transactionString = EntityUtils.toString(response.getEntity()); - logger.info(transactionString); - } catch (Exception e) { - e.printStackTrace(); - httppost.releaseConnection(); - return null; - } - return response; - } - /** constructor. */ public static HttpResponse getContractInfo(String httpNode, String contractAddress) { try { diff --git a/framework/src/test/java/stest/tron/wallet/common/client/utils/TransactionUtils.java b/framework/src/test/java/stest/tron/wallet/common/client/utils/TransactionUtils.java index cc2af15ec7b..179af83e083 100644 --- a/framework/src/test/java/stest/tron/wallet/common/client/utils/TransactionUtils.java +++ b/framework/src/test/java/stest/tron/wallet/common/client/utils/TransactionUtils.java @@ -24,7 +24,13 @@ import org.tron.common.crypto.ECKey; import org.tron.common.crypto.ECKey.ECDSASignature; import org.tron.common.parameter.CommonParameter; +import org.tron.common.utils.ByteArray; import org.tron.common.utils.Sha256Hash; +import org.tron.core.capsule.TransactionCapsule; +import org.tron.core.exception.PermissionException; +import org.tron.core.exception.SignatureFormatException; +import org.tron.core.services.http.JsonFormat; +import org.tron.core.store.AccountStore; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract; import org.tron.protos.contract.AccountContract.AccountCreateContract; @@ -168,7 +174,6 @@ public static boolean validTransaction(Transaction signedTransaction) { */ public static Transaction sign(Transaction transaction, ECKey myKey) { - ByteString lockSript = ByteString.copyFrom(myKey.getAddress()); Transaction.Builder transactionBuilderSigned = transaction.toBuilder(); byte[] hash = Sha256Hash.hash(CommonParameter @@ -185,6 +190,30 @@ public static Transaction sign(Transaction transaction, ECKey myKey) { return transaction; } + public static String getTransactionSign(String transaction, String priKey, + boolean selfType) { + byte[] privateKey = ByteArray.fromHexString(priKey); + Transaction.Builder builder = Transaction.newBuilder(); + try { + JsonFormat.merge(transaction, builder, selfType); + TransactionCapsule trx = new TransactionCapsule(builder.build()); + trx.sign(privateKey); + return JsonFormat.printToString(trx.getInstance(), selfType); + } catch (JsonFormat.ParseException e) { + logger.error("{}", e); + } + return null; + } + + public static TransactionCapsule addTransactionSign(Transaction transaction, String priKey, + AccountStore accountStore) + throws PermissionException, SignatureException, SignatureFormatException { + byte[] privateKey = ByteArray.fromHexString(priKey); + TransactionCapsule trx = new TransactionCapsule(transaction); + trx.addSign(privateKey, accountStore); + return trx; + } + /** * constructor. */ diff --git a/framework/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestEasyAccount001.java b/framework/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestEasyAccount001.java deleted file mode 100644 index a4d854547fd..00000000000 --- a/framework/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestEasyAccount001.java +++ /dev/null @@ -1,281 +0,0 @@ -package stest.tron.wallet.dailybuild.http; - -import com.alibaba.fastjson.JSONObject; -import lombok.extern.slf4j.Slf4j; -import org.apache.http.HttpResponse; -import org.junit.Assert; -import org.testng.annotations.AfterClass; -import org.testng.annotations.Test; -import org.tron.common.crypto.ECKey; -import org.tron.common.utils.ByteArray; -import org.tron.common.utils.Commons; -import org.tron.common.utils.Utils; -import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.HttpMethed; -import stest.tron.wallet.common.client.utils.PublicMethed; - -@Slf4j -public class HttpTestEasyAccount001 { - - private static String assetIssueId; - private final String testKey002 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key1"); - private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); - long beforeEasyBalance = 0L; - long afterEasyBalance = 0L; - long beforeGenerateBalance = 0L; - long afterGenerateBalance = 0L; - long beforeEasyAsset = 0L; - long afterEasyAsset = 0L; - long beforeGenerateAsset = 0L; - long afterGenerateAsset = 0L; - ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] assetAddress = ecKey1.getAddress(); - String assetKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - private JSONObject responseContent; - private HttpResponse response; - private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(0); - private long now = System.currentTimeMillis(); - private final long totalSupply = now; - private String userPassword = "ps_" + now; - private String assetName = "httpEasyAsset_" + now; - private String easyAddress = null; - private String generatePriKey = null; - private String generateAddress = null; - private String generateHexAddress = null; - - /** - * constructor. - */ - @Test(enabled = true, description = "Create address by http") - public void test01CreateAddress() { - logger.info(userPassword); - response = HttpMethed.createAddress(httpnode, userPassword); - logger.info("code is " + response.getStatusLine().getStatusCode()); - Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); - responseContent = HttpMethed.parseResponseContent(response); - HttpMethed.printJsonContent(responseContent); - easyAddress = responseContent.get("base58checkAddress").toString(); - - //Send trx to easy account - response = HttpMethed - .sendCoin(httpnode, fromAddress, Commons.decodeFromBase58Check(easyAddress), 5000000L, - testKey002); - Assert.assertTrue(HttpMethed.verificationResult(response)); - HttpMethed.waitToProduceOneBlock(httpnode); - - beforeEasyBalance = HttpMethed.getBalance(httpnode, Commons.decodeFromBase58Check(easyAddress)); - logger.info("beforeEasyBalance: " + beforeEasyBalance); - - } - - /** - * constructor. - */ - @Test(enabled = true, description = "Generate address by http") - public void test02GenerateAddress() { - response = HttpMethed.generateAddress(httpnode); - logger.info("code is " + response.getStatusLine().getStatusCode()); - Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); - responseContent = HttpMethed.parseResponseContent(response); - HttpMethed.printJsonContent(responseContent); - generateAddress = responseContent.get("address").toString(); - generateHexAddress = responseContent.get("hexAddress").toString(); - generatePriKey = responseContent.get("privateKey").toString(); - - //Send trx to easy account - response = HttpMethed - .sendCoin(httpnode, fromAddress, Commons.decodeFromBase58Check(generateAddress), 5000000L, - testKey002); - Assert.assertTrue(HttpMethed.verificationResult(response)); - HttpMethed.waitToProduceOneBlock(httpnode); - - beforeGenerateBalance = HttpMethed - .getBalance(httpnode, Commons.decodeFromBase58Check(generateAddress)); - logger.info("beforeGenerateBalance: " + beforeGenerateBalance); - } - - - /** - * constructor. - */ - @Test(enabled = true, description = "Validate address by http") - public void test03ValideteAddress() { - // Base58check format - response = HttpMethed.validateAddress(httpnode, generateAddress); - logger.info("code is " + response.getStatusLine().getStatusCode()); - Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); - responseContent = HttpMethed.parseResponseContent(response); - HttpMethed.printJsonContent(responseContent); - - // Hex string format - response = HttpMethed.validateAddress(httpnode, generateHexAddress); - logger.info("code is " + response.getStatusLine().getStatusCode()); - Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); - responseContent = HttpMethed.parseResponseContent(response); - HttpMethed.printJsonContent(responseContent); - } - - - /** - * constructor. - */ - @Test(enabled = true, description = "Easy transfer by http") - public void test04EasyTransfer() { - response = HttpMethed - .easyTransfer(httpnode, userPassword, Commons.decodeFromBase58Check(generateAddress), - 1000000L); - logger.info("code is " + response.getStatusLine().getStatusCode()); - Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); - HttpMethed.waitToProduceOneBlock(httpnode); - - //Send trx to easy account - afterEasyBalance = HttpMethed.getBalance(httpnode, Commons.decodeFromBase58Check(easyAddress)); - logger.info("afterEasyBalance: " + afterEasyBalance); - - afterGenerateBalance = HttpMethed - .getBalance(httpnode, Commons.decodeFromBase58Check(generateAddress)); - logger.info("afterGenerateBalance: " + afterGenerateBalance); - - Assert.assertEquals(beforeEasyBalance - afterEasyBalance, - afterGenerateBalance - beforeGenerateBalance); - beforeEasyBalance = afterEasyBalance; - beforeGenerateBalance = afterGenerateBalance; - } - - /** - * constructor. - */ - @Test(enabled = true, description = "Easy transfer by privateKey by http") - public void test05EasyTransferByPrivateKey() { - response = HttpMethed - .easyTransferByPrivate(httpnode, generatePriKey, Commons.decodeFromBase58Check(easyAddress), - 1000000L); - logger.info("code is " + response.getStatusLine().getStatusCode()); - Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); - HttpMethed.waitToProduceOneBlock(httpnode); - - //Send trx to easy account - afterEasyBalance = HttpMethed.getBalance(httpnode, Commons.decodeFromBase58Check(easyAddress)); - logger.info("beforeEasyBalance: " + beforeEasyBalance); - logger.info("afterEasyBalance: " + afterEasyBalance); - - afterGenerateBalance = HttpMethed - .getBalance(httpnode, Commons.decodeFromBase58Check(generateAddress)); - logger.info("beforeGenerateBalance: " + beforeGenerateBalance); - logger.info("afterGenerateBalance: " + afterGenerateBalance); - - Assert.assertEquals(beforeGenerateBalance - afterGenerateBalance, - afterEasyBalance - beforeEasyBalance); - } - - /** - * constructor. - */ - @Test(enabled = true, description = "Create asset issue by http") - public void test06CreateAssetIssue() { - Long amount = 2048000000L; - response = HttpMethed.sendCoin(httpnode, fromAddress, assetAddress, amount, testKey002); - Assert.assertTrue(HttpMethed.verificationResult(response)); - HttpMethed.waitToProduceOneBlock(httpnode); - //Create an asset issue - response = HttpMethed - .assetIssue(httpnode, assetAddress, assetName, assetName, totalSupply, 1, 1, - System.currentTimeMillis() + 5000, System.currentTimeMillis() + 50000000, 2, 3, - description, url, 1000L, 1000L, assetKey); - Assert.assertTrue(HttpMethed.verificationResult(response)); - HttpMethed.waitToProduceOneBlock(httpnode); - - response = HttpMethed.getAccount(httpnode, assetAddress); - responseContent = HttpMethed.parseResponseContent(response); - HttpMethed.printJsonContent(responseContent); - - assetIssueId = responseContent.getString("asset_issued_ID"); - logger.info(assetIssueId); - Assert.assertTrue(Integer.parseInt(assetIssueId) > 1000000); - - response = HttpMethed - .transferAsset(httpnode, assetAddress, Commons.decodeFromBase58Check(easyAddress), - assetIssueId, 100L, assetKey); - Assert.assertTrue(HttpMethed.verificationResult(response)); - HttpMethed.waitToProduceOneBlock(httpnode); - - response = HttpMethed.getAccount(httpnode, Commons.decodeFromBase58Check(easyAddress)); - responseContent = HttpMethed.parseResponseContent(response); - HttpMethed.printJsonContent(responseContent); - beforeEasyAsset = responseContent.getJSONArray("assetV2").getJSONObject(0) - .getLongValue("value"); - logger.info("beforeEasyAsset:" + beforeEasyAsset); - } - - /** - * constructor. - */ - @Test(enabled = true, description = "Easy transfer asset by http") - public void test07EasyTransferAsset() { - response = HttpMethed - .easyTransferAsset(httpnode, userPassword, Commons.decodeFromBase58Check(generateAddress), - 10L, assetIssueId); - logger.info("code is " + response.getStatusLine().getStatusCode()); - Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); - HttpMethed.waitToProduceOneBlock(httpnode); - - response = HttpMethed.getAccount(httpnode, Commons.decodeFromBase58Check(easyAddress)); - responseContent = HttpMethed.parseResponseContent(response); - HttpMethed.printJsonContent(responseContent); - afterEasyAsset = responseContent.getJSONArray("assetV2").getJSONObject(0).getLongValue("value"); - logger.info("afterEasyAsset:" + afterEasyAsset); - - response = HttpMethed.getAccount(httpnode, Commons.decodeFromBase58Check(generateAddress)); - responseContent = HttpMethed.parseResponseContent(response); - HttpMethed.printJsonContent(responseContent); - beforeGenerateAsset = responseContent.getJSONArray("assetV2").getJSONObject(0) - .getLongValue("value"); - logger.info("beforeGenerateAsset:" + beforeGenerateAsset); - Assert.assertEquals(beforeEasyAsset - afterEasyAsset, beforeGenerateAsset); - beforeEasyAsset = afterEasyAsset; - } - - /** - * constructor. - */ - @Test(enabled = true, description = "Easy transfer asset by private key by http") - public void test08EasyTransferAssetByPrivateKey() { - response = HttpMethed.easyTransferAssetByPrivate(httpnode, generatePriKey, - Commons.decodeFromBase58Check(easyAddress), 5L, assetIssueId); - logger.info("code is " + response.getStatusLine().getStatusCode()); - Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); - HttpMethed.waitToProduceOneBlock(httpnode); - - response = HttpMethed.getAccount(httpnode, Commons.decodeFromBase58Check(easyAddress)); - responseContent = HttpMethed.parseResponseContent(response); - HttpMethed.printJsonContent(responseContent); - afterEasyAsset = responseContent.getJSONArray("assetV2").getJSONObject(0).getLongValue("value"); - logger.info("beforeEasyAsset:" + beforeEasyAsset); - logger.info("afterEasyAsset:" + afterEasyAsset); - - response = HttpMethed.getAccount(httpnode, Commons.decodeFromBase58Check(generateAddress)); - responseContent = HttpMethed.parseResponseContent(response); - HttpMethed.printJsonContent(responseContent); - afterGenerateAsset = responseContent.getJSONArray("assetV2").getJSONObject(0) - .getLongValue("value"); - logger.info("afterGenerateAsset:" + afterGenerateAsset); - Assert.assertEquals(beforeGenerateAsset - afterGenerateAsset, afterEasyAsset - beforeEasyAsset); - } - - /** - * constructor. - */ - @AfterClass - public void shutdown() throws InterruptedException { - HttpMethed.freedResource(httpnode, Commons.decodeFromBase58Check(generateAddress), fromAddress, - generatePriKey); - HttpMethed.freedResource(httpnode, assetAddress, fromAddress, assetKey); - HttpMethed.disConnect(); - } - -} diff --git a/protocol/src/main/protos/api/api.proto b/protocol/src/main/protos/api/api.proto index 48cd64acc5b..70297d0959b 100644 --- a/protocol/src/main/protos/api/api.proto +++ b/protocol/src/main/protos/api/api.proto @@ -624,68 +624,6 @@ service Wallet { } }; } - //Warning: do not invoke this interface provided by others. - //Please use GetTransactionSign2 instead of this function. - rpc GetTransactionSign (TransactionSign) returns (Transaction) { - option (google.api.http) = { - post: "/wallet/gettransactionsign" - body: "*" - additional_bindings { - get: "/wallet/gettransactionsign" - } - }; - }; - //Warning: do not invoke this interface provided by others. - //Use this function instead of GetTransactionSign. - rpc GetTransactionSign2 (TransactionSign) returns (TransactionExtention) { - }; - //Warning: do not invoke this interface provided by others. - rpc CreateAddress (BytesMessage) returns (BytesMessage) { - option (google.api.http) = { - post: "/wallet/createaddress" - body: "*" - additional_bindings { - get: "/wallet/createaddress" - } - }; - }; - //Warning: do not invoke this interface provided by others. - rpc EasyTransferAsset (EasyTransferAssetMessage) returns (EasyTransferResponse) { - }; - //Warning: do not invoke this interface provided by others. - rpc EasyTransferAssetByPrivate (EasyTransferAssetByPrivateMessage) returns (EasyTransferResponse) { - }; - //Warning: do not invoke this interface provided by others. - rpc EasyTransfer (EasyTransferMessage) returns (EasyTransferResponse) { - option (google.api.http) = { - post: "/wallet/easytransfer" - body: "*" - additional_bindings { - get: "/wallet/easytransfer" - } - }; - }; - //Warning: do not invoke this interface provided by others. - rpc EasyTransferByPrivate (EasyTransferByPrivateMessage) returns (EasyTransferResponse) { - option (google.api.http) = { - post: "/wallet/easytransferbyprivate" - body: "*" - additional_bindings { - get: "/wallet/easytransferbyprivate" - } - }; - }; - //Warning: do not invoke this interface provided by others. - rpc GenerateAddress (EmptyMessage) returns (AddressPrKeyPairMessage) { - - option (google.api.http) = { - post: "/wallet/generateaddress" - body: "*" - additional_bindings { - get: "/wallet/generateaddress" - } - }; - } rpc GetTransactionInfoById (BytesMessage) returns (TransactionInfo) { option (google.api.http) = { @@ -707,10 +645,6 @@ service Wallet { }; } - rpc AddSign (TransactionSign) returns (TransactionExtention) { - - } - rpc GetTransactionSignWeight (Transaction) returns (TransactionSignWeight) { } @@ -968,17 +902,6 @@ service WalletSolidity { }; } - //Warning: do not invoke this interface provided by others. - rpc GenerateAddress (EmptyMessage) returns (AddressPrKeyPairMessage) { - option (google.api.http) = { - post: "/walletsolidity/generateaddress" - body: "*" - additional_bindings { - get: "/walletsolidity/generateaddress" - } - }; - } - rpc GetMerkleTreeVoucherInfo (OutputPointInfo) returns (IncrementalMerkleVoucherInfo) { } @@ -1269,43 +1192,6 @@ message PaginatedMessage { int64 limit = 2; } -message EasyTransferMessage { - bytes passPhrase = 1; - bytes toAddress = 2; - int64 amount = 3; -} - -message EasyTransferAssetMessage { - bytes passPhrase = 1; - bytes toAddress = 2; - string assetId = 3; - int64 amount = 4; -} - -message EasyTransferByPrivateMessage { - bytes privateKey = 1; - bytes toAddress = 2; - int64 amount = 3; -} - -message EasyTransferAssetByPrivateMessage { - bytes privateKey = 1; - bytes toAddress = 2; - string assetId = 3; - int64 amount = 4; -} - -message EasyTransferResponse { - Transaction transaction = 1; - Return result = 2; - bytes txid = 3; //transaction id = sha256(transaction.rowdata) -} - -message AddressPrKeyPairMessage { - string address = 1; - string privateKey = 2; -} - message TransactionExtention { Transaction transaction = 1; bytes txid = 2; //transaction id = sha256(transaction.rowdata) diff --git a/protocol/src/main/protos/core/Tron.proto b/protocol/src/main/protos/core/Tron.proto index 437f5bf85a2..e5145484f05 100644 --- a/protocol/src/main/protos/core/Tron.proto +++ b/protocol/src/main/protos/core/Tron.proto @@ -494,11 +494,6 @@ message Transactions { repeated Transaction transactions = 1; } -message TransactionSign { - Transaction transaction = 1; - bytes privateKey = 2; -} - message BlockHeader { message raw { int64 timestamp = 1;