예제 #1
0
func test(ctx *web.Context) {
	head, err := factom.GetChainHead("000000000000000000000000000000000000000000000000000000000000000a")
	log.Printf("test - %v, %v", head.ChainHead, err)
	/*body, err := factom.GetDBlock(head.KeyMR)
	str, _ := EncodeJSONString(body)
	log.Printf("test - %v, %v", str, err)
	Synchronize()*/
}
예제 #2
0
파일: mkchain.go 프로젝트: xbee/factom-cli
func mkchain(args []string) {
	os.Args = args
	var (
		eids extids
	)
	flag.Var(&eids, "e", "external id for the entry")
	flag.Parse()
	args = flag.Args()

	if len(args) < 1 {
		man("mkchain")
		return
	}
	name := args[0]

	e := factom.NewEntry()

	for _, id := range eids {
		e.ExtIDs = append(e.ExtIDs, []byte(id))
	}

	// Entry.Content is read from stdin
	if p, err := ioutil.ReadAll(os.Stdin); err != nil {
		errorln(err)
		return
	} else if size := len(p); size > 10240 {
		errorln(fmt.Errorf("Entry of %d bytes is too large", size))
		return
	} else {
		e.Content = p
	}

	c := factom.NewChain(e)

	if _, err := factom.GetChainHead(c.ChainID); err == nil {
		// no error means the client found the chain
		errorln("Chain", c.ChainID, "already exists")
		return
	}

	fmt.Println("Creating Chain:", c.ChainID)
	if err := factom.CommitChain(c, name); err != nil {
		errorln(err)
		return
	}
	time.Sleep(10 * time.Second)
	if err := factom.RevealChain(c); err != nil {
		errorln(err)
		return
	}
}
예제 #3
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
}
예제 #4
0
파일: get.go 프로젝트: xbee/factom-cli
func getChain(args []string) {
	os.Args = args
	flag.Parse()
	args = flag.Args()
	if len(args) < 1 {
		man("getChain")
		return
	}

	chainid := args[0]
	chain, err := factom.GetChainHead(chainid)
	if err != nil {
		errorln(err)
		return
	}

	fmt.Println(chain.ChainHead)
}
예제 #5
0
파일: put.go 프로젝트: xbee/factom-cli
// put commits then reveals an entry to factomd
func put(args []string) {
	os.Args = args
	var (
		cid  = flag.String("c", "", "hex encoded chainid for the entry")
		eids extids
	)
	flag.Var(&eids, "e", "external id for the entry")
	flag.Parse()
	args = flag.Args()

	if len(args) < 1 {
		man("put")
		return
	}
	name := args[0]

	e := factom.NewEntry()

	// use the default chainid and extids from the config file
	econf := ReadConfig().Entry
	if econf.Chainid != "" {
		e.ChainID = econf.Chainid
	}
	if *cid != "" {
		e.ChainID = *cid
	}
	if econf.Extid != "" {
		e.ExtIDs = append(e.ExtIDs, []byte(econf.Extid))
	}

	for _, v := range eids {
		e.ExtIDs = append(e.ExtIDs, []byte(v))
	}

	// Entry.Content is read from stdin
	if p, err := ioutil.ReadAll(os.Stdin); err != nil {
		errorln(err)
		return
	} else if size := len(p); size > 10240 {
		errorln(fmt.Errorf("Entry of %d bytes is too large", size))
		return
	} else {
		e.Content = p
	}

	// Make sure the Chain exists before writing the Entry
	if _, err := factom.GetChainHead(e.ChainID); err != nil {
		errorln("Chain:", e.ChainID, "does not exist")
		return
	}

	fmt.Printf("Creating Entry: %x\n", e.Hash())
	if err := factom.CommitEntry(e, name); err != nil {
		errorln(err)
		return
	}
	time.Sleep(10 * time.Second)
	if err := factom.RevealEntry(e); err != nil {
		errorln(err)
		return
	}
}
예제 #6
0
		flag.Parse()
		args = flag.Args()

		var chainid string

		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