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)
}
Beispiel #2
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
}
Beispiel #3
0
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
	}
}
Beispiel #4
0
func ComposeChainSubmit(name string, data []byte) ([]byte, error) {
	type chainsubmit struct {
		ChainID     string
		ChainCommit json.RawMessage
		EntryReveal json.RawMessage
	}

	e := factom.NewEntry()
	if err := e.UnmarshalJSON(data); err != nil {
		return nil, err
	}
	c := factom.NewChain(e)

	sub := new(chainsubmit)
	we := factoidState.GetDB().GetRaw([]byte(fct.W_NAME), []byte(name))
	switch we.(type) {
	case wallet.IWalletEntry:
		pub := new([fct.ADDRESS_LENGTH]byte)
		copy(pub[:], we.(wallet.IWalletEntry).GetKey(0))
		pri := new([fct.PRIVATE_LENGTH]byte)
		copy(pri[:], we.(wallet.IWalletEntry).GetPrivKey(0))

		sub.ChainID = c.ChainID

		if j, err := factom.ComposeChainCommit(pub, pri, c); err != nil {
			return nil, err
		} else {
			sub.ChainCommit = j
		}

		if j, err := factom.ComposeEntryReveal(c.FirstEntry); err != nil {
			return nil, err
		} else {
			sub.EntryReveal = j
		}

	default:
		return nil, fmt.Errorf("Cannot use non Entry Credit Address for Chain Commit")
	}

	return json.Marshal(sub)
}
Beispiel #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
	}
}