2018-03-04 13:56:49 +00:00
|
|
|
package transaction
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ClaimTX represents a claim transaction.
|
|
|
|
type ClaimTX struct {
|
|
|
|
Claims []*Input
|
|
|
|
}
|
|
|
|
|
|
|
|
// DecodeBinary implements the Payload interface.
|
|
|
|
func (tx *ClaimTX) DecodeBinary(r io.Reader) error {
|
2019-08-28 16:27:06 +00:00
|
|
|
br := util.BinReader{R: r}
|
|
|
|
lenClaims := br.ReadVarUint()
|
|
|
|
if br.Err != nil {
|
|
|
|
return br.Err
|
|
|
|
}
|
2018-03-04 13:56:49 +00:00
|
|
|
tx.Claims = make([]*Input, lenClaims)
|
|
|
|
for i := 0; i < int(lenClaims); i++ {
|
|
|
|
tx.Claims[i] = &Input{}
|
|
|
|
if err := tx.Claims[i].DecodeBinary(r); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// EncodeBinary implements the Payload interface.
|
|
|
|
func (tx *ClaimTX) EncodeBinary(w io.Writer) error {
|
2019-08-28 16:27:06 +00:00
|
|
|
bw := util.BinWriter{W: w}
|
|
|
|
bw.WriteVarUint(uint64(len(tx.Claims)))
|
|
|
|
if bw.Err != nil {
|
|
|
|
return bw.Err
|
2018-03-04 13:56:49 +00:00
|
|
|
}
|
|
|
|
for _, claim := range tx.Claims {
|
|
|
|
if err := claim.EncodeBinary(w); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2019-08-30 08:28:30 +00:00
|
|
|
|
2019-09-03 14:51:37 +00:00
|
|
|
// Size returns serialized binary size for this transaction.
|
2019-08-30 08:28:30 +00:00
|
|
|
func (tx *ClaimTX) Size() int {
|
|
|
|
sz := util.GetVarSize(uint64(len(tx.Claims)))
|
|
|
|
for _, claim := range tx.Claims {
|
|
|
|
sz += claim.Size()
|
|
|
|
}
|
|
|
|
return sz
|
|
|
|
}
|