Files
proto/p/txs/add_chain_validator_tx.go
zeekay 73a0a922f0 fix: update API to use InitRuntime instead of InitCtx
- Rename InitCtx → InitRuntime throughout
- Update imports for new package versions
- Update utxo/secp256k1fx usage
- Update consensus context references
2026-01-26 09:37:09 -08:00

82 lines
2.2 KiB
Go

// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package txs
import (
"context"
"errors"
"github.com/luxfi/constants"
"github.com/luxfi/crypto/bls"
"github.com/luxfi/ids"
"github.com/luxfi/runtime"
"github.com/luxfi/vm/components/verify"
)
var (
_ StakerTx = (*AddChainValidatorTx)(nil)
_ ScheduledStaker = (*AddChainValidatorTx)(nil)
errAddPrimaryNetworkValidator = errors.New("can't add primary network validator with AddChainValidatorTx")
)
// AddChainValidatorTx is an unsigned addChainValidatorTx
type AddChainValidatorTx struct {
// Metadata, inputs and outputs
BaseTx `serialize:"true"`
// The validator
ChainValidator `serialize:"true" json:"validator"`
// Auth that will be allowing this validator into the network
ChainAuth verify.Verifiable `serialize:"true" json:"chainAuthorization"`
}
func (tx *AddChainValidatorTx) NodeID() ids.NodeID {
return tx.ChainValidator.NodeID
}
func (*AddChainValidatorTx) PublicKey() (*bls.PublicKey, bool, error) {
return nil, false, nil
}
func (*AddChainValidatorTx) PendingPriority() Priority {
return ChainPermissionedValidatorPendingPriority
}
func (*AddChainValidatorTx) CurrentPriority() Priority {
return ChainPermissionedValidatorCurrentPriority
}
// SyntacticVerify returns nil iff [tx] is valid
func (tx *AddChainValidatorTx) SyntacticVerify(rt *runtime.Runtime) error {
switch {
case tx == nil:
return ErrNilTx
case tx.SyntacticallyVerified: // already passed syntactic verification
return nil
case tx.Chain == constants.PrimaryNetworkID:
return errAddPrimaryNetworkValidator
}
if err := tx.BaseTx.SyntacticVerify(rt); err != nil {
return err
}
if err := verify.All(&tx.Validator, tx.ChainAuth); err != nil {
return err
}
// cache that this is valid
tx.SyntacticallyVerified = true
return nil
}
func (tx *AddChainValidatorTx) Visit(visitor Visitor) error {
return visitor.AddChainValidatorTx(tx)
}
// InitializeWithContext initializes the transaction with consensus context
func (tx *AddChainValidatorTx) InitializeWithContext(ctx context.Context) error {
// Initialize any context-dependent fields here
return nil
}