-
Notifications
You must be signed in to change notification settings - Fork 54
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 #545 from nuls-io/2.3.0
2.3.0
- Loading branch information
Showing
22 changed files
with
384 additions
and
35 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
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
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
40 changes: 40 additions & 0 deletions
40
module/nuls-block/src/main/java/io/nuls/block/model/RollbackInfoPo.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,40 @@ | ||
package io.nuls.block.model; | ||
|
||
import io.nuls.base.basic.NulsByteBuffer; | ||
import io.nuls.base.basic.NulsOutputStreamBuffer; | ||
import io.nuls.base.data.BaseNulsData; | ||
import io.nuls.core.exception.NulsException; | ||
import io.nuls.core.parse.SerializeUtils; | ||
|
||
import java.io.IOException; | ||
|
||
public class RollbackInfoPo extends BaseNulsData { | ||
private long height; | ||
|
||
public RollbackInfoPo(){ | ||
} | ||
|
||
public RollbackInfoPo(long height){ | ||
this.height = height; | ||
} | ||
|
||
protected void serializeToStream(NulsOutputStreamBuffer stream) throws IOException { | ||
stream.writeVarInt(height); | ||
} | ||
|
||
public void parse(NulsByteBuffer byteBuffer) throws NulsException { | ||
this.height = byteBuffer.readVarInt(); | ||
} | ||
|
||
public int size() { | ||
return SerializeUtils.sizeOfVarInt(height); | ||
} | ||
|
||
public long getHeight() { | ||
return height; | ||
} | ||
|
||
public void setHeight(long height) { | ||
this.height = height; | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
module/nuls-block/src/main/java/io/nuls/block/storage/RollbackStorageService.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,9 @@ | ||
package io.nuls.block.storage; | ||
|
||
import io.nuls.block.model.RollbackInfoPo; | ||
|
||
public interface RollbackStorageService { | ||
public boolean save(RollbackInfoPo po, int chainId); | ||
|
||
public RollbackInfoPo get(int chainId); | ||
} |
39 changes: 39 additions & 0 deletions
39
module/nuls-block/src/main/java/io/nuls/block/storage/impl/RollbackServiceImpl.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 io.nuls.block.storage.impl; | ||
|
||
import io.nuls.base.basic.NulsByteBuffer; | ||
import io.nuls.block.constant.Constant; | ||
import io.nuls.block.model.RollbackInfoPo; | ||
import io.nuls.block.storage.RollbackStorageService; | ||
import io.nuls.core.core.annotation.Component; | ||
import io.nuls.core.model.ByteUtils; | ||
import io.nuls.core.rockdb.service.RocksDBService; | ||
import static io.nuls.block.utils.LoggerUtil.COMMON_LOG; | ||
|
||
@Component | ||
public class RollbackServiceImpl implements RollbackStorageService { | ||
public boolean save(RollbackInfoPo po, int chainId) { | ||
byte[] bytes; | ||
try { | ||
bytes = po.serialize(); | ||
return RocksDBService.put(Constant.ROLLBACK_HEIGHT, ByteUtils.intToBytes(chainId), bytes); | ||
} catch (Exception e) { | ||
COMMON_LOG.error("", e); | ||
return false; | ||
} | ||
} | ||
|
||
public RollbackInfoPo get(int chainId) { | ||
try { | ||
RollbackInfoPo po = new RollbackInfoPo(); | ||
byte[] bytes = RocksDBService.get(Constant.ROLLBACK_HEIGHT, ByteUtils.intToBytes(chainId)); | ||
if(bytes == null){ | ||
return null; | ||
} | ||
po.parse(new NulsByteBuffer(bytes)); | ||
return po; | ||
} catch (Exception e) { | ||
COMMON_LOG.error("", e); | ||
return null; | ||
} | ||
} | ||
} |
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
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.