Exemplo n.º 1
0
func SaveEntryBinary(entry interfaces.DatabaseBatchable, blockHeight uint32) error {
	data, err := entry.MarshalBinary()
	if err != nil {
		return err
	}

	strChainID := fmt.Sprintf("%x", entry.GetChainID())
	dir := DataStorePath + strChainID + "/entries"
	if FileNotExists(dir) {
		err := os.MkdirAll(dir, 0777)
		if err == nil {
			fmt.Println("Created directory " + dir)
		} else {
			return err
		}
	}

	err = ioutil.WriteFile(fmt.Sprintf(dir+"/store.%09d.%v.entry", blockHeight, entry.DatabasePrimaryIndex().String()), data, 0777)
	if err != nil {
		return err
	}
	return nil
}
Exemplo n.º 2
0
func SaveBinary(block interfaces.DatabaseBatchable) error {
	data, err := block.MarshalBinary()
	if err != nil {
		return err
	}

	strChainID := fmt.Sprintf("%x", block.GetChainID())
	dir := DataStorePath + strChainID
	if FileNotExists(dir) {
		err := os.MkdirAll(dir, 0777)
		if err == nil {
			fmt.Println("Created directory " + dir)
		} else {
			return err
		}
	}

	err = ioutil.WriteFile(fmt.Sprintf(dir+"/store.%09d.block", block.GetDatabaseHeight()), data, 0777)
	if err != nil {
		return err
	}
	return nil
}