forked from TrueCloudLab/neoneo-go
0da9fe6946
It's mostly used for Serializable and in other cases where one needs to estimate binary-encoded size of the stucture. This also simplifies future removal of the Size() from Serializable.
49 lines
1 KiB
Go
49 lines
1 KiB
Go
package transaction
|
|
|
|
import (
|
|
"github.com/CityOfZion/neo-go/pkg/io"
|
|
)
|
|
|
|
// ClaimTX represents a claim transaction.
|
|
type ClaimTX struct {
|
|
Claims []*Input
|
|
}
|
|
|
|
// DecodeBinary implements the Payload interface.
|
|
func (tx *ClaimTX) DecodeBinary(br *io.BinReader) error {
|
|
lenClaims := br.ReadVarUint()
|
|
if br.Err != nil {
|
|
return br.Err
|
|
}
|
|
tx.Claims = make([]*Input, lenClaims)
|
|
for i := 0; i < int(lenClaims); i++ {
|
|
tx.Claims[i] = &Input{}
|
|
if err := tx.Claims[i].DecodeBinary(br); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// EncodeBinary implements the Payload interface.
|
|
func (tx *ClaimTX) EncodeBinary(bw *io.BinWriter) error {
|
|
bw.WriteVarUint(uint64(len(tx.Claims)))
|
|
if bw.Err != nil {
|
|
return bw.Err
|
|
}
|
|
for _, claim := range tx.Claims {
|
|
if err := claim.EncodeBinary(bw); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Size returns serialized binary size for this transaction.
|
|
func (tx *ClaimTX) Size() int {
|
|
sz := io.GetVarSize(uint64(len(tx.Claims)))
|
|
for _, claim := range tx.Claims {
|
|
sz += claim.Size()
|
|
}
|
|
return sz
|
|
}
|