Skip to content

Commit

Permalink
change contract functions order
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitprincess committed Oct 18, 2023
1 parent e4c5ca8 commit 300649a
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions contract/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,6 @@ func Execute(execCtx context.Context, bs *state.BlockState, cdb ChainAccessor, t
return rv, events, usedFee, nil
}

// compute the base fee for a transaction
func TxFee(payloadSize int, GasPrice *big.Int, version int32) *big.Int {
if version < 2 {
return fee.PayloadTxFee(payloadSize)
}
// get the amount of gas needed for the payload
txGas := fee.TxGas(payloadSize)
// multiply the amount of gas with the gas price
return new(big.Int).Mul(new(big.Int).SetUint64(txGas), GasPrice)
}

// send a request to preload an executor for the next tx
func RequestPreload(bs *state.BlockState, bi *types.BlockHeaderInfo, next, current *types.Tx, preloadService int) {
loadReqCh <- &preloadRequest{preloadService, bs, bi, next, current}
Expand Down Expand Up @@ -298,6 +287,20 @@ func preloadWorker() {
}
}

//----------------------------------------------------------------------------------------//
// functions for tx Execute

// compute the base fee for a transaction
func TxFee(payloadSize int, GasPrice *big.Int, version int32) *big.Int {
if version < 2 {
return fee.PayloadTxFee(payloadSize)
}
// get the amount of gas needed for the payload
txGas := fee.TxGas(payloadSize)
// multiply the amount of gas with the gas price
return new(big.Int).Mul(new(big.Int).SetUint64(txGas), GasPrice)
}

// check if the tx is valid per tx type / fork version
func validateTxType(txType types.TxType, amount *big.Int, payloadSize int, version int32, isDeploy, isContract bool) (valid bool, err error) {
// transactions with type NORMAL should not call smart contracts
Expand Down Expand Up @@ -370,12 +373,8 @@ func GasLimit(version int32, isFeeDelegation bool, txGasLimit uint64, payloadSiz
return gasLimit, nil
}

func CreateContractID(account []byte, nonce uint64) []byte {
h := sha256.New()
h.Write(account)
h.Write([]byte(strconv.FormatUint(nonce, 10)))
recipientHash := h.Sum(nil) // byte array with length 32
return append([]byte{0x0C}, recipientHash...) // prepend 0x0C to make it same length as account addresses
func useGas(version int32) bool {
return version >= 2 && PubNet
}

func checkRedeploy(sender, receiver *state.V, contractState *state.ContractState) error {
Expand All @@ -398,8 +397,15 @@ func checkRedeploy(sender, receiver *state.V, contractState *state.ContractState
return nil
}

func useGas(version int32) bool {
return version >= 2 && PubNet
//----------------------------------------------------------------------------------------//
// functions for chain / block factory

func CreateContractID(account []byte, nonce uint64) []byte {
h := sha256.New()
h.Write(account)
h.Write([]byte(strconv.FormatUint(nonce, 10)))
recipientHash := h.Sum(nil) // byte array with length 32
return append([]byte{0x0C}, recipientHash...) // prepend 0x0C to make it same length as account addresses
}

func GasUsed(txFee, gasPrice *big.Int, txType types.TxType, version int32) uint64 {
Expand Down

0 comments on commit 300649a

Please sign in to comment.