Skip to content

Commit c2a2cf6

Browse files
committed
Merge branch 'develop' of https://github.com/tronprotocol/java-tron into develop
2 parents 57cd999 + 1c5d483 commit c2a2cf6

File tree

7 files changed

+30
-31
lines changed

7 files changed

+30
-31
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ public boolean execute(TransactionResultCapsule ret) throws ContractExeException
9393

9494
dbManager.getAccountStore().put(ownerAddress, accountCapsule);
9595
ret.setStatus(fee, code.SUCESS);
96-
return true;
9796
} catch (InvalidProtocolBufferException e) {
9897
logger.debug(e.getMessage(), e);
9998
ret.setStatus(fee, code.FAILED);
@@ -107,6 +106,8 @@ public boolean execute(TransactionResultCapsule ret) throws ContractExeException
107106
ret.setStatus(fee, code.FAILED);
108107
throw new ContractExeException(e.getMessage());
109108
}
109+
110+
return true;
110111
}
111112

112113
@Override
@@ -162,6 +163,9 @@ public boolean validate() throws ContractValidateException {
162163

163164
while (iterator.hasNext()) {
164165
FrozenSupply next = iterator.next();
166+
if (next.getFrozenAmount() <= 0) {
167+
throw new ContractValidateException("Frozen supply must be greater than 0!");
168+
}
165169
if (next.getFrozenAmount() > remainSupply) {
166170
throw new ContractValidateException("Frozen supply cannot exceed total supply");
167171
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public boolean execute(TransactionResultCapsule ret) throws ContractExeException
3838
long newBandwidth = calculateBandwidth(accountCapsule.getBandwidth(), freezeBalanceContract);
3939
long newBalance = accountCapsule.getBalance() - freezeBalanceContract.getFrozenBalance();
4040

41-
long nowFrozenBalance = accountCapsule.getFrozenBalance();
42-
long newFrozenBalance = freezeBalanceContract.getFrozenBalance() + nowFrozenBalance;
41+
long currentFrozenBalance = accountCapsule.getFrozenBalance();
42+
long newFrozenBalance = freezeBalanceContract.getFrozenBalance() + currentFrozenBalance;
4343

4444
Frozen newFrozen = Frozen.newBuilder()
4545
.setFrozenBalance(newFrozenBalance)
@@ -76,7 +76,6 @@ public boolean execute(TransactionResultCapsule ret) throws ContractExeException
7676
}
7777

7878
private long calculateBandwidth(long oldValue, FreezeBalanceContract freezeBalanceContract) {
79-
8079
try {
8180
return Math.addExact(oldValue, Math.multiplyExact(freezeBalanceContract.getFrozenBalance(),
8281
Math.multiplyExact(freezeBalanceContract.getFrozenDuration(),
@@ -137,7 +136,7 @@ public boolean validate() throws ContractValidateException {
137136
+ "and more than " + minFrozenTime + " days");
138137
}
139138

140-
} catch (Exception ex) {
139+
} catch (InvalidProtocolBufferException ex) {
141140
ex.printStackTrace();
142141
throw new ContractValidateException(ex.getMessage());
143142
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@ public boolean validate() throws ContractValidateException {
124124
}
125125

126126
//Whether the account exist
127-
AccountCapsule ac = this.dbManager.getAccountStore().get(ownerAddress);
128-
if (ac == null) {
127+
AccountCapsule ownerAccount = this.dbManager.getAccountStore().get(ownerAddress);
128+
if (ownerAccount == null) {
129129
throw new ContractValidateException("Account does not exist!");
130130
}
131131

132-
long fee = calcFee();
133132
//Whether the balance is enough
134-
if (ac.getBalance() < Math.addExact(amount, fee)) {
133+
long fee = calcFee();
134+
if (ownerAccount.getBalance() < Math.addExact(amount, fee)) {
135135
throw new ContractValidateException("No enough balance !");
136136
}
137137

@@ -159,10 +159,12 @@ public boolean validate() throws ContractValidateException {
159159
if (exchangeAmount <= 0) {
160160
throw new ContractValidateException("Can not process the exchange!");
161161
}
162+
162163
AccountCapsule toAccount = this.dbManager.getAccountStore().get(toAddress);
163164
if (toAccount == null) {
164165
throw new ContractValidateException("To account does not exist!");
165166
}
167+
166168
if (!toAccount.assetBalanceEnough(assetIssueCapsule.getName(), exchangeAmount)) {
167169
throw new ContractValidateException("Asset balance is not enough !");
168170
}
@@ -177,7 +179,7 @@ public boolean validate() throws ContractValidateException {
177179

178180
@Override
179181
public ByteString getOwnerAddress() throws InvalidProtocolBufferException {
180-
return null;
182+
return this.contract.unpack(Contract.ParticipateAssetIssueContract.class).getOwnerAddress();
181183
}
182184

183185
@Override

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
@Slf4j
2222
public class TransferActuator extends AbstractActuator {
2323

24-
TransferContract transferContract;
25-
byte[] ownerAddress;
26-
byte[] toAddress;
27-
long amount;
24+
private TransferContract transferContract;
25+
private byte[] ownerAddress;
26+
private byte[] toAddress;
27+
private long amount;
2828

2929
TransferActuator(Any contract, Manager dbManager) {
3030
super(contract, dbManager);
@@ -40,24 +40,20 @@ public class TransferActuator extends AbstractActuator {
4040

4141
@Override
4242
public boolean execute(TransactionResultCapsule ret) throws ContractExeException {
43-
4443
long fee = calcFee();
4544
try {
46-
47-
// if account with to_address is not existed, create it.
45+
// if account with to_address does not exist, create it first.
4846
AccountCapsule toAccount = dbManager.getAccountStore()
4947
.get(transferContract.getToAddress().toByteArray());
5048
if (toAccount == null) {
5149
toAccount = new AccountCapsule(ByteString.copyFrom(toAddress), AccountType.Normal,
5250
dbManager.getHeadBlockTimeStamp());
5351
dbManager.getAccountStore().put(toAddress, toAccount);
5452
}
55-
dbManager.adjustBalance(transferContract.getOwnerAddress().toByteArray(), -calcFee());
53+
dbManager.adjustBalance(transferContract.getOwnerAddress().toByteArray(), -fee);
5654
ret.setStatus(fee, code.SUCESS);
57-
dbManager.adjustBalance(transferContract.getOwnerAddress().toByteArray(),
58-
-amount);
59-
dbManager.adjustBalance(transferContract.getToAddress().toByteArray(),
60-
amount);
55+
dbManager.adjustBalance(transferContract.getOwnerAddress().toByteArray(), -amount);
56+
dbManager.adjustBalance(transferContract.getToAddress().toByteArray(), amount);
6157
} catch (BalanceInsufficientException e) {
6258
logger.debug(e.getMessage(), e);
6359
ret.setStatus(fee, code.FAILED);
@@ -112,7 +108,7 @@ public boolean validate() throws ContractValidateException {
112108
throw new ContractValidateException("balance is not sufficient.");
113109
}
114110

115-
// if account with to_address is not existed, create it.
111+
// if account with to_address is not existed, the minimum amount is 1 TRX
116112
AccountCapsule toAccount = dbManager.getAccountStore()
117113
.get(transferContract.getToAddress().toByteArray());
118114
if (toAccount == null) {
@@ -123,15 +119,14 @@ public boolean validate() throws ContractValidateException {
123119
}
124120
} else {
125121
//check to account balance if overflow
126-
balance = Math.addExact(toAccount.getBalance(), amount);
122+
long toAddressBalance = Math.addExact(toAccount.getBalance(), amount);
127123
}
128124
} catch (Exception ex) {
129125
throw new ContractValidateException(ex.getMessage());
130126
}
131127
return true;
132128
}
133129

134-
135130
@Override
136131
public ByteString getOwnerAddress() throws InvalidProtocolBufferException {
137132
return contract.unpack(TransferContract.class).getOwnerAddress();
@@ -141,4 +136,4 @@ public ByteString getOwnerAddress() throws InvalidProtocolBufferException {
141136
public long calcFee() {
142137
return ChainConstant.TRANSFER_FEE;
143138
}
144-
}
139+
}

src/main/java/org/tron/core/capsule/TransactionResultCapsule.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
@Slf4j
88
public class TransactionResultCapsule implements ProtoCapsule<Transaction.Result> {
9+
910
private Transaction.Result transactionResult;
1011

1112
/**
@@ -19,7 +20,6 @@ public TransactionResultCapsule() {
1920
this.transactionResult = Transaction.Result.newBuilder().build();
2021
}
2122

22-
2323
public TransactionResultCapsule(Transaction.Result.code code, long fee) {
2424
Transaction.Result ret = Transaction.Result.newBuilder().setRet(code).setFee(fee).build();
2525
}
@@ -38,7 +38,6 @@ public void setErrorCode(Transaction.Result.code code) {
3838
this.transactionResult = this.transactionResult.toBuilder().setRet(code).build();
3939
}
4040

41-
4241
@Override
4342
public byte[] getData() {
4443
return this.transactionResult.toByteArray();
@@ -48,4 +47,4 @@ public byte[] getData() {
4847
public Result getInstance() {
4948
return this.transactionResult;
5049
}
51-
}
50+
}

src/main/java/org/tron/core/config/Parameter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public interface Parameter {
44

55
interface ChainConstant {
66

7-
long TRANSFER_FEE = 0; // 1 drop
7+
long TRANSFER_FEE = 0; // free
88
long ASSET_ISSUE_FEE = 1024000000; // 1024 trx 1024*10^6
99
long VOTE_WITNESS_FEE = 10000; // 10000 drop
1010
long CREATE_ACCOUNT_FEE = 10000; // 10000 drop

src/main/java/org/tron/core/net/node/NodeImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public void add(Entry<Sha256Hash, InventoryType> id, PeerConnection peer) {
151151
}
152152

153153
public void add(PriorItem id, PeerConnection peer) {
154-
if (send.containsKey(peer) && send.get(peer).containsKey(id.getHash())) {
154+
if (send.containsKey(peer) && send.get(peer).containsKey(id.getType())) {
155155
send.get(peer).get(id.getType()).offer(id.getHash());
156156
} else if (send.containsKey(peer)) {
157157
send.get(peer).put(id.getType(), new LinkedList<>());

0 commit comments

Comments
 (0)