示例#1
0
文件: wsapi.go 项目: Kalipsol/factomd
func handleFactoidSubmit(ctx *web.Context) {
	type x struct{ Transaction string }
	t := new(x)

	var p []byte
	var err error
	if p, err = ioutil.ReadAll(ctx.Request.Body); err != nil {
		wsLog.Error(err)
		returnMsg(ctx, "Unable to read the request", false)
		return
	} else {
		if err := json.Unmarshal(p, t); err != nil {
			returnMsg(ctx, "Unable to Unmarshal the request", false)
			return
		}
	}

	msg := new(wire.MsgFactoidTX)

	if p, err = hex.DecodeString(t.Transaction); err != nil {
		returnMsg(ctx, "Unable to decode the transaction", false)
		return
	}

	msg.Transaction = new(fct.Transaction)
	_, err = msg.Transaction.UnmarshalBinaryData(p)
	if err != nil {
		returnMsg(ctx, err.Error(), false)
		return
	}

	err = common.FactoidState.Validate(1, msg.Transaction)
	if err != nil {
		returnMsg(ctx, err.Error(), false)
		return
	}

	inMessageQ <- msg

	returnMsg(ctx, "Successfully submitted the transaction", true)

}
示例#2
0
// processBuyEntryCredit validates the MsgCommitChain and adds it to processlist
func processBuyEntryCredit(msg *wire.MsgFactoidTX) error {
	// Update the credit balance in memory
	for _, v := range msg.Transaction.GetECOutputs() {
		pub := new([32]byte)
		copy(pub[:], v.GetAddress().Bytes())

		cred := int32(v.GetAmount() / uint64(FactoshisPerCredit))

		eCreditMap[string(pub[:])] += cred

	}

	h, _ := msg.Sha()
	if plMgr.IsMyPListExceedingLimit() {
		procLog.Warning("Exceeding MyProcessList size limit!")
		return fMemPool.addOrphanMsg(msg, &h)
	}

	if _, err := plMgr.AddMyProcessListItem(msg, &h, wire.ACK_FACTOID_TX); err != nil {
		return err
	}

	return nil
}
示例#3
0
文件: api.go 项目: 6londe/FactomCode
func FactoidTX(t fct.ITransaction) error {
	m := new(wire.MsgFactoidTX)
	m.SetTransaction(t)
	inMsgQ <- m
	return nil
}