-
Notifications
You must be signed in to change notification settings - Fork 643
/
transfer_output.go
56 lines (46 loc) · 1.47 KB
/
transfer_output.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
package nftfx
import (
"encoding/json"
"errors"
"github.com/ava-labs/avalanchego/vms/types"
"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/avalanchego/vms/components/verify"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
)
const (
// MaxPayloadSize is the maximum size that can be placed into a payload
MaxPayloadSize = units.KiB
)
var (
errNilTransferOutput = errors.New("nil transfer output")
errPayloadTooLarge = errors.New("payload too large")
_ verify.State = &TransferOutput{}
)
type TransferOutput struct {
GroupID uint32 `serialize:"true" json:"groupID"`
Payload types.JSONByteSlice `serialize:"true" json:"payload"`
secp256k1fx.OutputOwners `serialize:"true"`
}
// MarshalJSON marshals Amt and the embedded OutputOwners struct
// into a JSON readable format
// If OutputOwners cannot be serialised then this will return error
func (out *TransferOutput) MarshalJSON() ([]byte, error) {
result, err := out.OutputOwners.Fields()
if err != nil {
return nil, err
}
result["groupID"] = out.GroupID
result["payload"] = out.Payload
return json.Marshal(result)
}
func (out *TransferOutput) Verify() error {
switch {
case out == nil:
return errNilTransferOutput
case len(out.Payload) > MaxPayloadSize:
return errPayloadTooLarge
default:
return out.OutputOwners.Verify()
}
}
func (out *TransferOutput) VerifyState() error { return out.Verify() }