Exemplo n.º 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
}
Exemplo n.º 2
0
func (this *Version) WriteTo(w io.Writer) (int64, error) {

	var dw dataio.DataWriter
	dw.Init(w)

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

	err = dw.WriteUint64(this.Services)
	if err != nil {
		return dw.Count(), err
	}

	err = dw.WriteTime64(this.Time)
	if err != nil {
		return dw.Count(), err
	}

	err = dw.WriteWriterTo(&this.Receive)
	if err != nil {
		return dw.Count(), err
	}

	err = dw.WriteWriterTo(&this.From)
	if err != nil {
		return dw.Count(), err
	}

	err = dw.WriteUint64(this.Nonce)
	if err != nil {
		return dw.Count(), err
	}

	err = dw.WriteVarString(this.UserAgent)
	if err != nil {
		return dw.Count(), err
	}

	err = dw.WriteInt32(this.StartHeight)
	if err != nil {
		return dw.Count(), err
	}

	return dw.Count(), nil

}
Exemplo n.º 3
0
func (this *TxOut) WriteTo(w io.Writer) (int64, error) {
	var dw dataio.DataWriter
	dw.Init(w)

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

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

	return dw.Count(), nil
}
Exemplo n.º 4
0
func (this *NetworkAddress) WriteTo(w io.Writer) (int64, error) {

	var dw dataio.DataWriter
	dw.Init(w)

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

	err = dw.WriteWriterTo(&this.VersionNetworkAddress)
	if err != nil {
		return dw.Count(), err
	}

	return dw.Count(), nil
}
Exemplo n.º 5
0
func (this *VersionNetworkAddress) WriteTo(w io.Writer) (int64, error) {

	var dw dataio.DataWriter
	dw.Init(w)

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

	err = dw.WriteTCPAddr(&this.Address)
	if err != nil {
		return dw.Count(), err
	}

	return dw.Count(), nil
}
Exemplo n.º 6
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
}