mirror of
https://github.com/luxfi/cli.git
synced 2026-10-30 17:01:20 +00:00
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.
53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
// Copyright (C) 2022-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package txutils
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/luxfi/formatting"
|
|
"github.com/luxfi/proto/p/txs"
|
|
)
|
|
|
|
// SaveToDisk saves a given tx to the specified path.
|
|
func SaveToDisk(tx *txs.Tx, txPath string, forceOverwrite bool) error {
|
|
// Get the encoded (in hex + checksum) signed tx
|
|
txStr, err := formatting.Encode(formatting.Hex, tx.Bytes())
|
|
if err != nil {
|
|
return fmt.Errorf("couldn't encode signed tx: %w", err)
|
|
}
|
|
// save
|
|
if _, err := os.Stat(txPath); err == nil && !forceOverwrite {
|
|
return fmt.Errorf("couldn't create file to write tx to: file exists")
|
|
}
|
|
f, err := os.Create(txPath) //nolint:gosec // G304: Writing to user-specified path
|
|
if err != nil {
|
|
return fmt.Errorf("couldn't create file to write tx to: %w", err)
|
|
}
|
|
defer func() { _ = f.Close() }()
|
|
_, err = f.WriteString(txStr)
|
|
if err != nil {
|
|
return fmt.Errorf("couldn't write tx into file: %w", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// LoadFromDisk loads a tx from the specified path.
|
|
func LoadFromDisk(txPath string) (*txs.Tx, error) {
|
|
txEncodedBytes, err := os.ReadFile(txPath) //nolint:gosec // G304: Reading from user-specified path
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
txBytes, err := formatting.Decode(formatting.Hex, string(txEncodedBytes))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("couldn't decode signed tx: %w", err)
|
|
}
|
|
tx, err := txs.Parse(txBytes)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error parsing signed tx: %w", err)
|
|
}
|
|
return tx, nil
|
|
}
|