github.com/MetalBlockchain/metalgo@v1.11.9/vms/platformvm/txs/remove_subnet_validator_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 ) 14 15 var ( 16 _ UnsignedTx = (*RemoveSubnetValidatorTx)(nil) 17 18 ErrRemovePrimaryNetworkValidator = errors.New("can't remove primary network validator with RemoveSubnetValidatorTx") 19 ) 20 21 // Removes a validator from a subnet. 22 type RemoveSubnetValidatorTx struct { 23 BaseTx `serialize:"true"` 24 // The node to remove from the subnet. 25 NodeID ids.NodeID `serialize:"true" json:"nodeID"` 26 // The subnet to remove the node from. 27 Subnet ids.ID `serialize:"true" json:"subnetID"` 28 // Proves that the issuer has the right to remove the node from the subnet. 29 SubnetAuth verify.Verifiable `serialize:"true" json:"subnetAuthorization"` 30 } 31 32 func (tx *RemoveSubnetValidatorTx) SyntacticVerify(ctx *snow.Context) error { 33 switch { 34 case tx == nil: 35 return ErrNilTx 36 case tx.SyntacticallyVerified: 37 // already passed syntactic verification 38 return nil 39 case tx.Subnet == constants.PrimaryNetworkID: 40 return ErrRemovePrimaryNetworkValidator 41 } 42 43 if err := tx.BaseTx.SyntacticVerify(ctx); err != nil { 44 return err 45 } 46 if err := tx.SubnetAuth.Verify(); err != nil { 47 return err 48 } 49 50 tx.SyntacticallyVerified = true 51 return nil 52 } 53 54 func (tx *RemoveSubnetValidatorTx) Visit(visitor Visitor) error { 55 return visitor.RemoveSubnetValidatorTx(tx) 56 }