Skip to content

Commit

Permalink
Merge pull request tronprotocol#3154 from kaiserlinda/optimize_optimize
Browse files Browse the repository at this point in the history
optimize validBytes interface
  • Loading branch information
xxo1shine authored May 15, 2020
2 parents c0236f3 + e9f2f2e commit ce1d87f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 42 deletions.
36 changes: 17 additions & 19 deletions actuator/src/main/java/org/tron/core/utils/TransactionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,22 @@ public class TransactionUtil {
private static final int minAccountIdLen = 8;
private static final int maxAssetNameLen = 32;
private static final int maxTokenAbbrNameLen = 5;
private static final int maxAssetDescriptionLen = 200;
private static final int maxUrlLen = 256;

@Autowired
private ChainBaseManager chainBaseManager;

public static boolean validAccountName(byte[] accountName) {
if (ArrayUtils.isEmpty(accountName)) {
return true; //account name can be empty
}
return validBytes(accountName, maxAccountNameLen, true);
}

public static boolean validAssetDescription(byte[] description) {
return validBytes(description, maxAssetDescriptionLen, true);
}

return accountName.length <= maxAccountNameLen;
public static boolean validUrl(byte[] url) {
return validBytes(url, maxUrlLen, false);
}

public static boolean validAccountId(byte[] accountId) {
Expand All @@ -82,6 +88,13 @@ public static boolean validTokenAbbrName(byte[] abbrName) {
return validReadableBytes(abbrName, maxTokenAbbrNameLen);
}

private static boolean validBytes(byte[] bytes, int maxLength, boolean allowEmpty) {
if (ArrayUtils.isEmpty(bytes)) {
return allowEmpty;
}
return bytes.length <= maxLength;
}

private static boolean validReadableBytes(byte[] bytes, int maxLength) {
if (ArrayUtils.isEmpty(bytes) || bytes.length > maxLength) {
return false;
Expand All @@ -98,21 +111,6 @@ private static boolean validReadableBytes(byte[] bytes, int maxLength) {
return true;
}

public static boolean validAssetDescription(byte[] description) {
if (ArrayUtils.isEmpty(description)) {
return true; //description can empty
}

return description.length <= 200;
}

public static boolean validUrl(byte[] url) {
if (ArrayUtils.isEmpty(url)) {
return false;
}
return url.length <= 256;
}

public static boolean isNumber(byte[] id) {
if (ArrayUtils.isEmpty(id)) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.tron.common.utils.ByteArray;
import org.tron.common.utils.StringUtil;
import org.tron.common.utils.Utils;
import org.tron.common.utils.WalletUtil;
import org.tron.core.Wallet;
import org.tron.protos.Protocol;
import org.tron.protos.Protocol.TransactionInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
import org.tron.core.Wallet;
import org.tron.protos.Protocol;
import org.tron.protos.contract.WitnessContract;
import stest.tron.wallet.common.client.Configuration;
import stest.tron.wallet.common.client.Parameter.CommonConstant;
import stest.tron.wallet.common.client.utils.Base58;
import stest.tron.wallet.common.client.utils.PublicMethed;
import stest.tron.wallet.common.client.utils.PublicMethedForMutiSign;

Expand Down Expand Up @@ -81,13 +79,11 @@ public void testMutiSignForAccount() {
manager1Address = ecKey1.getAddress();
manager1Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes());


ecKey3 = new ECKey(Utils.getRandom());
ownerAddress = ecKey3.getAddress();
ownerKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes());
//PublicMethed.printAddress(ownerKey);


PublicMethed.sendcoin(ownerAddress, 200000000000L, fromAddress, testKey002,
blockingStubFull);
PublicMethed.waitProduceNextBlock(blockingStubFull);
Expand Down Expand Up @@ -117,7 +113,7 @@ public void testMutiSignForAccount() {
System.out.println("owner" + i + " --------------------------------------------------------");
PublicMethed.printAddress(ownerKey);
System.out.println("mutli sig address for owner "
+ i + " ----------------------------------");
+ i + " ----------------------------------");
PublicMethed.printAddress(manager1Key);
System.out.println("-------------------------------"
+ "-----------------------------------------");
Expand All @@ -138,15 +134,14 @@ public void test002CreateWitness() {
ownerKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes());
//PublicMethed.printAddress(ownerKey);


PublicMethed.sendcoin(ownerAddress, 50000000000L, fromAddress, testKey002,
blockingStubFull);

PublicMethed.waitProduceNextBlock(blockingStubFull);

String createWitnessUrl = "IOS-UI-Witness-00" + i;
byte[] createUrl = createWitnessUrl.getBytes();
createWitness(ownerAddress,createUrl,ownerKey);
createWitness(ownerAddress, createUrl, ownerKey);
PublicMethed.waitProduceNextBlock(blockingStubFull);
System.out.println("witness " + i + " -----------------------------"
+ "---------------------------");
Expand All @@ -163,7 +158,7 @@ public void test002CreateWitness() {

@Test(enabled = true, threadPoolSize = 1, invocationCount = 1)
public void test03MutiSignForAccount() {
HashMap<String,String> muti = new HashMap();
HashMap<String, String> muti = new HashMap();
muti.put("9a2ba173645be8d37a82084f984ba873fbcf817b589c62a59b3ba1494c3406e0",
"cefba96470224724bde255f3402fca3d67b6c7c5d34deb7a8524c9482c58fe8b");
muti.put("36f5430b4003f41ee8969421d9366ab1414e62111aec07a73d06eefcda8aad14",
Expand Down Expand Up @@ -247,7 +242,7 @@ public void test03MutiSignForAccount() {
System.out.println("owner " + i++ + " -----------------"
+ "---------------------------------------");
PublicMethed.printAddress(ownerKey);
System.out.println("mutli sig address for owner " + i++ + " ------------"
System.out.println("mutli sig address for owner " + i++ + " ------------"
+ "----------------------");
PublicMethed.printAddress(manager1Key);
System.out.println("-----------------------------------"
Expand Down Expand Up @@ -285,7 +280,7 @@ public void test004CreateWitness() {

String createWitnessUrl = "IOS-UI-Witness-00" + i++;
byte[] createUrl = createWitnessUrl.getBytes();
createWitness(ownerAddress,createUrl,ownerKey);
createWitness(ownerAddress, createUrl, ownerKey);
PublicMethed.waitProduceNextBlock(blockingStubFull);
PublicMethed.printAddress(ownerKey);
System.out.println("witness url is : " + createWitnessUrl);
Expand All @@ -297,10 +292,6 @@ public void test004CreateWitness() {
}






@Test(enabled = true, threadPoolSize = 1, invocationCount = 1)
public void test005SendTrc20() {

Expand Down Expand Up @@ -332,12 +323,13 @@ public void test005SendTrc20() {
+ "\"" + ", 20000000000";
System.out.println(triggerString);
//dapp chain trc20 tract TXkdXbzjoLpxGAD2strP1zwjJzR6osNfD7
byte[] contractAddress = PublicMethed.decode58Check("TXkdXbzjoLpxGAD2strP1zwjJzR6osNfD7");
byte[] contractAddress = PublicMethed.decode58Check("TXkdXbzjoLpxGAD2strP1zwjJzR6osNfD7");
//main chain TRC 20 contract TCCcBZEdTHmS1NfFtCYfwpjBKeTv515n71
//byte[] contractAddress = PublicMethed.decode58Check("TCCcBZEdTHmS1NfFtCYfwpjBKeTv515n71");

PublicMethed.triggerContract(contractAddress,"transfer(address,uint256)",triggerString,false,
0,1000000000,"0",0,fromAddress,testKey002,blockingStubFull);
PublicMethed
.triggerContract(contractAddress, "transfer(address,uint256)", triggerString, false,
0, 1000000000, "0", 0, fromAddress, testKey002, blockingStubFull);
PublicMethed.waitProduceNextBlock(blockingStubFull);


Expand All @@ -347,11 +339,6 @@ public void test005SendTrc20() {
}







/**
* constructor.
*/
Expand Down

0 comments on commit ce1d87f

Please sign in to comment.