コード例 #1
0
//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
}
コード例 #2
0
ファイル: api.go プロジェクト: 6londe/FactomCode
func CommitEntry(c *common.CommitEntry) error {
	m := wire.NewMsgCommitEntry()
	m.CommitEntry = c
	inMsgQ <- m
	return nil
}