@@ -61,10 +61,10 @@ public boolean execute(Object result) throws ContractExeException {
6161
6262 AccountCapsule ownerCapsule = accountStore
6363 .get (delegateResourceContract .getOwnerAddress ().toByteArray ());
64-
64+ DynamicPropertiesStore dynamicStore = chainBaseManager . getDynamicPropertiesStore ();
6565 long delegateBalance = delegateResourceContract .getBalance ();
6666 boolean lock = delegateResourceContract .getLock ();
67- long lockPeriod = delegateResourceContract . getLockPeriod ();
67+ long lockPeriod = getLockPeriod (dynamicStore , delegateResourceContract );
6868 byte [] receiverAddress = delegateResourceContract .getReceiverAddress ().toByteArray ();
6969
7070 // delegate resource to receiver
@@ -219,7 +219,7 @@ public boolean validate() throws ContractValidateException {
219219
220220 boolean lock = delegateResourceContract .getLock ();
221221 if (lock && dynamicStore .supportMaxDelegateLockPeriod ()) {
222- long lockPeriod = delegateResourceContract . getLockPeriod ();
222+ long lockPeriod = getLockPeriod (dynamicStore , delegateResourceContract );
223223 long maxDelegateLockPeriod = dynamicStore .getMaxDelegateLockPeriod ();
224224 if (lockPeriod < 0 || lockPeriod > maxDelegateLockPeriod ) {
225225 throw new ContractValidateException (
@@ -257,6 +257,16 @@ public boolean validate() throws ContractValidateException {
257257 return true ;
258258 }
259259
260+ private long getLockPeriod (DynamicPropertiesStore dynamicStore ,
261+ DelegateResourceContract delegateResourceContract ) {
262+ long lockPeriod = delegateResourceContract .getLockPeriod ();
263+ if (dynamicStore .supportMaxDelegateLockPeriod ()) {
264+ return lockPeriod == 0 ? DELEGATE_PERIOD / 3000 : lockPeriod ;
265+ } else {
266+ return 0 ;
267+ }
268+ }
269+
260270 private void validRemainTime (ResourceCode resourceCode , long lockPeriod , long expireTime ,
261271 long now ) throws ContractValidateException {
262272 long remainTime = expireTime - now ;
@@ -294,7 +304,7 @@ private void delegateResource(byte[] ownerAddress, byte[] receiverAddress, boole
294304 long expireTime = 0 ;
295305 if (lock ) {
296306 if (dynamicPropertiesStore .supportMaxDelegateLockPeriod ()) {
297- expireTime = now + ( lockPeriod == 0 ? DELEGATE_PERIOD : lockPeriod * 3 * 1000 ) ;
307+ expireTime = now + lockPeriod * 3 * 1000 ;
298308 } else {
299309 expireTime = now + DELEGATE_PERIOD ;
300310 }
0 commit comments