forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 4
/
create_subnet_tx.go
51 lines (42 loc) · 1.35 KB
/
create_subnet_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
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package txs
import (
"github.com/MetalBlockchain/metalgo/snow"
"github.com/MetalBlockchain/metalgo/vms/platformvm/fx"
)
var _ UnsignedTx = (*CreateSubnetTx)(nil)
// CreateSubnetTx is an unsigned proposal to create a new subnet
type CreateSubnetTx struct {
// Metadata, inputs and outputs
BaseTx `serialize:"true"`
// Who is authorized to manage this subnet
Owner fx.Owner `serialize:"true" json:"owner"`
}
// InitCtx sets the FxID fields in the inputs and outputs of this
// [CreateSubnetTx]. Also sets the [ctx] to the given [vm.ctx] so that
// the addresses can be json marshalled into human readable format
func (tx *CreateSubnetTx) InitCtx(ctx *snow.Context) {
tx.BaseTx.InitCtx(ctx)
tx.Owner.InitCtx(ctx)
}
// SyntacticVerify verifies that this transaction is well-formed
func (tx *CreateSubnetTx) SyntacticVerify(ctx *snow.Context) error {
switch {
case tx == nil:
return ErrNilTx
case tx.SyntacticallyVerified: // already passed syntactic verification
return nil
}
if err := tx.BaseTx.SyntacticVerify(ctx); err != nil {
return err
}
if err := tx.Owner.Verify(); err != nil {
return err
}
tx.SyntacticallyVerified = true
return nil
}
func (tx *CreateSubnetTx) Visit(visitor Visitor) error {
return visitor.CreateSubnetTx(tx)
}