Documentation
¶
Overview ¶
Package genesis builds X-Chain (XVM) genesis bytes from a small, caller-supplied descriptor, and owns the codec those bytes are written with. A caller (e.g. a primary-network genesis builder) describes the primary asset and gets bytes back; the asset shape and its serialization sit together here.
The package is intentionally narrow: it owns the AssetDescriptor + Holder + BuildBytes contract, and nothing else. Bech32 formatting, allocation sorting, memo composition, and the "is X-Chain opt-in for this network?" policy all stay in the caller — those are network-level concerns, not XVM concerns.
Index ¶
- func AssetIDFromBytes(genesisBytes []byte) (ids.ID, error)
- func AssetIDFromGenesisBytes(genesisBytes []byte) (ids.ID, error)
- func BuildBytes(networkID uint32, asset AssetDescriptor, holders []Holder, memo []byte) ([]byte, error)
- type AssetDescriptor
- type AssetInitialState
- type Genesis
- type GenesisAsset
- type GenesisAssetDefinition
- type GenesisHolder
- type GenesisOwners
- type Holder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssetIDFromBytes ¶ added in v1.4.11
AssetIDFromBytes returns the runtime X-Chain native asset ID derived from the canonical XVM genesis bytes (the same blob BuildBytes produces). This is the value vm.initGenesis assigns to the first genesis CreateAssetTx — the ID under which the X-Chain's fee asset is indexed in state.
Callers (genesis/builder, config.getGenesisData) use this to derive the X-Chain native asset ID from genesis content rather than constants.UTXOAssetIDFor(networkID). On sovereign L1s the two values differ: the constant is network-id-keyed and identical across every L1 sharing a primary-network ID, while the genesis-derived ID captures the asset's actual on-chain identity (different per L1).
func AssetIDFromGenesisBytes ¶ added in v1.4.7
AssetIDFromGenesisBytes returns the first genesis asset's runtime asset ID — the ID vm.initGenesis assigns to genesis.Txs[0]. This is the X-Chain native fee asset by convention (the same asset the platform-vm reports via platform.getStakingAssetID and the wallet builder context's UTXOAssetID).
Returns an error when genesisBytes is malformed or contains zero assets — both are unrecoverable on a primary-network bootstrap.
func BuildBytes ¶ added in v1.4.11
func BuildBytes( networkID uint32, asset AssetDescriptor, holders []Holder, memo []byte, ) ([]byte, error)
BuildBytes constructs the canonical XVM genesis bytes for a network whose primary asset is `asset`, with the supplied initial fixed-cap holders and an optional opaque memo. The asset is registered in the genesis under `asset.Symbol` (the same key callers use today).
The returned bytes are stable across calls with identical inputs because NewGenesis sorts both the asset set and each asset's states deterministically.
Types ¶
type AssetDescriptor ¶ added in v1.4.11
type AssetDescriptor struct {
Name string `json:"name"`
Symbol string `json:"symbol"`
Denomination byte `json:"denomination"`
}
AssetDescriptor is the JSON-shaped primary-asset descriptor that callers carry on their network config (e.g. genesiscfg.XChainGenesis). The JSON tags mirror the existing on-disk xChainGenesis shard shape:
{"symbol":"LUX","name":"Lux","denomination":9}
type AssetInitialState ¶
type AssetInitialState struct {
FixedCap []GenesisHolder
VariableCap []GenesisOwners
}
AssetInitialState describes the initial state of an asset
type Genesis ¶
type Genesis struct {
Txs []*GenesisAsset `serialize:"true"`
}
Genesis represents the genesis state of the XVM
func NewGenesis ¶
func NewGenesis( networkID uint32, genesisData map[string]GenesisAssetDefinition, ) (*Genesis, error)
NewGenesis creates a new Genesis from genesis data
func ParseGenesisBytes ¶ added in v1.4.7
ParseGenesisBytes decodes the canonical XVM genesis bytes produced by (*Genesis).Bytes() back into a *Genesis with each GenesisAsset's embedded CreateAssetTx initialised against the genesis codec. After Initialize, each tx's deterministic ID (tx.ID()) is the runtime asset ID of that genesis-minted asset — i.e. the same value vm.initGenesis computes when bootstrapping the X-Chain.
Callers (genesis/builder, config/getGenesisData) use this to derive the X-Chain native asset ID from genesis content rather than the network-id-keyed constants.UTXOAssetIDFor(networkID). On sovereign L1s those two values DIFFER — the wallet builder context's UTXOAssetID must be the genesis-derived one or every fee-paying tx fails with "insufficient funds, needs N more nLUX".
type GenesisAsset ¶
type GenesisAsset struct {
Alias string `serialize:"true"`
txs.CreateAssetTx `serialize:"true"`
}
GenesisAsset represents an asset in the genesis block
func (*GenesisAsset) Compare ¶
func (g *GenesisAsset) Compare(other *GenesisAsset) int
Compare implements ordering.Sortable for GenesisAsset
type GenesisAssetDefinition ¶
type GenesisAssetDefinition struct {
Name string
Symbol string
Denomination byte
InitialState AssetInitialState
Memo []byte
}
GenesisAssetDefinition describes a genesis asset and its initial state
type GenesisHolder ¶
GenesisHolder describes how much asset is owned by an address
type GenesisOwners ¶
GenesisOwners describes who can perform an action