@@ -49,7 +49,9 @@ type Store interface {
// New returns a new ledger which writes to the writer
func New(w io.Writer, s Store) *Ledger {
c := &Ledger{channel: w, blockchain: s}
- c.newGenesis()
+ if s.Len() == 0 {
+ c.newGenesis()
+ }
return c
}
@@ -31,6 +31,9 @@ func (m *MemoryStore) Add(b Block) {
func (m *MemoryStore) Len() int {
m.Lock()
defer m.Unlock()
+ if m.block == nil {
+ return 0
return m.block.Index