Files
proto/zap_native/remove_chain_validator_tx.go
Hanzo AI 5f375f2db6 proto: lift zap_native from node/vms/platformvm/txs/ to proto/zap_native
Decouples the platformvm ZAP TxKind dispatch from luxfi/node so
proto/p can consume it directly for the codec rip (#101 Wave 1B).
Previously the package lived downstream of proto, making the proto/p
migration architecturally impossible.

Package name kept as zap_native (236 outer-luxfi/zap references would
otherwise need aliasing). Directory matches. Public sub-package (not
internal/) so node's 8 existing consumers can also import it via the
new path:

  github.com/luxfi/node/vms/platformvm/txs/zap_native
    ↓
  github.com/luxfi/proto/zap_native

Standalone tests pass:
  ok  github.com/luxfi/proto/zap_native
2026-06-05 14:40:27 -07:00

77 lines
2.4 KiB
Go

// Copyright (C) 2026, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package zap_native
import (
"github.com/luxfi/ids"
"github.com/luxfi/zap"
)
// RemoveChainValidatorTx v3 schema — TxKind + NodeID (20B) + Network (32B).
//
// Legacy struct also has ChainAuth (verify.Verifiable credential) which lives
// outside the unsigned-tx bytes in the signed wrapper — the unsigned encoding
// here pins only the identity tuple the executor matches against state.
//
// Fixed-section layout (size 53 bytes):
//
// TxKind uint8 @ 0
// NodeID 20B @ 1 (ids.NodeID)
// Network 32B @ 21 (ids.ID)
const (
SchemaVersionRemoveChainValidatorTx uint16 = 3
OffsetRemoveChainValidatorTx_NodeID = 1
OffsetRemoveChainValidatorTx_Network = OffsetRemoveChainValidatorTx_NodeID + ids.ShortIDLen
SizeRemoveChainValidatorTx = OffsetRemoveChainValidatorTx_Network + 32
)
type RemoveChainValidatorTx struct {
msg *zap.Message
obj zap.Object
}
func (t RemoveChainValidatorTx) NodeID() ids.NodeID {
var out ids.NodeID
for i := 0; i < ids.ShortIDLen; i++ {
out[i] = t.obj.Uint8(OffsetRemoveChainValidatorTx_NodeID + i)
}
return out
}
// Network returns the L1 network ID (32B) the validator belongs to.
func (t RemoveChainValidatorTx) Network() ids.ID {
var out ids.ID
for i := 0; i < 32; i++ {
out[i] = t.obj.Uint8(OffsetRemoveChainValidatorTx_Network + i)
}
return out
}
func (t RemoveChainValidatorTx) Bytes() []byte { return t.msg.Bytes() }
func (t RemoveChainValidatorTx) IsZero() bool { return t.msg == nil }
func WrapRemoveChainValidatorTx(b []byte) (RemoveChainValidatorTx, error) {
msg, obj, err := parseAndCheckKind(b, TxKindRemoveChainValidator)
if err != nil {
return RemoveChainValidatorTx{}, err
}
return RemoveChainValidatorTx{msg: msg, obj: obj}, nil
}
func NewRemoveChainValidatorTx(nodeID ids.NodeID, network ids.ID) RemoveChainValidatorTx {
b := zap.NewBuilder(zap.HeaderSize + 16 + SizeRemoveChainValidatorTx)
ob := b.StartObject(SizeRemoveChainValidatorTx)
ob.SetUint8(OffsetTxKind, uint8(TxKindRemoveChainValidator))
for i := 0; i < ids.ShortIDLen; i++ {
ob.SetUint8(OffsetRemoveChainValidatorTx_NodeID+i, nodeID[i])
}
for i := 0; i < 32; i++ {
ob.SetUint8(OffsetRemoveChainValidatorTx_Network+i, network[i])
}
ob.FinishAsRoot()
msg, _ := zap.Parse(b.Finish())
return RemoveChainValidatorTx{msg: msg, obj: msg.Root()}
}