3535import java .util .HashMap ;
3636import java .util .List ;
3737import lombok .extern .slf4j .Slf4j ;
38- import org .apache .commons .lang3 .StringUtils ;
3938import org .apache .commons .lang3 .tuple .Pair ;
4039import org .spongycastle .util .encoders .Hex ;
4140import org .tron .common .crypto .ECKey ;
42- import org .tron .common .crypto .Hash ;
4341import org .tron .common .crypto .zksnark .BN128 ;
4442import org .tron .common .crypto .zksnark .BN128Fp ;
4543import org .tron .common .crypto .zksnark .BN128G1 ;
4644import org .tron .common .crypto .zksnark .BN128G2 ;
4745import org .tron .common .crypto .zksnark .Fp ;
4846import org .tron .common .crypto .zksnark .PairingCheck ;
4947import org .tron .common .runtime .vm .program .Program ;
50- import org .tron .common .runtime .vm .program .Program .PrecompiledContractException ;
5148import org .tron .common .runtime .vm .program .ProgramResult ;
5249import org .tron .common .storage .Deposit ;
5350import org .tron .common .utils .BIUtil ;
5451import org .tron .common .utils .ByteArray ;
55- import org .tron .common .utils .ByteUtil ;
5652import org .tron .common .utils .Sha256Hash ;
57- import org .tron .core .Constant ;
5853import org .tron .core .Wallet ;
5954import org .tron .core .actuator .Actuator ;
6055import org .tron .core .actuator .ActuatorFactory ;
6156import org .tron .core .capsule .TransactionCapsule ;
62- import org .tron .core .config .args .Args ;
6357import org .tron .core .exception .ContractExeException ;
6458import org .tron .core .exception .ContractValidateException ;
6559import org .tron .protos .Contract ;
@@ -88,7 +82,7 @@ public class PrecompiledContracts {
8882 private static final BN128Multiplication altBN128Mul = new BN128Multiplication ();
8983 private static final BN128Pairing altBN128Pairing = new BN128Pairing ();
9084 private static final VoteWitnessNative voteContract = new VoteWitnessNative ();
91- // private static final FreezeBalanceNative freezeBalance = new FreezeBalanceNative();
85+ // private static final FreezeBalanceNative freezeBalance = new FreezeBalanceNative();
9286// private static final UnfreezeBalanceNative unFreezeBalance = new UnfreezeBalanceNative();
9387 private static final WithdrawBalanceNative withdrawBalance = new WithdrawBalanceNative ();
9488 private static final ProposalApproveNative proposalApprove = new ProposalApproveNative ();
@@ -97,10 +91,11 @@ public class PrecompiledContracts {
9791 private static final ConvertFromTronBytesAddressNative convertFromTronBytesAddress = new ConvertFromTronBytesAddressNative ();
9892 private static final ConvertFromTronBase58AddressNative convertFromTronBase58Address = new ConvertFromTronBase58AddressNative ();
9993 private static final TransferAssetNative transferAsset = new TransferAssetNative ();
100- private static final GetTransferAssetNative getTransferAssetAmount = new GetTransferAssetNative ();
94+ private static final GetTransferAssetNative getTransferAssetAmount = new GetTransferAssetNative ();
10195
10296 private static final ECKey addressCheckECKey = new ECKey ();
103- private static final String addressCheckECKeyAddress = Wallet .encode58Check (addressCheckECKey .getAddress ());
97+ private static final String addressCheckECKeyAddress = Wallet
98+ .encode58Check (addressCheckECKey .getAddress ());
10499
105100
106101 private static final DataWord ecRecoverAddr = new DataWord (
@@ -121,7 +116,7 @@ public class PrecompiledContracts {
121116 "0000000000000000000000000000000000000000000000000000000000000008" );
122117 private static final DataWord voteContractAddr = new DataWord (
123118 "0000000000000000000000000000000000000000000000000000000000010001" );
124- // private static final DataWord freezeBalanceAddr = new DataWord(
119+ // private static final DataWord freezeBalanceAddr = new DataWord(
125120// "0000000000000000000000000000000000000000000000000000000000010002");
126121// private static final DataWord unFreezeBalanceAddr = new DataWord(
127122// "0000000000000000000000000000000000000000000000000000000000010003");
@@ -194,10 +189,18 @@ public static PrecompiledContract getContractForAddress(DataWord address) {
194189 }
195190
196191 // Byzantium precompiles
197- if (address .equals (modExpAddr )) return modExp ;
198- if (address .equals (altBN128AddAddr )) return altBN128Add ;
199- if (address .equals (altBN128MulAddr )) return altBN128Mul ;
200- if (address .equals (altBN128PairingAddr )) return altBN128Pairing ;
192+ if (address .equals (modExpAddr )) {
193+ return modExp ;
194+ }
195+ if (address .equals (altBN128AddAddr )) {
196+ return altBN128Add ;
197+ }
198+ if (address .equals (altBN128MulAddr )) {
199+ return altBN128Mul ;
200+ }
201+ if (address .equals (altBN128PairingAddr )) {
202+ return altBN128Pairing ;
203+ }
201204 return null ;
202205 }
203206
@@ -423,7 +426,7 @@ public long getEnergyForData(byte[] data) {
423426 .multiply (BigInteger .valueOf (Math .max (adjExpLen , 1 )))
424427 .divide (GQUAD_DIVISOR );
425428
426- return isLessThan (energy , BigInteger .valueOf (Long .MAX_VALUE )) ? energy .longValue ()
429+ return isLessThan (energy , BigInteger .valueOf (Long .MAX_VALUE )) ? energy .longValueExact ()
427430 : Long .MAX_VALUE ;
428431 }
429432
@@ -701,7 +704,7 @@ public long getEnergyForData(byte[] data) {
701704 @ Override
702705 public Pair <Boolean , byte []> execute (byte [] data ) {
703706
704- if (isRootCallConstant ()){
707+ if (isRootCallConstant ()) {
705708 return Pair .of (true , new DataWord (0 ).getData ());
706709 }
707710 if (data == null || data .length != 2 * DataWord .DATAWORD_UNIT_SIZE ) {
@@ -887,7 +890,7 @@ public long getEnergyForData(byte[] data) {
887890 @ Override
888891 public Pair <Boolean , byte []> execute (byte [] data ) {
889892
890- if (isRootCallConstant ()){
893+ if (isRootCallConstant ()) {
891894 return Pair .of (true , new DataWord (0 ).getData ());
892895 }
893896
@@ -944,7 +947,7 @@ public long getEnergyForData(byte[] data) {
944947 @ Override
945948 public Pair <Boolean , byte []> execute (byte [] data ) {
946949
947- if (isRootCallConstant ()){
950+ if (isRootCallConstant ()) {
948951 return Pair .of (true , new DataWord (0 ).getData ());
949952 }
950953
@@ -1008,11 +1011,12 @@ public long getEnergyForData(byte[] data) {
10081011 @ Override
10091012 public Pair <Boolean , byte []> execute (byte [] data ) {
10101013
1011- if (isRootCallConstant ()){
1014+ if (isRootCallConstant ()) {
10121015 return Pair .of (true , new DataWord (0 ).getData ());
10131016 }
10141017
1015- if (data == null || data .length == 0 || (data .length % (2 * DataWord .DATAWORD_UNIT_SIZE ) != 0 )) {
1018+ if (data == null || data .length == 0 || (data .length % (2 * DataWord .DATAWORD_UNIT_SIZE )
1019+ != 0 )) {
10161020 return Pair .of (false , new DataWord (0 ).getData ());
10171021 }
10181022
@@ -1078,7 +1082,7 @@ public long getEnergyForData(byte[] data) {
10781082 @ Override
10791083 public Pair <Boolean , byte []> execute (byte [] data ) {
10801084
1081- if (isRootCallConstant ()){
1085+ if (isRootCallConstant ()) {
10821086 return Pair .of (true , new DataWord (0 ).getData ());
10831087 }
10841088
@@ -1175,8 +1179,7 @@ public Pair<Boolean, byte[]> execute(byte[] data) {
11751179 }
11761180
11771181 /**
1178- * Native function for transferring Asset to another account. <br/>
1179- * <br/>
1182+ * Native function for transferring Asset to another account. <br/> <br/>
11801183 *
11811184 * Input data[]: <br/> toAddress, amount, assetName <br/>
11821185 *
@@ -1192,11 +1195,12 @@ public long getEnergyForData(byte[] data) {
11921195 @ Override
11931196 public Pair <Boolean , byte []> execute (byte [] data ) {
11941197
1195- if (isRootCallConstant ()){
1198+ if (isRootCallConstant ()) {
11961199 return Pair .of (true , new DataWord (0 ).getData ());
11971200 }
11981201
1199- if (data == null || (data .length <= DataWord .DATAWORD_UNIT_SIZE * 2 || data .length > DataWord .DATAWORD_UNIT_SIZE * 3 )) {
1202+ if (data == null || (data .length <= DataWord .DATAWORD_UNIT_SIZE * 2
1203+ || data .length > DataWord .DATAWORD_UNIT_SIZE * 3 )) {
12001204 return Pair .of (false , new DataWord (0 ).getData ());
12011205 }
12021206
@@ -1206,20 +1210,20 @@ public Pair<Boolean, byte[]> execute(byte[] data) {
12061210 System .arraycopy (data , 32 + 16 + 8 , amount , 0 , 8 );
12071211 // we already have a restrict for token name length, no more than 32 bytes. don't need to check again
12081212 byte [] name = new byte [32 ];
1209- System .arraycopy (data , 64 , name , 0 , data .length - 64 );
1210- int length =name .length ;
1211- while (length > 0 && name [length -1 ] ==0 ) {
1213+ System .arraycopy (data , 64 , name , 0 , data .length - 64 );
1214+ int length = name .length ;
1215+ while (length > 0 && name [length - 1 ] == 0 ) {
12121216 length --;
12131217 }
1214- name = ByteArray .subArray (name ,0 , length );
1218+ name = ByteArray .subArray (name , 0 , length );
12151219 Contract .TransferAssetContract .Builder builder = Contract .TransferAssetContract
12161220 .newBuilder ();
12171221 builder .setOwnerAddress (ByteString .copyFrom (getCallerAddress ()));
1218- builder .setToAddress (ByteString .copyFrom (convertToTronAddress (new DataWord (toAddress ).getLast20Bytes ())));
1222+ builder .setToAddress (
1223+ ByteString .copyFrom (convertToTronAddress (new DataWord (toAddress ).getLast20Bytes ())));
12191224 builder .setAmount (Longs .fromByteArray (amount ));
12201225 builder .setAssetName (ByteString .copyFrom (name ));
12211226
1222-
12231227 TransferAssetContract contract = builder .build ();
12241228
12251229 TransactionCapsule trx = new TransactionCapsule (contract ,
@@ -1246,10 +1250,8 @@ public Pair<Boolean, byte[]> execute(byte[] data) {
12461250 }
12471251
12481252
1249-
12501253 /**
1251- * Native function for check Asset balance basing on targetAddress and Asset name. <br/>
1252- * <br/>
1254+ * Native function for check Asset balance basing on targetAddress and Asset name. <br/> <br/>
12531255 *
12541256 * Input data[]: <br/> address targetAddress, byte[] assetName <br/>
12551257 *
@@ -1274,11 +1276,11 @@ public Pair<Boolean, byte[]> execute(byte[] data) {
12741276 // we already have a restrict for token name length, no more than 32 bytes. don't need to check again
12751277 byte [] name = new byte [32 ];
12761278 System .arraycopy (data , 32 , name , 0 , 32 );
1277- int length =name .length ;
1278- while (length > 0 && name [length -1 ] ==0 ) {
1279+ int length = name .length ;
1280+ while (length > 0 && name [length - 1 ] == 0 ) {
12791281 length --;
12801282 }
1281- name = ByteArray .subArray (name ,0 , length );
1283+ name = ByteArray .subArray (name , 0 , length );
12821284
12831285 long assetBalance = this .getDeposit ().getDbManager ().getAccountStore ().
12841286 get (convertToTronAddress (new DataWord (targetAddress ).getLast20Bytes ())).
0 commit comments