-
Notifications
You must be signed in to change notification settings - Fork 672
/
mint_operation.go
61 lines (51 loc) · 1.48 KB
/
mint_operation.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
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package nftfx
import (
"errors"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/vms/components/verify"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
"github.com/ava-labs/avalanchego/vms/types"
)
var errNilMintOperation = errors.New("nil mint operation")
type MintOperation struct {
MintInput secp256k1fx.Input `serialize:"true" json:"mintInput"`
GroupID uint32 `serialize:"true" json:"groupID"`
Payload types.JSONByteSlice `serialize:"true" json:"payload"`
Outputs []*secp256k1fx.OutputOwners `serialize:"true" json:"outputs"`
}
func (op *MintOperation) InitCtx(ctx *snow.Context) {
for _, out := range op.Outputs {
out.InitCtx(ctx)
}
}
func (op *MintOperation) Cost() (uint64, error) {
return op.MintInput.Cost()
}
// Outs Returns []TransferOutput as []verify.State
func (op *MintOperation) Outs() []verify.State {
outs := []verify.State{}
for _, out := range op.Outputs {
outs = append(outs, &TransferOutput{
GroupID: op.GroupID,
Payload: op.Payload,
OutputOwners: *out,
})
}
return outs
}
func (op *MintOperation) Verify() error {
switch {
case op == nil:
return errNilMintOperation
case len(op.Payload) > MaxPayloadSize:
return errPayloadTooLarge
}
for _, out := range op.Outputs {
if err := out.Verify(); err != nil {
return err
}
}
return op.MintInput.Verify()
}