2018-03-04 13:56:49 +00:00
|
|
|
package transaction
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/binary"
|
|
|
|
"io"
|
|
|
|
|
2018-03-21 16:11:04 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/util"
|
2018-03-04 13:56:49 +00:00
|
|
|
)
|
|
|
|
|
2019-02-20 17:39:32 +00:00
|
|
|
// Input represents a Transaction input (CoinReference).
|
2018-03-04 13:56:49 +00:00
|
|
|
type Input struct {
|
|
|
|
// The hash of the previous transaction.
|
2019-02-20 17:39:32 +00:00
|
|
|
PrevHash util.Uint256 `json:"txid"`
|
2018-03-04 13:56:49 +00:00
|
|
|
|
|
|
|
// The index of the previous transaction.
|
2019-02-20 17:39:32 +00:00
|
|
|
PrevIndex uint16 `json:"vout"`
|
2018-03-04 13:56:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DecodeBinary implements the Payload interface.
|
|
|
|
func (in *Input) DecodeBinary(r io.Reader) error {
|
|
|
|
if err := binary.Read(r, binary.LittleEndian, &in.PrevHash); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return binary.Read(r, binary.LittleEndian, &in.PrevIndex)
|
|
|
|
}
|
|
|
|
|
|
|
|
// EncodeBinary implements the Payload interface.
|
|
|
|
func (in *Input) EncodeBinary(w io.Writer) error {
|
|
|
|
if err := binary.Write(w, binary.LittleEndian, in.PrevHash); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := binary.Write(w, binary.LittleEndian, in.PrevIndex); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2019-02-20 17:39:32 +00:00
|
|
|
|
|
|
|
// Size returns the size in bytes of the Input
|
|
|
|
func (in *Input) Size() int {
|
|
|
|
return in.PrevHash.Size() + 2 // 2 = sizeOf uint16
|
|
|
|
}
|