Esempio n. 1
0
// This is the Baby of Asset tracking!  We get the current height of our block
// and we go through each entry, unmarshalling it and building a "block".  We
// then process that block.
//
// We process transactions in our chain, and maintain a balance of our assets.
//
func (fs *AssetState) LoadState() error {

	// First we need to build our list of blocks going back.
	var blklist []factom.EBlock

	// Get me a chain head...
	blkmr, err := factom.GetChainHead(hex.EncodeToString(fs.ChainID()))
	if err != nil {
		return err
	}
	blk, err := factom.GetEBlock(blkmr.ChainHead)

	for {
		if blk.Header.BlockSequenceNumber < fs.nextblockheight {
			break
		}
		blklist = append(blklist, *blk)
		if blk.Header.BlockSequenceNumber == 0 {
			break
		}
		nblk, err := factom.GetEBlock(blk.Header.PrevKeyMR)
		if err != nil {
			fmt.Println("Error Reading Entry blocks")
			time.Sleep(time.Second)
			continue
		}
		blk = nblk
	}

	// Now process blocks forward

	for i := len(blklist) - 1; i >= 0; i-- {
		for _, entry := range blklist[i].EntryList {
			transEntry, err := factom.GetEntry(entry.EntryHash)
			t := new(fct.Transaction)
			transdata, err := hex.DecodeString(transEntry.Content)
			if err != nil {
				continue
			} // Ignore bad entries.
			err = t.UnmarshalBinary(transdata)
			if err != nil {
				continue
			} // Ignore bad entries.
			fs.AddTransaction(t)
		}
	}

	return nil
}
Esempio n. 2
0
func getEntry(args []string) {
	os.Args = args
	flag.Parse()
	args = flag.Args()
	if len(args) < 1 {
		man("getEntry")
		return
	}

	hash := args[0]
	entry, err := factom.GetEntry(hash)
	if err != nil {
		errorln(err)
		return
	}

	printEntry(entry)
}
Esempio n. 3
0
var getEntry = func() *fctCmd {
	cmd := new(fctCmd)
	cmd.helpMsg = "factom-cli get entry HASH"
	cmd.description = "Get entry by hash"
	cmd.execFunc = func(args []string) {
		os.Args = args
		flag.Parse()
		args = flag.Args()
		if len(args) < 1 {
			fmt.Println(cmd.helpMsg)
			return
		}

		hash := args[0]
		entry, err := factom.GetEntry(hash)
		if err != nil {
			errorln(err)
			return
		}
		fmt.Println(entry)
	}
	help.Add("get entry", cmd)
	return cmd
}()

var getFirstEntry = func() *fctCmd {
	cmd := new(fctCmd)
	cmd.helpMsg = "factom-cli get firstentry [-n NAME1 -N HEXNAME2 ...] CHAINID"
	cmd.description = "Get the first entry from a chain"
	cmd.execFunc = func(args []string) {