示例#1
0
func HandleV2RevealEntry(state interfaces.IState, params interface{}) (interface{}, *primitives.JSONError) {
	e := new(EntryRequest)
	err := MapToObject(params, e)
	if err != nil {
		return nil, NewInvalidParamsError()
	}

	entry := entryBlock.NewEntry()
	if p, err := hex.DecodeString(e.Entry); err != nil {
		return nil, NewInvalidEntryError()
	} else {
		_, err := entry.UnmarshalBinaryData(p)
		if err != nil {
			return nil, NewInvalidEntryError()
		}
	}

	msg := new(messages.RevealEntryMsg)
	msg.Entry = entry
	msg.Timestamp = state.GetTimestamp()
	state.APIQueue() <- msg

	resp := new(RevealEntryResponse)
	resp.Message = "Entry Reveal Success"
	resp.EntryHash = entry.GetHash().String()

	return resp, nil
}
示例#2
0
文件: wsapi.go 项目: jjdevbiz/factomd
func HandleRevealEntry(ctx *web.Context) {
	type revealentry struct {
		Entry string
	}

	e := new(revealentry)
	if p, err := ioutil.ReadAll(ctx.Request.Body); err != nil {
		returnMsg(ctx, "Error Reveal Entry: "+err.Error(), false)
		return
	} else {
		if err := json.Unmarshal(p, e); err != nil {
			returnMsg(ctx, "Error Reveal Entry: "+err.Error(), false)
			return
		}
	}

	entry := entryBlock.NewEntry()
	if p, err := hex.DecodeString(e.Entry); err != nil {
		returnMsg(ctx, "Error Reveal Entry: "+err.Error(), false)
		return
	} else {
		_, err := entry.UnmarshalBinaryData(p)
		if err != nil {
			returnMsg(ctx, "Error Reveal Entry: "+err.Error(), false)
			return
		}
	}

	state := ctx.Server.Env["state"].(interfaces.IState)

	msg := new(messages.RevealEntryMsg)
	msg.Entry = entry
	msg.Timestamp = state.GetTimestamp()
	state.InMsgQueue() <- msg

	returnMsg(ctx, "Entry Reveal Success", true)
}