Example #1
0
func JustFactomizeChain(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
	}

	chain := factom.NewChain(e)

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

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

	return tx1, tx2, nil
}
Example #2
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
	}
}
Example #3
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 #4
0
		if balance == 0 {
			errorln("Entry Credit balance is zero")
			return
		}
		// commit the chain
		txID, err := factom.CommitChain(c, ec)
		if err != nil {
			errorln(err)
			return
		}
		fmt.Println("Commiting Chain Transaction ID:", txID)

		// TODO - get commit acknowledgement

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

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

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