2121@ Slf4j
2222public 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+ }
0 commit comments