Files
zeekay f480e48e39 run on the native fleet
Adds .hanzo/workflows/cicd.yml calling the canonical pipeline and drops the
GitHub-hosted workflows it replaces. Lands here because this is where the repo
is written — git.hanzo.ai is upstream and github.com is its push mirror, so the
same change made on github.com never reaches the runner fleet.
2026-08-20 20:20:25 -07:00

149 lines
3.1 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/proto/x/state"
"github.com/luxfi/proto/x/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
}