mirror of
https://github.com/luxfi/proto.git
synced 2026-10-30 15:21:09 +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.
66 lines
1.4 KiB
Go
66 lines
1.4 KiB
Go
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package fee
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/luxfi/proto/p/txs"
|
|
"github.com/luxfi/vm/components/gas"
|
|
)
|
|
|
|
var (
|
|
_ Calculator = (*dynamicCalculator)(nil)
|
|
|
|
ErrCalculatingComplexity = errors.New("error calculating complexity")
|
|
ErrCalculatingGas = errors.New("error calculating gas")
|
|
ErrCalculatingCost = errors.New("error calculating cost")
|
|
)
|
|
|
|
// NewDynamicCalculator returns a Calculator that prices txs against the
|
|
// supplied weights and gas price.
|
|
func NewDynamicCalculator(
|
|
weights gas.Dimensions,
|
|
price gas.Price,
|
|
) Calculator {
|
|
return &dynamicCalculator{
|
|
weights: weights,
|
|
price: price,
|
|
}
|
|
}
|
|
|
|
type dynamicCalculator struct {
|
|
weights gas.Dimensions
|
|
price gas.Price
|
|
}
|
|
|
|
func (c *dynamicCalculator) CalculateFee(tx txs.UnsignedTx) (uint64, error) {
|
|
complexity, err := TxComplexity(tx)
|
|
if err != nil {
|
|
return 0, fmt.Errorf("%w: %w", ErrCalculatingComplexity, err)
|
|
}
|
|
gas, err := complexity.ToGas(c.weights)
|
|
if err != nil {
|
|
return 0, fmt.Errorf(
|
|
"%w with complexity (%v) and weights (%v): %w",
|
|
ErrCalculatingGas,
|
|
complexity,
|
|
c.weights,
|
|
err,
|
|
)
|
|
}
|
|
fee, err := gas.Cost(c.price)
|
|
if err != nil {
|
|
return 0, fmt.Errorf(
|
|
"%w with gas (%d) and price (%d): %w",
|
|
ErrCalculatingCost,
|
|
gas,
|
|
c.price,
|
|
err,
|
|
)
|
|
}
|
|
return fee, nil
|
|
}
|