Exemplo n.º 1
0
func getAll() error {
	dbs := make([]*common.DirectoryBlock, 0, 100)
	next := DBHeadStr

	for {
		blk, err := factom.GetRaw(next)
		if err != nil {
			panic(err.Error())
		}
		db := new(common.DirectoryBlock)
		err = db.UnmarshalBinary(blk)
		if err != nil {
			panic(err.Error())
		}
		dbs = append(dbs, db)
		if bytes.Equal(db.Header.PrevKeyMR.Bytes(), DBHeadLast) {
			break
		}
		next = hex.EncodeToString(db.Header.PrevKeyMR.Bytes())
	}

	DBHeadLast = DBHead

	for i := len(dbs) - 1; i >= 0; i-- {
		DirectoryBlocks = append(DirectoryBlocks, dbs[i])
		fb := new(block.FBlock)
		var fcnt int
		for _, dbe := range dbs[i].DBEntries {
			if bytes.Equal(dbe.ChainID.Bytes(), common.FACTOID_CHAINID) {
				fcnt++
				hashstr := hex.EncodeToString(dbe.KeyMR.Bytes())
				fdata, err := factom.GetRaw(hashstr)
				if err != nil {
					panic(err.Error())
				}
				err = fb.UnmarshalBinary(fdata)
				if err != nil {
					panic(err.Error())
				}
				FactoidBlocks = append(FactoidBlocks, fb)
				break
			}
		}
		if fb == nil {
			panic("Missing Factoid Block from a directory block")
		}
		if fcnt > 1 {
			panic("More than one Factom Block found in a directory block.")
		}
		if err := ProcessFB(fb); err != nil {
			return err
		}
	}
	return nil
}
Exemplo n.º 2
0
func getAll() error {
	dbs := make([]*common.DirectoryBlock, 0, 100)
	next := DBHeadStr

	for {
		blk, err := factom.GetRaw(next)
		if err != nil {
			panic(err.Error())
		}
		db := new(common.DirectoryBlock)
		err = db.UnmarshalBinary(blk)
		if err != nil {
			panic(err.Error())
		}
		dbs = append(dbs, db)
		if bytes.Equal(db.Header.PrevKeyMR.Bytes(), common.ZERO_HASH[:]) {
			break
		}
		next = hex.EncodeToString(db.Header.PrevKeyMR.Bytes())
	}

	for i := len(dbs) - 1; i >= 0; i-- {
		DirectoryBlocks = append(DirectoryBlocks, dbs[i])
		fb := new(block.FBlock)
		for _, dbe := range dbs[i].DBEntries {
			if bytes.Equal(dbe.ChainID.Bytes(), common.FACTOID_CHAINID) {
				hashstr := hex.EncodeToString(dbe.KeyMR.Bytes())
				fdata, err := factom.GetRaw(hashstr)
				if err != nil {
					panic(err.Error())
				}
				err = fb.UnmarshalBinary(fdata)
				if err != nil {
					panic(err.Error())
				}
				FactoidBlocks = append(FactoidBlocks, fb)
				break
			}
		}
		if fb == nil {
			fmt.Println("Missing Factoid Block")
		}
	}
	return nil
}