func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, tx types.SelfTransaction, usedGas *uint64, cfg vm.Config) (*types.Receipt, uint64, error) {
	if !BlackListFilter(tx, statedb) {
		return nil, 0, errors.New("blacklist account")
	}

	// Create a new context to be used in the EVM environment
	from, err := tx.GetTxFrom()
	if err != nil {
		from, err = types.Sender(types.NewEIP155Signer(config.ChainId), tx)
	}
	context := NewEVMContext(from, tx.GasPrice(), header, bc, author)

	vmenv := vm.NewEVM(context, statedb, config, cfg)

	//如果是委托gas并且是按时间委托
	if tx.GetIsEntrustGas() && tx.GetIsEntrustByTime() {
		if !statedb.GetIsEntrustByTime(from, header.Time.Uint64()) {
			log.Error("按时间委托gas的交易失效")
			return nil, 0, errors.New("entrustTx invalid")
		}
	}

	// Apply the transaction to the current state (included in the env)
	var gas uint64
	var failed bool
	if tx.TxType() == types.BroadCastTxIndex {
		if extx := tx.GetMatrix_EX(); (extx != nil) && len(extx) > 0 && extx[0].TxType == 1 {
			gas = uint64(0)
			failed = true
		}
	} else {
		_, gas, failed, err = ApplyMessage(vmenv, tx, gp)
		if err != nil && err != ErrSpecialTxFailed {
			return nil, 0, err
		}
	}

	// Update the state with pending changes
	var root []byte
	if config.IsByzantium(header.Number) {
		statedb.Finalise(true)
	} else {
		root = statedb.IntermediateRoot(config.IsEIP158(header.Number)).Bytes()
	}
	*usedGas += gas

	// Create a new receipt for the transaction, storing the intermediate root and gas used by the tx
	// based on the eip phase, we're passing wether the root touch-delete accounts.
	receipt := types.NewReceipt(root, failed, *usedGas)
	receipt.TxHash = tx.Hash()
	receipt.GasUsed = gas
	// if the transaction created a contract, store the creation address in the receipt.
	if tx.To() == nil {
		receipt.ContractAddress = crypto.CreateAddress(vmenv.Context.Origin, tx.Nonce())
	}
	// Set the receipt logs and create a bloom for filtering
	receipt.Logs = statedb.GetLogs(tx.Hash())
	receipt.Bloom = types.CreateBloom(types.Receipts{receipt})

	return receipt, gas, err
}
// ApplyTransaction attempts to apply a transaction to the given state database
// and uses the input parameters for its environment. It returns the receipt
// for the transaction, gas used and an error if the transaction failed,
// indicating the block was invalid.
ApplyTransaction attempts to apply a transaction to the given state database
and uses the input parameters for its environment. It returns the receipt
for the transaction, gas used and an error if the transaction failed,
indicating the block was invalid.
// ApplyTransaction attempts to apply a transaction to the given state database // and uses the input parameters for its environment . It returns the receipt // for the transaction gas used and an error if the transaction failed // indicating the block was invalid .
func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, tx types.SelfTransaction, usedGas *uint64, cfg vm.Config) (*types.Receipt, uint64, error) {
	if !BlackListFilter(tx, statedb) {
		return nil, 0, errors.New("blacklist account")
	}
	from, err := tx.GetTxFrom()
	if err != nil {
		from, err = types.Sender(types.NewEIP155Signer(config.ChainId), tx)
	}
	context := NewEVMContext(from, tx.GasPrice(), header, bc, author)
	vmenv := vm.NewEVM(context, statedb, config, cfg)
	if tx.GetIsEntrustGas() && tx.GetIsEntrustByTime() {
		if !statedb.GetIsEntrustByTime(from, header.Time.Uint64()) {
			log.Error("按时间委托gas的交易失效")
			return nil, 0, errors.New("entrustTx invalid")
		}
	}
	var gas uint64
	var failed bool
	if tx.TxType() == types.BroadCastTxIndex {
		if extx := tx.GetMatrix_EX(); (extx != nil) && len(extx) > 0 && extx[0].TxType == 1 {
			gas = uint64(0)
			failed = true
		}
	} else {
		_, gas, failed, err = ApplyMessage(vmenv, tx, gp)
		if err != nil && err != ErrSpecialTxFailed {
			return nil, 0, err
		}
	}
	var root []byte
	if config.IsByzantium(header.Number) {
		statedb.Finalise(true)
	} else {
		root = statedb.IntermediateRoot(config.IsEIP158(header.Number)).Bytes()
	}
	*usedGas += gas
	receipt := types.NewReceipt(root, failed, *usedGas)
	receipt.TxHash = tx.Hash()
	receipt.GasUsed = gas
	if tx.To() == nil {
		receipt.ContractAddress = crypto.CreateAddress(vmenv.Context.Origin, tx.Nonce())
	}
	receipt.Logs = statedb.GetLogs(tx.Hash())
	receipt.Bloom = types.CreateBloom(types.Receipts{receipt})
	return receipt, gas, err
}
func ApplyTransaction ( config * params . ChainConfig , bc ChainContext , author * common . Address , gp * GasPool , statedb * state . StateDB , header * types . Header , tx types . SelfTransaction , usedGas * uint64 , cfg vm . Config ) ( * types . Receipt , uint64 , error ) { if ! BlackListFilter ( tx , statedb ) { return nil , 0 , errors . New ( " " ) } from , err := tx . GetTxFrom ( ) if err != nil { from , err = types . Sender ( types . NewEIP155Signer ( config . ChainId ) , tx ) } context := NewEVMContext ( from , tx . GasPrice ( ) , header , bc , author ) vmenv := vm . NewEVM ( context , statedb , config , cfg ) if tx . GetIsEntrustGas ( ) && tx . GetIsEntrustByTime ( ) { if ! statedb . GetIsEntrustByTime ( from , header . Time . Uint64 ( ) ) { log . Error ( " return nil , 0 , errors . New ( " " ) } } var gas uint64 var failed bool if tx . TxType ( ) == types . BroadCastTxIndex { if extx := tx . GetMatrix_EX ( ) ; ( extx != nil ) && len ( extx ) > 0 && extx [ 0 ] . TxType == 1 { gas = uint64 ( 0 ) failed = true } } else { _ , gas , failed , err = ApplyMessage ( vmenv , tx , gp ) if err != nil && err != ErrSpecialTxFailed { return nil , 0 , err } } var root [ ] byte if config . IsByzantium ( header . Number ) { statedb . Finalise ( true ) } else { root = statedb . IntermediateRoot ( config . IsEIP158 ( header . Number ) ) . Bytes ( ) } * usedGas += gas receipt := types . NewReceipt ( root , failed , * usedGas ) receipt . TxHash = tx . Hash ( ) receipt . GasUsed = gas if tx . To ( ) == nil { receipt . ContractAddress = crypto . CreateAddress ( vmenv . Context . Origin , tx . Nonce ( ) ) } receipt . Logs = statedb . GetLogs ( tx . Hash ( ) ) receipt . Bloom = types . CreateBloom ( types . Receipts { receipt } ) return receipt , gas , err }
ApplyTransaction attempts to apply a transaction to the given state database
and uses the input parameters for its environment.
ApplyTransaction attempts to apply a transaction to the given state database and uses the input parameters for its environment .
// Create a new context to be used in the EVM environment //如果是委托gas并且是按时间委托 // Apply the transaction to the current state (included in the env) // Update the state with pending changes // Create a new receipt for the transaction, storing the intermediate root and gas used by the tx // based on the eip phase, we're passing wether the root touch-delete accounts. // if the transaction created a contract, store the creation address in the receipt. // Set the receipt logs and create a bloom for filtering