Browse Source

block_height is int32

pull/1780/head
Ethan Buchman 8 years ago
parent
commit
df299d03c4
2 changed files with 33 additions and 33 deletions
  1. +32
    -32
      example/dummy/persistent_dummy.go
  2. +1
    -1
      types/types.proto

+ 32
- 32
example/dummy/persistent_dummy.go View File

@ -10,38 +10,6 @@ import (
"github.com/tendermint/tmsp/types"
)
//-----------------------------------------
// persist the last block info
var lastBlockKey = []byte("lastblock")
// Get the last block from the db
func LoadLastBlock(db dbm.DB) (lastBlock types.LastBlockInfo) {
buf := db.Get(lastBlockKey)
if len(buf) != 0 {
r, n, err := bytes.NewReader(buf), new(int), new(error)
wire.ReadBinaryPtr(&lastBlock, r, 0, n, err)
if *err != nil {
// DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED
Exit(Fmt("Data has been corrupted or its spec has changed: %v\n", *err))
}
// TODO: ensure that buf is completely read.
}
return lastBlock
}
func SaveLastBlock(db dbm.DB, lastBlock types.LastBlockInfo) {
log.Notice("Saving block", "height", lastBlock.BlockHeight, "hash", lastBlock.BlockHash, "root", lastBlock.AppHash)
buf, n, err := new(bytes.Buffer), new(int), new(error)
wire.WriteBinary(lastBlock, buf, n, err)
if *err != nil {
// TODO
PanicCrisis(*err)
}
db.Set(lastBlockKey, buf.Bytes())
}
//-----------------------------------------
type PersistentDummyApplication struct {
@ -120,3 +88,35 @@ func (app *PersistentDummyApplication) BeginBlock(hash []byte, header *types.Hea
func (app *PersistentDummyApplication) EndBlock(height uint64) (diffs []*types.Validator) {
return nil
}
//-----------------------------------------
// persist the last block info
var lastBlockKey = []byte("lastblock")
// Get the last block from the db
func LoadLastBlock(db dbm.DB) (lastBlock types.LastBlockInfo) {
buf := db.Get(lastBlockKey)
if len(buf) != 0 {
r, n, err := bytes.NewReader(buf), new(int), new(error)
wire.ReadBinaryPtr(&lastBlock, r, 0, n, err)
if *err != nil {
// DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED
Exit(Fmt("Data has been corrupted or its spec has changed: %v\n", *err))
}
// TODO: ensure that buf is completely read.
}
return lastBlock
}
func SaveLastBlock(db dbm.DB, lastBlock types.LastBlockInfo) {
log.Notice("Saving block", "height", lastBlock.BlockHeight, "hash", lastBlock.BlockHash, "root", lastBlock.AppHash)
buf, n, err := new(bytes.Buffer), new(int), new(error)
wire.WriteBinary(lastBlock, buf, n, err)
if *err != nil {
// TODO
PanicCrisis(*err)
}
db.Set(lastBlockKey, buf.Bytes())
}

+ 1
- 1
types/types.proto View File

@ -219,7 +219,7 @@ message TMSPInfo {
}
message LastBlockInfo {
uint64 block_height = 1;
int32 block_height = 1;
bytes block_hash = 2;
bytes app_hash = 3;
}


Loading…
Cancel
Save