-
Notifications
You must be signed in to change notification settings - Fork 432
/
mod_deploy.go
65 lines (57 loc) · 1.48 KB
/
mod_deploy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"
)
func init() {
register("deploy-callme", func() blockModifier {
return &modDeploy{code: callmeCode}
})
register("deploy-callenv", func() blockModifier {
return &modDeploy{code: callenvCode}
})
register("deploy-callrevert", func() blockModifier {
return &modDeploy{code: callrevertCode}
})
}
type modDeploy struct {
code []byte
info *deployTxInfo
}
type deployTxInfo struct {
Contract common.Address `json:"contract"`
Block hexutil.Uint64 `json:"block"`
}
func (m *modDeploy) apply(ctx *genBlockContext) bool {
if m.info != nil {
return false // already deployed
}
var code []byte
code = append(code, deployerCode...)
code = append(code, m.code...)
gas := ctx.TxCreateIntrinsicGas(code)
gas += uint64(len(m.code)) * params.CreateDataGas
gas += 15000 // extra gas for constructor execution
if !ctx.HasGas(gas) {
return false
}
sender := ctx.TxSenderAccount()
nonce := ctx.AccountNonce(sender.addr)
ctx.AddNewTx(sender, &types.LegacyTx{
Nonce: nonce,
Gas: gas,
GasPrice: ctx.TxGasFeeCap(),
Data: code,
})
m.info = &deployTxInfo{
Contract: crypto.CreateAddress(sender.addr, nonce),
Block: hexutil.Uint64(ctx.block.Number().Uint64()),
}
return true
}
func (m *modDeploy) txInfo() any {
return m.info
}