示例#1
0
func MakeFEREntryWithHeightFromContent(passedResidentHeight uint32, passedTargetActivationHeight uint32,
	passedTargetPrice uint64, passedExpirationHeight uint32, passedPriority uint32) *FEREntryWithHeight {

	// Create and format the signing private key
	var signingPrivateKey [64]byte
	SigningPrivateKey := "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
	signingBytes, err := hex.DecodeString(SigningPrivateKey)
	if err != nil {
		fmt.Println("Signing private key isn't parsable")
		return nil
	}
	copy(signingPrivateKey[:], signingBytes[:])
	_ = ed.GetPublicKey(&signingPrivateKey) // Needed to format the public half of the key set

	anFEREntry := new(specialEntries.FEREntry)

	anFEREntry.SetExpirationHeight(passedExpirationHeight)
	anFEREntry.SetTargetActivationHeight(passedTargetActivationHeight)
	anFEREntry.SetPriority(passedPriority)
	anFEREntry.SetTargetPrice(passedTargetPrice)

	entryJson, err := json.Marshal(anFEREntry)
	if err != nil {
		fmt.Println("Bad marshal of anFEREntry")
		return nil
	}

	// Create the factom entry with the signing private key
	signingSignature := ed.Sign(&signingPrivateKey, entryJson)

	// Make a new factom entry and populate it
	anEntry := new(factom.Entry)
	anEntry.ChainID = "111111118d918a8be684e0dac725493a75862ef96d2d3f43f84b26969329bf03"
	anEntry.ExtIDs = append(anEntry.ExtIDs, signingSignature[:])
	anEntry.Content = entryJson

	// ce := common.NewEntry()
	emb, _ := anEntry.MarshalBinary()
	// ce.UnmarshalBinary(emb)

	EBEntry := entryBlock.NewEntry()
	_, err = EBEntry.UnmarshalBinaryData(emb)
	if err != nil {
		fmt.Println("Error 3:  couldn't unmarshal binary")
		return nil
	}

	ewh := new(FEREntryWithHeight)
	// Don't set the resident height in the actual FEREntry yet because the state validate loop will handle all that
	ewh.Height = passedResidentHeight
	ewh.AnFEREntry = EBEntry

	return ewh
}
示例#2
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++
	}

}
示例#3
0
		}
		ecpub := args[0]

		e := new(factom.Entry)

		e.ExtIDs = exidCollector

		// 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("Entry of %d bytes is too large", size)
			return
		} else {
			e.Content = p
		}

		c := factom.NewChain(e)

		if factom.ChainExists(c.ChainID) {
			errorln("Chain", c.ChainID, "already exists")
			return
		}

		// get the ec address from the wallet
		ec, err := factom.FetchECAddress(ecpub)
		if err != nil {
			errorln(err)
			return
		}