Persist blockchain with leveldb on disk (#48)
* Created test_data folder with block json files for testing + create separate file for block base. * Fixed bug in WriteVarUint + Trim logic + unit tests * Refactored store and add more tests for it. * restore headerList from chain file * Fix tx decode bug + lots of housekeeping. * Implemented Node restore state from chain file. * Created standalone package for storage. Added couple more methods to Batch and Store interfaces. * Block persisting + tests * bumped version -> 0.31.0
This commit is contained in:
parent
b41e14e0f0
commit
a67728628e
45 changed files with 1419 additions and 530 deletions
38
pkg/core/header.go
Normal file
38
pkg/core/header.go
Normal file
|
@ -0,0 +1,38 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
// Header holds the head info of a block.
|
||||
type Header struct {
|
||||
// Base of the block.
|
||||
BlockBase
|
||||
// Padding that is fixed to 0
|
||||
_ uint8
|
||||
}
|
||||
|
||||
// DecodeBinary impelements the Payload interface.
|
||||
func (h *Header) DecodeBinary(r io.Reader) error {
|
||||
if err := h.BlockBase.DecodeBinary(r); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var padding uint8
|
||||
binary.Read(r, binary.LittleEndian, &padding)
|
||||
if padding != 0 {
|
||||
return fmt.Errorf("format error: padding must equal 0 got %d", padding)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// EncodeBinary impelements the Payload interface.
|
||||
func (h *Header) EncodeBinary(w io.Writer) error {
|
||||
if err := h.BlockBase.EncodeBinary(w); err != nil {
|
||||
return err
|
||||
}
|
||||
return binary.Write(w, binary.LittleEndian, uint8(0))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue