Files
proto/p/txs/transfer_chain_ownership_tx.go

79 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"
"github.com/luxfi/runtime"
"errors"
"github.com/luxfi/constants"
"github.com/luxfi/ids"
"github.com/luxfi/proto/p/fx"
"github.com/luxfi/utxo/secp256k1fx"
"github.com/luxfi/vm/components/verify"
)
var (
_ UnsignedTx = (*TransferChainOwnershipTx)(nil)
ErrTransferPermissionlessChain = errors.New("cannot transfer ownership of a permissionless chain")
)
type TransferChainOwnershipTx struct {
// Metadata, inputs and outputs
BaseTx `serialize:"true"`
// ID of the chain this tx is modifying
Chain ids.ID `serialize:"true" json:"chainID"`
// Proves that the issuer has the right to modify the chain.
ChainAuth verify.Verifiable `serialize:"true" json:"chainAuthorization"`
// Who is now authorized to manage this chain
Owner fx.Owner `serialize:"true" json:"newOwner"`
}
// InitRuntime sets the FxID fields in the inputs and outputs of this
// [TransferChainOwnershipTx]. Also sets the [ctx] to the given [vm.ctx] so
// that the addresses can be json marshalled into human readable format
func (tx *TransferChainOwnershipTx) InitRuntime(rt *runtime.Runtime) {
tx.BaseTx.InitRuntime(rt)
// Initialize context for Owner if it's *secp256k1fx.OutputOwners
if owner, ok := tx.Owner.(*secp256k1fx.OutputOwners); ok {
owner.InitRuntime(rt)
}
}
func (tx *TransferChainOwnershipTx) 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 ErrTransferPermissionlessChain
}
if err := tx.BaseTx.SyntacticVerify(rt); err != nil {
return err
}
if err := verify.All(tx.ChainAuth, tx.Owner); err != nil {
return err
}
tx.SyntacticallyVerified = true
return nil
}
func (tx *TransferChainOwnershipTx) Visit(visitor Visitor) error {
return visitor.TransferChainOwnershipTx(tx)
}
// InitializeWithContext initializes the transaction with consensus context
func (tx *TransferChainOwnershipTx) InitializeWithContext(ctx context.Context) error {
// Initialize any context-dependent fields here
return nil
}