2019-01-16 15:47:43 +01:00
|
|
|
package input
|
2017-05-07 12:34:00 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/binary"
|
|
|
|
"io"
|
|
|
|
|
2018-06-05 03:34:16 +02:00
|
|
|
"github.com/btcsuite/btcd/wire"
|
2017-05-07 12:34:00 +02:00
|
|
|
)
|
|
|
|
|
2017-08-26 03:12:34 +02:00
|
|
|
// writeTxOut serializes a wire.TxOut struct into the passed io.Writer stream.
|
|
|
|
func writeTxOut(w io.Writer, txo *wire.TxOut) error {
|
2017-05-07 12:34:00 +02:00
|
|
|
var scratch [8]byte
|
|
|
|
|
|
|
|
binary.BigEndian.PutUint64(scratch[:], uint64(txo.Value))
|
|
|
|
if _, err := w.Write(scratch[:]); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := wire.WriteVarBytes(w, 0, txo.PkScript); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-08-26 03:12:34 +02:00
|
|
|
// readTxOut deserializes a wire.TxOut struct from the passed io.Reader stream.
|
|
|
|
func readTxOut(r io.Reader, txo *wire.TxOut) error {
|
2017-05-07 12:34:00 +02:00
|
|
|
var scratch [8]byte
|
|
|
|
|
|
|
|
if _, err := io.ReadFull(r, scratch[:]); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
value := int64(binary.BigEndian.Uint64(scratch[:]))
|
|
|
|
|
|
|
|
pkScript, err := wire.ReadVarBytes(r, 0, 80, "pkScript")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
*txo = wire.TxOut{
|
|
|
|
Value: value,
|
|
|
|
PkScript: pkScript,
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|