mirror of
https://github.com/luxfi/node.git
synced 2026-10-30 15:24:05 +00:00
The module already called itself github.com/luxfi/node while containing no node in Go: cmd/luxd was twenty-one lines that printed the size of a few types, and the Go column of the matrix measured a VM plugin. A repo that fetches the thing it claims to be has not replaced it, so the Go sources move in — 1515 files, the daemon and everything under it — and the build reaches outside this module for nothing. Rust and C++ sit beside it unchanged and are still measured against it by the differential. That is the point of one repo: the reference implementation and the two ports are the same checkout, so parity is a thing you can run rather than a thing you assert. Verified: builds, and the closure carries no lux-private — checked at build time rather than believed. The daemon starts twelve chains on a local network (P X C Q Z A B G K M F, plus D through its plugin) and reports healthy.
1053 lines
30 KiB
Go
1053 lines
30 KiB
Go
// Code generated by zip; DO NOT EDIT.
|
|
|
|
package api
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"fmt"
|
|
"strings"
|
|
|
|
formatting "github.com/luxfi/formatting"
|
|
ids "github.com/luxfi/ids"
|
|
json "github.com/luxfi/node/utils/json"
|
|
signer "github.com/luxfi/node/vms/platformvm/signer"
|
|
types "github.com/luxfi/vm/types"
|
|
zap "github.com/zap-proto/go"
|
|
)
|
|
|
|
// ---- APIL1Validator ----------------------------------------------------
|
|
|
|
const (
|
|
aPIL1ValidatorNodeIDAt = 0
|
|
aPIL1ValidatorWeightAt = 24
|
|
aPIL1ValidatorStartTimeAt = 32
|
|
aPIL1ValidatorBaseL1ValidatorAt = 40
|
|
aPIL1ValidatorSize = 48
|
|
)
|
|
|
|
var _ interface {
|
|
MarshalZAP() ([]byte, error)
|
|
UnmarshalZAP([]byte) error
|
|
} = (*APIL1Validator)(nil)
|
|
|
|
// MarshalZAP writes APIL1Validator from constant offsets.
|
|
func (x *APIL1Validator) MarshalZAP() ([]byte, error) {
|
|
if x == nil {
|
|
return nil, nil
|
|
}
|
|
b := zap.NewBuilder(aPIL1ValidatorSize + 256)
|
|
ob := b.StartObject(aPIL1ValidatorSize)
|
|
ob.SetBytesFixed(aPIL1ValidatorNodeIDAt, x.NodeID[:])
|
|
ob.SetUint64(aPIL1ValidatorWeightAt, uint64(x.Weight))
|
|
ob.SetUint64(aPIL1ValidatorStartTimeAt, uint64(x.StartTime))
|
|
innerBaseL1Validator, err := x.BaseL1Validator.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ob.SetBytes(aPIL1ValidatorBaseL1ValidatorAt, innerBaseL1Validator)
|
|
ob.FinishAsRoot()
|
|
return b.Finish(), nil
|
|
}
|
|
|
|
// UnmarshalZAP reads APIL1Validator out of the buffer that arrived.
|
|
func (x *APIL1Validator) UnmarshalZAP(data []byte) error {
|
|
if x == nil || len(data) == 0 {
|
|
return nil
|
|
}
|
|
m, err := zap.Parse(data)
|
|
if err != nil {
|
|
return fmt.Errorf("APIL1Validator: %w", err)
|
|
}
|
|
o := m.Root()
|
|
copy(x.NodeID[:], o.BytesFixed(aPIL1ValidatorNodeIDAt, 20))
|
|
x.Weight = json.Uint64(o.Uint64(aPIL1ValidatorWeightAt))
|
|
x.StartTime = json.Uint64(o.Uint64(aPIL1ValidatorStartTimeAt))
|
|
if raw := o.Bytes(aPIL1ValidatorBaseL1ValidatorAt); len(raw) > 0 {
|
|
if err := x.BaseL1Validator.UnmarshalZAP(raw); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ---- BaseL1Validator ---------------------------------------------------
|
|
|
|
const (
|
|
baseL1ValidatorValidationIDAt = 0
|
|
baseL1ValidatorPublicKeyAt = 32
|
|
baseL1ValidatorRemainingBalanceOwnerAt = 40
|
|
baseL1ValidatorDeactivationOwnerAt = 48
|
|
baseL1ValidatorMinNonceAt = 56
|
|
baseL1ValidatorBalanceAt = 64
|
|
baseL1ValidatorSize = 72
|
|
)
|
|
|
|
var _ interface {
|
|
MarshalZAP() ([]byte, error)
|
|
UnmarshalZAP([]byte) error
|
|
} = (*BaseL1Validator)(nil)
|
|
|
|
// MarshalZAP writes BaseL1Validator from constant offsets.
|
|
func (x *BaseL1Validator) MarshalZAP() ([]byte, error) {
|
|
if x == nil {
|
|
return nil, nil
|
|
}
|
|
b := zap.NewBuilder(baseL1ValidatorSize + 256)
|
|
ob := b.StartObject(baseL1ValidatorSize)
|
|
if x.ValidationID != nil {
|
|
ob.SetBytesFixed(baseL1ValidatorValidationIDAt, (*x.ValidationID)[:])
|
|
}
|
|
if x.PublicKey != nil {
|
|
ob.SetBytes(baseL1ValidatorPublicKeyAt, []byte((*x.PublicKey)))
|
|
}
|
|
if x.RemainingBalanceOwner != nil {
|
|
innerRemainingBalanceOwner, err := x.RemainingBalanceOwner.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ob.SetBytes(baseL1ValidatorRemainingBalanceOwnerAt, innerRemainingBalanceOwner)
|
|
}
|
|
if x.DeactivationOwner != nil {
|
|
innerDeactivationOwner, err := x.DeactivationOwner.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ob.SetBytes(baseL1ValidatorDeactivationOwnerAt, innerDeactivationOwner)
|
|
}
|
|
if x.MinNonce != nil {
|
|
ob.SetUint64(baseL1ValidatorMinNonceAt, uint64((*x.MinNonce)))
|
|
}
|
|
if x.Balance != nil {
|
|
ob.SetUint64(baseL1ValidatorBalanceAt, uint64((*x.Balance)))
|
|
}
|
|
ob.FinishAsRoot()
|
|
return b.Finish(), nil
|
|
}
|
|
|
|
// UnmarshalZAP reads BaseL1Validator out of the buffer that arrived.
|
|
func (x *BaseL1Validator) UnmarshalZAP(data []byte) error {
|
|
if x == nil || len(data) == 0 {
|
|
return nil
|
|
}
|
|
m, err := zap.Parse(data)
|
|
if err != nil {
|
|
return fmt.Errorf("BaseL1Validator: %w", err)
|
|
}
|
|
o := m.Root()
|
|
if raw := o.BytesFixed(baseL1ValidatorValidationIDAt, 32); len(raw) > 0 {
|
|
var v ids.ID
|
|
copy(v[:], raw)
|
|
if v != (ids.ID{}) {
|
|
x.ValidationID = &v
|
|
}
|
|
}
|
|
if raw := o.Bytes(baseL1ValidatorPublicKeyAt); len(raw) > 0 {
|
|
v := types.JSONByteSlice(append([]byte(nil), raw...))
|
|
x.PublicKey = &v
|
|
}
|
|
if raw := o.Bytes(baseL1ValidatorRemainingBalanceOwnerAt); len(raw) > 0 {
|
|
var v Owner
|
|
if err := v.UnmarshalZAP(raw); err != nil {
|
|
return err
|
|
}
|
|
x.RemainingBalanceOwner = &v
|
|
}
|
|
if raw := o.Bytes(baseL1ValidatorDeactivationOwnerAt); len(raw) > 0 {
|
|
var v Owner
|
|
if err := v.UnmarshalZAP(raw); err != nil {
|
|
return err
|
|
}
|
|
x.DeactivationOwner = &v
|
|
}
|
|
if v := json.Uint64(o.Uint64(baseL1ValidatorMinNonceAt)); v != json.Uint64(0) {
|
|
x.MinNonce = &v
|
|
}
|
|
if v := json.Uint64(o.Uint64(baseL1ValidatorBalanceAt)); v != json.Uint64(0) {
|
|
x.Balance = &v
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ---- BuildGenesisArgs --------------------------------------------------
|
|
|
|
const (
|
|
buildGenesisArgsUTXOAssetIDAt = 0
|
|
buildGenesisArgsNetworkIDAt = 32
|
|
buildGenesisArgsUTXOsAt = 40
|
|
buildGenesisArgsValidatorsAt = 48
|
|
buildGenesisArgsChainsAt = 56
|
|
buildGenesisArgsTimeAt = 64
|
|
buildGenesisArgsInitialSupplyAt = 72
|
|
buildGenesisArgsMessageAt = 80
|
|
buildGenesisArgsEncodingAt = 88
|
|
buildGenesisArgsSize = 96
|
|
)
|
|
|
|
var _ interface {
|
|
MarshalZAP() ([]byte, error)
|
|
UnmarshalZAP([]byte) error
|
|
} = (*BuildGenesisArgs)(nil)
|
|
|
|
// MarshalZAP writes BuildGenesisArgs from constant offsets.
|
|
func (x *BuildGenesisArgs) MarshalZAP() ([]byte, error) {
|
|
if x == nil {
|
|
return nil, nil
|
|
}
|
|
b := zap.NewBuilder(buildGenesisArgsSize + 256)
|
|
uTXOsAt, uTXOsN := 0, len(x.UTXOs)
|
|
if uTXOsN > 0 {
|
|
var blob []byte
|
|
for i := range x.UTXOs {
|
|
enc, err := x.UTXOs[i].MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var n [4]byte
|
|
binary.LittleEndian.PutUint32(n[:], uint32(len(enc)))
|
|
blob = append(blob, n[:]...)
|
|
blob = append(blob, enc...)
|
|
}
|
|
uTXOsAt = b.WriteBytes(blob)
|
|
}
|
|
validatorsAt, validatorsN := 0, len(x.Validators)
|
|
if validatorsN > 0 {
|
|
var blob []byte
|
|
for i := range x.Validators {
|
|
enc, err := x.Validators[i].MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var n [4]byte
|
|
binary.LittleEndian.PutUint32(n[:], uint32(len(enc)))
|
|
blob = append(blob, n[:]...)
|
|
blob = append(blob, enc...)
|
|
}
|
|
validatorsAt = b.WriteBytes(blob)
|
|
}
|
|
chainsAt, chainsN := 0, len(x.Chains)
|
|
if chainsN > 0 {
|
|
var blob []byte
|
|
for i := range x.Chains {
|
|
enc, err := x.Chains[i].MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var n [4]byte
|
|
binary.LittleEndian.PutUint32(n[:], uint32(len(enc)))
|
|
blob = append(blob, n[:]...)
|
|
blob = append(blob, enc...)
|
|
}
|
|
chainsAt = b.WriteBytes(blob)
|
|
}
|
|
ob := b.StartObject(buildGenesisArgsSize)
|
|
ob.SetBytesFixed(buildGenesisArgsUTXOAssetIDAt, x.UTXOAssetID[:])
|
|
ob.SetUint32(buildGenesisArgsNetworkIDAt, uint32(x.NetworkID))
|
|
ob.SetUint64(buildGenesisArgsTimeAt, uint64(x.Time))
|
|
ob.SetUint64(buildGenesisArgsInitialSupplyAt, uint64(x.InitialSupply))
|
|
ob.SetText(buildGenesisArgsMessageAt, string(x.Message))
|
|
ob.SetUint8(buildGenesisArgsEncodingAt, uint8(x.Encoding))
|
|
if uTXOsN > 0 {
|
|
ob.SetList(buildGenesisArgsUTXOsAt, uTXOsAt, uTXOsN)
|
|
}
|
|
if validatorsN > 0 {
|
|
ob.SetList(buildGenesisArgsValidatorsAt, validatorsAt, validatorsN)
|
|
}
|
|
if chainsN > 0 {
|
|
ob.SetList(buildGenesisArgsChainsAt, chainsAt, chainsN)
|
|
}
|
|
ob.FinishAsRoot()
|
|
return b.Finish(), nil
|
|
}
|
|
|
|
// UnmarshalZAP reads BuildGenesisArgs out of the buffer that arrived.
|
|
func (x *BuildGenesisArgs) UnmarshalZAP(data []byte) error {
|
|
if x == nil || len(data) == 0 {
|
|
return nil
|
|
}
|
|
m, err := zap.Parse(data)
|
|
if err != nil {
|
|
return fmt.Errorf("BuildGenesisArgs: %w", err)
|
|
}
|
|
o := m.Root()
|
|
copy(x.UTXOAssetID[:], o.BytesFixed(buildGenesisArgsUTXOAssetIDAt, 32))
|
|
x.NetworkID = json.Uint32(o.Uint32(buildGenesisArgsNetworkIDAt))
|
|
if l := o.List(buildGenesisArgsUTXOsAt); l.Len() > 0 {
|
|
rows := make([]UTXO, l.Len())
|
|
for i := range rows {
|
|
if err := rows[i].UnmarshalZAP(l.BytesAt(i)); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
x.UTXOs = rows
|
|
}
|
|
if l := o.List(buildGenesisArgsValidatorsAt); l.Len() > 0 {
|
|
rows := make([]GenesisPermissionlessValidator, l.Len())
|
|
for i := range rows {
|
|
if err := rows[i].UnmarshalZAP(l.BytesAt(i)); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
x.Validators = rows
|
|
}
|
|
if l := o.List(buildGenesisArgsChainsAt); l.Len() > 0 {
|
|
rows := make([]Chain, l.Len())
|
|
for i := range rows {
|
|
if err := rows[i].UnmarshalZAP(l.BytesAt(i)); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
x.Chains = rows
|
|
}
|
|
x.Time = json.Uint64(o.Uint64(buildGenesisArgsTimeAt))
|
|
x.InitialSupply = json.Uint64(o.Uint64(buildGenesisArgsInitialSupplyAt))
|
|
x.Message = string(strings.Clone(o.Text(buildGenesisArgsMessageAt)))
|
|
x.Encoding = formatting.Encoding(o.Uint8(buildGenesisArgsEncodingAt))
|
|
return nil
|
|
}
|
|
|
|
// ---- BuildGenesisReply -------------------------------------------------
|
|
|
|
const (
|
|
buildGenesisReplyBytesAt = 0
|
|
buildGenesisReplyEncodingAt = 8
|
|
buildGenesisReplySize = 16
|
|
)
|
|
|
|
var _ interface {
|
|
MarshalZAP() ([]byte, error)
|
|
UnmarshalZAP([]byte) error
|
|
} = (*BuildGenesisReply)(nil)
|
|
|
|
// MarshalZAP writes BuildGenesisReply from constant offsets.
|
|
func (x *BuildGenesisReply) MarshalZAP() ([]byte, error) {
|
|
if x == nil {
|
|
return nil, nil
|
|
}
|
|
b := zap.NewBuilder(buildGenesisReplySize + 256)
|
|
ob := b.StartObject(buildGenesisReplySize)
|
|
ob.SetText(buildGenesisReplyBytesAt, string(x.Bytes))
|
|
ob.SetUint8(buildGenesisReplyEncodingAt, uint8(x.Encoding))
|
|
ob.FinishAsRoot()
|
|
return b.Finish(), nil
|
|
}
|
|
|
|
// UnmarshalZAP reads BuildGenesisReply out of the buffer that arrived.
|
|
func (x *BuildGenesisReply) UnmarshalZAP(data []byte) error {
|
|
if x == nil || len(data) == 0 {
|
|
return nil
|
|
}
|
|
m, err := zap.Parse(data)
|
|
if err != nil {
|
|
return fmt.Errorf("BuildGenesisReply: %w", err)
|
|
}
|
|
o := m.Root()
|
|
x.Bytes = string(strings.Clone(o.Text(buildGenesisReplyBytesAt)))
|
|
x.Encoding = formatting.Encoding(o.Uint8(buildGenesisReplyEncodingAt))
|
|
return nil
|
|
}
|
|
|
|
// ---- Chain -------------------------------------------------------------
|
|
|
|
const (
|
|
chainGenesisDataAt = 0
|
|
chainVMIDAt = 8
|
|
chainFxIDsAt = 40
|
|
chainNameAt = 48
|
|
chainChainIDAt = 56
|
|
chainSize = 88
|
|
)
|
|
|
|
var _ interface {
|
|
MarshalZAP() ([]byte, error)
|
|
UnmarshalZAP([]byte) error
|
|
} = (*Chain)(nil)
|
|
|
|
// MarshalZAP writes Chain from constant offsets.
|
|
func (x *Chain) MarshalZAP() ([]byte, error) {
|
|
if x == nil {
|
|
return nil, nil
|
|
}
|
|
b := zap.NewBuilder(chainSize + 256)
|
|
fxIDsAt, fxIDsN := 0, len(x.FxIDs)
|
|
if fxIDsN > 0 {
|
|
var blob []byte
|
|
for i := range x.FxIDs {
|
|
enc := x.FxIDs[i][:]
|
|
var n [4]byte
|
|
binary.LittleEndian.PutUint32(n[:], uint32(len(enc)))
|
|
blob = append(blob, n[:]...)
|
|
blob = append(blob, enc...)
|
|
}
|
|
fxIDsAt = b.WriteBytes(blob)
|
|
}
|
|
ob := b.StartObject(chainSize)
|
|
ob.SetText(chainGenesisDataAt, string(x.GenesisData))
|
|
ob.SetBytesFixed(chainVMIDAt, x.VMID[:])
|
|
ob.SetText(chainNameAt, string(x.Name))
|
|
ob.SetBytesFixed(chainChainIDAt, x.ChainID[:])
|
|
if fxIDsN > 0 {
|
|
ob.SetList(chainFxIDsAt, fxIDsAt, fxIDsN)
|
|
}
|
|
ob.FinishAsRoot()
|
|
return b.Finish(), nil
|
|
}
|
|
|
|
// UnmarshalZAP reads Chain out of the buffer that arrived.
|
|
func (x *Chain) UnmarshalZAP(data []byte) error {
|
|
if x == nil || len(data) == 0 {
|
|
return nil
|
|
}
|
|
m, err := zap.Parse(data)
|
|
if err != nil {
|
|
return fmt.Errorf("Chain: %w", err)
|
|
}
|
|
o := m.Root()
|
|
x.GenesisData = string(strings.Clone(o.Text(chainGenesisDataAt)))
|
|
copy(x.VMID[:], o.BytesFixed(chainVMIDAt, 32))
|
|
if l := o.List(chainFxIDsAt); l.Len() > 0 {
|
|
rows := make([]ids.ID, l.Len())
|
|
for i := range rows {
|
|
copy(rows[i][:], l.BytesAt(i))
|
|
}
|
|
x.FxIDs = rows
|
|
}
|
|
x.Name = string(strings.Clone(o.Text(chainNameAt)))
|
|
copy(x.ChainID[:], o.BytesFixed(chainChainIDAt, 32))
|
|
return nil
|
|
}
|
|
|
|
// ---- GenesisPermissionlessValidator ------------------------------------
|
|
|
|
const (
|
|
genesisPermissionlessValidatorGenesisValidatorAt = 0
|
|
genesisPermissionlessValidatorRewardOwnerAt = 8
|
|
genesisPermissionlessValidatorDelegationFeeAt = 16
|
|
genesisPermissionlessValidatorExactDelegationFeeAt = 20
|
|
genesisPermissionlessValidatorStakedAt = 24
|
|
genesisPermissionlessValidatorSignerAt = 32
|
|
genesisPermissionlessValidatorSize = 40
|
|
)
|
|
|
|
var _ interface {
|
|
MarshalZAP() ([]byte, error)
|
|
UnmarshalZAP([]byte) error
|
|
} = (*GenesisPermissionlessValidator)(nil)
|
|
|
|
// MarshalZAP writes GenesisPermissionlessValidator from constant offsets.
|
|
func (x *GenesisPermissionlessValidator) MarshalZAP() ([]byte, error) {
|
|
if x == nil {
|
|
return nil, nil
|
|
}
|
|
b := zap.NewBuilder(genesisPermissionlessValidatorSize + 256)
|
|
stakedAt, stakedN := 0, len(x.Staked)
|
|
if stakedN > 0 {
|
|
var blob []byte
|
|
for i := range x.Staked {
|
|
enc, err := x.Staked[i].MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var n [4]byte
|
|
binary.LittleEndian.PutUint32(n[:], uint32(len(enc)))
|
|
blob = append(blob, n[:]...)
|
|
blob = append(blob, enc...)
|
|
}
|
|
stakedAt = b.WriteBytes(blob)
|
|
}
|
|
ob := b.StartObject(genesisPermissionlessValidatorSize)
|
|
innerGenesisValidator, err := x.GenesisValidator.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ob.SetBytes(genesisPermissionlessValidatorGenesisValidatorAt, innerGenesisValidator)
|
|
if x.RewardOwner != nil {
|
|
innerRewardOwner, err := x.RewardOwner.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ob.SetBytes(genesisPermissionlessValidatorRewardOwnerAt, innerRewardOwner)
|
|
}
|
|
ob.SetFloat32(genesisPermissionlessValidatorDelegationFeeAt, float32(x.DelegationFee))
|
|
if x.ExactDelegationFee != nil {
|
|
ob.SetUint32(genesisPermissionlessValidatorExactDelegationFeeAt, uint32((*x.ExactDelegationFee)))
|
|
}
|
|
if x.Signer != nil {
|
|
innerSigner, err := x.Signer.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ob.SetBytes(genesisPermissionlessValidatorSignerAt, innerSigner)
|
|
}
|
|
if stakedN > 0 {
|
|
ob.SetList(genesisPermissionlessValidatorStakedAt, stakedAt, stakedN)
|
|
}
|
|
ob.FinishAsRoot()
|
|
return b.Finish(), nil
|
|
}
|
|
|
|
// UnmarshalZAP reads GenesisPermissionlessValidator out of the buffer that arrived.
|
|
func (x *GenesisPermissionlessValidator) UnmarshalZAP(data []byte) error {
|
|
if x == nil || len(data) == 0 {
|
|
return nil
|
|
}
|
|
m, err := zap.Parse(data)
|
|
if err != nil {
|
|
return fmt.Errorf("GenesisPermissionlessValidator: %w", err)
|
|
}
|
|
o := m.Root()
|
|
if raw := o.Bytes(genesisPermissionlessValidatorGenesisValidatorAt); len(raw) > 0 {
|
|
if err := x.GenesisValidator.UnmarshalZAP(raw); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
if raw := o.Bytes(genesisPermissionlessValidatorRewardOwnerAt); len(raw) > 0 {
|
|
var v Owner
|
|
if err := v.UnmarshalZAP(raw); err != nil {
|
|
return err
|
|
}
|
|
x.RewardOwner = &v
|
|
}
|
|
x.DelegationFee = json.Float32(o.Float32(genesisPermissionlessValidatorDelegationFeeAt))
|
|
if v := json.Uint32(o.Uint32(genesisPermissionlessValidatorExactDelegationFeeAt)); v != json.Uint32(0) {
|
|
x.ExactDelegationFee = &v
|
|
}
|
|
if l := o.List(genesisPermissionlessValidatorStakedAt); l.Len() > 0 {
|
|
rows := make([]UTXO, l.Len())
|
|
for i := range rows {
|
|
if err := rows[i].UnmarshalZAP(l.BytesAt(i)); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
x.Staked = rows
|
|
}
|
|
if raw := o.Bytes(genesisPermissionlessValidatorSignerAt); len(raw) > 0 {
|
|
var v signer.ProofOfPossession
|
|
if err := v.UnmarshalZAP(raw); err != nil {
|
|
return err
|
|
}
|
|
x.Signer = &v
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ---- GenesisValidator --------------------------------------------------
|
|
|
|
const (
|
|
genesisValidatorTxIDAt = 0
|
|
genesisValidatorStartTimeAt = 32
|
|
genesisValidatorEndTimeAt = 40
|
|
genesisValidatorWeightAt = 48
|
|
genesisValidatorNodeIDAt = 56
|
|
genesisValidatorStakeAmountAt = 80
|
|
genesisValidatorSize = 88
|
|
)
|
|
|
|
var _ interface {
|
|
MarshalZAP() ([]byte, error)
|
|
UnmarshalZAP([]byte) error
|
|
} = (*GenesisValidator)(nil)
|
|
|
|
// MarshalZAP writes GenesisValidator from constant offsets.
|
|
func (x *GenesisValidator) MarshalZAP() ([]byte, error) {
|
|
if x == nil {
|
|
return nil, nil
|
|
}
|
|
b := zap.NewBuilder(genesisValidatorSize + 256)
|
|
ob := b.StartObject(genesisValidatorSize)
|
|
ob.SetBytesFixed(genesisValidatorTxIDAt, x.TxID[:])
|
|
ob.SetUint64(genesisValidatorStartTimeAt, uint64(x.StartTime))
|
|
ob.SetUint64(genesisValidatorEndTimeAt, uint64(x.EndTime))
|
|
ob.SetUint64(genesisValidatorWeightAt, uint64(x.Weight))
|
|
ob.SetBytesFixed(genesisValidatorNodeIDAt, x.NodeID[:])
|
|
if x.StakeAmount != nil {
|
|
ob.SetUint64(genesisValidatorStakeAmountAt, uint64((*x.StakeAmount)))
|
|
}
|
|
ob.FinishAsRoot()
|
|
return b.Finish(), nil
|
|
}
|
|
|
|
// UnmarshalZAP reads GenesisValidator out of the buffer that arrived.
|
|
func (x *GenesisValidator) UnmarshalZAP(data []byte) error {
|
|
if x == nil || len(data) == 0 {
|
|
return nil
|
|
}
|
|
m, err := zap.Parse(data)
|
|
if err != nil {
|
|
return fmt.Errorf("GenesisValidator: %w", err)
|
|
}
|
|
o := m.Root()
|
|
copy(x.TxID[:], o.BytesFixed(genesisValidatorTxIDAt, 32))
|
|
x.StartTime = json.Uint64(o.Uint64(genesisValidatorStartTimeAt))
|
|
x.EndTime = json.Uint64(o.Uint64(genesisValidatorEndTimeAt))
|
|
x.Weight = json.Uint64(o.Uint64(genesisValidatorWeightAt))
|
|
copy(x.NodeID[:], o.BytesFixed(genesisValidatorNodeIDAt, 20))
|
|
if v := json.Uint64(o.Uint64(genesisValidatorStakeAmountAt)); v != json.Uint64(0) {
|
|
x.StakeAmount = &v
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ---- Owner -------------------------------------------------------------
|
|
|
|
const (
|
|
ownerLocktimeAt = 0
|
|
ownerThresholdAt = 8
|
|
ownerAddressesAt = 16
|
|
ownerSize = 24
|
|
)
|
|
|
|
var _ interface {
|
|
MarshalZAP() ([]byte, error)
|
|
UnmarshalZAP([]byte) error
|
|
} = (*Owner)(nil)
|
|
|
|
// MarshalZAP writes Owner from constant offsets.
|
|
func (x *Owner) MarshalZAP() ([]byte, error) {
|
|
if x == nil {
|
|
return nil, nil
|
|
}
|
|
b := zap.NewBuilder(ownerSize + 256)
|
|
addressesAt, addressesN := 0, len(x.Addresses)
|
|
if addressesN > 0 {
|
|
var blob []byte
|
|
for i := range x.Addresses {
|
|
enc := []byte(x.Addresses[i])
|
|
var n [4]byte
|
|
binary.LittleEndian.PutUint32(n[:], uint32(len(enc)))
|
|
blob = append(blob, n[:]...)
|
|
blob = append(blob, enc...)
|
|
}
|
|
addressesAt = b.WriteBytes(blob)
|
|
}
|
|
ob := b.StartObject(ownerSize)
|
|
ob.SetUint64(ownerLocktimeAt, uint64(x.Locktime))
|
|
ob.SetUint32(ownerThresholdAt, uint32(x.Threshold))
|
|
if addressesN > 0 {
|
|
ob.SetList(ownerAddressesAt, addressesAt, addressesN)
|
|
}
|
|
ob.FinishAsRoot()
|
|
return b.Finish(), nil
|
|
}
|
|
|
|
// UnmarshalZAP reads Owner out of the buffer that arrived.
|
|
func (x *Owner) UnmarshalZAP(data []byte) error {
|
|
if x == nil || len(data) == 0 {
|
|
return nil
|
|
}
|
|
m, err := zap.Parse(data)
|
|
if err != nil {
|
|
return fmt.Errorf("Owner: %w", err)
|
|
}
|
|
o := m.Root()
|
|
x.Locktime = json.Uint64(o.Uint64(ownerLocktimeAt))
|
|
x.Threshold = json.Uint32(o.Uint32(ownerThresholdAt))
|
|
if l := o.List(ownerAddressesAt); l.Len() > 0 {
|
|
rows := make([]string, l.Len())
|
|
for i := range rows {
|
|
rows[i] = string(l.BytesAt(i))
|
|
}
|
|
x.Addresses = rows
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ---- PermissionlessValidator -------------------------------------------
|
|
|
|
const (
|
|
permissionlessValidatorStakerAt = 0
|
|
permissionlessValidatorBaseL1ValidatorAt = 8
|
|
permissionlessValidatorRewardOwnerAt = 16
|
|
permissionlessValidatorValidationRewardOwnerAt = 24
|
|
permissionlessValidatorDelegationRewardOwnerAt = 32
|
|
permissionlessValidatorPotentialRewardAt = 40
|
|
permissionlessValidatorAccruedDelegateeRewardAt = 48
|
|
permissionlessValidatorDelegationFeeAt = 56
|
|
permissionlessValidatorExactDelegationFeeAt = 60
|
|
permissionlessValidatorUptimeAt = 64
|
|
permissionlessValidatorConnectedAt = 68
|
|
permissionlessValidatorStakedAt = 72
|
|
permissionlessValidatorSignerAt = 80
|
|
permissionlessValidatorDelegatorCountAt = 88
|
|
permissionlessValidatorDelegatorWeightAt = 96
|
|
permissionlessValidatorDelegatorsAt = 104
|
|
permissionlessValidatorSize = 112
|
|
)
|
|
|
|
var _ interface {
|
|
MarshalZAP() ([]byte, error)
|
|
UnmarshalZAP([]byte) error
|
|
} = (*PermissionlessValidator)(nil)
|
|
|
|
// MarshalZAP writes PermissionlessValidator from constant offsets.
|
|
func (x *PermissionlessValidator) MarshalZAP() ([]byte, error) {
|
|
if x == nil {
|
|
return nil, nil
|
|
}
|
|
b := zap.NewBuilder(permissionlessValidatorSize + 256)
|
|
stakedAt, stakedN := 0, len(x.Staked)
|
|
if stakedN > 0 {
|
|
var blob []byte
|
|
for i := range x.Staked {
|
|
enc, err := x.Staked[i].MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var n [4]byte
|
|
binary.LittleEndian.PutUint32(n[:], uint32(len(enc)))
|
|
blob = append(blob, n[:]...)
|
|
blob = append(blob, enc...)
|
|
}
|
|
stakedAt = b.WriteBytes(blob)
|
|
}
|
|
delegatorsAt, delegatorsN := 0, 0
|
|
if x.Delegators != nil {
|
|
delegatorsN = len((*x.Delegators))
|
|
}
|
|
if delegatorsN > 0 {
|
|
var blob []byte
|
|
for i := range *x.Delegators {
|
|
enc, err := (*x.Delegators)[i].MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var n [4]byte
|
|
binary.LittleEndian.PutUint32(n[:], uint32(len(enc)))
|
|
blob = append(blob, n[:]...)
|
|
blob = append(blob, enc...)
|
|
}
|
|
delegatorsAt = b.WriteBytes(blob)
|
|
}
|
|
ob := b.StartObject(permissionlessValidatorSize)
|
|
innerStaker, err := x.Staker.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ob.SetBytes(permissionlessValidatorStakerAt, innerStaker)
|
|
innerBaseL1Validator, err := x.BaseL1Validator.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ob.SetBytes(permissionlessValidatorBaseL1ValidatorAt, innerBaseL1Validator)
|
|
if x.RewardOwner != nil {
|
|
innerRewardOwner, err := x.RewardOwner.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ob.SetBytes(permissionlessValidatorRewardOwnerAt, innerRewardOwner)
|
|
}
|
|
if x.ValidationRewardOwner != nil {
|
|
innerValidationRewardOwner, err := x.ValidationRewardOwner.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ob.SetBytes(permissionlessValidatorValidationRewardOwnerAt, innerValidationRewardOwner)
|
|
}
|
|
if x.DelegationRewardOwner != nil {
|
|
innerDelegationRewardOwner, err := x.DelegationRewardOwner.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ob.SetBytes(permissionlessValidatorDelegationRewardOwnerAt, innerDelegationRewardOwner)
|
|
}
|
|
if x.PotentialReward != nil {
|
|
ob.SetUint64(permissionlessValidatorPotentialRewardAt, uint64((*x.PotentialReward)))
|
|
}
|
|
if x.AccruedDelegateeReward != nil {
|
|
ob.SetUint64(permissionlessValidatorAccruedDelegateeRewardAt, uint64((*x.AccruedDelegateeReward)))
|
|
}
|
|
ob.SetFloat32(permissionlessValidatorDelegationFeeAt, float32(x.DelegationFee))
|
|
if x.ExactDelegationFee != nil {
|
|
ob.SetUint32(permissionlessValidatorExactDelegationFeeAt, uint32((*x.ExactDelegationFee)))
|
|
}
|
|
if x.Uptime != nil {
|
|
ob.SetFloat32(permissionlessValidatorUptimeAt, float32((*x.Uptime)))
|
|
}
|
|
if x.Connected != nil {
|
|
ob.SetBool(permissionlessValidatorConnectedAt, bool((*x.Connected)))
|
|
}
|
|
if x.Signer != nil {
|
|
innerSigner, err := x.Signer.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ob.SetBytes(permissionlessValidatorSignerAt, innerSigner)
|
|
}
|
|
if x.DelegatorCount != nil {
|
|
ob.SetUint64(permissionlessValidatorDelegatorCountAt, uint64((*x.DelegatorCount)))
|
|
}
|
|
if x.DelegatorWeight != nil {
|
|
ob.SetUint64(permissionlessValidatorDelegatorWeightAt, uint64((*x.DelegatorWeight)))
|
|
}
|
|
if stakedN > 0 {
|
|
ob.SetList(permissionlessValidatorStakedAt, stakedAt, stakedN)
|
|
}
|
|
if delegatorsN > 0 {
|
|
ob.SetList(permissionlessValidatorDelegatorsAt, delegatorsAt, delegatorsN)
|
|
}
|
|
ob.FinishAsRoot()
|
|
return b.Finish(), nil
|
|
}
|
|
|
|
// UnmarshalZAP reads PermissionlessValidator out of the buffer that arrived.
|
|
func (x *PermissionlessValidator) UnmarshalZAP(data []byte) error {
|
|
if x == nil || len(data) == 0 {
|
|
return nil
|
|
}
|
|
m, err := zap.Parse(data)
|
|
if err != nil {
|
|
return fmt.Errorf("PermissionlessValidator: %w", err)
|
|
}
|
|
o := m.Root()
|
|
if raw := o.Bytes(permissionlessValidatorStakerAt); len(raw) > 0 {
|
|
if err := x.Staker.UnmarshalZAP(raw); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
if raw := o.Bytes(permissionlessValidatorBaseL1ValidatorAt); len(raw) > 0 {
|
|
if err := x.BaseL1Validator.UnmarshalZAP(raw); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
if raw := o.Bytes(permissionlessValidatorRewardOwnerAt); len(raw) > 0 {
|
|
var v Owner
|
|
if err := v.UnmarshalZAP(raw); err != nil {
|
|
return err
|
|
}
|
|
x.RewardOwner = &v
|
|
}
|
|
if raw := o.Bytes(permissionlessValidatorValidationRewardOwnerAt); len(raw) > 0 {
|
|
var v Owner
|
|
if err := v.UnmarshalZAP(raw); err != nil {
|
|
return err
|
|
}
|
|
x.ValidationRewardOwner = &v
|
|
}
|
|
if raw := o.Bytes(permissionlessValidatorDelegationRewardOwnerAt); len(raw) > 0 {
|
|
var v Owner
|
|
if err := v.UnmarshalZAP(raw); err != nil {
|
|
return err
|
|
}
|
|
x.DelegationRewardOwner = &v
|
|
}
|
|
if v := json.Uint64(o.Uint64(permissionlessValidatorPotentialRewardAt)); v != json.Uint64(0) {
|
|
x.PotentialReward = &v
|
|
}
|
|
if v := json.Uint64(o.Uint64(permissionlessValidatorAccruedDelegateeRewardAt)); v != json.Uint64(0) {
|
|
x.AccruedDelegateeReward = &v
|
|
}
|
|
x.DelegationFee = json.Float32(o.Float32(permissionlessValidatorDelegationFeeAt))
|
|
if v := json.Uint32(o.Uint32(permissionlessValidatorExactDelegationFeeAt)); v != json.Uint32(0) {
|
|
x.ExactDelegationFee = &v
|
|
}
|
|
if v := json.Float32(o.Float32(permissionlessValidatorUptimeAt)); v != json.Float32(0) {
|
|
x.Uptime = &v
|
|
}
|
|
if v := bool(o.Bool(permissionlessValidatorConnectedAt)); v {
|
|
x.Connected = &v
|
|
}
|
|
if l := o.List(permissionlessValidatorStakedAt); l.Len() > 0 {
|
|
rows := make([]UTXO, l.Len())
|
|
for i := range rows {
|
|
if err := rows[i].UnmarshalZAP(l.BytesAt(i)); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
x.Staked = rows
|
|
}
|
|
if raw := o.Bytes(permissionlessValidatorSignerAt); len(raw) > 0 {
|
|
var v signer.ProofOfPossession
|
|
if err := v.UnmarshalZAP(raw); err != nil {
|
|
return err
|
|
}
|
|
x.Signer = &v
|
|
}
|
|
if v := json.Uint64(o.Uint64(permissionlessValidatorDelegatorCountAt)); v != json.Uint64(0) {
|
|
x.DelegatorCount = &v
|
|
}
|
|
if v := json.Uint64(o.Uint64(permissionlessValidatorDelegatorWeightAt)); v != json.Uint64(0) {
|
|
x.DelegatorWeight = &v
|
|
}
|
|
if l := o.List(permissionlessValidatorDelegatorsAt); l.Len() > 0 {
|
|
rows := make([]PrimaryDelegator, l.Len())
|
|
for i := range rows {
|
|
if err := rows[i].UnmarshalZAP(l.BytesAt(i)); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
x.Delegators = &rows
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ---- PrimaryDelegator --------------------------------------------------
|
|
|
|
const (
|
|
primaryDelegatorStakerAt = 0
|
|
primaryDelegatorRewardOwnerAt = 8
|
|
primaryDelegatorPotentialRewardAt = 16
|
|
primaryDelegatorSize = 24
|
|
)
|
|
|
|
var _ interface {
|
|
MarshalZAP() ([]byte, error)
|
|
UnmarshalZAP([]byte) error
|
|
} = (*PrimaryDelegator)(nil)
|
|
|
|
// MarshalZAP writes PrimaryDelegator from constant offsets.
|
|
func (x *PrimaryDelegator) MarshalZAP() ([]byte, error) {
|
|
if x == nil {
|
|
return nil, nil
|
|
}
|
|
b := zap.NewBuilder(primaryDelegatorSize + 256)
|
|
ob := b.StartObject(primaryDelegatorSize)
|
|
innerStaker, err := x.Staker.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ob.SetBytes(primaryDelegatorStakerAt, innerStaker)
|
|
if x.RewardOwner != nil {
|
|
innerRewardOwner, err := x.RewardOwner.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ob.SetBytes(primaryDelegatorRewardOwnerAt, innerRewardOwner)
|
|
}
|
|
if x.PotentialReward != nil {
|
|
ob.SetUint64(primaryDelegatorPotentialRewardAt, uint64((*x.PotentialReward)))
|
|
}
|
|
ob.FinishAsRoot()
|
|
return b.Finish(), nil
|
|
}
|
|
|
|
// UnmarshalZAP reads PrimaryDelegator out of the buffer that arrived.
|
|
func (x *PrimaryDelegator) UnmarshalZAP(data []byte) error {
|
|
if x == nil || len(data) == 0 {
|
|
return nil
|
|
}
|
|
m, err := zap.Parse(data)
|
|
if err != nil {
|
|
return fmt.Errorf("PrimaryDelegator: %w", err)
|
|
}
|
|
o := m.Root()
|
|
if raw := o.Bytes(primaryDelegatorStakerAt); len(raw) > 0 {
|
|
if err := x.Staker.UnmarshalZAP(raw); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
if raw := o.Bytes(primaryDelegatorRewardOwnerAt); len(raw) > 0 {
|
|
var v Owner
|
|
if err := v.UnmarshalZAP(raw); err != nil {
|
|
return err
|
|
}
|
|
x.RewardOwner = &v
|
|
}
|
|
if v := json.Uint64(o.Uint64(primaryDelegatorPotentialRewardAt)); v != json.Uint64(0) {
|
|
x.PotentialReward = &v
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ---- Staker ------------------------------------------------------------
|
|
|
|
const (
|
|
stakerTxIDAt = 0
|
|
stakerStartTimeAt = 32
|
|
stakerEndTimeAt = 40
|
|
stakerWeightAt = 48
|
|
stakerNodeIDAt = 56
|
|
stakerStakeAmountAt = 80
|
|
stakerSize = 88
|
|
)
|
|
|
|
var _ interface {
|
|
MarshalZAP() ([]byte, error)
|
|
UnmarshalZAP([]byte) error
|
|
} = (*Staker)(nil)
|
|
|
|
// MarshalZAP writes Staker from constant offsets.
|
|
func (x *Staker) MarshalZAP() ([]byte, error) {
|
|
if x == nil {
|
|
return nil, nil
|
|
}
|
|
b := zap.NewBuilder(stakerSize + 256)
|
|
ob := b.StartObject(stakerSize)
|
|
ob.SetBytesFixed(stakerTxIDAt, x.TxID[:])
|
|
ob.SetUint64(stakerStartTimeAt, uint64(x.StartTime))
|
|
ob.SetUint64(stakerEndTimeAt, uint64(x.EndTime))
|
|
ob.SetUint64(stakerWeightAt, uint64(x.Weight))
|
|
ob.SetBytesFixed(stakerNodeIDAt, x.NodeID[:])
|
|
if x.StakeAmount != nil {
|
|
ob.SetUint64(stakerStakeAmountAt, uint64((*x.StakeAmount)))
|
|
}
|
|
ob.FinishAsRoot()
|
|
return b.Finish(), nil
|
|
}
|
|
|
|
// UnmarshalZAP reads Staker out of the buffer that arrived.
|
|
func (x *Staker) UnmarshalZAP(data []byte) error {
|
|
if x == nil || len(data) == 0 {
|
|
return nil
|
|
}
|
|
m, err := zap.Parse(data)
|
|
if err != nil {
|
|
return fmt.Errorf("Staker: %w", err)
|
|
}
|
|
o := m.Root()
|
|
copy(x.TxID[:], o.BytesFixed(stakerTxIDAt, 32))
|
|
x.StartTime = json.Uint64(o.Uint64(stakerStartTimeAt))
|
|
x.EndTime = json.Uint64(o.Uint64(stakerEndTimeAt))
|
|
x.Weight = json.Uint64(o.Uint64(stakerWeightAt))
|
|
copy(x.NodeID[:], o.BytesFixed(stakerNodeIDAt, 20))
|
|
if v := json.Uint64(o.Uint64(stakerStakeAmountAt)); v != json.Uint64(0) {
|
|
x.StakeAmount = &v
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ---- UTXO --------------------------------------------------------------
|
|
|
|
const (
|
|
uTXOLocktimeAt = 0
|
|
uTXOAmountAt = 8
|
|
uTXOAddressAt = 16
|
|
uTXOMessageAt = 24
|
|
uTXOSize = 32
|
|
)
|
|
|
|
var _ interface {
|
|
MarshalZAP() ([]byte, error)
|
|
UnmarshalZAP([]byte) error
|
|
} = (*UTXO)(nil)
|
|
|
|
// MarshalZAP writes UTXO from constant offsets.
|
|
func (x *UTXO) MarshalZAP() ([]byte, error) {
|
|
if x == nil {
|
|
return nil, nil
|
|
}
|
|
b := zap.NewBuilder(uTXOSize + 256)
|
|
ob := b.StartObject(uTXOSize)
|
|
ob.SetUint64(uTXOLocktimeAt, uint64(x.Locktime))
|
|
ob.SetUint64(uTXOAmountAt, uint64(x.Amount))
|
|
ob.SetText(uTXOAddressAt, string(x.Address))
|
|
ob.SetText(uTXOMessageAt, string(x.Message))
|
|
ob.FinishAsRoot()
|
|
return b.Finish(), nil
|
|
}
|
|
|
|
// UnmarshalZAP reads UTXO out of the buffer that arrived.
|
|
func (x *UTXO) UnmarshalZAP(data []byte) error {
|
|
if x == nil || len(data) == 0 {
|
|
return nil
|
|
}
|
|
m, err := zap.Parse(data)
|
|
if err != nil {
|
|
return fmt.Errorf("UTXO: %w", err)
|
|
}
|
|
o := m.Root()
|
|
x.Locktime = json.Uint64(o.Uint64(uTXOLocktimeAt))
|
|
x.Amount = json.Uint64(o.Uint64(uTXOAmountAt))
|
|
x.Address = string(strings.Clone(o.Text(uTXOAddressAt)))
|
|
x.Message = string(strings.Clone(o.Text(uTXOMessageAt)))
|
|
return nil
|
|
}
|