2020-05-11 08:59:39 +00:00
|
|
|
package accounting
|
|
|
|
|
2020-05-11 10:14:31 +00:00
|
|
|
import (
|
|
|
|
"encoding/binary"
|
|
|
|
"io"
|
|
|
|
)
|
2020-05-11 08:59:39 +00:00
|
|
|
|
|
|
|
// SignedData returns payload bytes of the request.
|
|
|
|
func (m BalanceRequest) SignedData() ([]byte, error) {
|
|
|
|
data := make([]byte, m.SignedDataSize())
|
|
|
|
|
|
|
|
if _, err := m.ReadSignedData(data); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return data, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SignedDataSize returns payload size of the request.
|
|
|
|
func (m BalanceRequest) SignedDataSize() int {
|
|
|
|
return m.GetOwnerID().Size()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReadSignedData copies payload bytes to passed buffer.
|
|
|
|
//
|
|
|
|
// If the buffer size is insufficient, io.ErrUnexpectedEOF returns.
|
|
|
|
func (m BalanceRequest) ReadSignedData(p []byte) (int, error) {
|
|
|
|
sz := m.SignedDataSize()
|
|
|
|
if len(p) < sz {
|
|
|
|
return 0, io.ErrUnexpectedEOF
|
|
|
|
}
|
|
|
|
|
|
|
|
copy(p, m.GetOwnerID().Bytes())
|
|
|
|
|
|
|
|
return sz, nil
|
|
|
|
}
|
2020-05-11 09:54:21 +00:00
|
|
|
|
|
|
|
// SignedData returns payload bytes of the request.
|
|
|
|
func (m GetRequest) SignedData() ([]byte, error) {
|
|
|
|
data := make([]byte, m.SignedDataSize())
|
|
|
|
|
|
|
|
if _, err := m.ReadSignedData(data); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return data, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SignedDataSize returns payload size of the request.
|
|
|
|
func (m GetRequest) SignedDataSize() int {
|
|
|
|
return m.GetID().Size() + m.GetOwnerID().Size()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReadSignedData copies payload bytes to passed buffer.
|
|
|
|
//
|
|
|
|
// If the buffer size is insufficient, io.ErrUnexpectedEOF returns.
|
|
|
|
func (m GetRequest) ReadSignedData(p []byte) (int, error) {
|
|
|
|
sz := m.SignedDataSize()
|
|
|
|
if len(p) < sz {
|
|
|
|
return 0, io.ErrUnexpectedEOF
|
|
|
|
}
|
|
|
|
|
|
|
|
var off int
|
|
|
|
|
|
|
|
off += copy(p[off:], m.GetID().Bytes())
|
|
|
|
|
|
|
|
copy(p[off:], m.GetOwnerID().Bytes())
|
|
|
|
|
|
|
|
return sz, nil
|
|
|
|
}
|
2020-05-11 10:14:31 +00:00
|
|
|
|
|
|
|
// SignedData returns payload bytes of the request.
|
|
|
|
func (m PutRequest) SignedData() ([]byte, error) {
|
|
|
|
data := make([]byte, m.SignedDataSize())
|
|
|
|
|
|
|
|
if _, err := m.ReadSignedData(data); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return data, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SignedDataSize returns payload size of the request.
|
|
|
|
func (m PutRequest) SignedDataSize() (sz int) {
|
|
|
|
sz += m.GetOwnerID().Size()
|
|
|
|
|
|
|
|
sz += m.GetMessageID().Size()
|
|
|
|
|
|
|
|
sz += 8
|
|
|
|
|
|
|
|
if amount := m.GetAmount(); amount != nil {
|
|
|
|
sz += amount.Size()
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReadSignedData copies payload bytes to passed buffer.
|
|
|
|
//
|
|
|
|
// If the buffer size is insufficient, io.ErrUnexpectedEOF returns.
|
|
|
|
func (m PutRequest) ReadSignedData(p []byte) (int, error) {
|
|
|
|
if len(p) < m.SignedDataSize() {
|
|
|
|
return 0, io.ErrUnexpectedEOF
|
|
|
|
}
|
|
|
|
|
|
|
|
var off int
|
|
|
|
|
|
|
|
off += copy(p[off:], m.GetOwnerID().Bytes())
|
|
|
|
|
|
|
|
off += copy(p[off:], m.GetMessageID().Bytes())
|
|
|
|
|
|
|
|
binary.BigEndian.PutUint64(p[off:], m.GetHeight())
|
|
|
|
off += 8
|
|
|
|
|
|
|
|
if amount := m.GetAmount(); amount != nil {
|
|
|
|
n, err := amount.MarshalTo(p[off:])
|
|
|
|
off += n
|
|
|
|
if err != nil {
|
|
|
|
return off + n, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return off, nil
|
|
|
|
}
|
2020-05-11 10:20:58 +00:00
|
|
|
|
|
|
|
// SignedData returns payload bytes of the request.
|
|
|
|
func (m ListRequest) SignedData() ([]byte, error) {
|
|
|
|
data := make([]byte, m.SignedDataSize())
|
|
|
|
|
|
|
|
if _, err := m.ReadSignedData(data); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return data, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SignedDataSize returns payload size of the request.
|
|
|
|
func (m ListRequest) SignedDataSize() int {
|
|
|
|
return m.GetOwnerID().Size()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReadSignedData copies payload bytes to passed buffer.
|
|
|
|
//
|
|
|
|
// If the buffer size is insufficient, io.ErrUnexpectedEOF returns.
|
|
|
|
func (m ListRequest) ReadSignedData(p []byte) (int, error) {
|
|
|
|
sz := m.SignedDataSize()
|
|
|
|
if len(p) < sz {
|
|
|
|
return 0, io.ErrUnexpectedEOF
|
|
|
|
}
|
|
|
|
|
|
|
|
copy(p, m.GetOwnerID().Bytes())
|
|
|
|
|
|
|
|
return sz, nil
|
|
|
|
}
|
2020-05-11 10:29:04 +00:00
|
|
|
|
|
|
|
// SignedData returns payload bytes of the request.
|
|
|
|
func (m DeleteRequest) SignedData() ([]byte, error) {
|
|
|
|
data := make([]byte, m.SignedDataSize())
|
|
|
|
|
|
|
|
if _, err := m.ReadSignedData(data); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return data, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SignedDataSize returns payload size of the request.
|
2020-05-11 10:57:23 +00:00
|
|
|
func (m DeleteRequest) SignedDataSize() (sz int) {
|
|
|
|
sz += m.GetID().Size()
|
|
|
|
|
|
|
|
sz += m.GetOwnerID().Size()
|
|
|
|
|
|
|
|
sz += m.GetMessageID().Size()
|
|
|
|
|
|
|
|
return
|
2020-05-11 10:29:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ReadSignedData copies payload bytes to passed buffer.
|
|
|
|
//
|
|
|
|
// If the buffer size is insufficient, io.ErrUnexpectedEOF returns.
|
|
|
|
func (m DeleteRequest) ReadSignedData(p []byte) (int, error) {
|
|
|
|
if len(p) < m.SignedDataSize() {
|
|
|
|
return 0, io.ErrUnexpectedEOF
|
|
|
|
}
|
|
|
|
|
|
|
|
var off int
|
|
|
|
|
|
|
|
off += copy(p[off:], m.GetID().Bytes())
|
|
|
|
|
|
|
|
off += copy(p[off:], m.GetOwnerID().Bytes())
|
|
|
|
|
|
|
|
off += copy(p[off:], m.GetMessageID().Bytes())
|
|
|
|
|
|
|
|
return off, nil
|
|
|
|
}
|