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.
136 lines
2.4 KiB
Go
136 lines
2.4 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package xvm
|
|
|
|
import (
|
|
"github.com/luxfi/node/vms/xvm/fxs"
|
|
"github.com/luxfi/node/vms/xvm/txs"
|
|
)
|
|
|
|
var _ txs.Visitor = (*txInit)(nil)
|
|
|
|
// txInit initializes FxID where required
|
|
type txInit struct {
|
|
tx *txs.Tx
|
|
fxIndex *txs.FxIndex
|
|
fxs []*fxs.ParsedFx
|
|
}
|
|
|
|
func (t *txInit) getFx(val interface{}) (int, error) {
|
|
fx, ok := t.fxIndex.GetFx(val)
|
|
if !ok {
|
|
return 0, errUnknownFx
|
|
}
|
|
return fx, nil
|
|
}
|
|
|
|
// getParsedFx returns the parsedFx object for a given TransferableInput
|
|
// or TransferableOutput object
|
|
func (t *txInit) getParsedFx(val interface{}) (*fxs.ParsedFx, error) {
|
|
idx, err := t.getFx(val)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return t.fxs[idx], nil
|
|
}
|
|
|
|
func (t *txInit) init() error {
|
|
for _, cred := range t.tx.Creds {
|
|
fx, err := t.getParsedFx(cred.Credential)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
cred.FxID = fx.ID
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (t *txInit) BaseTx(tx *txs.BaseTx) error {
|
|
if err := t.init(); err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, in := range tx.Ins {
|
|
fx, err := t.getParsedFx(in.In)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
in.FxID = fx.ID
|
|
}
|
|
|
|
for _, out := range tx.Outs {
|
|
fx, err := t.getParsedFx(out.Out)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
out.FxID = fx.ID
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (t *txInit) CreateAssetTx(tx *txs.CreateAssetTx) error {
|
|
if err := t.init(); err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, state := range tx.States {
|
|
fx := t.fxs[state.FxIndex]
|
|
state.FxID = fx.ID
|
|
}
|
|
|
|
for _, in := range tx.Ins {
|
|
fx, err := t.getParsedFx(in.In)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
in.FxID = fx.ID
|
|
}
|
|
return t.BaseTx(&tx.BaseTx)
|
|
}
|
|
|
|
func (t *txInit) ImportTx(tx *txs.ImportTx) error {
|
|
if err := t.init(); err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, in := range tx.ImportedIns {
|
|
fx, err := t.getParsedFx(in.In)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
in.FxID = fx.ID
|
|
}
|
|
return t.BaseTx(&tx.BaseTx)
|
|
}
|
|
|
|
func (t *txInit) ExportTx(tx *txs.ExportTx) error {
|
|
if err := t.init(); err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, out := range tx.ExportedOuts {
|
|
fx, err := t.getParsedFx(out.Out)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
out.FxID = fx.ID
|
|
}
|
|
return t.BaseTx(&tx.BaseTx)
|
|
}
|
|
|
|
func (t *txInit) OperationTx(tx *txs.OperationTx) error {
|
|
if err := t.init(); err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, op := range tx.Ops {
|
|
fx, err := t.getParsedFx(op.Op)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
op.FxID = fx.ID
|
|
}
|
|
return t.BaseTx(&tx.BaseTx)
|
|
}
|