github.com/ava-labs/avalanchego@v1.11.11/vms/platformvm/txs/txstest/context.go (about)

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package txstest
     5  
     6  import (
     7  	"github.com/ava-labs/avalanchego/snow"
     8  	"github.com/ava-labs/avalanchego/vms/components/gas"
     9  	"github.com/ava-labs/avalanchego/vms/platformvm/config"
    10  	"github.com/ava-labs/avalanchego/vms/platformvm/state"
    11  	"github.com/ava-labs/avalanchego/wallet/chain/p/builder"
    12  )
    13  
    14  func newContext(
    15  	ctx *snow.Context,
    16  	config *config.Config,
    17  	state state.State,
    18  ) *builder.Context {
    19  	var (
    20  		timestamp      = state.GetTimestamp()
    21  		builderContext = &builder.Context{
    22  			NetworkID:   ctx.NetworkID,
    23  			AVAXAssetID: ctx.AVAXAssetID,
    24  		}
    25  	)
    26  	switch {
    27  	case config.UpgradeConfig.IsEtnaActivated(timestamp):
    28  		builderContext.ComplexityWeights = config.DynamicFeeConfig.Weights
    29  		builderContext.GasPrice = gas.CalculatePrice(
    30  			config.DynamicFeeConfig.MinPrice,
    31  			state.GetFeeState().Excess,
    32  			config.DynamicFeeConfig.ExcessConversionConstant,
    33  		)
    34  	case config.UpgradeConfig.IsApricotPhase3Activated(timestamp):
    35  		builderContext.StaticFeeConfig = config.StaticFeeConfig
    36  	default:
    37  		builderContext.StaticFeeConfig = config.StaticFeeConfig
    38  		builderContext.StaticFeeConfig.CreateSubnetTxFee = config.CreateAssetTxFee
    39  		builderContext.StaticFeeConfig.CreateBlockchainTxFee = config.CreateAssetTxFee
    40  	}
    41  	return builderContext
    42  }