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.
149 lines
3.2 KiB
Go
149 lines
3.2 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package executor
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/luxfi/ids"
|
|
"github.com/luxfi/math/set"
|
|
"github.com/luxfi/node/vms/xvm/state"
|
|
"github.com/luxfi/node/vms/xvm/txs"
|
|
lux "github.com/luxfi/utxo"
|
|
"github.com/luxfi/vm/chains/atomic"
|
|
)
|
|
|
|
var _ txs.Visitor = (*Executor)(nil)
|
|
|
|
type Executor struct {
|
|
State state.Chain // state will be modified
|
|
Tx *txs.Tx
|
|
Inputs set.Set[ids.ID] // imported inputs
|
|
AtomicRequests map[ids.ID]*atomic.Requests // may be nil
|
|
}
|
|
|
|
func (e *Executor) BaseTx(tx *txs.BaseTx) error {
|
|
txID := e.Tx.ID()
|
|
lux.Consume(e.State, tx.Ins)
|
|
lux.Produce(e.State, txID, tx.Outs)
|
|
return nil
|
|
}
|
|
|
|
func (e *Executor) CreateAssetTx(tx *txs.CreateAssetTx) error {
|
|
if err := e.BaseTx(&tx.BaseTx); err != nil {
|
|
return err
|
|
}
|
|
|
|
txID := e.Tx.ID()
|
|
index := len(tx.Outs)
|
|
for _, state := range tx.States {
|
|
for _, out := range state.Outs {
|
|
e.State.AddUTXO(&lux.UTXO{
|
|
UTXOID: lux.UTXOID{
|
|
TxID: txID,
|
|
OutputIndex: uint32(index),
|
|
},
|
|
Asset: lux.Asset{
|
|
ID: txID,
|
|
},
|
|
Out: out,
|
|
})
|
|
index++
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (e *Executor) OperationTx(tx *txs.OperationTx) error {
|
|
if err := e.BaseTx(&tx.BaseTx); err != nil {
|
|
return err
|
|
}
|
|
|
|
txID := e.Tx.ID()
|
|
index := len(tx.Outs)
|
|
for _, op := range tx.Ops {
|
|
for _, utxoID := range op.UTXOIDs {
|
|
e.State.DeleteUTXO(utxoID.InputID())
|
|
}
|
|
asset := op.AssetID()
|
|
for _, out := range op.Op.Outs() {
|
|
e.State.AddUTXO(&lux.UTXO{
|
|
UTXOID: lux.UTXOID{
|
|
TxID: txID,
|
|
OutputIndex: uint32(index),
|
|
},
|
|
Asset: lux.Asset{ID: asset},
|
|
Out: out,
|
|
})
|
|
index++
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (e *Executor) ImportTx(tx *txs.ImportTx) error {
|
|
if err := e.BaseTx(&tx.BaseTx); err != nil {
|
|
return err
|
|
}
|
|
|
|
utxoIDs := make([][]byte, len(tx.ImportedIns))
|
|
for i, in := range tx.ImportedIns {
|
|
utxoID := in.UTXOID.InputID()
|
|
|
|
e.Inputs.Add(utxoID)
|
|
utxoIDs[i] = utxoID[:]
|
|
}
|
|
e.AtomicRequests = map[ids.ID]*atomic.Requests{
|
|
tx.SourceChain: {
|
|
RemoveRequests: utxoIDs,
|
|
},
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (e *Executor) ExportTx(tx *txs.ExportTx) error {
|
|
if err := e.BaseTx(&tx.BaseTx); err != nil {
|
|
return err
|
|
}
|
|
|
|
txID := e.Tx.ID()
|
|
index := len(tx.Outs)
|
|
elems := make([]*atomic.Element, len(tx.ExportedOuts))
|
|
for i, out := range tx.ExportedOuts {
|
|
utxo := &lux.UTXO{
|
|
UTXOID: lux.UTXOID{
|
|
TxID: txID,
|
|
OutputIndex: uint32(index),
|
|
},
|
|
Asset: lux.Asset{ID: out.AssetID()},
|
|
Out: out.Out,
|
|
}
|
|
index++
|
|
|
|
// ZAP-native wire envelope — matches GetAtomicUTXOs' utxo.ParseUTXO
|
|
// dispatch on the import side. Same bytes flow on shared memory
|
|
// and disk (state.PutUTXO uses WireBytes too).
|
|
utxoBytes, err := utxo.WireBytes()
|
|
if err != nil {
|
|
return fmt.Errorf("failed to marshal UTXO: %w", err)
|
|
}
|
|
utxoID := utxo.InputID()
|
|
elem := &atomic.Element{
|
|
Key: utxoID[:],
|
|
Value: utxoBytes,
|
|
}
|
|
if out, ok := utxo.Out.(lux.Addressable); ok {
|
|
elem.Traits = out.Addresses()
|
|
}
|
|
|
|
elems[i] = elem
|
|
}
|
|
e.AtomicRequests = map[ids.ID]*atomic.Requests{
|
|
tx.DestinationChain: {
|
|
PutRequests: elems,
|
|
},
|
|
}
|
|
return nil
|
|
}
|