github.com/MetalBlockchain/metalgo@v1.11.9/vms/platformvm/txs/create_subnet_tx.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package txs 5 6 import ( 7 "github.com/MetalBlockchain/metalgo/snow" 8 "github.com/MetalBlockchain/metalgo/vms/platformvm/fx" 9 ) 10 11 var _ UnsignedTx = (*CreateSubnetTx)(nil) 12 13 // CreateSubnetTx is an unsigned proposal to create a new subnet 14 type CreateSubnetTx struct { 15 // Metadata, inputs and outputs 16 BaseTx `serialize:"true"` 17 // Who is authorized to manage this subnet 18 Owner fx.Owner `serialize:"true" json:"owner"` 19 } 20 21 // InitCtx sets the FxID fields in the inputs and outputs of this 22 // [CreateSubnetTx]. Also sets the [ctx] to the given [vm.ctx] so that 23 // the addresses can be json marshalled into human readable format 24 func (tx *CreateSubnetTx) InitCtx(ctx *snow.Context) { 25 tx.BaseTx.InitCtx(ctx) 26 tx.Owner.InitCtx(ctx) 27 } 28 29 // SyntacticVerify verifies that this transaction is well-formed 30 func (tx *CreateSubnetTx) SyntacticVerify(ctx *snow.Context) error { 31 switch { 32 case tx == nil: 33 return ErrNilTx 34 case tx.SyntacticallyVerified: // already passed syntactic verification 35 return nil 36 } 37 38 if err := tx.BaseTx.SyntacticVerify(ctx); err != nil { 39 return err 40 } 41 if err := tx.Owner.Verify(); err != nil { 42 return err 43 } 44 45 tx.SyntacticallyVerified = true 46 return nil 47 } 48 49 func (tx *CreateSubnetTx) Visit(visitor Visitor) error { 50 return visitor.CreateSubnetTx(tx) 51 }