func main() {

	inFile, _ := os.Open(inputfile)
	defer inFile.Close()
	scanner := bufio.NewScanner(inFile)
	scanner.Split(bufio.ScanLines)
	counter := 0
	for scanner.Scan() {
		line := scanner.Text()
		index := strings.Index(line, "entry: ")
		index = index + 7
		bytes, err := hex.DecodeString(line[index:])
		if err == nil {
			entry := common.NewEntry()
			entry.UnmarshalBinary(bytes)

			factomEntry := factom.NewEntry()
			factomEntry.ChainID = entry.ChainID.String()
			factomEntry.Content = hex.EncodeToString(entry.Content)
			factom.CommitEntry(factomEntry, ecname)
			time.Sleep(3 * time.Second)
			factom.RevealEntry(factomEntry)

			fmt.Println("Successfully submitted:", spew.Sdump(entry))
		}

		counter++
	}

	fmt.Println("Total number of lines:", counter)
}
Example #2
0
func JustFactomize(entry *entryBlock.Entry) (string, string, error) {
	//Convert entryBlock Entry into factom Entry
	//fmt.Printf("Entry - %v\n", entry)
	j, err := entry.JSONByte()
	if err != nil {
		return "", "", err
	}
	e := new(factom.Entry)
	err = e.UnmarshalJSON(j)
	if err != nil {
		return "", "", err
	}

	//Commit and reveal
	tx1, err := factom.CommitEntry(e, ECAddress)
	if err != nil {
		fmt.Println("Entry commit error : ", err)
		return "", "", err
	}

	time.Sleep(3 * time.Second)
	tx2, err := factom.RevealEntry(e)
	if err != nil {
		fmt.Println("Entry reveal error : ", err)
		return "", "", err
	}

	return tx1, tx2, nil
}
Example #3
0
// Create a factom.Entry and commit/reveal
func (a *APICall) Factomize() error {
	type entryBody struct {
		APIMethod  string
		ReturnData string
		Timestamp  int64
	}
	b := new(entryBody)

	b.APIMethod = a.APIMethod

	// get the ReturnData from the api call
	resp, err := http.Get(a.APIMethod)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	data, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err
	}
	if resp.StatusCode != 200 {
		return fmt.Errorf(string(data))
	}
	b.ReturnData = string(data)

	// get the current time
	b.Timestamp = time.Now().Unix()

	// create the factom entry
	e := factom.NewEntry()

	e.ChainID = a.ChainID
	if e.Content, err = json.Marshal(b); err != nil {
		return err
	}

	// Write the signature of the Entry Content to the first ExtID
	e.ExtIDs = append(e.ExtIDs, func() []byte {
		sec := new([64]byte)
		if s, err := hex.DecodeString(a.SecKey); err != nil {
			log.Fatal(err)
		} else {
			copy(sec[:], s)
		}
		return ed.Sign(sec, e.Content)[:]
	}())

	// Commit+Reveal the Entry to the Factom Network
	if err := factom.CommitEntry(e, a.ECAddr); err != nil {
		return err
	}
	time.Sleep(10 * time.Second)
	if err := factom.RevealEntry(e); err != nil {
		return err
	}

	return nil
}
Example #4
0
func main() {

	var (
		sflag = flag.String("s", "localhost:8088", "address of api server")
		wflag = flag.String("w", "localhost:8089", "address of wallet api server")
	)
	flag.Parse()
	//args := flag.Args()

	factom.SetFactomdServer(*sflag)
	factom.SetWalletServer(*wflag)

	fmt.Println("Using factomd at", *sflag)
	fmt.Println("Using factom-walletd at", *wflag)

	e := new(factom.Entry)

	ecAddr, _ := factom.GetECAddress("Es2Rf7iM6PdsqfYCo3D1tnAR65SkLENyWJG1deUzpRMQmbh9F3eG")
	bal, err := factom.GetECBalance(ecAddr.String())
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("address", ecAddr, "has a balance of", bal)

	e.ExtIDs = append(e.ExtIDs, []byte("id"))
	e.Content = []byte("payload")

	c := factom.NewChain(e)

	txID, err := factom.CommitChain(c, ecAddr)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("commiting txid:", txID)

	hash, err := factom.RevealChain(c)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println("revealed entry:", hash)

	i := 0
	for {
		e.Content = []byte(strconv.Itoa(i))

		//c.ChainID

		txID, err := factom.CommitEntry(e, ecAddr)
		if err != nil {
			fmt.Println(err)
			return
		}

		fmt.Println("commiting txid:", txID)

		hash, err := factom.RevealEntry(e)
		if err != nil {
			fmt.Println(err)
			return
		}
		fmt.Println("revealed entry:", hash)
		time.Sleep(2 * time.Millisecond)
		i++
	}

}
Example #5
0
// 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
	}
}
Example #6
0
			errorln("Entry Credit balance is zero")
			return
		}

		// commit the chain
		txID, err := factom.CommitEntry(e, ec)
		if err != nil {
			errorln(err)
			return
		}
		fmt.Println("Commiting Entry Transaction ID:", txID)

		// TODO - get commit acknowledgement

		// reveal chain
		hash, err := factom.RevealEntry(e)
		if err != nil {
			errorln(err)
			return
		}
		fmt.Println("ChainID:", *cid)
		fmt.Println("Entryhash:", hash)

		// ? get reveal ack
	}
	help.Add("addentry", cmd)
	return cmd
}()

var composeentry = func() *fctCmd {
	cmd := new(fctCmd)