Пример #1
0
func (this *TxIn) WriteTo(w io.Writer) (int64, error) {
	var dw dataio.DataWriter
	dw.Init(w)

	err := dw.Write(this.Previous.Hash[:])
	if err != nil {
		return dw.Count(), err
	}

	err = dw.WriteUint32(this.Previous.Index)
	if err != nil {
		return dw.Count(), err
	}

	err = dw.WriteVarBytes(this.Script)
	if err != nil {
		return dw.Count(), err
	}

	err = dw.WriteUint32(this.Sequence)
	if err != nil {
		return dw.Count(), err
	}

	return dw.Count(), nil
}
Пример #2
0
func (this *Tx) WriteTo(w io.Writer) (int64, error) {
	if this.Version > 2 {
		return 0, UnsupportedTxVersionError(this.Version)
	}

	var dw dataio.DataWriter
	dw.Init(w)

	err := dw.WriteUint32(this.Version)
	if err != nil {
		return dw.Count(), err
	}

	err = dw.WriteVarInt(uint64(len(this.Inputs)))
	if err != nil {
		return dw.Count(), err
	}

	for i, _ := range this.Inputs {
		err := dw.WriteWriterTo(&this.Inputs[i])
		if err != nil {
			return dw.Count(), err
		}
	}

	err = dw.WriteVarInt(uint64(len(this.Outputs)))
	if err != nil {
		return dw.Count(), err
	}

	for i, _ := range this.Outputs {
		err := dw.WriteWriterTo(&this.Outputs[i])
		if err != nil {
			return dw.Count(), err
		}
	}

	err = dw.WriteUint32(this.LockTime)
	if err != nil {
		return dw.Count(), err
	}

	return dw.Count(), nil
}