-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #192 from vision-consensus/feature/mainnet_1.2.1
Feature/mainnet 1.2.1 to master
- Loading branch information
Showing
21 changed files
with
541 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
chainstorage/src/main/java/org/vision/core/capsule/FreezeAccountCapsule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package org.vision.core.capsule; | ||
|
||
import com.google.protobuf.ByteString; | ||
import com.google.protobuf.InvalidProtocolBufferException; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.vision.protos.Protocol.FreezeAccount; | ||
|
||
import java.util.List; | ||
|
||
|
||
@Slf4j(topic = "capsule") | ||
public class FreezeAccountCapsule implements ProtoCapsule<FreezeAccount> { | ||
|
||
private FreezeAccount freezeAccount; | ||
|
||
public FreezeAccountCapsule(final FreezeAccount freezeAccount) { | ||
this.freezeAccount = freezeAccount; | ||
} | ||
|
||
public FreezeAccountCapsule(final byte[] data) { | ||
try { | ||
this.freezeAccount = FreezeAccount.parseFrom(data); | ||
} catch (InvalidProtocolBufferException e) { | ||
logger.debug(e.getMessage(), e); | ||
} | ||
} | ||
|
||
public FreezeAccountCapsule(List<ByteString> freezeAccounts) { | ||
this.freezeAccount = FreezeAccount.newBuilder() | ||
.addAllFreezeAccounts(freezeAccounts) | ||
.build(); | ||
} | ||
|
||
|
||
public void setAllAddresses(List<ByteString> freezeAccounts) { | ||
this.freezeAccount = this.freezeAccount.toBuilder() | ||
.clearFreezeAccounts() | ||
.addAllFreezeAccounts(freezeAccounts) | ||
.build(); | ||
} | ||
|
||
public void addAddress(ByteString freezeAddress) { | ||
this.freezeAccount = this.freezeAccount.toBuilder() | ||
.addFreezeAccounts(freezeAddress) | ||
.build(); | ||
} | ||
|
||
public void addAllAddress(List<ByteString> freezeAccounts) { | ||
this.freezeAccount = this.freezeAccount.toBuilder() | ||
.addAllFreezeAccounts(freezeAccounts) | ||
.build(); | ||
} | ||
|
||
public List<ByteString> getAddressesList() { | ||
return this.freezeAccount.getFreezeAccountsList(); | ||
} | ||
|
||
public boolean checkFreeze(ByteString address) { | ||
return this.getAddressesList().contains(address); | ||
} | ||
|
||
public byte[] createFreezeAccountDbKey() { | ||
return "FREEZE_ACCOUNT_KEY".getBytes(); | ||
} | ||
|
||
@Override | ||
public byte[] getData() { | ||
return this.freezeAccount.toByteArray(); | ||
} | ||
|
||
@Override | ||
public FreezeAccount getInstance() { | ||
return this.freezeAccount; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
chainstorage/src/main/java/org/vision/core/store/FreezeAccountStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.vision.core.store; | ||
|
||
import org.apache.commons.lang3.ArrayUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
import org.vision.core.capsule.FreezeAccountCapsule; | ||
import org.vision.core.db.VisionStoreWithRevoking; | ||
|
||
|
||
|
||
@Component | ||
public class FreezeAccountStore extends VisionStoreWithRevoking<FreezeAccountCapsule> { | ||
|
||
@Autowired | ||
public FreezeAccountStore(@Value("freeze-account") String dbName) { | ||
super(dbName); | ||
} | ||
|
||
@Override | ||
public FreezeAccountCapsule get(byte[] key) { | ||
byte[] value = revokingDB.getUnchecked(key); | ||
return ArrayUtils.isEmpty(value) ? null : new FreezeAccountCapsule(value); | ||
} | ||
|
||
public void put(byte[] key, FreezeAccountCapsule item) { | ||
super.put(key, item); | ||
} | ||
|
||
@Override | ||
public void delete(byte[] key) { | ||
super.delete(key); | ||
} | ||
|
||
public byte[] createFreezeAccountDbKey() { | ||
return "FREEZE_ACCOUNT_KEY".getBytes(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.