github.com/MetalBlockchain/metalgo@v1.11.9/vms/platformvm/txs/add_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/utils/crypto/bls"
    13  	"github.com/MetalBlockchain/metalgo/vms/components/verify"
    14  )
    15  
    16  var (
    17  	_ StakerTx        = (*AddSubnetValidatorTx)(nil)
    18  	_ ScheduledStaker = (*AddSubnetValidatorTx)(nil)
    19  
    20  	errAddPrimaryNetworkValidator = errors.New("can't add primary network validator with AddSubnetValidatorTx")
    21  )
    22  
    23  // AddSubnetValidatorTx is an unsigned addSubnetValidatorTx
    24  type AddSubnetValidatorTx struct {
    25  	// Metadata, inputs and outputs
    26  	BaseTx `serialize:"true"`
    27  	// The validator
    28  	SubnetValidator `serialize:"true" json:"validator"`
    29  	// Auth that will be allowing this validator into the network
    30  	SubnetAuth verify.Verifiable `serialize:"true" json:"subnetAuthorization"`
    31  }
    32  
    33  func (tx *AddSubnetValidatorTx) NodeID() ids.NodeID {
    34  	return tx.SubnetValidator.NodeID
    35  }
    36  
    37  func (*AddSubnetValidatorTx) PublicKey() (*bls.PublicKey, bool, error) {
    38  	return nil, false, nil
    39  }
    40  
    41  func (*AddSubnetValidatorTx) PendingPriority() Priority {
    42  	return SubnetPermissionedValidatorPendingPriority
    43  }
    44  
    45  func (*AddSubnetValidatorTx) CurrentPriority() Priority {
    46  	return SubnetPermissionedValidatorCurrentPriority
    47  }
    48  
    49  // SyntacticVerify returns nil iff [tx] is valid
    50  func (tx *AddSubnetValidatorTx) SyntacticVerify(ctx *snow.Context) error {
    51  	switch {
    52  	case tx == nil:
    53  		return ErrNilTx
    54  	case tx.SyntacticallyVerified: // already passed syntactic verification
    55  		return nil
    56  	case tx.Subnet == constants.PrimaryNetworkID:
    57  		return errAddPrimaryNetworkValidator
    58  	}
    59  
    60  	if err := tx.BaseTx.SyntacticVerify(ctx); err != nil {
    61  		return err
    62  	}
    63  	if err := verify.All(&tx.Validator, tx.SubnetAuth); err != nil {
    64  		return err
    65  	}
    66  
    67  	// cache that this is valid
    68  	tx.SyntacticallyVerified = true
    69  	return nil
    70  }
    71  
    72  func (tx *AddSubnetValidatorTx) Visit(visitor Visitor) error {
    73  	return visitor.AddSubnetValidatorTx(tx)
    74  }