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)
}
Exemple #2
0
func handleRevealEntry(ctx *web.Context) {
	type revealentry struct {
		Entry string
	}

	e := new(revealentry)
	if p, err := ioutil.ReadAll(ctx.Request.Body); err != nil {
		wsLog.Error(err)
		ctx.WriteHeader(httpBad)
		ctx.Write([]byte(err.Error()))
		return
	} else {
		if err := json.Unmarshal(p, e); err != nil {
			wsLog.Error(err)
			ctx.WriteHeader(httpBad)
			ctx.Write([]byte(err.Error()))
			return
		}
	}

	entry := common.NewEntry()
	if p, err := hex.DecodeString(e.Entry); err != nil {
		wsLog.Error(err)
		ctx.WriteHeader(httpBad)
		ctx.Write([]byte(err.Error()))
		return
	} else {
		_, err := entry.UnmarshalBinaryData(p)
		if err != nil {
			wsLog.Error(err)
			ctx.WriteHeader(httpBad)
			ctx.Write([]byte(err.Error()))
			return
		}
	}

	if err := factomapi.RevealEntry(entry); err != nil {
		wsLog.Error(err)
		ctx.WriteHeader(httpBad)
		ctx.Write([]byte(err.Error()))
		return
	}

	//	ctx.WriteHeader(httpOK)
}
//Construct the entry and submit it to the server
func submitEntryToAnchorChain(aRecord *AnchorRecord) error {

	//Marshal aRecord into json
	jsonARecord, err := json.Marshal(aRecord)
	anchorLog.Debug("submitEntryToAnchorChain - jsonARecord: ", string(jsonARecord))
	if err != nil {
		return err
	}
	bufARecord := new(bytes.Buffer)
	bufARecord.Write(jsonARecord)
	//Sign the json aRecord with the server key
	aRecordSig := serverPrivKey.Sign(jsonARecord)
	//Encode sig into Hex string
	bufARecord.Write([]byte(hex.EncodeToString(aRecordSig.Sig[:])))

	//Create a new entry
	entry := common.NewEntry()
	entry.ChainID = anchorChainID
	anchorLog.Debug("anchorChainID: ", anchorChainID)
	entry.Content = bufARecord.Bytes()

	buf := new(bytes.Buffer)
	// 1 byte version
	buf.Write([]byte{0})
	// 6 byte milliTimestamp (truncated unix time)
	buf.Write(milliTime())
	// 32 byte Entry Hash
	buf.Write(entry.Hash().Bytes())
	// 1 byte number of entry credits to pay
	binaryEntry, err := entry.MarshalBinary()
	if err != nil {
		return err
	}

	anchorLog.Info("jsonARecord binary entry: ", hex.EncodeToString(binaryEntry))
	if c, err := util.EntryCost(binaryEntry); err != nil {
		return err
	} else {
		buf.WriteByte(byte(c))
	}
	tmp := buf.Bytes()
	sig := serverECKey.Sign(tmp)
	buf = bytes.NewBuffer(tmp)
	buf.Write(serverECKey.Pub.Key[:])
	buf.Write(sig.Sig[:])

	commit := common.NewCommitEntry()
	err = commit.UnmarshalBinary(buf.Bytes())
	if err != nil {
		return err
	}

	// create a CommitEntry msg and send it to the local inmsgQ
	cm := factomwire.NewMsgCommitEntry()
	cm.CommitEntry = commit
	inMsgQ <- cm

	// create a RevealEntry msg and send it to the local inmsgQ
	rm := factomwire.NewMsgRevealEntry()
	rm.Entry = entry
	inMsgQ <- rm

	return nil
}