Skip to content

Commit 6827cd1

Browse files
authored
Merge pull request tronprotocol#3 from tronprotocol/develop
update fork
2 parents 3074abc + fa1e580 commit 6827cd1

File tree

23 files changed

+45
-154
lines changed

23 files changed

+45
-154
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,7 @@ public boolean execute(Object object) throws ContractExeException {
5656
Commons.adjustBalance(accountStore, accountStore.getBlackhole().createDbKey(), fee);
5757

5858
result.setStatus(fee, code.SUCESS);
59-
} catch (BalanceInsufficientException e) {
60-
logger.debug(e.getMessage(), e);
61-
result.setStatus(fee, code.FAILED);
62-
throw new ContractExeException(e.getMessage());
63-
} catch (InvalidProtocolBufferException e) {
59+
} catch (BalanceInsufficientException | InvalidProtocolBufferException e) {
6460
logger.debug(e.getMessage(), e);
6561
result.setStatus(fee, code.FAILED);
6662
throw new ContractExeException(e.getMessage());

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

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,6 @@ public boolean execute(Object result) throws ContractExeException {
6565
byte[] ownerAddress = assetIssueContract.getOwnerAddress().toByteArray();
6666
AssetIssueCapsule assetIssueCapsule = new AssetIssueCapsule(assetIssueContract);
6767
AssetIssueCapsule assetIssueCapsuleV2 = new AssetIssueCapsule(assetIssueContract);
68-
// String name = new String(assetIssueCapsule.getName().toByteArray(),
69-
// Charset.forName("UTF-8")); // getName().toStringUtf8()
70-
// long order = 0;
71-
// byte[] key = name.getBytes();
72-
// while (this.dbManager.getAssetIssueStore().get(key) != null) {
73-
// order++;
74-
// String nameKey = AssetIssueCapsule.createDbKeyString(name, order);
75-
// key = nameKey.getBytes();
76-
// }
77-
// assetIssueCapsule.setOrder(order);
7868
long tokenIdNum = dynamicStore.getTokenIdNum();
7969
tokenIdNum++;
8070
assetIssueCapsule.setId(Long.toString(tokenIdNum));
@@ -127,15 +117,8 @@ public boolean execute(Object result) throws ContractExeException {
127117

128118
ret.setAssetIssueID(Long.toString(tokenIdNum));
129119
ret.setStatus(fee, code.SUCESS);
130-
} catch (InvalidProtocolBufferException e) {
131-
logger.debug(e.getMessage(), e);
132-
ret.setStatus(fee, code.FAILED);
133-
throw new ContractExeException(e.getMessage());
134-
} catch (BalanceInsufficientException e) {
135-
logger.debug(e.getMessage(), e);
136-
ret.setStatus(fee, code.FAILED);
137-
throw new ContractExeException(e.getMessage());
138-
} catch (ArithmeticException e) {
120+
}
121+
catch (InvalidProtocolBufferException | BalanceInsufficientException | ArithmeticException e){
139122
logger.debug(e.getMessage(), e);
140123
ret.setStatus(fee, code.FAILED);
141124
throw new ContractExeException(e.getMessage());
@@ -180,7 +163,7 @@ public boolean validate() throws ContractValidateException {
180163

181164
if (dynamicStore.getAllowSameTokenName() != 0) {
182165
String name = assetIssueContract.getName().toStringUtf8().toLowerCase();
183-
if (name.equals("trx")) {
166+
if (("trx").equals(name)) {
184167
throw new ContractValidateException("assetName can't be trx");
185168
}
186169
}
@@ -293,23 +276,6 @@ public boolean validate() throws ContractValidateException {
293276
if (accountCapsule.getBalance() < calcFee()) {
294277
throw new ContractValidateException("No enough balance for fee!");
295278
}
296-
//
297-
// AssetIssueCapsule assetIssueCapsule = new AssetIssueCapsule(assetIssueContract);
298-
// String name = new String(assetIssueCapsule.getName().toByteArray(),
299-
// Charset.forName("UTF-8")); // getName().toStringUtf8()
300-
// long order = 0;
301-
// byte[] key = name.getBytes();
302-
// while (this.dbManager.getAssetIssueStore().get(key) != null) {
303-
// order++;
304-
// String nameKey = AssetIssueCapsule.createDbKeyString(name, order);
305-
// key = nameKey.getBytes();
306-
// }
307-
// assetIssueCapsule.setOrder(order);
308-
//
309-
// if (!TransactionUtil.validAssetName(assetIssueCapsule.createDbKey())) {
310-
// throw new ContractValidateException("Invalid assetID");
311-
// }
312-
313279
return true;
314280
}
315281

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,7 @@ public boolean execute(Object object) throws ContractExeException {
102102

103103
ret.setExchangeInjectAnotherAmount(anotherTokenQuant);
104104
ret.setStatus(fee, code.SUCESS);
105-
} catch (ItemNotFoundException e) {
106-
logger.debug(e.getMessage(), e);
107-
ret.setStatus(fee, code.FAILED);
108-
throw new ContractExeException(e.getMessage());
109-
} catch (InvalidProtocolBufferException e) {
105+
} catch (ItemNotFoundException | InvalidProtocolBufferException e) {
110106
logger.debug(e.getMessage(), e);
111107
ret.setStatus(fee, code.FAILED);
112108
throw new ContractExeException(e.getMessage());
@@ -201,19 +197,17 @@ public boolean validate() throws ContractValidateException {
201197
BigInteger bigFirstTokenBalance = new BigInteger(String.valueOf(firstTokenBalance));
202198
BigInteger bigSecondTokenBalance = new BigInteger(String.valueOf(secondTokenBalance));
203199
BigInteger bigTokenQuant = new BigInteger(String.valueOf(tokenQuant));
204-
long newTokenBalance, newAnotherTokenBalance;
200+
long newTokenBalance;
201+
long newAnotherTokenBalance;
202+
205203
if (Arrays.equals(tokenID, firstTokenID)) {
206204
anotherTokenID = secondTokenID;
207-
// anotherTokenQuant = Math
208-
// .floorDiv(Math.multiplyExact(secondTokenBalance, tokenQuant), firstTokenBalance);
209205
anotherTokenQuant = bigSecondTokenBalance.multiply(bigTokenQuant)
210206
.divide(bigFirstTokenBalance).longValueExact();
211207
newTokenBalance = firstTokenBalance + tokenQuant;
212208
newAnotherTokenBalance = secondTokenBalance + anotherTokenQuant;
213209
} else {
214210
anotherTokenID = firstTokenID;
215-
// anotherTokenQuant = Math
216-
// .floorDiv(Math.multiplyExact(firstTokenBalance, tokenQuant), secondTokenBalance);
217211
anotherTokenQuant = bigFirstTokenBalance.multiply(bigTokenQuant)
218212
.divide(bigSecondTokenBalance).longValueExact();
219213
newTokenBalance = secondTokenBalance + tokenQuant;

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,7 @@ public boolean execute(Object result) throws ContractExeException {
9292
logger.debug(e.getMessage(), e);
9393
ret.setStatus(fee, code.FAILED);
9494
throw new ContractExeException(e.getMessage());
95-
} catch (InvalidProtocolBufferException e) {
96-
ret.setStatus(fee, code.FAILED);
97-
throw new ContractExeException(e.getMessage());
98-
} catch (ArithmeticException e) {
95+
} catch (InvalidProtocolBufferException | ArithmeticException e) {
9996
ret.setStatus(fee, code.FAILED);
10097
throw new ContractExeException(e.getMessage());
10198
}
@@ -140,9 +137,7 @@ public boolean validate() throws ContractValidateException {
140137
if (!DecodeUtil.addressValid(toAddress)) {
141138
throw new ContractValidateException("Invalid toAddress");
142139
}
143-
// if (!TransactionUtil.validAssetName(assetName)) {
144-
// throw new ContractValidateException("Invalid assetName");
145-
// }
140+
146141
if (amount <= 0) {
147142
throw new ContractValidateException("Amount must be greater than 0.");
148143
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,7 @@ public boolean execute(Object object) throws ContractExeException {
7272

7373
accountStore.put(ownerAddress, accountCapsule);
7474
ret.setStatus(fee, code.SUCESS);
75-
} catch (InvalidProtocolBufferException e) {
76-
logger.debug(e.getMessage(), e);
77-
ret.setStatus(fee, code.FAILED);
78-
throw new ContractExeException(e.getMessage());
79-
} catch (ArithmeticException e) {
75+
} catch (InvalidProtocolBufferException | ArithmeticException e) {
8076
logger.debug(e.getMessage(), e);
8177
ret.setStatus(fee, code.FAILED);
8278
throw new ContractExeException(e.getMessage());

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ public boolean execute(Object object) throws ContractExeException {
5151

5252
AccountCapsule accountCapsule = accountStore.get(ownerAddress);
5353

54-
AssetIssueCapsule assetIssueCapsule, assetIssueCapsuleV2;
54+
AssetIssueCapsule assetIssueCapsule;
55+
AssetIssueCapsule assetIssueCapsuleV2;
5556

5657
AssetIssueStore assetIssueStoreV2 = assetIssueV2Store;
5758
assetIssueCapsuleV2 = assetIssueStoreV2.get(accountCapsule.getAssetIssuedID().toByteArray());

actuator/src/main/java/org/tron/core/vm/repository/Repository.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ public interface Repository {
8080

8181
byte[] getBlackHoleAddress();
8282

83-
public BlockCapsule getBlockByNum(final long num);
83+
BlockCapsule getBlockByNum(final long num);
8484

85-
public AccountCapsule createNormalAccount(byte[] address);
85+
AccountCapsule createNormalAccount(byte[] address);
8686

8787
}

actuator/src/main/java/org/tron/core/vm/repository/RepositoryImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public class RepositoryImpl implements Repository {
4949

5050
//for energycal
5151
private long precision = Parameter.ChainConstant.PRECISION;
52-
;
5352
private long windowSize = Parameter.ChainConstant.WINDOW_SIZE_MS /
5453
BLOCK_PRODUCED_INTERVAL;
5554

chainbase/src/main/java/org/tron/common/runtime/Runtime.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
public interface Runtime {
99

10-
public void execute(TransactionContext context)
10+
void execute(TransactionContext context)
1111
throws ContractValidateException, ContractExeException;
1212

1313
ProgramResult getResult();

chainbase/src/main/java/org/tron/core/capsule/BlockCapsule.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.util.ArrayList;
2424
import java.util.Arrays;
2525
import java.util.List;
26-
import java.util.Vector;
2726
import java.util.stream.Collectors;
2827
import lombok.Getter;
2928
import lombok.Setter;
@@ -55,7 +54,7 @@ public class BlockCapsule implements ProtoCapsule<Block> {
5554

5655
private Block block;
5756
private List<TransactionCapsule> transactions = new ArrayList<>();
58-
private StringBuffer toStringBuff = new StringBuffer();
57+
private StringBuilder toStringBuff = new StringBuilder();
5958

6059
public BlockCapsule(long number, Sha256Hash hash, long when, ByteString witnessAddress) {
6160
// blockheader raw
@@ -140,7 +139,6 @@ private void initTxs() {
140139
}
141140

142141
public void sign(byte[] privateKey) {
143-
// TODO private_key == null
144142
ECKey ecKey = ECKey.fromPrivate(privateKey);
145143
ECDSASignature signature = ecKey.sign(getRawHash().getBytes());
146144
ByteString sig = ByteString.copyFrom(signature.toByteArray());
@@ -191,10 +189,10 @@ public Sha256Hash calcMerkleRoot() {
191189
return Sha256Hash.ZERO_HASH;
192190
}
193191

194-
Vector<Sha256Hash> ids = transactionsList.stream()
192+
ArrayList<Sha256Hash> ids = transactionsList.stream()
195193
.map(TransactionCapsule::new)
196194
.map(TransactionCapsule::getMerkleHash)
197-
.collect(Collectors.toCollection(Vector::new));
195+
.collect(Collectors.toCollection(ArrayList::new));
198196

199197
return MerkleTree.getInstance().createTree(ids).getRoot().getHash();
200198
}

chainbase/src/main/java/org/tron/core/capsule/BytesCapsule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public class BytesCapsule implements ProtoCapsule {
44

5-
byte[] bytes;
5+
private byte[] bytes;
66

77
public BytesCapsule(byte[] bytes) {
88
this.bytes = bytes;

chainbase/src/main/java/org/tron/core/capsule/TransactionCapsule.java

Lines changed: 8 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public class TransactionCapsule implements ProtoCapsule<Transaction> {
9393
@Getter
9494
@Setter
9595
private TransactionTrace trxTrace;
96-
private StringBuffer toStringBuff = new StringBuffer();
96+
private StringBuilder toStringBuff = new StringBuilder();
9797

9898
/**
9999
* constructor TransactionCapsule.
@@ -113,23 +113,6 @@ public TransactionCapsule(byte[] data) throws BadItemException {
113113
}
114114
}
115115

116-
/*lll
117-
public TransactionCapsule(byte[] key, long value) throws IllegalArgumentException {
118-
if (!Wallet.addressValid(key)) {
119-
throw new IllegalArgumentException("Invalid address");
120-
}
121-
TransferContract transferContract = TransferContract.newBuilder()
122-
.setAmount(value)
123-
.setOwnerAddress(ByteString.copyFrom("0x0000000000000000000".getBytes()))
124-
.setToAddress(ByteString.copyFrom(key))
125-
.build();
126-
Transaction.raw.Builder transactionBuilder = Transaction.raw.newBuilder().addContract(
127-
Transaction.Contract.newBuilder().setType(ContractType.TransferContract).setParameter(
128-
Any.pack(transferContract)).build());
129-
logger.info("Transaction create succeeded!");
130-
transaction = Transaction.newBuilder().setRawData(transactionBuilder.build()).build();
131-
}*/
132-
133116
public TransactionCapsule(CodedInputStream codedInputStream) throws BadItemException {
134117
try {
135118
this.transaction = Transaction.parseFrom(codedInputStream);
@@ -148,7 +131,6 @@ public TransactionCapsule(AccountCreateContract contract, AccountStore accountSt
148131
}
149132

150133
public TransactionCapsule(TransferContract contract, AccountStore accountStore) {
151-
Transaction.Contract.Builder contractBuilder = Transaction.Contract.newBuilder();
152134

153135
AccountCapsule owner = accountStore.get(contract.getOwnerAddress().toByteArray());
154136
if (owner == null || owner.getBalance() < contract.getAmount()) {
@@ -209,9 +191,6 @@ public static long checkWeight(Permission permission, List<ByteString> sigs, byt
209191
List<ByteString> approveList)
210192
throws SignatureException, PermissionException, SignatureFormatException {
211193
long currentWeight = 0;
212-
// if (signature.size() % 65 != 0) {
213-
// throw new SignatureFormatException("Signature size is " + signature.size());
214-
// }
215194
if (sigs.size() > permission.getKeysCount()) {
216195
throw new PermissionException(
217196
"Signature count is " + (sigs.size()) + " more than key counts of permission : "
@@ -251,7 +230,7 @@ public static byte[] getShieldTransactionHashIgnoreTypeException(TransactionCaps
251230
} catch (ContractValidateException | InvalidProtocolBufferException e) {
252231
logger.debug(e.getMessage(), e);
253232
}
254-
return null;
233+
return new byte[0];
255234
}
256235

257236
public static byte[] hashShieldTransaction(TransactionCapsule tx)
@@ -304,7 +283,7 @@ public static byte[] getOwner(Transaction.Contract contract) {
304283
if (!shieldedTransferContract.getTransparentFromAddress().isEmpty()) {
305284
owner = shieldedTransferContract.getTransparentFromAddress();
306285
} else {
307-
return null;
286+
return new byte[0];
308287
}
309288
break;
310289
}
@@ -314,21 +293,21 @@ public static byte[] getOwner(Transaction.Contract contract) {
314293
.getContract(contract.getType());
315294
if (clazz == null) {
316295
logger.error("not exist {}", contract.getType());
317-
return null;
296+
return new byte[0];
318297
}
319298
GeneratedMessageV3 generatedMessageV3 = contractParameter.unpack(clazz);
320299
owner = ReflectUtils.getFieldValue(generatedMessageV3, OWNER_ADDRESS);
321300
if (owner == null) {
322301
logger.error("not exist [{}] field,{}", OWNER_ADDRESS, clazz);
323-
return null;
302+
return new byte[0];
324303
}
325304
break;
326305
}
327306
}
328307
return owner.toByteArray();
329308
} catch (Exception ex) {
330309
logger.error(ex.getMessage());
331-
return null;
310+
return new byte[0];
332311
}
333312
}
334313

@@ -392,24 +371,21 @@ public static byte[] getToAddress(Transaction.Contract contract) {
392371
case ParticipateAssetIssueContract:
393372
to = contractParameter.unpack(ParticipateAssetIssueContract.class).getToAddress();
394373
break;
395-
// todo add other contract
396374

397375
default:
398-
return null;
376+
return new byte[0];
399377
}
400378
return to.toByteArray();
401379
} catch (Exception ex) {
402380
logger.error(ex.getMessage());
403-
return null;
381+
return new byte[0];
404382
}
405383
}
406384

407385
// todo mv this static function to capsule util
408386
public static long getCallValue(Transaction.Contract contract) {
409-
int energyForTrx;
410387
try {
411388
Any contractParameter = contract.getParameter();
412-
long callValue;
413389
switch (contract.getType()) {
414390
case TriggerSmartContract:
415391
return contractParameter.unpack(TriggerSmartContract.class).getCallValue();
@@ -426,27 +402,6 @@ public static long getCallValue(Transaction.Contract contract) {
426402
}
427403
}
428404

429-
// todo mv this static function to capsule util
430-
public static long getCallTokenValue(Transaction.Contract contract) {
431-
int energyForTrx;
432-
try {
433-
Any contractParameter = contract.getParameter();
434-
long callValue;
435-
switch (contract.getType()) {
436-
case TriggerSmartContract:
437-
return contractParameter.unpack(TriggerSmartContract.class).getCallTokenValue();
438-
439-
case CreateSmartContract:
440-
return contractParameter.unpack(CreateSmartContract.class).getCallTokenValue();
441-
default:
442-
return 0L;
443-
}
444-
} catch (Exception ex) {
445-
logger.error(ex.getMessage());
446-
return 0L;
447-
}
448-
}
449-
450405
public static String getBase64FromByteString(ByteString sign) {
451406
byte[] r = sign.substring(0, 32).toByteArray();
452407
byte[] s = sign.substring(32, 64).toByteArray();

chainbase/src/main/java/org/tron/core/db2/core/Chainbase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
public class Chainbase implements IRevokingDB {
2121

22-
public static Map<String, byte[]> assertsAddress = new HashMap<>(); // key = name , value = address
22+
protected static Map<String, byte[]> assertsAddress = new HashMap<>(); // key = name , value = address
2323
//true:fullnode, false:soliditynode
2424
private ThreadLocal<Boolean> mode = new ThreadLocal<>();
2525
private Snapshot head;

0 commit comments

Comments
 (0)