Skip to content

Commit 86aed89

Browse files
committed
Merge remote-tracking branch 'origin/develop' into feature/ls_debug1
2 parents 3f44ebe + 1f848c7 commit 86aed89

42 files changed

Lines changed: 462 additions & 230 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ pernodedata.*
2929
ringstate.*
3030
shareddata.*
3131

32-
# svn
33-
.svn
34-
3532
# protobuf generated classes
3633
src/main/gen
3734

@@ -53,4 +50,4 @@ src/main/resources/META-INF/
5350
/output_manager/
5451
/output_witness/
5552

56-
nodeId.properties
53+
nodeId.properties

.travis.yml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1-
---
21
sudo: required
32
language: java
43
jdk: oraclejdk8
5-
64
script:
7-
- ./gradlew lint
8-
- ./gradlew test
9-
5+
- ./gradlew lint
6+
- ./gradlew test
7+
- cat tron > ~/.ssh/id_rsa
8+
- chmod 600 ~/.ssh/id_rsa
9+
addons:
10+
ssh_known_hosts:
11+
- 47.93.9.236:22008
12+
- 47.93.33.201:22008
13+
- 123.56.10.6:22008
14+
- 39.107.80.135:22008
15+
- 47.93.184.2:22008
1016
skip_build:
11-
- README.md
12-
- LICENSE
17+
- README.md
18+
- LICENSE
19+
deploy:
20+
provider: script
21+
script: bash deploy.sh
22+
on:
23+
branch: develop
24+
before_install:
25+
- openssl aes-256-cbc -K $encrypted_e5855cb9e09c_key -iv $encrypted_e5855cb9e09c_iv
26+
-in tron.enc -out tron -d

deploy.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
./gradlew clean shadowJar
3+
ssh tron@47.93.9.236 -p 22008 mkdir java-tron
4+
scp -P 22008 build/libs/java-tron.jar tron@47.93.9.236:/home/tron/java-tron/
5+
scp -P 22008 start.sh tron@47.93.9.236:/home/tron/java-tron/
6+
# ssh tron@47.93.9.236 -p 22008 sh java-tron/start.sh
7+
ls -a

