Ejemplo n.º 1
0
func (b *FBlock) MarshalTrans() ([]byte, error) {
	var out bytes.Buffer
	var periodMark = 0
	var i int
	var trans fct.ITransaction
	for i, trans = range b.Transactions {

		for periodMark < len(b.endOfPeriod) &&
			b.endOfPeriod[periodMark] > 0 && // Ignore if markers are not set
			i == b.endOfPeriod[periodMark] {

			out.WriteByte(fct.MARKER)
			periodMark++
		}

		data, err := trans.MarshalBinary()
		if err != nil {
			return nil, err
		}
		out.Write(data)
		if err != nil {
			return nil, err
		}
	}
	for periodMark < len(b.endOfPeriod) {
		out.WriteByte(fct.MARKER)
		periodMark++
	}
	return out.Bytes(), nil
}
Ejemplo n.º 2
0
// FactoidSubmit assumes the caller has already validated and signed
// the transaction.  No checking is done, it is just submitted to Factom.
func FactoidSubmit(trans fct.ITransaction) (err error) {

	var data []byte
	if data, err = trans.MarshalBinary(); err != nil {
		return err
	}

	transdata := string(hex.EncodeToString(data))

	s := struct{ Transaction string }{transdata}

	var js []byte
	if js, err = json.Marshal(s); err != nil {
		return err
	}

	resp, err := http.Post(
		fmt.Sprintf("http://%s/v1/factoid-submit/", ipaddressFD+portNumberFD),
		"application/json",
		bytes.NewBuffer(js))

	if err != nil {
		return err
	}

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err
	}

	resp.Body.Close()

	type rtnStruct struct {
		Response string
		Success  bool
	}
	rtn := new(rtnStruct)
	if err := json.Unmarshal(body, rtn); err != nil {
		return err
	}

	if !rtn.Success {
		return fmt.Errorf(rtn.Response)
	}

	return nil
}