|
2 | 2 |
|
3 | 3 | import com.google.protobuf.Any; |
4 | 4 | import com.google.protobuf.GeneratedMessageV3; |
| 5 | +import org.tron.common.math.Maths; |
| 6 | +import org.tron.common.utils.Commons; |
5 | 7 | import org.tron.common.utils.ForkController; |
6 | 8 | import org.tron.core.ChainBaseManager; |
| 9 | +import org.tron.core.capsule.AccountCapsule; |
7 | 10 | import org.tron.core.capsule.TransactionCapsule; |
| 11 | +import org.tron.core.exception.BalanceInsufficientException; |
| 12 | +import org.tron.core.store.AccountStore; |
8 | 13 | import org.tron.protos.Protocol.Transaction.Contract; |
9 | 14 | import org.tron.protos.Protocol.Transaction.Contract.ContractType; |
10 | 15 |
|
@@ -63,4 +68,61 @@ public AbstractActuator setForkUtils(ForkController forkController) { |
63 | 68 | return this; |
64 | 69 | } |
65 | 70 |
|
| 71 | + public long addExact(long x, long y) { |
| 72 | + return Maths.addExact(x, y, this.disableJavaLangMath()); |
| 73 | + } |
| 74 | + |
| 75 | + public long addExact(int x, int y) { |
| 76 | + return Maths.addExact(x, y, this.disableJavaLangMath()); |
| 77 | + } |
| 78 | + |
| 79 | + public long floorDiv(long x, long y) { |
| 80 | + return Maths.floorDiv(x, y, this.disableJavaLangMath()); |
| 81 | + } |
| 82 | + |
| 83 | + public long floorDiv(long x, int y) { |
| 84 | + return this.floorDiv(x, (long) y); |
| 85 | + } |
| 86 | + |
| 87 | + public long multiplyExact(long x, long y) { |
| 88 | + return Maths.multiplyExact(x, y, this.disableJavaLangMath()); |
| 89 | + } |
| 90 | + |
| 91 | + public long multiplyExact(long x, int y) { |
| 92 | + return this.multiplyExact(x, (long) y); |
| 93 | + } |
| 94 | + |
| 95 | + public int multiplyExact(int x, int y) { |
| 96 | + return Maths.multiplyExact(x, y, this.disableJavaLangMath()); |
| 97 | + } |
| 98 | + |
| 99 | + public long subtractExact(long x, long y) { |
| 100 | + return Maths.subtractExact(x, y, this.disableJavaLangMath()); |
| 101 | + } |
| 102 | + |
| 103 | + public int min(int a, int b) { |
| 104 | + return Maths.min(a, b, this.disableJavaLangMath()); |
| 105 | + } |
| 106 | + |
| 107 | + public long min(long a, long b) { |
| 108 | + return Maths.min(a, b, this.disableJavaLangMath()); |
| 109 | + } |
| 110 | + |
| 111 | + public void adjustBalance(AccountStore accountStore, byte[] accountAddress, long amount) |
| 112 | + throws BalanceInsufficientException { |
| 113 | + AccountCapsule account = accountStore.getUnchecked(accountAddress); |
| 114 | + this.adjustBalance(accountStore, account, amount); |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * judge balance. |
| 119 | + */ |
| 120 | + public void adjustBalance(AccountStore accountStore, AccountCapsule account, long amount) |
| 121 | + throws BalanceInsufficientException { |
| 122 | + Commons.adjustBalance(accountStore, account, amount, this.disableJavaLangMath()); |
| 123 | + } |
| 124 | + |
| 125 | + boolean disableJavaLangMath() { |
| 126 | + return chainBaseManager.getDynamicPropertiesStore().disableJavaLangMath(); |
| 127 | + } |
66 | 128 | } |
0 commit comments