-
Notifications
You must be signed in to change notification settings - Fork 664
/
transfer_output.go
60 lines (47 loc) · 1.25 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
57
58
59
60
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package secp256k1fx
import (
"encoding/json"
"errors"
"github.com/ava-labs/avalanchego/vms/components/verify"
)
var (
_ verify.State = (*OutputOwners)(nil)
ErrNoValueOutput = errors.New("output has no value")
)
type TransferOutput struct {
Amt uint64 `serialize:"true" json:"amount"`
OutputOwners `serialize:"true"`
}
// MarshalJSON marshals Amt and the embedded OutputOwners struct
// into a JSON readable format
// If OutputOwners cannot be serialized then this will return error
func (out *TransferOutput) MarshalJSON() ([]byte, error) {
result, err := out.OutputOwners.Fields()
if err != nil {
return nil, err
}
result["amount"] = out.Amt
return json.Marshal(result)
}
// Amount returns the quantity of the asset this output consumes
func (out *TransferOutput) Amount() uint64 {
return out.Amt
}
func (out *TransferOutput) Verify() error {
switch {
case out == nil:
return ErrNilOutput
case out.Amt == 0:
return ErrNoValueOutput
default:
return out.OutputOwners.Verify()
}
}
func (out *TransferOutput) VerifyState() error {
return out.Verify()
}
func (out *TransferOutput) Owners() interface{} {
return &out.OutputOwners
}