src/main/java/org/tron/common/crypto/ECKey.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import java.util.Arrays;
4141
import javax.annotation.Nullable;
4242
import javax.crypto.KeyAgreement;
43-
4443
import lombok.extern.slf4j.Slf4j;
4544
import org.spongycastle.asn1.ASN1InputStream;
4645
import org.spongycastle.asn1.ASN1Integer;
@@ -367,7 +366,7 @@ public static byte[] publicKeyFromPrivate(BigInteger privKey, boolean
367366
* Compute an address from an encoded public key.
368367
*
369368
* @param pubBytes an encoded (uncompressed) public key
370-
* @return 20-byte address
369+
* @return 21-byte address
371370
*/
372371
public static byte[] computeAddress(byte[] pubBytes) {
373372
return Hash.sha3omit12(
@@ -378,7 +377,7 @@ public static byte[] computeAddress(byte[] pubBytes) {
378377
* Compute an address from a public point.
379378
*
380379
* @param pubPoint a public point
381-
* @return 20-byte address
380+
* @return 21-byte address
382381
*/
383382
public static byte[] computeAddress(ECPoint pubPoint) {
384383
return computeAddress(pubPoint.getEncoded(/* uncompressed */ false));

src/main/java/org/tron/common/crypto/Hash.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626
import java.security.Security;
2727
import lombok.extern.slf4j.Slf4j;
2828
import org.tron.common.crypto.jce.TronCastleProvider;
29+
import org.tron.core.Wallet;
2930

3031
@Slf4j
3132
public class Hash {
33+
3234
private static final Provider CRYPTO_PROVIDER;
3335

3436
private static final String HASH_256_ALGORITHM_NAME;
@@ -124,10 +126,12 @@ public static byte[] sha512(byte[] input) {
124126
* Calculates RIGTMOST160(SHA3(input)). This is used in address calculations. *
125127
*
126128
* @param input - data
127-
* @return - 20 right bytes of the hash keccak of the data
129+
* @return - add_pre_fix + 20 right bytes of the hash keccak of the data
128130
*/
129131
public static byte[] sha3omit12(byte[] input) {
130132
byte[] hash = sha3(input);
131-
return copyOfRange(hash, 12, hash.length);
133+
byte[] address = copyOfRange(hash, 11, hash.length);
134+
address[0] = Wallet.getAddressPreFixByte();
135+
return address;
132136
}
133137
}

src/main/java/org/tron/common/overlay/server/SyncPool.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.slf4j.Logger;
3131
import org.slf4j.LoggerFactory;
3232
import org.springframework.beans.factory.annotation.Autowired;
33+
import org.springframework.context.ApplicationContext;
3334
import org.springframework.stereotype.Component;
3435
import org.tron.common.overlay.client.PeerClient;
3536
import org.tron.common.overlay.discover.Node;
@@ -52,6 +53,8 @@ public class SyncPool {
5253
private NodeManager nodeManager;
5354

5455
@Autowired
56+
private ApplicationContext ctx;
57+
5558
private ChannelManager channelManager;
5659

5760
private PeerConnectionDelegate peerDel;
@@ -70,10 +73,11 @@ public class SyncPool {
7073
public SyncPool(PeerConnectionDelegate peerDel, PeerClient peerClient) {
7174
this.peerDel = peerDel;
7275
this.peerClient = peerClient;
73-
init();
7476
}
7577

7678
public void init() {
79+
channelManager = ctx.getBean(ChannelManager.class);
80+
7781
poolLoopExecutor.scheduleWithFixedDelay(() -> {
7882
try {
7983
fillUp();

src/main/java/org/tron/core/Constant.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,10 @@ public class Constant {
3333
public static final String NORMAL_CONF = "config.conf";
3434
public static final String TEST_CONF = "config-test.conf";
3535
public static final String DATABASE_DIR = "storage.directory";
36+
37+
public static final byte ADD_PRE_FIX_BYTE_MAINNET = (byte) 0xa1; //a1 + address ,a1 is version
38+
public static final String ADD_PRE_FIX_STRING_MAINNET = "a1";
39+
public static final byte ADD_PRE_FIX_BYTE_TESTNET = (byte) 0xa0; //a0 + address ,a0 is version
40+
public static final String ADD_PRE_FIX_STRING_TESTNET = "a0";
41+
public static final int ADDRESS_SIZE = 42;
3642
}

src/main/java/org/tron/core/Wallet.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ public class Wallet {
7070
private Application app;
7171
private Node p2pnode;
7272
private Manager dbManager;
73+
private static String addressPreFixString = Constant.ADD_PRE_FIX_STRING_TESTNET; //default testnet
74+
private static byte addressPreFixByte = Constant.ADD_PRE_FIX_BYTE_TESTNET;
7375

7476
/**
7577
* Creates a new Wallet with a random ECKey.
@@ -102,6 +104,66 @@ public byte[] getAddress() {
102104
return ecKey.getAddress();
103105
}
104106

107+
public static String getAddressPreFixString() {
108+
return addressPreFixString;
109+
}
110+
111+
public static void setAddressPreFixString(String addressPreFixString) {
112+
Wallet.addressPreFixString = addressPreFixString;
113+
}
114+
115+
public static byte getAddressPreFixByte() {
116+
return addressPreFixByte;
117+
}
118+
119+
public static void setAddressPreFixByte(byte addressPreFixByte) {
120+
Wallet.addressPreFixByte = addressPreFixByte;
121+
}
122+
123+
public static boolean addressValid(ByteString bsAddress) {
124+
125+
if (bsAddress == null || bsAddress.size() == 0) {
126+
logger.warn("Warning: Address is empty !!");
127+
return false;
128+
}
129+
byte[] address = bsAddress.toByteArray();
130+
return addressValid(address);
131+
}
132+
133+
public static boolean addressValid(byte[] address) {
134+
if (address == null || address.length == 0) {
135+
logger.warn("Warning: Address is empty !!");
136+
return false;
137+
}
138+
if (address.length != Constant.ADDRESS_SIZE / 2) {
139+
logger.warn(
140+
"Warning: Address length need " + Constant.ADDRESS_SIZE + " but " + address.length
141+
+ " !!");
142+
return false;
143+
}
144+
if (address[0] != addressPreFixByte) {
145+
logger.warn("Warning: Address need prefix with " + addressPreFixByte + " but "
146+
+ address[0] + " !!");
147+
return false;
148+
}
149+
//Other rule;
150+
return true;
151+
}
152+
153+
public static boolean addressValid(String addressStr) {
154+
if (addressStr == null || "".equals(addressStr)) {
155+
logger.warn("Warning: Address is empty !!");
156+
return false;
157+
}
158+
try {
159+
byte[] address = ByteArray.fromHexString(addressStr);
160+
return addressValid(address);
161+
} catch (Exception e) {
162+
logger.error(e.getMessage());
163+
return false;
164+
}
165+
}
166+
105167
/**
106168
* Get balance by address.
107169
*/

src/main/java/org/tron/core/actuator/AssetIssueActuator.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.google.protobuf.InvalidProtocolBufferException;
2222
import lombok.extern.slf4j.Slf4j;
2323
import org.tron.common.utils.ByteArray;
24+
import org.tron.core.Wallet;
2425
import org.tron.core.capsule.AccountCapsule;
2526
import org.tron.core.capsule.AssetIssueCapsule;
2627
import org.tron.core.capsule.TransactionResultCapsule;
@@ -85,7 +86,9 @@ public boolean validate() throws ContractValidateException {
8586
try {
8687
final AssetIssueContract assetIssueContract = this.contract.unpack(AssetIssueContract.class);
8788

88-
Preconditions.checkNotNull(assetIssueContract.getOwnerAddress(), "OwnerAddress is null");
89+
if (!Wallet.addressValid(assetIssueContract.getOwnerAddress())) {
90+
throw new ContractValidateException("Invalidate ownerAddress");
91+
}
8992
Preconditions.checkNotNull(assetIssueContract.getName(), "name is null");
9093

9194
if (this.dbManager.getAssetIssueStore().get(assetIssueContract.getName().toByteArray())

src/main/java/org/tron/core/actuator/CreateAccountActuator.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.google.protobuf.ByteString;
66
import com.google.protobuf.InvalidProtocolBufferException;
77
import lombok.extern.slf4j.Slf4j;
8+
import org.tron.core.Wallet;
89
import org.tron.core.capsule.AccountCapsule;
910
import org.tron.core.capsule.TransactionResultCapsule;
1011
import org.tron.core.db.Manager;
@@ -52,7 +53,9 @@ public boolean validate() throws ContractValidateException {
5253
AccountCreateContract contract = this.contract.unpack(AccountCreateContract.class);
5354

5455
Preconditions.checkNotNull(contract.getAccountName(), "AccountName is null");
55-
Preconditions.checkNotNull(contract.getOwnerAddress(), "OwnerAddress is null");
56+
if (!Wallet.addressValid(contract.getOwnerAddress())) {
57+
throw new ContractValidateException("Invalidate ownerAddress");
58+
}
5659
Preconditions.checkNotNull(contract.getType(), "Type is null");
5760

5861
if (dbManager.getAccountStore().has(contract.getOwnerAddress().toByteArray())) {

0 commit comments

Comments
 (0)