func parseToJSON(a []Block) (j []byte) {
	j, e := json.Marshal(a)
	if e != nil {
		panic(e)
	}
	return
}
parseToJSON converts the chain into Marshallable JSON.
package file
import (
	"encoding/json"
	"fmt"
	"os"
	"runtime"
	"strings"
	"sync"
	"time"
)
var Chains *ChainSet
func init() {
	Chains = NewChainSet(FlushAsTime, time.Second*10)
	Chains.Run()
}
const (
	BlockDataSeparator = "|"
	FileExtension = ".json"
)
const (
	FlushAsTime = 0
	FlushAsSpace = 1
)
type ChainSet struct {
	FlushDuration time.Duration
	flushType     int
	Cmap          map[string]*chain
	cancel        chan interface{}
	mux           sync.RWMutex
}
func NewChainSet(flushType int, flushDuration time.Duration) *ChainSet {
	return &ChainSet{
		FlushDuration: flushDuration,
		flushType:     flushType,
		Cmap:          make(map[string]*chain),
		cancel:        make(chan interface{}),
	}
}
func (cs *ChainSet) Cancel() {
	cs.cancel <- ""
}
func (cs *ChainSet) Get(name string) (*chain, bool) {
	if _, ok := cs.Cmap[name]; !ok {
		return nil, false
	}
	return cs.Cmap[name], true
}
func (cs *ChainSet) NewChain(name, url string, useTestDir bool) (Appendable, ChainUtils) {
	c := newChain(name, url, useTestDir)
	c.init()
	cs.register(name, c)
	return c, c
}
func (cs *ChainSet) DeleteChain(name string) error {
	_, exists := cs.Cmap[name]
	if !exists {
		return fmt.Errorf("chain '%s' does not exists", name)
	}
	cs.Cmap[name] = nil
	delete(cs.Cmap, name)
	return nil
}
func (cs *ChainSet) register(name string, c *chain) {
	cs.mux.Lock()
	defer cs.mux.Unlock()
	cs.Cmap[name] = c
}
func (cs *ChainSet) Run() {
	switch cs.flushType {
	case FlushAsTime:
		go func() {
			for {
				select {
				case <-cs.cancel:
					return
				default:
				}
				cs.mux.Lock()
				for _, chain := range cs.Cmap {
					if chain.containsNewBlocks {
						chain.commit()
					} else {
						chain.inActiveIterations++
					}
				}
				cs.mux.Unlock()
				runtime.GC()
				time.Sleep(cs.FlushDuration)
			}
		}()
	case FlushAsSpace:
		return
	}
}