Exemplo n.º 1
0
func getHead() {
	head, err := factom.GetDBlockHead()
	if err != nil {
		errorln(err)
		return
	}
	fmt.Println(head.KeyMR)
}
Exemplo n.º 2
0
// Refresh the Directory Block Head.  If it has changed, return true.
// Otherwise return false.
func getDBHead() bool {
	db, err := factom.GetDBlockHead()
	if err != nil {
		panic(err.Error())
	}

	if db.KeyMR != DBHeadStr {
		DBHeadStr = db.KeyMR
		DBHead, err = hex.DecodeString(db.KeyMR)
		if err != nil {
			panic(err.Error())
		}

		return true
	}
	return false
}
func Synchronize() error {
	log.Println("Synchronize()")
	head, err := factom.GetDBlockHead()
	if err != nil {
		Log("Error - %v", err)
		return err
	}
	previousKeyMR := head.KeyMR
	dataStatus := LoadDataStatus()
	maxHeight := dataStatus.DBlockHeight
	for {

		block, err := LoadDBlock(previousKeyMR)
		if err != nil {
			Log("Error - %v", err)
			return err
		}

		if block != nil {
			if maxHeight < block.SequenceNumber {
				maxHeight = block.SequenceNumber
			}
			if previousKeyMR == dataStatus.LastKnownBlock {
				dataStatus.LastKnownBlock = head.KeyMR
				dataStatus.DBlockHeight = maxHeight
				break
			} else {
				previousKeyMR = block.PrevBlockKeyMR
				continue
			}
		}
		body, err := GetDBlockFromFactom(previousKeyMR)
		if err != nil {
			Log("Error - %v", err)
			return err
		}

		log.Printf("\n\nProcessing dblock number %v\n", body.SequenceNumber)

		str, err := EncodeJSONString(body)
		if err != nil {
			Log("Error - %v", err)
			return err
		}
		log.Printf("%v", str)

		for _, v := range body.EntryBlockList {
			fetchedBlock, err := FetchBlock(v.ChainID, v.KeyMR, body.BlockTimeStr)
			if err != nil {
				Log("Error - %v", err)
				return err
			}
			switch v.ChainID {
			case "000000000000000000000000000000000000000000000000000000000000000a":
				body.AdminEntries += fetchedBlock.EntryCount
				body.AdminBlock = ListEntry{ChainID: v.ChainID, KeyMR: v.KeyMR}
				break
			case "000000000000000000000000000000000000000000000000000000000000000c":
				body.EntryCreditEntries += fetchedBlock.EntryCount
				body.EntryCreditBlock = ListEntry{ChainID: v.ChainID, KeyMR: v.KeyMR}
				break
			case "000000000000000000000000000000000000000000000000000000000000000f":
				body.FactoidEntries += fetchedBlock.EntryCount
				body.FactoidBlock = ListEntry{ChainID: v.ChainID, KeyMR: v.KeyMR}
				break
			default:
				body.EntryEntries += fetchedBlock.EntryCount
				break
			}
		}
		body.EntryBlockList = body.EntryBlockList[3:]

		err = SaveDBlock(body)
		if err != nil {
			Log("Error - %v", err)
			return err
		}

		if maxHeight < body.SequenceNumber {
			maxHeight = body.SequenceNumber
		}
		previousKeyMR = body.PrevBlockKeyMR
		if previousKeyMR == "0000000000000000000000000000000000000000000000000000000000000000" {
			dataStatus.LastKnownBlock = head.KeyMR
			dataStatus.DBlockHeight = maxHeight
			break
		}

	}
	err = SaveDataStatus(dataStatus)
	if err != nil {
		Log("Error - %v", err)
		return err
	}
	return nil
}
Exemplo n.º 4
0
		if err != nil {
			errorln(err)
			return
		}
		fmt.Println(entry)
	}
	help.Add("get firstentry", cmd)
	return cmd
}()

var getHead = func() *fctCmd {
	cmd := new(fctCmd)
	cmd.helpMsg = "factom-cli get head"
	cmd.description = "Get the latest completed directory block"
	cmd.execFunc = func(args []string) {
		head, err := factom.GetDBlockHead()
		if err != nil {
			errorln(err)
			return
		}
		dblock, err := factom.GetDBlock(head)
		if err != nil {
			errorln(err)
			return
		}
		fmt.Println("DBlock:", head)
		fmt.Println(dblock)
	}
	help.Add("get head", cmd)
	return cmd
}()