Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(freezeV2): optimize msg format #5267

Merged
merged 1 commit into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ public boolean execute(Object result) throws ContractExeException {

AccountCapsule ownerCapsule = accountStore
.get(delegateResourceContract.getOwnerAddress().toByteArray());

DynamicPropertiesStore dynamicStore = chainBaseManager.getDynamicPropertiesStore();
long delegateBalance = delegateResourceContract.getBalance();
boolean lock = delegateResourceContract.getLock();
long lockPeriod = delegateResourceContract.getLockPeriod();
long lockPeriod = getLockPeriod(dynamicStore, delegateResourceContract);
byte[] receiverAddress = delegateResourceContract.getReceiverAddress().toByteArray();

// delegate resource to receiver
Expand Down Expand Up @@ -219,7 +219,7 @@ public boolean validate() throws ContractValidateException {

boolean lock = delegateResourceContract.getLock();
if (lock && dynamicStore.supportMaxDelegateLockPeriod()) {
long lockPeriod = delegateResourceContract.getLockPeriod();
long lockPeriod = getLockPeriod(dynamicStore, delegateResourceContract);
long maxDelegateLockPeriod = dynamicStore.getMaxDelegateLockPeriod();
if (lockPeriod < 0 || lockPeriod > maxDelegateLockPeriod) {
throw new ContractValidateException(
Expand Down Expand Up @@ -257,6 +257,16 @@ public boolean validate() throws ContractValidateException {
return true;
}

private long getLockPeriod(DynamicPropertiesStore dynamicStore,
DelegateResourceContract delegateResourceContract) {
long lockPeriod = delegateResourceContract.getLockPeriod();
if (dynamicStore.supportMaxDelegateLockPeriod()) {
return lockPeriod == 0 ? DELEGATE_PERIOD / 3000 : lockPeriod;
} else {
return 0;
}
}

private void validRemainTime(ResourceCode resourceCode, long lockPeriod, long expireTime,
long now) throws ContractValidateException {
long remainTime = expireTime - now;
Expand Down Expand Up @@ -294,7 +304,7 @@ private void delegateResource(byte[] ownerAddress, byte[] receiverAddress, boole
long expireTime = 0;
if (lock) {
if (dynamicPropertiesStore.supportMaxDelegateLockPeriod()) {
expireTime = now + (lockPeriod == 0 ? DELEGATE_PERIOD : lockPeriod * 3 * 1000);
expireTime = now + lockPeriod * 3 * 1000;
} else {
expireTime = now + DELEGATE_PERIOD;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
if (value <= maxDelegateLockPeriod || value > 10512000L) {
throw new ContractValidateException(
"This value[MAX_DELEGATE_LOCK_PERIOD] is only allowed to be greater than "
+ maxDelegateLockPeriod + "and less than or equal to 10512000 !");
+ maxDelegateLockPeriod + " and less than or equal to 10512000 !");
}
if (dynamicPropertiesStore.getUnfreezeDelayDays() == 0) {
throw new ContractValidateException(
Expand Down