8484import org .tron .core .capsule .BlockCapsule ;
8585import org .tron .core .capsule .BlockCapsule .BlockId ;
8686import org .tron .core .capsule .ContractCapsule ;
87+ import org .tron .core .capsule .DeferredTransactionCapsule ;
8788import org .tron .core .capsule .DelegatedResourceAccountIndexCapsule ;
8889import org .tron .core .capsule .DelegatedResourceCapsule ;
8990import org .tron .core .capsule .ExchangeCapsule ;
9293import org .tron .core .capsule .TransactionInfoCapsule ;
9394import org .tron .core .capsule .TransactionResultCapsule ;
9495import org .tron .core .capsule .WitnessCapsule ;
96+ import org .tron .core .capsule .utils .TransactionUtil ;
9597import org .tron .core .config .Parameter .ChainConstant ;
9698import org .tron .core .config .args .Args ;
9799import org .tron .core .db .AccountIdIndexStore ;
124126import org .tron .protos .Protocol ;
125127import org .tron .protos .Protocol .Account ;
126128import org .tron .protos .Protocol .Block ;
129+ import org .tron .protos .Protocol .DeferredTransaction ;
127130import org .tron .protos .Protocol .DelegatedResourceAccountIndex ;
128131import org .tron .protos .Protocol .Exchange ;
129132import org .tron .protos .Protocol .Permission ;
@@ -415,6 +418,10 @@ public TransactionCapsule createTransactionCapsule(com.google.protobuf.Message m
415418 public GrpcAPI .Return broadcastTransaction (Transaction signaturedTransaction ) {
416419 GrpcAPI .Return .Builder builder = GrpcAPI .Return .newBuilder ();
417420 TransactionCapsule trx = new TransactionCapsule (signaturedTransaction );
421+ if (trx .getDeferredSeconds () != 0 && !TransactionUtil .validateDeferredTransaction (trx )) {
422+ return builder .setResult (false ).setCode (response_code .DEFERRED_SECONDS_ILLEGAL_ERROR ).build ();
423+ }
424+
418425 Message message = new TransactionMessage (signaturedTransaction );
419426
420427 try {
@@ -871,6 +878,12 @@ public Protocol.ChainParameters getChainParameters() {
871878 .setKey ("getAllowAdaptiveEnergy" )
872879 .setValue (dbManager .getDynamicPropertiesStore ().getAllowAdaptiveEnergy ())
873880 .build ());
881+ // ALLOW_DEFERRED_TRANSACTION, // 1, 24
882+ builder .addChainParameter (
883+ Protocol .ChainParameters .ChainParameter .newBuilder ()
884+ .setKey ("getAllowDeferredTransaction" )
885+ .setValue (dbManager .getDynamicPropertiesStore ().getAllowDeferredTransaction ())
886+ .build ());
874887 //other chainParameters
875888 builder .addChainParameter (Protocol .ChainParameters .ChainParameter .newBuilder ()
876889 .setKey ("getTotalEnergyTargetLimit" )
@@ -892,6 +905,26 @@ public Protocol.ChainParameters getChainParameters() {
892905 .setValue (dbManager .getDynamicPropertiesStore ().getMultiSignFee ())
893906 .build ());
894907
908+ builder .addChainParameter (Protocol .ChainParameters .ChainParameter .newBuilder ()
909+ .setKey ("maxDeferredTransactionProcessTime" )
910+ .setValue (dbManager .getDynamicPropertiesStore ().getMaxDeferredTransactionProcessTime ())
911+ .build ());
912+
913+ builder .addChainParameter (Protocol .ChainParameters .ChainParameter .newBuilder ()
914+ .setKey ("getDeferredTransactionFee" )
915+ .setValue (dbManager .getDynamicPropertiesStore ().getDeferredTransactionFee ())
916+ .build ());
917+
918+ builder .addChainParameter (Protocol .ChainParameters .ChainParameter .newBuilder ()
919+ .setKey ("getCancelDeferredTransactionFee" )
920+ .setValue (dbManager .getDynamicPropertiesStore ().getCancelDeferredTransactionFee ())
921+ .build ());
922+
923+ builder .addChainParameter (Protocol .ChainParameters .ChainParameter .newBuilder ()
924+ .setKey ("getUpdateAccountPermissionFee" )
925+ .setValue (dbManager .getDynamicPropertiesStore ().getUpdateAccountPermissionFee ())
926+ .build ());
927+
895928 return builder .build ();
896929 }
897930
@@ -1194,6 +1227,37 @@ public Transaction getTransactionById(ByteString transactionId) {
11941227 return null ;
11951228 }
11961229
1230+ public DeferredTransaction getDeferredTransactionById (ByteString transactionId ) {
1231+ if (Objects .isNull (transactionId )) {
1232+ return null ;
1233+ }
1234+
1235+ DeferredTransactionCapsule deferredTransactionCapsule = dbManager .getDeferredTransactionStore ()
1236+ .getByTransactionId (transactionId );
1237+ if (deferredTransactionCapsule != null ) {
1238+ return deferredTransactionCapsule .getDeferredTransaction ();
1239+ }
1240+
1241+ TransactionCapsule transactionCapsule = dbManager .getTransactionStore ()
1242+ .getUnchecked (transactionId .toByteArray ());
1243+
1244+ if (Objects .nonNull (transactionCapsule )) {
1245+ transactionCapsule .setDeferredStage (Constant .EXECUTINGDEFERREDTRANSACTION );
1246+ TransactionCapsule generateTransaction = dbManager .getTransactionStore ()
1247+ .getUnchecked (transactionCapsule .getTransactionId ().getBytes ());
1248+ if (Objects .nonNull (generateTransaction )) {
1249+ DeferredTransaction .Builder deferredTransaction = DeferredTransaction .newBuilder ();
1250+ deferredTransaction .setTransactionId (transactionCapsule .getTransactionId ().getByteString ());
1251+ deferredTransaction .setSenderAddress (transactionCapsule .getSenderAddress ());
1252+ deferredTransaction .setReceiverAddress (transactionCapsule .getToAddress ());
1253+ deferredTransaction .setTransaction (transactionCapsule .getInstance ());
1254+ return deferredTransaction .build ();
1255+ }
1256+ }
1257+ return null ;
1258+ }
1259+
1260+
11971261 public TransactionInfo getTransactionInfoById (ByteString transactionId ) {
11981262 if (Objects .isNull (transactionId )) {
11991263 return null ;
@@ -1210,6 +1274,45 @@ public TransactionInfo getTransactionInfoById(ByteString transactionId) {
12101274 return null ;
12111275 }
12121276
1277+ public TransactionInfo getDeferredTransactionInfoById (ByteString transactionId ) {
1278+ if (Objects .isNull (transactionId )) {
1279+ return null ;
1280+ }
1281+ try {
1282+ TransactionCapsule transactionCapsule = dbManager .getTransactionStore ()
1283+ .getUnchecked (transactionId .toByteArray ());
1284+ if (Objects .nonNull (transactionCapsule )) {
1285+ transactionCapsule .setDeferredStage (Constant .EXECUTINGDEFERREDTRANSACTION );
1286+ if (Objects .isNull (transactionCapsule .getTransactionId ())) {
1287+ return null ;
1288+ }
1289+ TransactionInfoCapsule transactionInfo = dbManager .getTransactionHistoryStore ()
1290+ .get (transactionCapsule .getTransactionId ().getBytes ());
1291+ if (Objects .nonNull (transactionInfo )) {
1292+ return transactionInfo .getInstance ();
1293+ }
1294+ }
1295+
1296+ } catch (StoreException e ) {
1297+ }
1298+
1299+ return null ;
1300+ }
1301+
1302+ public Return cancelDeferredTransaction (ByteString transactionId ) {
1303+ GrpcAPI .Return .Builder builder = GrpcAPI .Return .newBuilder ();
1304+
1305+ if (Objects .isNull (transactionId )) {
1306+ return builder .setResult (false ).build ();
1307+ }
1308+
1309+ if (dbManager .cancelDeferredTransaction (transactionId )) {
1310+ return builder .setResult (true ).build ();
1311+ } else {
1312+ return builder .setResult (false ).build ();
1313+ }
1314+ }
1315+
12131316 public Proposal getProposalById (ByteString proposalId ) {
12141317 if (Objects .isNull (proposalId )) {
12151318 return null ;
0 commit comments