github.com/ava-labs/avalanchego@v1.11.11/vms/nftfx/mint_operation.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package nftfx 5 6 import ( 7 "errors" 8 9 "github.com/ava-labs/avalanchego/snow" 10 "github.com/ava-labs/avalanchego/vms/components/verify" 11 "github.com/ava-labs/avalanchego/vms/secp256k1fx" 12 "github.com/ava-labs/avalanchego/vms/types" 13 ) 14 15 var errNilMintOperation = errors.New("nil mint operation") 16 17 type MintOperation struct { 18 MintInput secp256k1fx.Input `serialize:"true" json:"mintInput"` 19 GroupID uint32 `serialize:"true" json:"groupID"` 20 Payload types.JSONByteSlice `serialize:"true" json:"payload"` 21 Outputs []*secp256k1fx.OutputOwners `serialize:"true" json:"outputs"` 22 } 23 24 func (op *MintOperation) InitCtx(ctx *snow.Context) { 25 for _, out := range op.Outputs { 26 out.InitCtx(ctx) 27 } 28 } 29 30 func (op *MintOperation) Cost() (uint64, error) { 31 return op.MintInput.Cost() 32 } 33 34 // Outs Returns []TransferOutput as []verify.State 35 func (op *MintOperation) Outs() []verify.State { 36 outs := []verify.State{} 37 for _, out := range op.Outputs { 38 outs = append(outs, &TransferOutput{ 39 GroupID: op.GroupID, 40 Payload: op.Payload, 41 OutputOwners: *out, 42 }) 43 } 44 return outs 45 } 46 47 func (op *MintOperation) Verify() error { 48 switch { 49 case op == nil: 50 return errNilMintOperation 51 case len(op.Payload) > MaxPayloadSize: 52 return errPayloadTooLarge 53 } 54 55 for _, out := range op.Outputs { 56 if err := out.Verify(); err != nil { 57 return err 58 } 59 } 60 return op.MintInput.Verify() 61 }