Пример #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)
}
Пример #5
0
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)
}
Пример #20
0
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)
}