Beispiel #1
0
func ExportEChain(chainID string, db interfaces.DBOverlay) error {
	fmt.Printf("ExportEChain %v\n", chainID)
	id, err := primitives.NewShaHashFromStr(chainID)
	if err != nil {
		return err
	}
	eBlocks, err := db.FetchAllEBlocksByChain(id)
	if err != nil {
		return err
	}
	fmt.Printf("Fetched %v blocks\n", len(eBlocks))
	sort.Sort(util.ByEBlockIDAccending(eBlocks))

	for _, block := range eBlocks {
		SaveBinary(block.(interfaces.DatabaseBatchable))
		SaveJSON(block.(interfaces.DatabaseBatchable))
		height := block.GetDatabaseHeight()
		entryHashes := block.GetBody().GetEBEntries()
		for _, hash := range entryHashes {
			entry, err := db.FetchEntryByHash(hash)
			if err != nil {
				return err
			}
			err = ExportEntry(entry.(interfaces.DatabaseBatchable), height)
			if err != nil {
				return err
			}
		}
	}
	return nil
}