github.com/MetalBlockchain/metalgo@v1.11.9/vms/platformvm/txs/transfer_subnet_ownership_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 "errors" 8 9 "github.com/MetalBlockchain/metalgo/ids" 10 "github.com/MetalBlockchain/metalgo/snow" 11 "github.com/MetalBlockchain/metalgo/utils/constants" 12 "github.com/MetalBlockchain/metalgo/vms/components/verify" 13 "github.com/MetalBlockchain/metalgo/vms/platformvm/fx" 14 ) 15 16 var ( 17 _ UnsignedTx = (*TransferSubnetOwnershipTx)(nil) 18 19 ErrTransferPermissionlessSubnet = errors.New("cannot transfer ownership of a permissionless subnet") 20 ) 21 22 type TransferSubnetOwnershipTx struct { 23 // Metadata, inputs and outputs 24 BaseTx `serialize:"true"` 25 // ID of the subnet this tx is modifying 26 Subnet ids.ID `serialize:"true" json:"subnetID"` 27 // Proves that the issuer has the right to remove the node from the subnet. 28 SubnetAuth verify.Verifiable `serialize:"true" json:"subnetAuthorization"` 29 // Who is now authorized to manage this subnet 30 Owner fx.Owner `serialize:"true" json:"newOwner"` 31 } 32 33 // InitCtx sets the FxID fields in the inputs and outputs of this 34 // [TransferSubnetOwnershipTx]. Also sets the [ctx] to the given [vm.ctx] so 35 // that the addresses can be json marshalled into human readable format 36 func (tx *TransferSubnetOwnershipTx) InitCtx(ctx *snow.Context) { 37 tx.BaseTx.InitCtx(ctx) 38 tx.Owner.InitCtx(ctx) 39 } 40 41 func (tx *TransferSubnetOwnershipTx) SyntacticVerify(ctx *snow.Context) error { 42 switch { 43 case tx == nil: 44 return ErrNilTx 45 case tx.SyntacticallyVerified: 46 // already passed syntactic verification 47 return nil 48 case tx.Subnet == constants.PrimaryNetworkID: 49 return ErrTransferPermissionlessSubnet 50 } 51 52 if err := tx.BaseTx.SyntacticVerify(ctx); err != nil { 53 return err 54 } 55 if err := verify.All(tx.SubnetAuth, tx.Owner); err != nil { 56 return err 57 } 58 59 tx.SyntacticallyVerified = true 60 return nil 61 } 62 63 func (tx *TransferSubnetOwnershipTx) Visit(visitor Visitor) error { 64 return visitor.TransferSubnetOwnershipTx(tx) 65 }