示例#1
0
func ExportDatabaseJSON(db interfaces.IDatabase, convertNames bool) error {
	fmt.Printf("Exporting the database\n")
	if db == nil {
		return nil
	}
	buckets, err := db.ListAllBuckets()
	if err != nil {
		return err
	}
	answer := map[string]interface{}{}
	for _, bucket := range buckets {
		m := map[string]interface{}{}
		data, keys, err := db.GetAll(bucket, new(primitives.ByteSlice))
		if err != nil {
			return err
		}
		for i, key := range keys {
			m[fmt.Sprintf("%x", key)] = data[i]
		}
		if convertNames == true {
			answer[KeyToName(bucket)] = m
		} else {
			answer[fmt.Sprintf("%x", bucket)] = m
		}
	}

	data, err := primitives.EncodeJSON(answer)
	if err != nil {
		return err
	}

	var out bytes.Buffer
	json.Indent(&out, data, "", "\t")
	data = out.Next(out.Len())
	/*
		dir := be.DataStorePath
		if dir != "" {
			if FileNotExists(dir) {
				err := os.MkdirAll(dir, 0777)
				if err == nil {
					fmt.Println("Created directory " + dir)
				} else {
					return err
				}
			}
		}
		if dir != "" {
			dir = dir + "/db.txt"
		} else {
			dir = "db.txt"
		}*/
	dir := "db.txt"
	err = ioutil.WriteFile(dir, data, 0777)
	if err != nil {
		return err
	}
	return nil
}
示例#2
0
func (e *MissingMsg) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(e)
}
func (e *AddFederatedServer) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(e)
}
示例#4
0
func (e *Bounce) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(e)
}
func (e *EntryBlockResponse) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(e)
}
示例#6
0
func (e *MsgRevealChain) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(e)
}
示例#7
0
func (e *SignatureBlock) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(e)
}
示例#8
0
func (e *AdminBlock) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(e)
}
示例#9
0
func (e *FEREntry) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(e)
}
示例#10
0
func (e *DataResponse) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(e)
}
示例#11
0
func (e *RequestBlock) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(e)
}
示例#12
0
func (e *DBStateMissing) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(e)
}
示例#13
0
func (e *MsgGetEntryData) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(e)
}
示例#14
0
func (e ByteStore) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(e)
}
示例#15
0
func (s *FactoidSignature) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(s)
}
示例#16
0
func (e *FactoidTransaction) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(e)
}
示例#17
0
func (e *MsgAck) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(e)
}
示例#18
0
func (e *EndOfMinuteEntry) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(e)
}
示例#19
0
func (e *ServerFault) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(e)
}
func (e *AddAuditServer) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(e)
}
示例#21
0
func (e *EBlockHeader) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(e)
}
示例#22
0
func (e *Heartbeat) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(e)
}
示例#23
0
func (e *DirectoryBlock) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(e)
}
示例#24
0
func (e *ServerIndexNumber) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(e)
}
示例#25
0
func (e *ECBlockBody) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(e)
}
示例#26
0
func (e *IncreaseBalance) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(e)
}
func (e *IncreaseServerCount) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(e)
}
示例#28
0
func (e *CommitEntryMsg) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(e)
}
示例#29
0
func (e *MsgFactoidTX) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(e)
}
示例#30
0
func (e *Identity) JSONByte() ([]byte, error) {
	return primitives.EncodeJSON(e)
}