// 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 }
func getEBlock(args []string) { os.Args = args flag.Parse() args = flag.Args() if len(args) < 1 { man("getEBlock") return } keymr := args[0] eblock, err := factom.GetEBlock(keymr) if err != nil { errorln(err) return } fmt.Println("BlockSequenceNumber:", eblock.Header.BlockSequenceNumber) fmt.Println("ChainID:", eblock.Header.ChainID) fmt.Println("PrevKeyMR:", eblock.Header.PrevKeyMR) fmt.Println("Timestamp:", eblock.Header.Timestamp) for _, v := range eblock.EntryList { fmt.Println("EBEntry {") fmt.Println(" Timestamp", v.Timestamp) fmt.Println(" EntryHash", v.EntryHash) fmt.Println("}") } }
if len(args) < 1 && len(nameCollector) == 0 { fmt.Println(cmd.helpMsg) return } if len(nameCollector) != 0 { chainid = nametoid(nameCollector) } else { chainid = args[0] } head, err := factom.GetChainHead(chainid) if err != nil { errorln(err) return } eblock, err := factom.GetEBlock(head) if err != nil { errorln(err) return } fmt.Println("EBlock:", head) fmt.Println(eblock) } help.Add("get chainhead", cmd) return cmd }() var getDBlock = func() *fctCmd { cmd := new(fctCmd) cmd.helpMsg = "factom-cli get dblock KEYMR"