forked from blockwatch-cc/tzgo
/
increase_paid_storage.go
68 lines (58 loc) · 1.82 KB
/
increase_paid_storage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) 2023 Blockwatch Data Inc.
// Author: alex@blockwatch.cc
package codec
import (
"bytes"
"strconv"
"github.com/mavryk-network/mvgo/mavryk"
)
// IncreasePaidStorage represents "increase_paid_storage" operation
type IncreasePaidStorage struct {
Manager
Amount mavryk.Z `json:"amount"`
Destination mavryk.Address `json:"destination"`
}
func (o IncreasePaidStorage) Kind() mavryk.OpType {
return mavryk.OpTypeIncreasePaidStorage
}
func (o IncreasePaidStorage) MarshalJSON() ([]byte, error) {
buf := bytes.NewBuffer(nil)
buf.WriteByte('{')
buf.WriteString(`"kind":`)
buf.WriteString(strconv.Quote(o.Kind().String()))
buf.WriteByte(',')
o.Manager.EncodeJSON(buf)
buf.WriteString(`,"amount":`)
buf.WriteString(strconv.Quote(o.Amount.String()))
buf.WriteString(`,"destination":`)
buf.WriteString(strconv.Quote(o.Destination.String()))
buf.WriteByte('}')
return buf.Bytes(), nil
}
func (o IncreasePaidStorage) EncodeBuffer(buf *bytes.Buffer, p *mavryk.Params) error {
buf.WriteByte(o.Kind().TagVersion(p.OperationTagsVersion))
o.Manager.EncodeBuffer(buf, p)
o.Amount.EncodeBuffer(buf)
buf.Write(o.Destination.EncodePadded())
return nil
}
func (o *IncreasePaidStorage) DecodeBuffer(buf *bytes.Buffer, p *mavryk.Params) (err error) {
if err = ensureTagAndSize(buf, o.Kind(), p.OperationTagsVersion); err != nil {
return
}
if err = o.Manager.DecodeBuffer(buf, p); err != nil {
return err
}
if err = o.Amount.DecodeBuffer(buf); err != nil {
return err
}
return o.Destination.Decode(buf.Next(22))
}
func (o IncreasePaidStorage) MarshalBinary() ([]byte, error) {
buf := bytes.NewBuffer(nil)
err := o.EncodeBuffer(buf, mavryk.DefaultParams)
return buf.Bytes(), err
}
func (o *IncreasePaidStorage) UnmarshalBinary(data []byte) error {
return o.DecodeBuffer(bytes.NewBuffer(data), mavryk.DefaultParams)
}