diff --git a/example/dummy/persistent_dummy.go b/example/dummy/persistent_dummy.go index df46b8d1..cb2171f5 100644 --- a/example/dummy/persistent_dummy.go +++ b/example/dummy/persistent_dummy.go @@ -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()) +} diff --git a/types/types.proto b/types/types.proto index 7b6a7915..6633d4e3 100644 --- a/types/types.proto +++ b/types/types.proto @@ -219,7 +219,7 @@ message TMSPInfo { } message LastBlockInfo { - uint64 block_height = 1; + int32 block_height = 1; bytes block_hash = 2; bytes app_hash = 3; }