-
Notifications
You must be signed in to change notification settings - Fork 664
/
add_subnet_validator_tx.go
74 lines (60 loc) · 2.02 KB
/
add_subnet_validator_tx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package txs
import (
"errors"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
"github.com/ava-labs/avalanchego/vms/components/verify"
)
var (
_ StakerTx = (*AddSubnetValidatorTx)(nil)
_ ScheduledStaker = (*AddSubnetValidatorTx)(nil)
errAddPrimaryNetworkValidator = errors.New("can't add primary network validator with AddSubnetValidatorTx")
)
// AddSubnetValidatorTx is an unsigned addSubnetValidatorTx
type AddSubnetValidatorTx struct {
// Metadata, inputs and outputs
BaseTx `serialize:"true"`
// The validator
SubnetValidator `serialize:"true" json:"validator"`
// Auth that will be allowing this validator into the network
SubnetAuth verify.Verifiable `serialize:"true" json:"subnetAuthorization"`
}
func (tx *AddSubnetValidatorTx) NodeID() ids.NodeID {
return tx.SubnetValidator.NodeID
}
func (*AddSubnetValidatorTx) PublicKey() (*bls.PublicKey, bool, error) {
return nil, false, nil
}
func (*AddSubnetValidatorTx) PendingPriority() Priority {
return SubnetPermissionedValidatorPendingPriority
}
func (*AddSubnetValidatorTx) CurrentPriority() Priority {
return SubnetPermissionedValidatorCurrentPriority
}
// SyntacticVerify returns nil iff [tx] is valid
func (tx *AddSubnetValidatorTx) SyntacticVerify(ctx *snow.Context) error {
switch {
case tx == nil:
return ErrNilTx
case tx.SyntacticallyVerified: // already passed syntactic verification
return nil
case tx.Subnet == constants.PrimaryNetworkID:
return errAddPrimaryNetworkValidator
}
if err := tx.BaseTx.SyntacticVerify(ctx); err != nil {
return err
}
if err := verify.All(&tx.Validator, tx.SubnetAuth); err != nil {
return err
}
// cache that this is valid
tx.SyntacticallyVerified = true
return nil
}
func (tx *AddSubnetValidatorTx) Visit(visitor Visitor) error {
return visitor.AddSubnetValidatorTx(tx)
}